]> Git — Sourcephile - sourcephile-nix.git/blob - machines/losurdo/fail2ban.nix
nix: polish flake.nix
[sourcephile-nix.git] / machines / losurdo / fail2ban.nix
1 { pkgs, lib, config, machines, ... }:
2 {
3 #services.sshd.logLevel = "VERBOSE";
4 services.postgresql.extraConfig = "log_line_prefix = '%h '";
5 /*
6 systemd.services.nftables.postStart = '' systemctl reload fail2ban '';
7 */
8 services.fail2ban = {
9 enable = true;
10 banaction = "nftables-multiport";
11 banaction-allports = "nftables-allports";
12 bantime-increment = {
13 enable = true;
14 factor = "1";
15 formula = "ban.Time * (1 << min(ban.Count, 20)) * banFactor";
16 maxtime = "1y";
17 multipliers = "";
18 overalljails = false;
19 rndtime = "";
20 };
21 packageFirewall = pkgs.nftables;
22 ignoreIP = [
23 machines.mermet.extraArgs.ipv4
24 machines.mermet.extraArgs.wireguard.wg-intranet.ipv4
25 machines.losurdo.extraArgs.ipv4
26 "198.252.154.1" # wren.riseup.net
27 ];
28 jails = {
29 DEFAULT = ''
30 '';
31 sshd = ''
32 enabled = true
33 bantime = 5m
34 findtime = 1d
35 maxretry = 1
36 mode = aggressive
37 '';
38 postgresql = ''
39 enabled = true
40 bantime = 1m
41 filter = postgresql
42 findtime = 1d
43 port = 5432
44 '';
45 };
46 };
47 environment.etc."fail2ban/action.d/nftables-common.local".text = ''
48 [Init]
49 blocktype = drop
50 '';
51 environment.etc."fail2ban/filter.d/postgresql.local".text = ''
52 [INCLUDES]
53 before = common.conf
54 [DEFAULT]
55 _daemon = postgresql-start
56 [Definition]
57 journalmatch = _SYSTEMD_UNIT=postgresql.service + _COMM=postgres
58 prefregex = ^<F-MLFID>%(__prefix_line)s</F-MLFID><F-CONTENT>.+</F-CONTENT>$
59 failregex = ^<HOST>\s+FATAL:\s*no pg_hba.conf entry for host.+$
60 ^<HOST>\s+FATAL:\s*no PostgreSQL user name specified in startup packet.+$
61 ^<HOST>\s+FATAL:\s*password authentication failed for user.+$
62 ^<HOST>\s+FATAL:\s*unsupported frontend protocol.+$
63 maxlines = 1
64 #ignoreregex = duration:
65 '';
66 }