Skip to content

Lesson 6 of 9 · 28m

Security Boundaries, Capabilities, and Escape Paths

Evaluate what actually separates containerized code from the host: capabilities, syscall filtering, LSM policy, mounts, sockets, and user namespaces.

The worst sentence in container security is "it is inside Docker, so it cannot hurt the host." Docker's defaults are useful guardrails, not a force field. Real boundary analysis starts by listing what the containerized process inherits: UID mapping, capabilities, syscalls, mounts, devices, sockets, network reachability, and LSM confinement. Escape usually comes from an excessive grant, not a mystical container-breaking payload.

Root inside is often root outside

Without user-namespace remapping, UID 0 in the container is UID 0 on the host. Docker still drops many capabilities by default, but root remains powerful. Check the effective shape:

docker run --rm alpine:3.20 sh -c 'id; grep Cap /proc/self/status'
docker run --rm --cap-drop ALL --cap-add NET_BIND_SERVICE   -u 10001:10001 alpine:3.20 sh -c 'id; grep Cap /proc/self/status'

Decode capability masks if needed:

capsh --decode=00000000a80425fb

The exact mask matters less than the discipline: grant named capabilities deliberately, never because an application failed to start and someone copied a forum answer.

The dangerous flags are dangerous for a reason

--privileged effectively removes much of the boundary: broad capabilities, device access, weakened LSM confinement, and host-level mutation power. These are usually code words for "we did not identify the actual requirement":

docker run --privileged -v /:/host alpine:3.20 chroot /host

That pattern is close to handing the container the host. Some legitimate system agents need elevated access, but the correct design normally narrows the grant to specific capabilities, devices, mounts, and read/write modes.

Mounts are capability grants

A mount is not just file access; it can be control-plane access. The canonical example is the Docker socket:

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock docker:27-cli   docker ps

Whoever can talk to that socket can usually start a privileged container, mount host paths, and become host root. Treat socket access as host administrator access. The same caution applies to /proc, /sys, /dev, Kubernetes service account tokens, cloud credentials, and writable host configuration directories.

seccomp and LSMs reduce kernel surface

Seccomp filters syscalls. Docker's default profile blocks many dangerous operations while preserving normal application behavior. Custom profiles should be derived from observed application needs, not copied wholesale:

docker run --rm --security-opt seccomp=/opt/seccomp/api.json api:2.4.1

AppArmor or SELinux add mandatory access policy around file and system object access. Check whether they are enforcing before assuming they protect you:

aa-status 2>/dev/null || true
getenforce 2>/dev/null || true
docker info --format '{{json .SecurityOptions}}'

User namespaces are powerful but operationally real

User namespace remapping maps container root to an unprivileged host UID range. It dramatically improves boundary quality, but it complicates bind mounts, volume ownership, image compatibility, and some nested container use cases. Do not enable it casually in one place and blindly in another; test storage, logging, backup, and privileged agent behavior as a system.

Evaluate boundary questions in a fixed order

1. Which host UID is this process really running as?
2. Which capabilities does it hold?
3. Which syscalls does seccomp permit?
4. Which host paths and sockets are mounted, and are they writable?
5. Which devices and network identities are reachable?
6. Which LSM profile applies, and is it enforcing?

Field notes

  • CAP_SYS_ADMIN is close to "new root" in practical exploit terms; treat it with extreme suspicion.
  • Read-only mounts reduce damage but do not compensate for socket or privileged access.
  • Rootless Docker changes the threat model substantially, but networking and storage behavior deserve their own tests.
  • Container breakout risk compounds with kernel exposure: unpatched host kernels are a shared fate.
  • If a security control breaks the app, record which permission it needs. "Turned off hardening" is not a diagnosis.

Was this lesson helpful?

Sign in to rate