Skip to content

Commit

Permalink
nixos/sing-box: harden systemd service
Browse files Browse the repository at this point in the history
  • Loading branch information
Guanran928 committed Feb 6, 2025
1 parent e2f0dcd commit 2ea1ee9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions nixos/modules/services/networking/sing-box.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,37 @@ in
""
"${lib.getExe cfg.package} -D \${STATE_DIRECTORY} -C \${RUNTIME_DIRECTORY} run"
];

# Hardening
DeviceAllow = "/dev/net/tun";
DevicePolicy = "closed";
DynamicUser = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateMounts = true;
PrivateTmp = true;
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_NETLINK"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = "@system-service";
UMask = "0077";
};
wantedBy = [ "multi-user.target" ];
};
Expand Down

0 comments on commit 2ea1ee9

Please sign in to comment.