Description
For upcoming Gitea 1.9, there has been new logging implemented as described here:
https://docs.gitea.io/en-us/logging-configuration/
One thing that happens is that it enables colorized file logs by default, which it turns out will break things like fail2ban and potentially other software that is parsing logs for a specific regex. This specific case was reported in Discord earlier.
In our own fail2ban example here:
https://docs.gitea.io/en-us/fail2ban-setup/
It says to use failregex = .*Failed authentication attempt for .* from <HOST>
Which used to work, since the log file looked like this:
2019/05/13 21:57:53 [I] Failed authentication attempt for mrsdizzie from 24.46.193.14
But with colorized logs it looks like:
ESC[36m2019/05/14 02:14:53 ESC[0mESC[32mrouters/user/auth.go:159:ESC[32mSignInPost()ESC[0m ESC[1;32m[I]ESC[0m Failed authentication attempt for ESC[1mmrsdizzieESC[0m from ESC[1m24.46.193.14ESC[0m
A few things happen. This breaks the <HOST>
match in fail2ban. In the example above, <HOST>
would now be ESC[1m24.46.193.14ESC[0m
But worse, the log entry isn't matched at all because it now doesn't match any of the default date template patterns since it starts with ESC[36m2019/05/14 02:14:53
For reference, this is the fail2ban pattern gitea logs match now:
{^LN-BEG}ExYear(?P<_sep>[-/.])Month(?P=_sep)Day(?:T| ?)24hour:Minute:Second(?:[.,]Microseconds)?(?:\s*Zone offset)?
You can test these with:
fail2ban-regex -v --print-all-matched /var/lib/gitea/log/gitea.log '.*Failed authentication attempt for .* from <HOST>'
on master
Not really sure the best way to go about this. I think if we keep COLORIZE = true
as a default it would be a bad breaking change in these situations.
Making Colorize false by default will keep things working, but still leaves people who do want to colorize with no simple fail2ban option.
It could also just never colorize those Authentication lines, which is a fix for people who are currently checking that. It would still break any other rules people may have created based on other log lines (and be inconsistent/not ideal), but would probably mitigate the most common case.
Suggestions welcome, perhaps theres an obvious solution I don't know.