FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Linux Capabilities & Seccomp Hardening

Linux POSIX capabilities (CAP_SYS_ADMIN), seccomp syscall filtering, and AppArmor profiles.

Freshness: current•15 min read•Software and Web Engineering

Key Learning Outcomes

  • ✓Restrict root process privileges using Linux capabilities
  • ✓Build restrictive seccomp BPF filters for production containers
Full Technical Reference Document

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.

Container Starts Non-Root + --cap-drop=ALL
Enforce no-new-privileges PRCTL Flag
App Invokes Linux Syscall (e.g. execve/ptrace)
Kernel Evaluates Seccomp-BPF Filter Program
Allow Scoped Syscall or Trap EPERM / SIGSYS
Conceptual teaching model synthesized from:linux-kernel-docs,kubernetes-docs

Theory

Container runtimes combine four orthogonal Linux kernel hardening layers so compromise in one control is contained immediately by the others:

Hardening MechanismKernel Enforcement LayerAttack Surface RemovedProduction Kubernetes / Docker Baseline
POSIX Capabilities DropKernel credential capability sets (Effective, Permitted, Bounding)Removes CAP_NET_RAW (ARP/DNS spoofing), CAP_DAC_OVERRIDE, CAP_SYS_PTRACEdrop: ["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 privilegesallowPrivilegeEscalation: false / --security-opt=no-new-privileges
Seccomp-BPFIn-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 UIDVFS mount MS_RDONLY + isolated non-zero UID (1001)Prevents writing trojan binaries, modifying /app, or escalating via host-shared UID 0readOnlyRootFilesystem: 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-depth
apiVersion: v1
kind: Pod
metadata:
name: rag-api-hardened
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: api
image: ghcr.io/acme/rag-api:2026.11
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
volumeMounts:
- name: ephemeral-tmp
mountPath: /tmp
volumes:
- name: ephemeral-tmp
emptyDir:
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 + RuntimeDefault Seccomp + Non-Root (Restricted Pod Security Standard): Minimal effort, zero app code changes on well-built containers listening on ports >= 1024, eliminates over 75% of documented container breakout CVEs without measuring custom syscalls per binary.
  • Custom Tightly Scoped App Seccomp Allowlists (Inspector Gadget / seccomp operator): Cuts accessible kernel syscalls from ~300 down to just ~45–70 actually exercised by a Node/Go service (SCMP_ACT_ERRNO deny-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/shadow blocked even for read())—and Firecracker microVMs eliminate shared host kernel syscalls completely for untrusted code runners.

Failure modes and misconceptions

  1. Passing --privileged or Mounting /var/run/docker.sock to Fix Permission Errors: Either mistake hands full host root compromise immediately to any container code execution—--privileged disables Seccomp, AppArmor, and Capability drops at once, while mounting docker.sock lets the container trivially spawn docker run -v /:/host .... Never mount docker.sock or use --privileged in production services.
  2. Neglecting CAP_NET_RAW in Default Docker/K8s Configurations: Leaving default capabilities un-dropped keeps CAP_NET_RAW active, enabling compromised containers to craft raw ICMP/ARP spoofing or DNS poisoning packets across shared cluster CNI bridges! Always drop ALL explicitly (--cap-drop=ALL).
  3. Writing allowPrivilegeEscalation Left Default true Alongside --cap-drop=ALL: Without allowPrivilegeEscalation: false (PR_SET_NO_NEW_PRIVS), SUID host/base-image binaries inside the container image could still raise effective privileges during execve(). Always enforce no-new-privileges.
  4. Blocking Unseen libc Upgrade Syscalls With SCMP_ACT_KILL Without 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 under SIGSYS if a brittle custom Seccomp profile wasn't captured under load or fails with ERRNO grace. Test custom profiles thoroughly in SCMP_ACT_LOG mode first!
Reflect before revealing the guide

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 0 authority and why CAP_SYS_ADMIN / CAP_NET_RAW must be dropped.
  • Configure no-new-privileges, capabilities.drop: ["ALL"], non-root UID, and readOnlyRootFilesystem safely in Docker and Kubernetes.
  • Trace how Seccomp-BPF intercepts syscalls before kernel execution and compare SCMP_ACT_ERRNO, SCMP_ACT_LOG, and SCMP_ACT_KILL_PROCESS.
  • Avoid --privileged and docker.sock anti-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.

Prerequisites & Related Concepts (2)

Private notes

0 words
Recommended Free Track
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.