“Systemd will solve all your problems,” they said.
Having used a number of systemd’s security features to configure a service, I am beginning to suspect everyone uses containers because container runtimes are trying to be secure already.
It's possible to improve the security of a service with systemd, of course. I’ve worked hard at it. But in the end, over half the *.service
file is consumed with “trying to build my own container out of systemd directives.” ProtectHome, ProtectSystem, ProtectKernelTunables, Protect This, Protect That, blah blah blah. The process starts from insecure by default, and then asks me to layer on every individual protection. This is exactly the sort of thing Linux zealots used to yell at Microsoft about. ¯\_(ツ)_/¯
But I digress. I ended up with an excessively long systemd service configuration file, and to apply that to any other service, there’s no option besides copying and pasting those directives. With every release of systemd, I have to comb the man pages again to see what else is available now, and carefully apply that to every service file. It’s not easy to tell whether the security posture is up-to-date when the policy is so verbose.
[Updated 2022-03-19: systemd-analyze security foo.service
is your friend. This is the best way to get a list of everything systemd thinks about security, and whether it is applied to the unit. It's a little less bad than I thought, but it is still fundamentally the Default Permit and Enumerating Badness approaches.]
Whereas a container has an isolated filesystem (its image) already, so whole classes of configuration (ProtectHome, ProtectSystem, TemporaryFileSystem) become irrelevant. On top of that, container runtimes start with a more limited set of privileges by default, instead of handing out CAP_SYS_ADMIN
and leaving it up to the administrator to carefully disable it. Escaping from the container runtime is considered a vulnerability; escaping from a poorly-secured systemd service is considered user error.
This is all orthogonal to “containers are interop”, but I think both forces are feeding the containerization craze. I’m left with the feeling again that systemd should have been the “obvious correct choice,” except they decided usability didn’t matter.