Mental model
Traditional Unix security treats UID 0 (root) as an all-or-nothing master key: a daemon needing merely to bind TCP port 443 receives unrestricted rights to read every host file, load kernel modules, and inspect arbitrary process memory. Linux Capabilities shatter coarse root omnipotence into ~41 granular kernel privileges (like CAP_NET_BIND_SERVICE), while Seccomp-BPF installs an in-kernel syscall allowlist firewall that inspects every kernel system-call number and register argument before the kernel executes it. Enforcing --cap-drop=ALL, no-new-privileges:true, RuntimeDefault Seccomp, non-root UID 1001, and readOnlyRootFilesystem enforces deep defense-in-depth so even an application RCE cannot escalate or break out cleanly.
Theory
Container runtimes combine four orthogonal Linux kernel hardening layers so compromise in one control is contained immediately by the others:
| Hardening Mechanism | Kernel Enforcement Layer | Attack Surface Removed | Production Kubernetes / Docker Baseline |
|---|---|---|---|
| POSIX Capabilities Drop | Kernel credential capability sets (Effective, Permitted, Bounding) | Removes CAP_NET_RAW (ARP/DNS spoofing), CAP_DAC_OVERRIDE, CAP_SYS_PTRACE | drop: ["ALL"] (even non-root images drop ambient bounding bits!) |
no-new-privileges (PR_SET_NO_NEW_PRIVS) | Inherited sticky task_struct kernel bit across fork()/execve() | Blocks SUID/SGID binaries (sudo, su, file capabilities) from ever elevating privileges | allowPrivilegeEscalation: false / --security-opt=no-new-privileges |
| Seccomp-BPF | In-kernel cBPF filter hooked directly onto syscall entry (~40+ calls blocked by default) | Blocks dangerous host-escape / debug syscalls (ptrace, kexec_load, mount, unshare, init_module, bpf, often io_uring!) | seccompProfile: { type: RuntimeDefault } (or strict app-specific JSON allowlist) |
| Read-Only RootFS + Non-Root UID | VFS mount MS_RDONLY + isolated non-zero UID (1001) | Prevents writing trojan binaries, modifying /app, or escalating via host-shared UID 0 | readOnlyRootFilesystem: true (emptyDir strictly for /tmp if needed) + runAsNonRoot: true |
Why CAP_SYS_ADMIN Is Effectively Full Root—And Why SCMP_ACT_ERRNO Beats SCMP_ACT_KILL
Engineers sometimes assume adding only CAP_SYS_ADMIN (for example, to let a container mount an NFS/FUSE volume) is "mostly scoped." In reality, CAP_SYS_ADMIN acts as Linux's catch-all super-capability, authorizing mount(), pivot_root(), namespace manipulation (setns), kernel keyring tampering, and numerous container escape vectors! Never attach CAP_SYS_ADMIN (or --privileged, which clears AppArmor/SELinux, disables Seccomp completely, and grants every capability!). When writing custom Seccomp-BPF JSON profiles, keep defaultAction: "SCMP_ACT_ERRNO" (returning clean -EPERM so libc/Go/Python feature probes like statx or clone3 fall back gracefully to open/clone) rather than SCMP_ACT_KILL_PROCESS during development—only flipping explicit trap actions (SCMP_ACT_KILL_PROCESS / SCMP_ACT_LOG) once strace/eBPF syscall audits (Inspector Gadget / OCI Seccomp operator) confirm clean runtime coverage across edge paths and shutdown signals!
yaml# Production Kubernetes Pod SecurityContext implementing defense-in-depthapiVersion: v1kind: Podmetadata:name: rag-api-hardenedspec:securityContext:runAsNonRoot: truerunAsUser: 1001runAsGroup: 1001seccompProfile:type: RuntimeDefaultcontainers:- name: apiimage: ghcr.io/acme/rag-api:2026.11securityContext:allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truecapabilities:drop: ["ALL"]volumeMounts:- name: ephemeral-tmpmountPath: /tmpvolumes:- name: ephemeral-tmpemptyDir:sizeLimit: 128Mi
Note also Docker/Container Capabilities vs Kubernetes Unprivileged Ports (> 1024): modern Docker (20.10+) and Kubernetes runtimes bind ports >= 1024 (like :3000, :8000) without needing CAP_NET_BIND_SERVICE at all, allowing --cap-drop=ALL cleanly with zero add exceptions on nearly all web microservices!
Alternatives and trade-offs
--cap-drop=ALL+no-new-privileges+RuntimeDefaultSeccomp + Non-Root (RestrictedPod Security Standard): Minimal effort, zero app code changes on well-built containers listening on ports>= 1024, eliminates over75%of documented container breakout CVEs without measuring custom syscalls per binary.- Custom Tightly Scoped App Seccomp Allowlists (
Inspector Gadget/seccompoperator): Cuts accessible kernel syscalls from~300down to just~45–70actually exercised by a Node/Go service (SCMP_ACT_ERRNOdeny-by-default), maximizing kernel CVE resilience at the maintenance cost of re-auditing syscall lists after libc/Node/Python runtime upgrades! - AppArmor / SELinux Mandatory Access Control (
MAC) + MicroVMs: Seccomp filters which syscalls run (openat()), whereas AppArmor/SELinux constrain which exact file paths those syscalls may touch (/etc/shadowblocked even forread())—and Firecracker microVMs eliminate shared host kernel syscalls completely for untrusted code runners.
Failure modes and misconceptions
- Passing
--privilegedor Mounting/var/run/docker.sockto Fix Permission Errors: Either mistake hands full host root compromise immediately to any container code execution—--privilegeddisables Seccomp, AppArmor, and Capability drops at once, while mountingdocker.socklets the container trivially spawndocker run -v /:/host .... Never mountdocker.sockor use--privilegedin production services. - Neglecting
CAP_NET_RAWin Default Docker/K8s Configurations: Leaving default capabilities un-dropped keepsCAP_NET_RAWactive, enabling compromised containers to craft raw ICMP/ARP spoofing or DNS poisoning packets across shared cluster CNI bridges! Always dropALLexplicitly (--cap-drop=ALL). - Writing
allowPrivilegeEscalationLeft DefaulttrueAlongside--cap-drop=ALL: WithoutallowPrivilegeEscalation: false(PR_SET_NO_NEW_PRIVS), SUID host/base-image binaries inside the container image could still raise effective privileges duringexecve(). Always enforceno-new-privileges. - Blocking Unseen
libcUpgrade Syscalls WithSCMP_ACT_KILLWithout Testing Error Paths: An app might pass smoke tests yet call a rare syscall (clone3,futex_time64,rseq, or crash-handler signals) only during heavy GC or graceful shutdown—crashing instantly underSIGSYSif a brittle custom Seccomp profile wasn't captured under load or fails withERRNOgrace. Test custom profiles thoroughly inSCMP_ACT_LOGmode first!
Decision scenario
Your production platform runs public-facing Next.js and FastAPI/MCP containers (UID 1001) alongside occasional Kubernetes cluster nodes exposing high-risk syscalls like io_uring and ptrace that have historically spawned Linux privilege-escalation CVEs. Lock every deployment into the Kubernetes Restricted Pod Security Standard: run strictly as non-root UID 1001 (runAsNonRoot: true) listening on unprivileged ports (:3000/:3100), apply capabilities.drop: ["ALL"], allowPrivilegeEscalation: false (no-new-privileges), readOnlyRootFilesystem: true (mounting a 128 MiB emptyDir strictly for /tmp and shared SQLite /app/data), and enforce seccompProfile: RuntimeDefault (upgraded cleanly to Localhost custom allowlists via staging SCMP_ACT_LOG profiling for critical internet edge gateways).
Learning outcomes
- Explain how Linux POSIX Capabilities decompose root
UID 0authority and whyCAP_SYS_ADMIN/CAP_NET_RAWmust be dropped. - Configure
no-new-privileges,capabilities.drop: ["ALL"], non-rootUID, andreadOnlyRootFilesystemsafely in Docker and Kubernetes. - Trace how Seccomp-BPF intercepts syscalls before kernel execution and compare
SCMP_ACT_ERRNO,SCMP_ACT_LOG, andSCMP_ACT_KILL_PROCESS. - Avoid
--privilegedanddocker.sockanti-patterns and recognize where MAC (SELinux/AppArmor) complements Seccomp.
Trade-offs
Enforcing capability drops, no-new-privileges, and Seccomp-BPF hardens containerized APIs with practically zero CPU runtime overhead, balanced against strict port binding (>= 1024), explicit /tmp / writable mount declarations, and syscall re-validation whenever base OS runtimes upgrade.