Kubernetes Security

From a compromised pod to cluster control, and how to stop it

Kubernetes runs containers across a cluster and is controlled through its API server. If an attacker compromises one application container, the next question is what that pod can reach: other services, cloud metadata, or the API server with a powerful service account. Good defaults contain the damage.

Advanced · 5 steps

Control planeAPI server, controlled by RBAC
Pod identityService account token
IsolationNetwork policies, namespaces
Workload rulesPod Security Standards (restricted)
Escape techniqueT1611 (Escape to Host)
BenchmarkCIS Kubernetes Benchmark

Step by step

  1. Foothold in a pod One vulnerable app container

    An attacker exploits a bug in the web app and can run commands inside its container. They look around: environment variables, mounted files, and the service account token Kubernetes mounts into pods by default.

  2. Ask the API server What can this service account do?

    With the token, the attacker queries the API server. In a well-configured cluster, the web app's service account has no permissions at all, and every request is denied. In a poorly configured one, it might be able to list secrets or create pods.

  3. Move sideways Network policies

    Next the attacker tries to reach the payments database directly. Without network policies, every pod can talk to every other pod. Here a default-deny policy only lets the payments API reach the database, so the connection is dropped.

  4. Try to escape Privileged containers and host mounts

    If the pod ran as privileged or mounted the host filesystem, the attacker could break out to the worker node and every pod on it. The "restricted" Pod Security Standard blocks those settings, so this pod runs as non-root with no extra capabilities.

  5. Layered defaults Each layer limits the blast radius

    Because the token wasn't useful, network policies blocked lateral movement and the pod couldn't escape, the compromise stayed inside one container. Runtime detection alerted on the unusual shell, and the pod was replaced from a clean image while the app bug was fixed.

Best practices

More in Cloud Security.