From 650945df314e58a40e6f4dab7be3448301929f5f Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Tue, 28 Dec 2021 13:49:14 +0100 Subject: [PATCH] nixos/minecraft-server: systemd unit hardening Does not set MemoryDenyWriteExecute as OpenJDK need to mark memory page as executable. Does not set ProcSubset as /proc/cpuinfo and /proc/meminfo are needed. --- .../services/games/minecraft-server.nix | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nixos/modules/services/games/minecraft-server.nix b/nixos/modules/services/games/minecraft-server.nix index ddbe9508a4dc..5bb8eff57629 100644 --- a/nixos/modules/services/games/minecraft-server.nix +++ b/nixos/modules/services/games/minecraft-server.nix @@ -182,6 +182,27 @@ in { Restart = "always"; User = "minecraft"; WorkingDirectory = cfg.dataDir; + # Hardening + CapabilityBoundingSet = [ "" ]; + DeviceAllow = [ "" ]; + LockPersonality = true; + PrivateDevices = true; + PrivateTmp = true; + PrivateUsers = true; + ProtectClock = true; + ProtectControlGroups = true; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectProc = "invisible"; + RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ]; + RestrictNamespaces = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + SystemCallArchitectures = "native"; + UMask = "0077"; }; preStart = ''