brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: SystemCallFilter= blocks whole groups of system calls in a systemd service

Systemd
~/tips/tip-systemd-syscall-filter

[Service]

Forbid a service from calling things like mount or reboot at the kernel level.

Even a service running as root does not need every system call the kernel offers. systemd can put a seccomp filter in front of it with a list of named groups.

A tilde means block these groups; without it the list is what the service may use:

[Service]
SystemCallFilter=@system-service
SystemCallFilter=~@mount @reboot @swap
SystemCallErrorNumber=EPERM

@system-service is a group meant for ordinary services. The second line takes mounting, rebooting and swap calls away again. SystemCallErrorNumber=EPERM makes a blocked call fail with a permission error instead of killing the process, which is easier to debug.

See what a group holds before you use it:

systemd-analyze syscall-filter @mount

That lists mount, chroot, fsopen and friends. A one-off unit shows it: systemd-run --wait -P -p SystemCallFilter=~@mount -p SystemCallErrorNumber=EPERM mount -t tmpfs none /mnt fails with permission denied, while the same command without the filter mounts fine.

I’d start with a blocklist like this rather than a tight allowlist. A program that hits a missing call in some rare code path breaks only at that moment, maybe weeks later. Without SystemCallErrorNumber= the default action kills the process with SIGSYS, so look for that in systemctl status when a hardened service dies.

Further reading: systemd.exec man page, systemd-analyze man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link