From e99f342f1166b33c0cbabc68037a7da3fa2f5478 Mon Sep 17 00:00:00 2001 From: Morgan Jones Date: Thu, 29 Dec 2022 13:57:17 -0800 Subject: [PATCH] nixos/nebula: harden systemd unit --- nixos/modules/services/networking/nebula.nix | 23 +++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/nebula.nix b/nixos/modules/services/networking/nebula.nix index 71f8991b70ae..e1a8c6740f57 100644 --- a/nixos/modules/services/networking/nebula.nix +++ b/nixos/modules/services/networking/nebula.nix @@ -204,8 +204,27 @@ in Type = "simple"; Restart = "always"; ExecStart = "${netCfg.package}/bin/nebula -config ${configFile}"; + UMask = "0027"; CapabilityBoundingSet = "CAP_NET_ADMIN"; AmbientCapabilities = "CAP_NET_ADMIN"; + LockPersonality = true; + NoNewPrivileges = true; + PrivateDevices = false; # needs access to /dev/net/tun (below) + DeviceAllow = "/dev/net/tun rw"; + DevicePolicy = "closed"; + PrivateTmp = true; + PrivateUsers = false; # CapabilityBoundingSet needs to apply to the host namespace + ProtectClock = true; + ProtectControlGroups = true; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectProc = "invisible"; + ProtectSystem = "strict"; + RestrictNamespaces = true; + RestrictSUIDSGID = true; User = networkId; Group = networkId; }; @@ -227,6 +246,8 @@ in }; }) enabledNetworks); - users.groups = mkMerge (mapAttrsToList (netName: netCfg: { ${nameToId netName} = {}; }) enabledNetworks); + users.groups = mkMerge (mapAttrsToList (netName: netCfg: { + ${nameToId netName} = {}; + }) enabledNetworks); }; }