aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/fa/fail2ban/module.nix
diff options
context:
space:
mode:
authorSoispha Peetz <soispha@b-peetz.de>2026-10-30 15:22:07 +0100
committerSoispha Peetz <soispha@b-peetz.de>2026-11-27 00:27:17 +0100
commit4834ad1ea13358f3f23e0139e3a8a3d1ccb804e2 (patch)
tree60b588b2d979bce6a6d19bd7acc0af05c90f12fd /modules/by-name/fa/fail2ban/module.nix
parenttreewide: Various fixes (diff)
downloadnixos-server-4834ad1ea13358f3f23e0139e3a8a3d1ccb804e2.zip
modules: Rename back to `by-name`
There is no point in keeping just vhack here.
Diffstat (limited to 'modules/by-name/fa/fail2ban/module.nix')
-rw-r--r--modules/by-name/fa/fail2ban/module.nix66
1 files changed, 66 insertions, 0 deletions
diff --git a/modules/by-name/fa/fail2ban/module.nix b/modules/by-name/fa/fail2ban/module.nix
new file mode 100644
index 0000000..e1304a7
--- /dev/null
+++ b/modules/by-name/fa/fail2ban/module.nix
@@ -0,0 +1,66 @@
+{
+ config,
+ lib,
+ ...
+}: let
+ cfg = config.vhack.fail2ban;
+in {
+ options.vhack.fail2ban = {
+ enable = lib.mkEnableOption "fail2ban";
+ };
+
+ config = lib.mkIf cfg.enable {
+ vhack.persist.directories = [
+ {
+ directory = "/var/lib/fail2ban";
+ user = "fail2ban";
+ group = "fail2ban";
+ mode = "0700";
+ }
+ ];
+
+ services.fail2ban = {
+ enable = true;
+ maxretry = 7; # ban after 7 failures
+ daemonSettings = {
+ Definition = {
+ logtarget = "SYSLOG";
+ socket = "/run/fail2ban/fail2ban.sock";
+ pidfile = "/run/fail2ban/fail2ban.pid";
+ dbfile = "/var/lib/fail2ban/db.sqlite3";
+ };
+ };
+ bantime-increment = {
+ enable = true;
+ rndtime = "8m";
+ overalljails = true;
+ multipliers = "2 4 16 128 256";
+ maxtime = "72h";
+ };
+ jails = {
+ dovecot = ''
+ # block IPs which failed to log-in
+ # aggressive mode add blocking for aborted connections
+ enabled = true
+ filter = dovecot[mode=aggressive]
+ maxretry = 2
+ '';
+ postfix = ''
+ enabled = true
+ filter = postfix[mode=aggressive]
+ findtime = 600
+ maxretry = 3
+ '';
+ };
+ };
+ users = {
+ groups.fail2ban = {
+ gid = config.vhack.constants.ids.gids.fail2ban;
+ };
+ users.fail2ban = {
+ uid = config.vhack.constants.ids.uids.fail2ban;
+ group = "fail2ban";
+ };
+ };
+ };
+}