Service Sandboxing Techniques
What you'll learn: How to lock down services using systemd sandboxing, seccomp filters, and namespace isolation to contain potential breaches.
The Core Idea
Service sandboxing creates a restricted execution environment that limits what a compromised service can access or damage. Think of it like running a wild animal in a secure enclosure—even if the animal escapes its cage, it's still contained within layers of protective barriers. By combining multiple isolation technologies, you create defense-in-depth that significantly reduces blast radius if a service is exploited.
Systemd Sandboxing Directives
Systemd provides powerful sandboxing options in service unit files. Key directives include:
PrivateTmp=yes— Isolates/tmpand/var/tmpProtectSystem=strict— Makes most of the filesystem read-onlyProtectHome=yes— Hides user home directoriesNoNewPrivileges=yes— Prevents privilege escalationPrivateDevices=yes— Restricts device accessProtectKernelTunables=yes— Protects/procand/sys
Seccomp Filters
Seccomp (Secure Computing Mode) restricts which system calls a process can make. Use SystemCallFilter= with allowlists to permit only necessary syscalls, blocking dangerous operations like execve, ptrace, or mount.
Namespace Isolation
Namespaces provide separate views of system resources:
- Network namespace — Isolate network stack
- Mount namespace — Separate filesystem view
- PID namespace — Hide other processes
- IPC namespace — Isolate inter-process communication
Systemd's PrivateNetwork=, MountFlags=, and related options leverage these namespaces automatically.
Layered Defense
Combine all three techniques: systemd directives for broad restrictions, seccomp for granular syscall filtering, and namespaces for resource isolation. This creates overlapping security boundaries.
Key Takeaway: Service sandboxing uses systemd configuration, seccomp system call filtering, and namespace isolation together to create multiple containment layers that limit the damage from compromised services.