{ pkgs, lib, ... }:
{
services.fail2ban = {
banaction = lib.mkDefault "nftables-multiport";
banaction-allports = lib.mkDefault "nftables-allports";
packageFirewall = lib.mkDefault pkgs.nftables;
bantime-increment = {
enable = true;
factor = "1";
formula = "ban.Time * (1 << min(ban.Count, 20)) * banFactor";
overalljails = false;
rndtime = "";
};
};
/*
systemd.services.nftables.postStart = '' systemctl reload fail2ban '';
*/
services.openssh.settings.LogLevel = "VERBOSE";
services.postgresql.logLinePrefix = "%h ";
environment.etc."fail2ban/action.d/nftables-common.local".text = ''
[Init]
blocktype = drop
'';
environment.etc."fail2ban/filter.d/postgresql.local".text = ''
[INCLUDES]
before = common.conf
[DEFAULT]
_daemon = postgresql-start
[Definition]
journalmatch = _SYSTEMD_UNIT=postgresql.service + _COMM=postgres
prefregex = ^%(__prefix_line)s.+$
failregex = ^\s+FATAL:\s*no pg_hba.conf entry for host.+$
^\s+FATAL:\s*no PostgreSQL user name specified in startup packet.+$
^\s+FATAL:\s*password authentication failed for user.+$
^\s+FATAL:\s*unsupported frontend protocol.+$
maxlines = 1
#ignoreregex = duration:
'';
}