r/VPS • u/Secure-Composer-9458 • 18h ago
Configs Several apps on one VPS, no Docker: the systemd settings I use so one app can't mess with the others
I run a handful of apps on one VPS with no Docker. Every process is a plain systemd service behind Caddy. Getting them running didn't take long. Making sure one hacked or runaway app can't hurt the others took a lot longer, and this is what ended up in every unit file.
User and privileges:
- User= and Group= set to a Linux user that only that app has. Not root, and not one www-data shared by everything.
- CapabilityBoundingSet= left empty, plus NoNewPrivileges=true. The app has no root powers and can't pick any up from a setuid binary.
Filesystem:
- ProtectSystem=strict with ReadWritePaths= pointing at the app's own folder. The rest of the disk is read-only to it.
- ProtectHome=true, PrivateTmp=true and PrivateDevices=true.
- ProtectProc=invisible, so other users' processes don't show up in /proc.
- InaccessiblePaths= for /run/dbus, the snapd sockets and /etc/systemd/system. On my Ubuntu 26.04 box the first two are sockets any user can connect to, and the last one holds every app's unit file, readable by everyone.
- LimitCORE=0. A core dump is a copy of the app's memory, secrets and all.
Syscalls and ports:
- SystemCallFilter=@system-service, with SystemCallErrorNumber=EPERM and SystemCallArchitectures=native. A blocked call gets an error back and the process keeps running. Without the EPERM line systemd kills it.
- A second line, SystemCallFilter=~@keyring. The kernel keyring isn't namespaced, so every app on the box shares it. Docker's default profile blocks the same calls.
- SocketBindAllow=tcp:PORT for its own port, plus SocketBindDeny= for the whole range I hand ports out from. Otherwise one app could listen on another app's port.
Limits:
- One slice per app with TasksMax=40%, so a fork bomb in one app stops before it takes the whole server.
- When I cap memory with MemoryMax= on the slice, I also set MemorySwapMax=0. With swap open, an app over its cap gets paged out and keeps growing. I'd rather it gets killed and restarted.
Things that bit me:
- The syscall allow list broke Elasticsearch (the one inside SonarQube). The JVM calls mincore, which that allow list leaves out, and every merge failed with "Operation not permitted". I had to add mincore to the allow line. If you run something with Lucene in it, try it under the filter before you trust it.
- RestrictSUIDSGID=true seemed like an easy extra, but with it on, tar on Ubuntu 26.04 couldn't extract files. I left it out. NoNewPrivileges already makes setuid files useless.
- Secrets go in an EnvironmentFile= that only root can read, never in Environment= lines. Unit files are world-readable.
This isn't a container or a VM, and everything still shares one kernel. It's still a lot better than a pile of apps all running as the same user.
Full disclosure: these units come out of a deploy tool I'm building, which is why I've stared at them this much. I'm not linking it, the post is only about the settings.
What's in your units that I'm missing?