123DevOps··9 min read

The Kubernetes attack surface: the complete map, from cloud to code

Understand every entry point into a Kubernetes cluster (API server, etcd, kubelet, runtime, pods, tokens, images, network, IMDS, dashboards, and CI/CD) through the 4C model, with a safe, read-only exercise on a kind cluster.

Kubernetes

Nobody protects well what they can’t see. Before talking about hardening, RBAC, or image scanners, it pays to draw the map: where someone can get into a Kubernetes cluster and what they gain once inside. This guide walks through each attack surface, organizes everything with the 4C model, and ends with a read-only exercise, actually run on a kind cluster with Kubernetes 1.37, that you can repeat in your own environment.

The 4C model: Cloud, Cluster, Container, Code

The 4C model, popularized by the Kubernetes documentation, describes security as four concentric layers. Each layer trusts the one outside it: flawless code won’t save a cluster whose etcd is exposed, and a well-configured cluster won’t save a cloud account with leaked credentials.

Layer What it includes Example failure
Cloud Account, VPC network, IAM, metadata service, nodes An IAM key with admin permissions leaked in a repository
Cluster API server, etcd, kubelet, RBAC, admission, add-ons A dashboard exposed to the internet with a powerful ServiceAccount
Container Image, runtime, privileges, capabilities A privileged pod with hostPath: / mounted
Code Application, dependencies, secrets in code An RCE in a library that gives a shell inside the pod

An attacker’s path almost always crosses layers: a flaw in the Code yields a shell in the container; the token mounted in the pod opens the API (Cluster); a privileged pod reaches the node; the node’s metadata service hands over Cloud credentials.

The surfaces, one by one

Control plane: API server and etcd

The API server is the front door: everything goes through it, and whoever has cluster-admin has everything. The risks are a public endpoint with no source restriction, weak authentication, and permissive RBAC. etcd stores the cluster state, including Secrets, which in a cluster without extra configuration are only base64-encoded, not encrypted (see what is etcd). Anyone who reads etcd directly bypasses RBAC entirely.

Nodes: kubelet, runtime, and host

The kubelet exposes an API on port 10250 that lists pods and can run commands in them. With anonymous authentication and AlwaysAllow authorization, it becomes a password-free kubectl exec. The container runtime (containerd, CRI-O) and its socket are another classic target: mounting the socket inside a pod is equivalent to controlling every container on the node. And the host itself (SSH, outdated packages, kernel) is still a Linux server like any other.

Pods with too many privileges

Four PodSpec fields turn a compromised container into a compromised node:

  • privileged: true: the container sees the host’s devices and escapes easily;
  • hostPath: mounts node directories such as /, /var/run, or /etc/kubernetes;
  • hostNetwork, hostPID, and hostIPC: share the host’s namespaces;
  • capabilities such as SYS_ADMIN or NET_ADMIN: chip away at isolation.

Pod Security Admission at the restricted level blocks all of them; cluster hardening shows how to apply it.

Auto-mounted ServiceAccount tokens

By default, every pod gets a token for its ServiceAccount at /var/run/secrets/kubernetes.io/serviceaccount. If the application is breached, the attacker inherits that ServiceAccount’s permissions. Most applications never talk to the Kubernetes API and don’t need that token.

Supply chain and images

An image with a CVE, a latest tag that changes without notice, or a tampered public registry bring hostile code into the cluster through the front door. The CI side is covered in supply chain security with cosign, SBOM, and SLSA; the cluster side in container image supply chain on Kubernetes.

East-west network

Without NetworkPolicy, every pod can talk to every pod, in any namespace. A breached container in the frontend reaches the database, Redis, and internal APIs. See Kubernetes networking for the default-deny pattern.

Cloud metadata (IMDS)

On cloud nodes, the address 169.254.169.254 serves metadata and often temporary credentials for the node’s IAM role. A pod that reaches that address can act in the cloud account with the node’s permissions. On AWS, the general recommendation is to require IMDSv2 with a hop limit that prevents access from pods, and to give each workload its own identity with EKS Pod Identity (or IRSA where Pod Identity isn’t supported). Check the current docs for your provider.

Exposed dashboards and add-ons

Kubernetes Dashboard, Grafana, Prometheus, Argo CD, and similar tools often run with powerful ServiceAccounts. Exposed without authentication, they become a public control panel. Even a “read-only” Prometheus reveals internal names, IPs, and versions.

CI/CD credentials

The pipeline that deploys has, by definition, permission to change the cluster. An admin kubeconfig stored as a CI variable, a token that never expires, or a shared runner are direct shortcuts to cluster-admin.

Risk and mitigation table

