-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix parsing of noncompliant RFC3339 timestamps missing only a timezone #3346
base: master
Are you sure you want to change the base?
Conversation
This commit fixes the parsing of dates that are almost RFC3339 compliant, except they missing a timezone. It seems that this format (which is still ISO 8601 compliant, just not RFC3339) is quite used in the wild. Some Crowdsec parsers from the hub faced this format and ended up appending a "Z" to make the timestamp UTC and make it RFC3339 compliant again: - authentik-logs: https://github.com/crowdsecurity/hub/blob/146659cd4ac19abfa87e39b5e5c0ec8bc4313bf8/parsers/s01-parse/firix/authentik-logs.yaml#L24 - redmine-logs: https://github.com/crowdsecurity/hub/blob/146659cd4ac19abfa87e39b5e5c0ec8bc4313bf8/parsers/s01-parse/LePresidente/redmine-logs.yaml#L22 - qbittorent [not upstreamed yet]: https://github.com/crowdsecurity/hub/pull/1179/files#diff-ba102ec88ac5a804fd6acfac54bdae1778b44992ed8b550a011082a32e6f9b9cR32 - I tried to be a bit smarted by checking if the timezone is actually missing from the string before adding UTC. I wasn't confident that the timezone-unawareness of the timestamps in logs weren't due to some system configuration (like some zone packages missing) rather than a format that was intentionally defined by the developer. I wouldn't be able to provide a single StrTimeFormat that would work consistently. Overall, I feel like handling this at the date parsing level would make things less fragile, and would prevent dirty hacks from spreading on the hub. Also please note that "adding UTC" to timezone-aware timestamps is not the actual correct thing to do. In theory, we should use the "local" timezone, which is probably only local to the machine that emitted the log. That sounds very cumbersome and error proof, so I think this solution is a good tradeoff that should work in most real-world use-cases
@gilbsgilbs: There are no 'kind' label on this PR. You need a 'kind' label to generate the release automatically.
DetailsI am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository. |
@gilbsgilbs: There are no area labels on this PR. You can add as many areas as you see fit.
DetailsI am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository. |
/kind fix |
/area agent |
This commit fixes the parsing of dates that are almost RFC3339 compliant, except they missing a timezone. It seems that this format (which is still ISO 8601 compliant, just not RFC3339) is quite used in the wild. Some Crowdsec parsers from the hub faced this format and ended up appending a "Z" to make the timestamp UTC and make it RFC3339 compliant again:
Overall, I feel like handling this at the date parsing level would make things less fragile, and would prevent dirty hacks from spreading on the hub.
Also please note that "adding UTC" to timezone-aware timestamps is not the actual correct thing to do. In theory, we should use the "local" timezone, which is probably only local to the machine that emitted the log. That sounds very cumbersome and error proof, so I think this solution is a good tradeoff that should work in most real-world use-cases