Skip to content

fix: fail2ban jail config broken on modern Debian and multi-server setups - #24

Open
rlei-odes wants to merge 1 commit into
captainzero93:mainfrom
rlei-odes:pr/fix-fail2ban-jail-config
Open

fix: fail2ban jail config broken on modern Debian and multi-server setups#24
rlei-odes wants to merge 1 commit into
captainzero93:mainfrom
rlei-odes:pr/fix-fail2ban-jail-config

Conversation

@rlei-odes

Copy link
Copy Markdown

Two separate issues found while running the script on a Debian 13 server, both causing fail2ban to fail on startup.

1. /var/log/auth.log doesn't exist on Debian 12+

The sshd jail config had logpath = /var/log/auth.log. On Debian 12 and 13, systemd-journald handles auth logging and /var/log/auth.log is not created by default. fail2ban starts, can't find the log file, and exits.

Fixed by replacing logpath with backend = systemd, which reads SSH auth events directly from the systemd journal. Works on older Debian/Ubuntu too since the journal has always existed alongside auth.log — so this is strictly more portable.

2. Both nginx and apache jails get written even if only one is installed

The web server jails were written inside a single if [[ "${has_web_server}" == "true" ]] block. That flag is set to true if either nginx or apache2 is found. The result: on an nginx-only server, an apache jail pointing at /var/log/apache*/*error.log (which doesn't exist) gets written. fail2ban then refuses to start because it can't find the log path.

Fixed by splitting into two separate command -v checks — each jail is only written if its corresponding binary is actually present on the system.

Both issues were hit in practice on a Debian 13 machine with nginx and no Apache installed.

Two related bugs in module_fail2ban():

1. When a web server was detected, both nginx-http-auth and apache-auth
   jails were always added together. On nginx-only systems (e.g. Passbolt)
   the apache-auth jail has no log file to watch, causing fail2ban to crash
   on startup with "Have not found any log file for apache-auth jail".
   Fix: check for each server independently at the point of writing the
   jail, so only installed servers get a jail entry.

2. The sshd jail hardcoded logpath = /var/log/auth.log, which does not
   exist on Debian 12+/13 (Trixie) where systemd-journald handles logging
   without writing syslog files. fail2ban crashed silently on these systems.
   Fix: replace logpath with backend = systemd so the sshd jail reads
   directly from the journal, which is correct on modern Debian/Ubuntu.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant