From dec36d2e9aaca7ca7149a244aa984e97925a3dba Mon Sep 17 00:00:00 2001 From: adikro Date: Sun, 17 May 2026 01:05:14 +0200 Subject: moved ssh and tailscale to srv, revamped netwroking modules --- os/srv/crowdsec.nix | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 os/srv/crowdsec.nix (limited to 'os/srv/crowdsec.nix') 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" + ]; + }; +} -- cgit v1.3