KCSA: Kubernetes Threat Model
16% of the KCSA exam, 7 competencies. Back to the KCSA overview.
Each competency lists what to know and the official documentation to read, then a demo you can run. Demos run on the demo lab, a throwaway kind cluster on your own machine; set it up once before you start.
Kubernetes Trust Boundaries and Data Flow
Section titled “Kubernetes Trust Boundaries and Data Flow”Know
- Boundaries sit between the internet and ingress, workloads and the API server, nodes and the control plane, and containers and their host.
Read
Demo: Follow a request across the boundaries
-
Watch kubectl talk to the API server.
Terminal window kubectl get pods -n kube-system -v=6 2>&1 | grep -E 'Config loaded|GET https' | head -3 -
Each component crosses the boundary with its own identity.
Terminal window docker exec kind-worker sh -c 'cat /var/lib/kubelet/pki/kubelet-client-current.pem' | openssl x509 -noout -subjectdocker exec kind-control-plane grep -E -- '--(kubelet-client-certificate|etcd-certfile)' /etc/kubernetes/manifests/kube-apiserver.yaml
What you should see: kubectl sends HTTPS requests to the API server. The kubelet authenticates as system:node:kind-worker in group system:nodes, and the API server uses separate client certificates to reach kubelets and etcd. Every arrow in the data-flow diagram is a TLS connection with its own credential, and each credential is something to protect.
Persistence
Section titled “Persistence”Know
- Attackers persist with CronJobs, DaemonSets, mutating webhooks, static pods, or stolen long-lived credentials. Audit those object types.
Read
Demo: Hunt for the places an attacker would hide
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-persistkubectl config set-context --current --namespace=kcsa-persist -
Plant three common persistence mechanisms.
Terminal window kubectl create cronjob beacon --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --schedule='*/5 * * * *' -- sh -c 'echo phoning home'kubectl create serviceaccount backdoorkubectl create clusterrolebinding backdoor-admin --clusterrole=cluster-admin --serviceaccount=kcsa-persist:backdoordocker exec kind-worker sh -c 'ls /etc/kubernetes/manifests/' -
Now hunt like a defender.
Terminal window kubectl get cronjobs,daemonsets -Akubectl get clusterrolebindings -o json | jq -r '.items[] | select(.roleRef.name=="cluster-admin") | "\(.metadata.name): \(.subjects // [] | map(.kind + ":" + (.namespace // "") + "/" + .name) | join(", "))"'kubectl get mutatingwebhookconfigurations,validatingwebhookconfigurationsfor n in kind-control-plane kind-worker kind-worker2; do echo "$n:"; docker exec $n ls /etc/kubernetes/manifests/ 2>/dev/null; done
What you should see: The hunt finds the CronJob and the backdoor-admin binding next to the legitimate cluster-admin bindings. Static pod directories on workers should be empty; a manifest there runs with no API object to delete. Webhooks are the subtle one: a mutating webhook can inject a container into every new pod.
Clean up:
kubectl delete clusterrolebinding backdoor-adminkubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-persistDenial of Service
Section titled “Denial of Service”Know
- Unbounded resource use, API request floods, and etcd exhaustion. Quotas, limit ranges, API priority and fairness defend.
Read
Demo: Cap object counts and see API fairness
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-doskubectl config set-context --current --namespace=kcsa-dos -
A quota on object counts, then try to exceed it.
Terminal window kubectl create quota objects --hard=count/configmaps=5,count/secrets=5,pods=5for i in $(seq 1 8); do kubectl create configmap c$i --from-literal=k=v 2>&1 | tail -1; done -
API Priority and Fairness keeps one noisy client from starving the rest.
Terminal window kubectl get prioritylevelconfigurationskubectl get flowschemas | head -12
What you should see: Creation stops at the quota with exceeded quota: objects (the namespace’s own root CA ConfigMap uses one slot). Without limits, a script creating objects in a loop can fill etcd. API Priority and Fairness queues requests by flow so a flood from one client doesn’t block the controllers.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-dosMalicious Code Execution and Compromised Applications in Containers
Section titled “Malicious Code Execution and Compromised Applications in Containers”Know
- Limit the blast radius: non-root, no privilege escalation, read-only filesystem, seccomp, and no service account token unless needed.
Read
Demo: Make a compromised container less useful
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-maliciouskubectl config set-context --current --namespace=kcsa-malicious -
An attacker in a normal container can download and run tools.
Terminal window kubectl run soft --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600kubectl wait --for=condition=Ready pod/soft --timeout=60skubectl exec soft -- sh -c 'cp /bin/busybox /usr/bin/tool && /usr/bin/tool echo dropped a binary' -
Read-only root, non-root user, no capabilities.
Terminal window kubectl run hard --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"securityContext":{"runAsNonRoot":true,"runAsUser":10001},"containers":[{"name":"hard","image":"registry.k8s.io/e2e-test-images/busybox:1.37.0-2","command":["sleep","3600"],"securityContext":{"readOnlyRootFilesystem":true,"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]}}}]}}'kubectl wait --for=condition=Ready pod/hard --timeout=60skubectl exec hard -- sh -c 'cp /bin/busybox /usr/bin/tool' || true -
And find out who can exec into pods at all.
Terminal window kubectl get clusterroles -o json | jq -r '.items[] | select(any(.rules[]?; (.resources // []) | index("pods/exec"))) | .metadata.name'
What you should see: The soft pod lets you drop and run a binary. The hard one fails with Read-only file system. Hardening doesn’t stop the initial exploit; it limits what the attacker can do next. Every role that grants pods/exec is a way in for anyone holding it.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-maliciousAttacker on the Network
Section titled “Attacker on the Network”Know
- Without NetworkPolicies or mTLS, a compromised pod can reach every other pod and often the cloud metadata service.
Read
Demo: Lateral movement on a flat network
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-networkkubectl config set-context --current --namespace=kcsa-network -
A “compromised” pod scans for services in other namespaces through DNS and connects.
Terminal window kubectl run attacker --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 -- sleep 3600kubectl wait --for=condition=Ready pod/attacker --timeout=60skubectl exec attacker -- nslookup kube-dns.kube-system.svc.cluster.localkubectl exec attacker -- nslookup metrics-server.kube-system.svc.cluster.localkubectl exec attacker -- sh -c 'nc -zv -w 2 metrics-server.kube-system.svc.cluster.local 443' -
Traffic between pods is plain unless you add encryption.
Terminal window kubectl create deployment web --image=registry.k8s.io/e2e-test-images/agnhost:2.66.1 -- /agnhost netexec --http-port=8080kubectl expose deployment web --port=8080 && kubectl rollout status deployment/webkubectl exec attacker -- wget -qO- -T 3 'http://web:8080/echo?msg=password=hunter2'; echo
What you should see: DNS answers for any Service in any namespace and the connection opens: there is no boundary by default. The echo travels as plain HTTP that anyone on the path can read. NetworkPolicy limits who can connect; mTLS or WireGuard (see the CKS pod-to-pod encryption demo) protects what is sent.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-networkAccess to Sensitive Data
Section titled “Access to Sensitive Data”Know
- Secrets in etcd, environment variables, logs, and backups. Restrict, encrypt, and audit access.
Read
Demo: Steal Secrets with an over-privileged service account
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-datakubectl config set-context --current --namespace=kcsa-data -
Someone gave the namespace’s default service account read access to Secrets.
Terminal window kubectl create secret generic db --from-literal=password=FromInsideThePodkubectl create rolebinding default-reads-secrets --clusterrole=view --serviceaccount=kcsa-data:defaultkubectl create role secret-reader --verb=get,list --resource=secretskubectl create rolebinding default-secret-reader --role=secret-reader --serviceaccount=kcsa-data:default -
Any pod in the namespace, compromised or not, can now read them.
Terminal window kubectl run thief --rm -i --restart=Never --image=registry.k8s.io/kubectl:v1.37.2 -- get secret db -o go-template='{{.data.password | base64decode}}'; echo -
Fix: remove the binding and stop mounting the token.
Terminal window kubectl delete rolebinding default-secret-readerkubectl patch serviceaccount default -p '{"automountServiceAccountToken":false}'kubectl run thief2 --rm -i --restart=Never --image=registry.k8s.io/kubectl:v1.37.2 -- get secret db
What you should see: The first pod prints the password using nothing but its mounted token. The built-in view role deliberately excludes Secrets, so it was the extra Role that leaked them. After the fix the pod has no token at all, so the in-cluster client has nothing to authenticate with.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-dataPrivilege Escalation
Section titled “Privilege Escalation”Know
- Privileged pods, hostPath mounts,
create podspermissions, and RBAC verbs likeescalate,bind, andimpersonatelead to cluster takeover.
Read
Demo: Create-pod rights become node root
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace kcsa-escalatekubectl config set-context --current --namespace=kcsa-escalate -
A pod that mounts the node and enters its namespaces.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: escapespec:hostPID: truecontainers:- name: shellimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sleep", "3600"]securityContext:privileged: trueEOFkubectl wait --for=condition=Ready pod/escape --timeout=60skubectl exec escape -- nsenter -t 1 -m -u -i -n -p -- sh -c 'hostname; ls /etc/kubernetes' -
The fix is admission, not hope.
Terminal window kubectl delete pod escapekubectl label namespace kcsa-escalate pod-security.kubernetes.io/enforce=baselinekubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: escapespec:hostPID: truecontainers:- name: shellimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sleep", "3600"]securityContext:privileged: trueEOF
What you should see: nsenter into PID 1’s namespaces gives a shell on the node itself: its hostname and its /etc/kubernetes. Anyone allowed to create pods in a namespace without Pod Security enforcement can do this. With baseline enforced the same pod is rejected.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace kcsa-escalateOn this site
Domain and competency names are from the CNCF KCSA curriculum (current curriculum (unversioned)), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.