diff options
| author | tv <tv@krebsco.de> | 2026-11-23 16:30:21 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-23 16:30:21 +0000 |
| commit | db677e545e9b69e7378154faeb4af0528ce8a35a (patch) | |
| tree | d7ee212e062273d3670d5c1a4360fcf0b36f5e36 /configs/fail2ban.nix | |
| parent | 478227378a84ddb488c1cf5a79df82a502644e5d (diff) | |
configs fail2ban: init
Diffstat (limited to 'configs/fail2ban.nix')
| -rw-r--r-- | configs/fail2ban.nix | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/configs/fail2ban.nix b/configs/fail2ban.nix new file mode 100644 index 00000000..8bffe704 --- /dev/null +++ b/configs/fail2ban.nix @@ -0,0 +1,69 @@ +{ + environment.etc."fail2ban/filter.d/sshd-normal.local".text = '' + [Definition] + failregex = ^.*: Failed password for .* from <HOST> port \d+.*$ + ^.*: pam_unix\(sshd:auth\): authentication failure;.* rhost=<HOST>\b.*$ + ignoreregex = ^.*: Failed password for root from <HOST> port \d+.*$ + ^.*: pam_unix\(sshd:auth\): authentication failure;.* rhost=<HOST>\b.* user=root\b.*$ + ''; + + # The pam_unix lines look like: + # pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=10.243.13.42 user=root + environment.etc."fail2ban/filter.d/sshd-instaban.local".text = '' + [Definition] + failregex = ^.*: (?:Failed password for invalid user|Invalid user|Failed password for root)\b.* from <HOST> port \d+.*$ + ^.*: pam_unix\(sshd:auth\): authentication failure;.* rhost=<HOST>\b.* user=root\b.*$ + ''; + + services.fail2ban = { + enable = true; + + ignoreIP = [ + "10.0.0.0/8" + "172.16.0.0/12" + "192.168.0.0/16" + "42::/16" + ]; + + bantime-increment = { + enable = true; + multipliers = "1 2 4 8 16 32 64"; + maxtime = "168h"; + overalljails = true; + }; + + jails = { + # Disable NixOS' default sshd jail. + sshd.enabled = false; + + sshd-instaban.settings = { + filter = "sshd-instaban"; + port = "ssh"; + findtime = 600; + maxretry = 1; + bantime = "24h"; + # nft verdicts are lowercase (iptables' would be DROP). + action = "%(action_)s[blocktype=drop]"; + + journalmatch = '' + SYSLOG_IDENTIFIER=sshd-session + ''; + }; + sshd-normal.settings = { + filter = "sshd-normal"; + port = "ssh"; + + journalmatch = '' + SYSLOG_IDENTIFIER=sshd-session + ''; + + findtime = 600; # 10 minutes + maxretry = 5; + bantime = "24h"; + }; + }; + }; + + # services.fail2ban sets this to "VERBOSE". + services.openssh.settings.LogLevel = "INFO"; +} |
