How do container breakout vulnerabilities (dirty cow, runc CVEs) occur and how do you harden container runtime security?
❓ Interview Prompt: Explain container breakout attack vectors — kernel vulnerabilities, privileged containers, mounted docker.sock — and multi-layer hardening strategies.
Container security failures fall into distinct categories, each requiring different mitigations:
Attack Vector 1: Kernel Exploits (e.g., Dirty COW, CVE-2019-5736):
All containers share the host kernel. A kernel vulnerability exploitable from a container process can escalate to host root regardless of container isolation.
Mitigation: Keep host kernel patched. Use gVisor/Kata Containers to introduce a separate user-space kernel layer.
Attack Vector 2: Privileged Containers:
docker run --privileged disables all namespace/cgroup isolation and grants full host kernel capabilities — effectively root on the host.
Mitigation: Never use --privileged. Instead, add only specific capabilities needed (--cap-add NET_ADMIN).
Attack Vector 3: Docker Socket Mount:
Mounting /var/run/docker.sock into a container gives it full Docker API access — equivalent to host root.
Mitigation: Never mount the Docker socket into untrusted containers.
Attack Vector 4: runc CVEs (e.g., CVE-2019-5736):
Vulnerabilities in the runc runtime itself (buffer overflows during container start) allow process escape.
Mitigation: Keep Docker/containerd/runc updated. Use Rootless Mode to reduce blast radius.
Defense-in-Depth Strategy:
readOnlyRootFilesystem: true.Code Implementation Example
# Kubernetes Pod with maximum security hardening
apiVersion: v1
kind: Pod
spec:
# Pod-level security
securityContext:
runAsNonRoot: true
runAsUser: 65534 # nobody user
runAsGroup: 65534
seccompProfile:
type: RuntimeDefault # default seccomp syscall filter
supplementalGroups: []
containers:
- name: app
image: gcr.io/distroless/nodejs20-debian12 # distroless — no shell
securityContext:
allowPrivilegeEscalation: false # blocks setuid/setgid
readOnlyRootFilesystem: true # no writes to /
capabilities:
drop: ["ALL"] # drop ALL linux capabilities
# add: ["NET_BIND_SERVICE"] # only if needed
# Writable tmpfs only for necessary paths
volumeMounts:
- mountPath: /tmp
name: tmp-dir
volumes:
- name: tmp-dir
emptyDir: {} # ephemeral, per-pod, no host persistenceContainer breakouts exploit kernel bugs, privileged mode, or docker.sock access. Defense-in-depth: distroless + non-root + readOnlyRootFS + drop capabilities + seccomp + gVisor for crown jewels.