diff options
| author | adikro <adikro@disroot.org> | 2026-05-17 01:05:14 +0200 |
|---|---|---|
| committer | adikro <adikro@disroot.org> | 2026-05-17 01:05:14 +0200 |
| commit | dec36d2e9aaca7ca7149a244aa984e97925a3dba (patch) | |
| tree | bdf3ec35e101beaa4e74c48930dca4341d48ae2c /os/srv/crowdsec.nix | |
| parent | 8bedd672ac49617d2e3a808efe470228cbb0240d (diff) | |
moved ssh and tailscale to srv, revamped netwroking modules
Diffstat (limited to 'os/srv/crowdsec.nix')
| -rw-r--r-- | os/srv/crowdsec.nix | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/os/srv/crowdsec.nix b/os/srv/crowdsec.nix new file mode 100644 index 0000000..79c8718 --- /dev/null +++ b/os/srv/crowdsec.nix @@ -0,0 +1,78 @@ +{ config, lib, ... }: +let + cfg = config.os.srv.security.crowdsec; +in +{ + options.os.srv.security.crowdsec = { + enable = lib.mkEnableOption "enables CrowdSec collaborative intrusion prevention"; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = config.networking.nftables.enable; + message = "CrowdSec requires networking.nftables to be enabled for blocking."; + } + ]; + + services.crowdsec = { + enable = true; + autoUpdateService = true; + + localConfig = { + acquisitions = [ + { + source = "journalctl"; + journalctl_filter = [ "_SYSTEMD_UNIT=sshd.service" ]; + labels.type = "syslog"; + } + { + filenames = [ + "/var/log/nginx/access.log" + "/var/log/nginx/error.log" + ]; + labels.type = "nginx"; + } + ]; + + parsers.s02Enrich = [ + { + name = "myips/whitelist"; + description = "Prevent local address ranges from triggering bans"; + whitelist = { + reason = "Internal private subnets"; + cidr = [ + "10.0.0.0/16" + ]; + }; + } + ]; + }; + + hub = { + collections = [ + "crowdsecurity/linux" + "crowdsecurity/nginx" + "crowdsecurity/sshd" + ]; + }; + + settings = { + lapi.credentialsFile = "/var/lib/crowdsec/state/lapi.yaml"; + capi.credentialsFile = "/var/lib/crowdsec/state/capi.yaml"; + }; + }; + + services.crowdsec-firewall-bouncer = { + enable = true; + settings = { + update_frequency = "10s"; + }; + }; + + users.users.crowdsec.extraGroups = [ + "nginx" + "systemd-journal" + ]; + }; +} |
