From 4e245c980ff67a347b945db4ba446d2d9267b65c Mon Sep 17 00:00:00 2001 From: Quinn Unger Date: Tue, 4 Aug 2026 14:17:08 +0100 Subject: [PATCH] lala/crowdsec: enroll to capi --- hosts/lala/netbird.nix | 156 +++++++++++++++++++---------------------- secrets/secrets.yaml | 7 +- 2 files changed, 77 insertions(+), 86 deletions(-) diff --git a/hosts/lala/netbird.nix b/hosts/lala/netbird.nix index 861dde4..bd5cf2c 100644 --- a/hosts/lala/netbird.nix +++ b/hosts/lala/netbird.nix @@ -15,14 +15,28 @@ let relayPort = 33080; proxyPort = 8443; crowdsecPort = 32487; + crowdsecURI = "localhost:${toString crowdsecPort}"; coturnPass = config.sops.secrets."lala/netbird/coturnPass".path; - dataStoreKey = config.sops.secrets."lala/netbird/dataStoreKey".path; - relaySecret = config.sops.secrets."lala/netbird/relaySecret".path; relaySecretEnv = config.sops.secrets."lala/netbird/relaySecretEnv".path; - proxySecret = config.sops.secrets."lala/netbird/proxySecret".path; - proxySecretEnv = config.sops.secrets."lala/netbird/proxySecretEnv".path; - idpKey = config.sops.secrets."lala/netbird/idpKey".path; - crowdsecLAPI = config.sops.secrets."lala/netbird/crowdsecLAPI".path; + hardening = { + # for systemd services (copied from netbird-management nixos module) + LockPersonality = true; + MemoryDenyWriteExecute = true; + NoNewPrivileges = true; + PrivateMounts = true; + ProtectClock = true; + ProtectControlGroups = true; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectSystem = true; + RemoveIPC = true; + RestrictNamespaces = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + }; in { sops.secrets = { @@ -30,10 +44,10 @@ in "lala/netbird/dataStoreKey" = { }; "lala/netbird/relaySecret" = { }; "lala/netbird/relaySecretEnv" = { }; - "lala/netbird/proxySecret" = { }; "lala/netbird/proxySecretEnv" = { }; "lala/netbird/idpKey" = { }; - "lala/netbird/crowdsecLAPI".owner = config.users.users.crowdsec.name; + "lala/netbird/crowdsecLAPI" = { }; + "lala/netbird/crowdsecCAPI".owner = config.users.users.crowdsec.name; }; networking.firewall = { @@ -208,9 +222,9 @@ in Relay = { Addresses = [ "rels://${netbirdDomain}:33080" ]; CredentialsTTL = "24h"; - Secret._secret = relaySecret; + Secret._secret = config.sops.secrets."lala/netbird/relaySecret".path; }; - DataStoreEncryptionKey._secret = dataStoreKey; + DataStoreEncryptionKey._secret = config.sops.secrets."lala/netbird/dataStoreKey".path; EmbeddedIdP = { Enabled = true; DataDir = "${stateDir}/idp"; @@ -220,7 +234,7 @@ in "${netbirdUrl}/nb-silent-auth" ]; }; - EncryptionKey._secret = idpKey; + EncryptionKey._secret = config.sops.secrets."lala/netbird/idpKey".path; }; }; }; @@ -241,30 +255,12 @@ in NB_PROXY_ACME_CHALLENGE_TYPE = "tls-alpn-01"; NB_PROXY_CERTIFICATE_DIRECTORY = "/var/lib/proxy-certs"; NB_PROXY_LOG_LEVEL = "info"; - NB_PROXY_CROWDSEC_API_URL = "http://127.0.0.1:${toString crowdsecPort}"; + NB_PROXY_CROWDSEC_API_URL = "http://${crowdsecURI}"; }; - serviceConfig = { - EnvironmentFile = proxySecretEnv; + serviceConfig = hardening // { + EnvironmentFile = config.sops.secrets."lala/netbird/proxySecretEnv".path; ExecStart = lib.getExe unstable.netbird-proxy; Restart = "always"; - - # hardening - LockPersonality = true; - MemoryDenyWriteExecute = true; - NoNewPrivileges = true; - PrivateMounts = true; - ProtectClock = true; - ProtectControlGroups = true; - ProtectHome = true; - ProtectHostname = true; - ProtectKernelLogs = true; - ProtectKernelModules = true; - ProtectKernelTunables = true; - ProtectSystem = true; - RemoveIPC = true; - RestrictNamespaces = true; - RestrictRealtime = true; - RestrictSUIDSGID = true; }; stopIfChanged = false; }; @@ -348,28 +344,10 @@ in NB_TLS_CERT_FILE = "/var/lib/acme/${netbirdDomain}/fullchain.pem"; NB_TLS_KEY_FILE = "/var/lib/acme/${netbirdDomain}/key.pem"; }; - serviceConfig = { + serviceConfig = hardening // { EnvironmentFile = relaySecretEnv; ExecStart = lib.getExe unstable.netbird-relay; Restart = "always"; - - # hardening - LockPersonality = true; - MemoryDenyWriteExecute = true; - NoNewPrivileges = true; - PrivateMounts = true; - ProtectClock = true; - ProtectControlGroups = true; - ProtectHome = true; - ProtectHostname = true; - ProtectKernelLogs = true; - ProtectKernelModules = true; - ProtectKernelTunables = true; - ProtectSystem = true; - RemoveIPC = true; - RestrictNamespaces = true; - RestrictRealtime = true; - RestrictSUIDSGID = true; }; stopIfChanged = false; }; @@ -377,39 +355,51 @@ in } ]; }; - services.crowdsec = - let - cfg = config.services.crowdsec; - in - { - enable = true; - autoUpdateService = true; - openFirewall = false; # using local api - settings = { - general = { - prometheus.enabled = false; - api.server = { - enable = true; - listen_uri = "127.0.0.1:${toString crowdsecPort}"; - trusted_ips = [ - "127.0.0.1" - "::1" - ]; - }; + + sops.templates."crowdsec_lapi.yaml" = { + owner = config.users.users.crowdsec.name; + content = '' + url: http://${crowdsecURI} + ${config.sops.placeholder."lala/netbird/crowdsecLAPI"} + ''; + }; + services.crowdsec = { + enable = true; + autoUpdateService = true; + openFirewall = false; # using local api + settings = { + general = { + prometheus.enabled = false; + api.server = { + enable = true; + listen_uri = crowdsecURI; + trusted_ips = [ + "127.0.0.1" + "::1" + ]; }; - lapi.credentialsFile = crowdsecLAPI; }; - hub.collections = [ "crowdsecurity/linux" ]; - localConfig.acquisitions = [ - { - journalctl_filter = [ - "_SYSTEMD_UNIT=sshd.service" - ]; - labels = { - type = "syslog"; - }; - source = "journalctl"; - } - ]; + lapi.credentialsFile = config.sops.templates."crowdsec_lapi.yaml".path; + capi.credentialsFile = config.sops.secrets."lala/netbird/crowdsecCAPI".path; + console.configuration = { + share_context = true; + share_custom = true; + share_manual_decisions = true; + share_tainted = true; + }; }; + hub.collections = [ "crowdsecurity/linux" ]; + localConfig.acquisitions = [ + # Need at least one data source for the service to start + { + journalctl_filter = [ + "_SYSTEMD_UNIT=sshd.service" + ]; + labels = { + type = "syslog"; + }; + source = "journalctl"; + } + ]; + }; } diff --git a/secrets/secrets.yaml b/secrets/secrets.yaml index 33f6525..eea7aa2 100644 --- a/secrets/secrets.yaml +++ b/secrets/secrets.yaml @@ -23,7 +23,8 @@ lala: proxySecretEnv: ENC[AES256_GCM,data:ZV9NepXjDvsOY9HueHIWyQxDNcLYQMGgK7OV81dsRhXaLGWeK1BFe2lKQHE+x/Bns6C7EGsaaZB7igG+0gjZLmARTf26K0U9MaZ0cKLa/M7Yv+byhPqckg2eznSXLPaH5A1ofCv6SUO/zSyZgEnb2b2OtN4m7kDzKAvBq9Hy,iv:pHhBEdxAhhimSr7UE8X/ptdgmDndUYS2ZjFOb4ztiPk=,tag:RrIfXuHDh/4hO0TZKVQk2w==,type:str] dataStoreKey: ENC[AES256_GCM,data:Em3LERUK78OtbPm57lo+j1qyn3Pkle42ThT7zSiAV0pJZnVHqtTxAxRnSJU=,iv:LFwhbCjv0HVhlKuV9f9REf01G/SKZOt8vB+pvx/CjdU=,tag:o6hUi/BQCRMxyWYxIRQXkw==,type:str] idpKey: ENC[AES256_GCM,data:cRgySkw7V8E+DnAg7HecynO1PUeR+lth6rQQJ/85W6rCxD5KIuzZ9zcwmRA=,iv:/Hcm7xpALsMX6qceL6/hpRocQxB7JJ56A8wnh8QVNVs=,tag:JK5T8QsXU9rEb05sJAjG6w==,type:str] - crowdsecLAPI: ENC[AES256_GCM,data:pf0wUxFHW+GXwvkg4c4vfhhJSK3OyKPYMdQM+YXjsv67T1Q0szcn/I/RsIs5cv+TW9u63DPNcLQN3k+yF+mpeCv1DMLBwYl9tMj40RUxLOZFdyFoGfdIP806ckzgPHeLDQP1sFeZEAYiYeRz99DUnQQc0mcWuapiT/Sn09924w==,iv:tADPcc6A3HLeaH4oA/lzqd7uEXL8JZjdI6EOJ2N6peI=,tag:8SMmKBdNh5Fgpphs3Z4Wcw==,type:str] + crowdsecLAPI: ENC[AES256_GCM,data:kaRIk/Y0eozW+jrfeqiqliE40cTIkhbremdk7Fj7UT5noCV1/iG61AWqkKy3vem6vf7l4HpwHFwSp3zDc/pS7RJnszMP95BySsPZ/ni1DsKYd6Ypq84Er2yIQ+1GOEuwH9Sb,iv:c50HL3b555eWPMzfPioBhSijsHSDZsZxiattRZQfSuQ=,tag:ETweA7ZaA54rjNyc9NyW6w==,type:str] + crowdsecCAPI: ENC[AES256_GCM,data:lp2pedoGTB40ExtN8TI6My6uyU+oBHQHGF2DHdeycyYgYmAKHlLJ+2GSeMpbquRiOuWQnqnluy1z8xTXHbiCt1upPKX6VbSgsnLhJZgxSZvVA1UlLTALlzXkHysYNLkV1hSJnKZ8Xmi3lakRAY9TEakQDW/RtatC/D82ZGGcbX5lQNLT4IIX3RM5vYifaygkttKQYEUr1rVQOj12CUiM+xDz,iv:PMTJxiLj3RSGCzMF1unjrjWsrkmz9L+ZqzQcyfhEJdk=,tag:hXxv6NMkJivzCx8PyCSMPw==,type:str] sops: age: - enc: | @@ -71,7 +72,7 @@ sops: JFaroA1RPAmhCC0nSl4seBSIuRl8QrPjfcBJy4mFycll5Mp/0/WwLA== -----END AGE ENCRYPTED FILE----- recipient: age1cpqgsevvfgk0nnmxacsdcwsrkefd0xcx7wkdlyaqj8vgvfvnm4rq4npjv6 - lastmodified: "2026-08-03T16:18:17Z" - mac: ENC[AES256_GCM,data:6x1VV0bzMmBWW/CHiaj/fGAGhStXjcNcmKwM/0T9Cvf6pYtFUjNevu+TlcZ001MKFjRwpuLHz5B6jy+6sauqfKHJT/UnI1nbSVgOKJXh8zzXB+SmJhpcdpcHtZqdeQB6Fj4NtUXDjsz4llzjRHwKgdN4iwSbVvPw5YK0CNjQeaM=,iv:X1TCPDxW3QHc5o95bZGmX0P6kUelojBVfuU37mAflZA=,tag:fnHORTcOKywxqX4S+bno1A==,type:str] + lastmodified: "2026-08-04T12:32:39Z" + mac: ENC[AES256_GCM,data:2if4ZPYpBeSsskCMZryc+I99GYpNfdY9XWxoECKrgARkghxLOJrXwv+dCmWk/YsCCh/z0oxYIm/znhKBQpRS81d+QUg3Em/gbf8joyjWAL233ZH/lG90AZGXddoLVtHT4fYrDfItkG0qdsuCCg0/zunlXvcXGdPDagjjR8SU5z0=,iv:wtghfI996SrKsD0nHVXhOWw2UPrfkAYXXWe/mn2XKH4=,tag:qDpR6C14jMT53d+n9r2VdQ==,type:str] unencrypted_suffix: _unencrypted version: 3.13.3 -- knotmirror 0.0.1