systemd unit hardening checker
Paste a .service unit and see which sandboxing directives are missing or weak: User, NoNewPrivileges, ProtectSystem, PrivateTmp and more, with reasons.
Checked as you type. Nothing you paste leaves this page.
The file is read in your browser. It is not uploaded.
Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the systemd unit hardening checker
- Paste the unit file (systemctl cat name.service prints it), drop it, or load the example.
- Give the service its own User= first, or DynamicUser=yes.
- Add the medium directives, restart the service and check that it still works.
- Add the info directives one group at a time, watching the journal for denied operations.
About this tool
systemd can confine a service with a few lines in its unit file: a read-only file system, no access to home directories, a private /tmp, a short list of capabilities and system calls. None of it is on by default, so a unit with only ExecStart runs as root with access to everything root has.
This checker reads the [Service] section and reports what is missing or weak, following systemd.exec(5). Running as root is the one high finding. The main protections (NoNewPrivileges, ProtectSystem, ProtectHome, PrivateTmp, PrivateDevices, CapabilityBoundingSet) are medium, and the finer ones are info. It knows what DynamicUser=yes turns on by itself, and that list settings add up across lines.
These are hardening suggestions, not vulnerabilities, and some do not fit every service: a runtime with a JIT compiler cannot use MemoryDenyWriteExecute. Add directives a few at a time and test. On the server, systemd-analyze security gives a score for the unit as it is actually loaded, including drop-in files this page cannot see.
Sources
Questions
It mounts the whole file system read-only for the service, except /dev, /proc and /sys. The service then needs explicit write access through ReadWritePaths= or the StateDirectory=, CacheDirectory= and LogsDirectory= settings. The weaker values full and yes leave /var, and with yes also /etc, writable.
A system service with no User= runs as root. Set User= and Group= to a dedicated account, or use DynamicUser=yes, which creates a temporary user for the lifetime of the service and turns on several protections with it.
Run systemd-analyze security name.service on the machine. It lists every sandboxing setting with its state and gives an exposure score from 0 to 10, where lower is better. It reads the loaded unit, so drop-in files and defaults are included.
Yes. Run it as an unprivileged user and add AmbientCapabilities=CAP_NET_BIND_SERVICE, with CapabilityBoundingSet=CAP_NET_BIND_SERVICE so that it is the only capability the service can ever hold. Socket activation is another way.