2021-01-01 18:19:06 -08:00
|
|
|
{ config, options, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with lib.my;
|
|
|
|
let cfg = config.modules.services.fail2ban;
|
|
|
|
in {
|
|
|
|
options.modules.services.fail2ban = {
|
|
|
|
enable = mkBoolOpt false;
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.fail2ban = {
|
|
|
|
enable = true;
|
|
|
|
ignoreIP = [ "127.0.0.1/16" "192.168.1.0/24" ];
|
2021-01-30 01:41:21 -08:00
|
|
|
banaction-allports = "iptables-allports";
|
|
|
|
jails = {
|
|
|
|
DEFAULT = ''
|
|
|
|
blocktype = DROP
|
|
|
|
bantime = 6h
|
|
|
|
findtime = 15m
|
|
|
|
'';
|
|
|
|
sshd = ''
|
|
|
|
bantime = 24h
|
|
|
|
findtime = 1h
|
|
|
|
'';
|
|
|
|
};
|
2021-01-01 18:19:06 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
# Extra filters
|
|
|
|
environment.etc = {
|
|
|
|
"fail2ban/filter.d/bitwarden_rs.conf".text = ''
|
|
|
|
[INCLUDES]
|
|
|
|
before = common.conf
|
|
|
|
|
|
|
|
[Definition]
|
|
|
|
failregex = ^.*Username or password is incorrect\. Try again\. IP: <ADDR>\. Username:.*$
|
|
|
|
ignoreregex =
|
2021-01-30 02:06:31 -08:00
|
|
|
journalmatch = _SYSTEMD_UNIT=bitwarden_rs.service
|
2021-01-01 18:19:06 -08:00
|
|
|
'';
|
|
|
|
"fail2ban/filter.d/gitea.conf".text = ''
|
|
|
|
[Definition]
|
|
|
|
failregex = .*(Failed authentication attempt|invalid credentials|Attempted access of unknown user).* from <HOST>
|
|
|
|
ignoreregex =
|
2021-01-30 02:06:31 -08:00
|
|
|
journalmatch = _SYSTEMD_UNIT=gitea.service
|
2021-01-01 18:19:06 -08:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|