From b3c825d1eff82e1f9789d8ac620659f873956cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9za=20B=C3=BAza?= Date: Mon, 16 Jan 2023 14:36:15 +0100 Subject: [PATCH] nixos/jackett: add Systemd sandboxing configuration Apply security sandboxing via Systemd service configuration: - All unnecessary privileges are dropped. - The only writable directories are /tmp and the home of the jackett user. - Only can execute installed applications from the Nix store. - Network access is not restricted as the setup can vary across users. So it should be configured in the firewall. --- nixos/modules/services/misc/jackett.nix | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/nixos/modules/services/misc/jackett.nix b/nixos/modules/services/misc/jackett.nix index b0edf0d18da4..897ca5a1d9ec 100644 --- a/nixos/modules/services/misc/jackett.nix +++ b/nixos/modules/services/misc/jackett.nix @@ -60,6 +60,55 @@ in Group = cfg.group; ExecStart = "${cfg.package}/bin/Jackett --NoUpdates --DataFolder '${cfg.dataDir}'"; Restart = "on-failure"; + + # Sandboxing + CapabilityBoundingSet = [ + "CAP_NET_BIND_SERVICE" + ]; + ExecPaths = [ + "${builtins.storeDir}" + ]; + LockPersonality = true; + NoExecPaths = [ + "/" + ]; + NoNewPrivileges = true; + PrivateDevices = true; + PrivateMounts = true; + PrivateTmp = true; + PrivateUsers = true; + ProtectClock = true; + ProtectControlGroups = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectProc = "invisible"; + ProtectSystem = "strict"; + ReadWritePaths = [ + "${config.users.users.${cfg.user}.home}" + ]; + RemoveIPC = true; + RestrictAddressFamilies = [ + "AF_INET" + "AF_INET6" + ]; + RestrictNamespaces = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + SystemCallArchitectures = "native"; + SystemCallFilter = [ + "@system-service" + "~@clock" + "~@cpu-emulation" + "~@debug" + "~@obsolete" + "~@reboot" + "~@module" + "~@mount" + "~@swap" + ]; + UMask = "0077"; }; };