Skip to content
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

logpath issue: move logic "collecting of logfiles" from client to server resp. filter ... #1379

Open
1 of 6 tasks
sebres opened this issue Apr 1, 2016 · 21 comments
Open
1 of 6 tasks
Assignees
Labels

Comments

@sebres
Copy link
Contributor

sebres commented Apr 1, 2016

Just a reminder for me (will too long provide a PR for this, waiting for 716-cs ... and #1346).

Should fix imho great problem with "collecting of logfiles" client side: current solution uses fixedly list of the log files, found by the moment of the fail2ban starting.
Variable logfiles of some services (multiple domains, etc.) will not be taken into account, unless fail2ban or jails are reloaded.

  • move logic "collecting of logfiles" from client to server resp. filter ... (* pro rata realized in my own branch);
  • support appearing of new log files (matched) - (for example search in X minutes for new log files, or via pyinotify callback, if supported);
  • better support disappearing of the log files (log-rotate, service down, etc...), and reactivating of jail from idle if log files found again;
  • add logregex as additionally extended "replacement" for logpath;
  • add logregex-ignore (and logpath-ignore) for negative filter (resp. see Add excludepath config option #1756);
  • encapsulate reading of messages from filter modules to a backend modules, refactor multiple parsing of same log file / journal (RFE refactor multiple parsing of same log file #529)
@sebres sebres self-assigned this Apr 1, 2016
@sebres
Copy link
Contributor Author

sebres commented May 9, 2016

should resolve #1407

@sebres
Copy link
Contributor Author

sebres commented Nov 26, 2016

Several issues refer to Have not found any log file, in relation to "prevent to start fail2ban service" are partially fixed in #1619

@eadthem
Copy link

eadthem commented Jun 17, 2017

What version was this merged in? Specificity the 1407 (Related to log files having dates in the name).

Thanks
Eadthem

@sebres
Copy link
Contributor Author

sebres commented Jun 19, 2017

What version was this merged in?

Nowhere. It's an issue. I should still finish it. Just persistently no time...
And it is a pre-requirement for 1407, that as you can see is still open also.

@szepeviktor
Copy link
Member

szepeviktor commented Oct 11, 2018

@sebres Should Fail2ban v0.9.7-2 accept multiline logpaths?

logpath  = %(apache_error_log)s
           /home/*/website/log/*error.log

it says

$ fail2ban-client reload apache-combined
ERROR  Error in action definition sendmail-geoip-lines[name=apache-combined, sender="webmaster@agrya.hu", dest="admin@szepe.net", logpath="/var/log/apache2/*error.log
ERROR  Errors in jail 'apache-combined'. Skipping...

@sebres
Copy link
Contributor Author

sebres commented Oct 11, 2018

Fail2ban self does it... it looks rather as an issue of ConfigReader's and/or ExtractOptions (by supplying to the action "sendmail-geoip-lines").
Currently I don't know which versions are affected (0.9 is too old, so it could be fixed in-between).

The alternative for you which could work - switch to another action (e. g. that using <matches> info instead of the log-files).

@szepeviktor
Copy link
Member

Thank you.

@sebres
Copy link
Contributor Author

sebres commented Oct 11, 2018

yw

using <matches> info instead of the log-files

Oh, forgotten that we had a grave issue with not proper "escaped" <matches> - #1726 (fixed for >= 0.10), so be carefully with that in 0.9.

@szepeviktor
Copy link
Member

szepeviktor commented Oct 11, 2018

Thank you.

So

GET /`rm -rf /`

could destroy servers of my clients?

@sebres
Copy link
Contributor Author

sebres commented Oct 11, 2018

Not this way directly, but we don't want to provide here any advices for script-kiddis :)
But I have one advice for you - just upgrade your fail2ban and relax.

@kevin-olbrich
Copy link

This issue is really annoying. I try to provision fail2ban jail.d using a CMDB, based on which packages are installed.
Example: I got a lot of VMs that have apache2 and nginx installed and using the CMDB, the host decides which one is used. In my CMDB I deploy both jails but one will fail on fresh hosts, as the log won't exist.
I can touch the log files but that is just a workaround.

Maybe it would be good idea to add an option in fail2ban, that allows silent fails for jails. Currently fail2ban crashs if something is wrong (which is fine to allow monitoring tools to notify the admin).
With on option, the admin can decide what he wants:
a) Crash as a whole to show something is not working correctly.
b) Keep running without jails that failed and just warn in log.

Currently this is a blocker for me, is there any chance to make this configurable soon?

@ChuckNorrison
Copy link

want to try install fail2ban manually on ubuntu 20 server... it fails with this

@szepeviktor
Copy link
Member

szepeviktor commented Aug 24, 2020

Hello Chuck! Willkommen zu Fail2Ban!

@ChuckNorrison
Copy link

Solved with systemd in jail.conf. Works great, thanks

@gnat
Copy link

gnat commented Mar 23, 2021

Still an issue re: #2756

Using emptylog as a workaround:

[jail]
logpath = %(known/logpath)s
          /etc/fail2ban/emptylog

nodiscc added a commit to nodiscc/xsrv that referenced this issue Aug 3, 2023
- do not repeat jail options that are already defined in `jail.conf`, in jail.d/*conf`
- gitea/jellyfin: do not disable gitea/jellyfin jails if the corresponding service is disabled
- prevent missing/not-yet-creat log files from causing failban reloads/restart to fail (e.g. when a service is initially deployed with `*_enable_service: no`) by creating a placeholder/empty log file and adding the the list of `logpath` for each service (related fail2ban/fail2ban#2756, fail2ban/fail2ban#1379)
- do not enable the `pam-generic` jail by default as no service uses it
- use values provided in `fail2ban_default_maxretry` (default 5), `fail2ban_default_findtime` (10min) and `fail2ban_default_bantime` (1 year) for all jails
- only ban offenders on HTTP/HTTPS ports for auth failures on web applications. This way it is still possible to log in via SSH to unban an IP if the controller IP gets banned by mistake
- standardize order of instalaltion/configuration tasks
nodiscc added a commit to nodiscc/xsrv that referenced this issue Aug 3, 2023
- do not repeat jail options that are already defined in `jail.conf`, in jail.d/*conf`
- gitea/jellyfin: do not disable gitea/jellyfin jails if the corresponding service is disabled
- prevent missing/not-yet-creat log files from causing failban reloads/restart to fail (e.g. when a service is initially deployed with `*_enable_service: no`) by creating a placeholder/empty log file and adding the the list of `logpath` for each service (related fail2ban/fail2ban#2756, fail2ban/fail2ban#1379)
- do not enable the `pam-generic` jail by default as no service uses it
- use values provided in `fail2ban_default_maxretry` (default 5), `fail2ban_default_findtime` (10min) and `fail2ban_default_bantime` (1 year) for all jails
- only ban offenders on HTTP/HTTPS ports for auth failures on web applications. This way it is still possible to log in via SSH to unban an IP if the controller IP gets banned by mistake
- standardize order of instalaltion/configuration tasks
nodiscc added a commit to nodiscc/xsrv that referenced this issue Aug 3, 2023
- do not repeat jail options that are already defined in `jail.conf`, in jail.d/*conf`
- gitea/jellyfin: do not disable gitea/jellyfin jails if the corresponding service is disabled
- prevent missing/not-yet-creat log files from causing failban reloads/restart to fail (e.g. when a service is initially deployed with `*_enable_service: no`) by creating a placeholder/empty log file and adding the the list of `logpath` for each service (related fail2ban/fail2ban#2756, fail2ban/fail2ban#1379)
- do not enable the `pam-generic` jail by default as no service uses it
- use values provided in `fail2ban_default_maxretry` (default 5), `fail2ban_default_findtime` (10min) and `fail2ban_default_bantime` (1 year) for all jails
- only ban offenders on HTTP/HTTPS ports for auth failures on web applications. This way it is still possible to log in via SSH to unban an IP if the controller IP gets banned by mistake
- standardize order of instalaltion/configuration tasks
@Jomshanseat
Copy link

Jomshanseat commented Mar 10, 2024

I run it on a self-made server, ubuntu server 22.04.04(LTS) and after trying to insert the 403 error message giver of here, the service complains over the lacking log file for the selinux-ssh jail.

Already tried all the options given here, with the error persisting through purges and installing again afterwards.

Kinda unsure on what to do here.

@sebres
Copy link
Contributor Author

sebres commented Mar 11, 2024

I run it on a self-made server, ubuntu server 22.04.04(LTS) and after trying to insert the 403 error message giver of here, the service complains over the lacking log file for the selinux-ssh jail.

The mentioned description doesn't speak about selinux-ssh jail at all (it is rather about new jail httpd-forbidden).

Either check the jail selinux-ssh (set proper logpath or backend = systemd if it is logging to systemd-journal) or in worse case disable this jail if you don't have it.

@Jomshanseat
Copy link

Jomshanseat commented Mar 11, 2024

The mentioned description doesn't speak about selinux-ssh jail at all (it is rather about new jail httpd-forbidden).

Ye, I know, personally find it rather weird that that file complains.

Either check the jail selinux-ssh (set proper logpath or backend = systemd if it is logging to systemd-journal) or in worse case disable this jail if you don't have it.

Checked selinux-ssh.conf and it doesn't seem to have either a logpath or backend inside.
Exact error code is [67789]: ERROR Failed during configuration: Have not found any log file for selinux-ssh jail, if that helps

@sebres
Copy link
Contributor Author

sebres commented Mar 11, 2024

Checked selinux-ssh.conf and it doesn't seem to have either a logpath or backend inside.

Well every local jail-configuration (no matter in jail.local or jail.d/*.conf) overwrites default configuration jail.conf,
which contains:

fail2ban/config/jail.conf

Lines 292 to 295 in 8be16f1

[selinux-ssh]
port = ssh
logpath = %(auditd_log)s

The default backend and logpath (or here the value of auditd_log) is a matter of maintainer of fail2ban for your distribution.
If they not correct (outdated) for some reason, one needs to overwrite them by oneself (if one enables a jail).
Normally no one jail should be enabled by default, but (who knows) again it may be in some maintainer patches for that distro.

To check what is configured, one can also use:

# dump config:
fail2ban-client -d
# or pretty dump:
fail2ban-client --dp

@Jomshanseat
Copy link

Fail2Ban_Dump.txt
Did that, it actually seems that all of the log files are missing and the selinux jail was just the first to trigger the error.
Is there a way to regenerate the log file(s) or deleting whatever is currently not allowing them to be recreated so the purge+reinstall process can do that?

@sebres
Copy link
Contributor Author

sebres commented Mar 13, 2024

Fail2ban doesn't have currently any possibility to detect which services are active or not and to enable corresponding jails fully automatically.

Don't enable all jails (do it only for jails you need for services you really have).
Don't set enabled = true for default section - it'd again enable all jails.
Silencing the errors by creating of empty log-files is wrong way - neither it is good practice, nor it'd really protect everything:
such jails will never find any failure, if service logs to different logpath for some reason (logpath is wrong) or service logs to systemd journal but jail monitors log-file yet (backend is wrong), but would consume system resources (so the extra load is unnecessary).
More about in https://github.com/fail2ban/fail2ban/wiki/Proper-fail2ban-configuration
This is the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants