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