]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/losurdo/fail2ban.nix
sanoid: keep monthly snapshots (and hopefully bookmarks)
[sourcephile-nix.git] / hosts / losurdo / fail2ban.nix
1 { pkgs, lib, config, hosts, ... }:
2 {
3 services.openssh.logLevel = "VERBOSE";
4 services.postgresql.logLinePrefix = "%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 #"0.0.0.0/8"
24 #"10.0.0.0/8"
25 "127.0.0.0/8"
26 #"169.254.0.0/16"
27 #"172.16.0.0/12"
28 #"192.0.2.0/24"
29 "192.168.0.0/16"
30 #"224.0.0.0/3"
31 #"240.0.0.0/5"
32 hosts.mermet.extraArgs.ipv4
33 "losurdo.sourcephile.fr"
34 "vpn.riseup.net"
35 ];
36 jails = {
37 DEFAULT = ''
38 '';
39 sshd = ''
40 enabled = true
41 bantime = 5m
42 findtime = 1d
43 maxretry = 1
44 mode = aggressive
45 '';
46 postgresql = ''
47 enabled = true
48 bantime = 1m
49 filter = postgresql
50 findtime = 1d
51 port = 5432
52 '';
53 };
54 };
55 environment.etc."fail2ban/action.d/nftables-common.local".text = ''
56 [Init]
57 blocktype = drop
58 '';
59 environment.etc."fail2ban/filter.d/postgresql.local".text = ''
60 [INCLUDES]
61 before = common.conf
62 [DEFAULT]
63 _daemon = postgresql-start
64 [Definition]
65 journalmatch = _SYSTEMD_UNIT=postgresql.service + _COMM=postgres
66 prefregex = ^<F-MLFID>%(__prefix_line)s</F-MLFID><F-CONTENT>.+</F-CONTENT>$
67 failregex = ^<HOST>\s+FATAL:\s*no pg_hba.conf entry for host.+$
68 ^<HOST>\s+FATAL:\s*no PostgreSQL user name specified in startup packet.+$
69 ^<HOST>\s+FATAL:\s*password authentication failed for user.+$
70 ^<HOST>\s+FATAL:\s*unsupported frontend protocol.+$
71 maxlines = 1
72 #ignoreregex = duration:
73 '';
74 }