Surface Main risk Mitigation Go deeper
API server Broad access with a weak credential Private endpoint, strong authentication, minimal RBAC #14, #15
etcd Reading every Secret mTLS, isolated network, encryption at rest #13
kubelet (10250) Remote exec without authentication Anonymous off, Webhook authorization #13
Runtime and host Escape to the node Immutable nodes, patches, socket never mounted #13
Privileged pods Container becomes root on the node Pod Security restricted #13
Mounted tokens Attacker inherits the ServiceAccount automountServiceAccountToken: false, minimal RBAC #15
Images Malicious or vulnerable code Signing, admission-time verification, digests #16
East-west network Lateral movement Default-deny NetworkPolicy #5
IMDS Cloud credentials IMDSv2, network blocking, per-pod identity #13
Dashboards and add-ons Public control panel No external exposure, SSO, dedicated RBAC #17
CI/CD Stolen deploy credential Short-lived tokens, OIDC, pull-based GitOps #14
All of the above Attacks that leave no trace Audit logs and runtime detection #17, #18

Safe exercise: what a breached pod can see

This exercise is read-only: it exploits nothing, it just shows what an attacker would see. Run it on a lab cluster, such as a local kind cluster.

First, a new ServiceAccount and the list of what it can do:

kubectl create namespace e-surface
kubectl -n e-surface create serviceaccount e-app
kubectl auth can-i --list --as=system:serviceaccount:e-surface:e-app -n e-surface
Resources                                       Non-Resource URLs     Resource Names   Verbs
selfsubjectreviews.authentication.k8s.io        []                    []               [create]
selfsubjectaccessreviews.authorization.k8s.io   []                    []               [create]
selfsubjectrulesreviews.authorization.k8s.io    []                    []               [create]
clustertrustbundles.certificates.k8s.io         []                    []               [get list watch]
                                                [/api/*]              []               [get]
                                                [/version]            []               [get]
...

A brand-new ServiceAccount can do almost nothing: only discover the API and ask about its own permissions. The danger shows up when someone gives it a generous RoleBinding. Now, a pod using that ServiceAccount:

kubectl -n e-surface run e-curious --image=busybox:1.37 --restart=Never \
  --overrides='{"spec":{"serviceAccountName":"e-app"}}' -- sleep 3600
kubectl -n e-surface exec e-curious -- ls /var/run/secrets/kubernetes.io/serviceaccount
ca.crt
namespace
token

The token is there, ready to use. From inside a pod with curl, it authenticates against the API, and RBAC is the only thing standing in the way:

$ curl -s --cacert $SA/ca.crt -H "Authorization: Bearer $(cat $SA/token)" \
    https://kubernetes.default.svc/api/v1/namespaces/e-surface/pods
"message": "pods is forbidden: User \"system:serviceaccount:e-surface:e-app\"
            cannot list resource \"pods\" in API group \"\" in the namespace \"e-surface\"",
"code": 403

In the lab, the projected volume asked for expirationSeconds: 3607, but the decoded token’s exp was a year out, with a warnafter field set one hour ahead. That is the API server extending projected tokens for compatibility with older clients (the --service-account-extend-token-expiration flag, on by default; check the current docs). In other words, a stolen token may live much longer than an hour.

The fix, for workloads that don’t use the API:

apiVersion: v1
kind: Pod
metadata:
  name: e-no-token
  namespace: e-surface
spec:
  serviceAccountName: e-app
  automountServiceAccountToken: false
  containers:
    - name: app
      image: busybox:1.37
      command: ["sleep", "3600"]
$ kubectl -n e-surface exec e-no-token -- ls /var/run/secrets/kubernetes.io/serviceaccount
ls: /var/run/secrets/kubernetes.io/serviceaccount: No such file or directory

You can also turn it off on the ServiceAccount itself with kubectl patch serviceaccount e-app -p '{"automountServiceAccountToken": false}'; in the lab, a new pod created afterward came up with no volume at all. The pod field, when present, takes precedence.

Two extra tests, from the same pod and equally harmless, showed other surfaces well locked down in kind: https://<node-ip>:10250/pods answered 401 Unauthorized (kubelet without anonymous access), and etcd’s port 2379 was reachable from the pod network but rejected the handshake with alert certificate required. Reachable and protected by mTLS are different things: in production, ideally the connection shouldn’t get there at all.

Cleanup:

kubectl delete namespace e-surface

Frameworks to go further

To turn the map into a testing and detection plan, two public resources help structure your thinking: the MITRE ATT&CK for Containers matrix and the OWASP Kubernetes Top 10. Use them as a coverage checklist, matching each technique to its mitigation and to the detection signal you already have.

Checklist

  • API server endpoint private or restricted by source
  • etcd isolated on the network, with mTLS and Secrets encrypted at rest
  • kubelet with anonymous authentication off and Webhook authorization
  • Pod Security restricted (or baseline with documented exceptions) in every application namespace
  • automountServiceAccountToken: false wherever the application doesn’t use the API
  • Default-deny NetworkPolicy and IMDS access blocked for pods
  • Dashboards off the internet and short-lived CI credentials

You don’t eliminate attack surface, you shrink it: every closed door is one less path between an application bug and your cloud account.

Get updates on new posts and stay in the loop!