From 25c827b3cc1dc9885f4885b68b9df83c7697b1af Mon Sep 17 00:00:00 2001 From: pennae Date: Sat, 24 Apr 2021 17:42:31 +0200 Subject: [PATCH 1/2] nixos/fail2ban: add maxretry option it's not possible to set a different default maxretry value in the DEFAULT jail because the module already does so. expose the maxretry option to the configuration to remedy this. (we can't really remove it entirely because fail2ban defaults to 5) --- nixos/modules/services/security/fail2ban.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/security/fail2ban.nix b/nixos/modules/services/security/fail2ban.nix index b901b19cf31..22abbb518ff 100644 --- a/nixos/modules/services/security/fail2ban.nix +++ b/nixos/modules/services/security/fail2ban.nix @@ -62,6 +62,12 @@ in description = "The firewall package used by fail2ban service."; }; + maxretry = mkOption { + default = 3; + type = types.ints.unsigned; + description = "Number of failures before a host gets banned."; + }; + banaction = mkOption { default = "iptables-multiport"; type = types.str; @@ -291,7 +297,7 @@ in ''} # Miscellaneous options ignoreip = 127.0.0.1/8 ${optionalString config.networking.enableIPv6 "::1"} ${concatStringsSep " " cfg.ignoreIP} - maxretry = 3 + maxretry = ${toString cfg.maxretry} backend = systemd # Actions banaction = ${cfg.banaction} From afb6fe2ffffbcb864ca4df92635fb9fd473cc2e1 Mon Sep 17 00:00:00 2001 From: pennae Date: Sat, 24 Apr 2021 18:14:56 +0200 Subject: [PATCH 2/2] nixos/fail2ban: add extraPackages option some ban actions need additional packages (eg ipset). since actions can be provided by the user we need something general that's easy to configure. we could also enable ipset regardless of the actual configuration of the system if the iptables firewall is in use (like sshguard does), but that seems very clumsy and wouldn't easily solve the binary-not-found problems other actions may also have. --- nixos/modules/services/security/fail2ban.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/security/fail2ban.nix b/nixos/modules/services/security/fail2ban.nix index 22abbb518ff..0c24972823d 100644 --- a/nixos/modules/services/security/fail2ban.nix +++ b/nixos/modules/services/security/fail2ban.nix @@ -62,6 +62,16 @@ in description = "The firewall package used by fail2ban service."; }; + extraPackages = mkOption { + default = []; + type = types.listOf types.package; + example = lib.literalExample "[ pkgs.ipset ]"; + description = '' + Extra packages to be made available to the fail2ban service. The example contains + the packages needed by the `iptables-ipset-proto6` action. + ''; + }; + maxretry = mkOption { default = 3; type = types.ints.unsigned; @@ -249,7 +259,7 @@ in restartTriggers = [ fail2banConf jailConf pathsConf ]; reloadIfChanged = true; - path = [ cfg.package cfg.packageFirewall pkgs.iproute2 ]; + path = [ cfg.package cfg.packageFirewall pkgs.iproute2 ] ++ cfg.extraPackages; unitConfig.Documentation = "man:fail2ban(1)";