Kubernetes pentest: RBAC, secrets, admission
Brief
In Kubernetes most escalation is a handful of verbs: list on secrets, create on pods, and escalate, bind or impersonate on RBAC. The first hour finds who holds them, where the secrets are, and whether admission control would stop a privileged pod, all with reads and one dry run that stores nothing.
On this page
- Check first
- Who am I in this cluster and what can I do?
- Which subjects hold cluster-admin or an escalation verb?
- Where are the secrets, and who can read them without printing values?
- Does admission stop a privileged pod?
- The defender sees
- Done when
- Not covered
- Tools
- Related research
- Where this page fits
- Reviewed
- Situation
- A kubeconfig for a review identity the client created for the test, bound to the built-in
viewrole cluster-wide plus read on RBAC objects, whichviewleaves out. That is EKS, AKS, GKE or a self-managed cluster; the commands are the same. Everything here is a read except one server-side dry run, which passes through admission and is never stored, and only in the clusters and namespaces the scope letter names. - Goal
- A cluster map: the review identity's own rights, every subject holding an escalation verb, the workloads that carry secrets in plain view, and the admission level of each namespace.
- Outputs
- Representative examples on placeholder hosts, trimmed to the lines that matter. Not captured from a public fixture yet.
Check first
- The cluster, its provider and version, and which namespaces the letter names.
- The review identity's bindings, so its own rights are known before anything else is read.
- How people and pipelines authenticate: cloud identity, OIDC or static tokens.
- Whether the API server audit log is on; on EKS it stays off until control plane logging enables
audit. - Which admission controls are in place: Pod Security Admission labels, a policy engine, or nothing.
Steps
Who am I in this cluster and what can I do?
kubectl config current-context
kubectl auth whoami
kubectl auth can-i --list --namespace payments
Expected output
$ kubectl auth whoami
ATTRIBUTE VALUE
Username atarus-review
Groups [atarus-reviewers system:authenticated]
$ kubectl auth can-i --list --namespace payments
Resources Non-Resource URLs Resource Names Verbs
*.* [] [] [get list watch] # <- every resource, secrets included
selfsubjectreviews.authentication.k8s.io [] [] [create]
selfsubjectrulesreviews.authorization.k8s.io [] [] [create]
can-i --list asks the API server which rules apply to us in that namespace. A "read-only" role built as get list watch on * is not read-only in any useful sense, because list on secrets returns their contents. The built-in view role leaves secrets out for that reason. When the output looks like the block above, we stop, record it as the first finding, and ask the client to rebind the identity to view before going further.
Negative result. The rules match view plus read on rbac.authorization.k8s.io, and kubectl auth can-i list secrets --all-namespaces answers no.
Fix. Build review and support roles from view, never from a wildcard, and test each new role with kubectl auth can-i --list --as before handing it out.
Which subjects hold cluster-admin or an escalation verb?
kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.roleRef.name == "cluster-admin")
| [.metadata.name, ([.subjects[]? | .kind + ":" + .name] | join(","))] | @tsv'
kubectl get clusterroles,roles -A -o json | jq -r '.items[] | select(.metadata.name | startswith("system:") | not)
| select(any(.rules[]?; any(.verbs[]; . == "*" or . == "escalate" or . == "bind" or . == "impersonate")))
| (.metadata.namespace // "cluster") + "\t" + .metadata.name'
Expected output
cluster-admin Group:system:masters
ci-deploy-admin ServiceAccount:ci-deploy # <- a pipeline's service account holds cluster-admin
cluster cluster-admin
cluster ops-support # <- impersonate: act as any user or group the rule allows
payments payments-dev
These verbs each end at cluster-admin: escalate lets a subject write a role with rights it does not hold, bind lets it grant one, impersonate lets it act as someone else, and a wildcard covers all three. Two more belong on the same list: create on pods, which runs a pod as any service account in the namespace with any secret mounted, and create on pods/exec. We read the bindings for each role found and note every service account that a workload outside the platform team runs as.
Negative result. cluster-admin bound only to system:masters and a named platform group, and no non-system role with those verbs.
Fix. Bind pipelines to namespaced roles that create only the kinds they deploy. Remove impersonate, escalate and bind from everything but the platform team's break-glass role, and review bindings on a schedule.
Where are the secrets, and who can read them without printing values?
kubectl auth can-i list secrets --all-namespaces
kubectl get deploy,statefulset,daemonset -A -o json | jq -r '.items[] | (.metadata.namespace + "/" + .metadata.name) as $w
| .spec.template.spec.containers[].env[]? | select(.value != null)
| select(.name | test("PASS|SECRET|TOKEN|KEY"; "i")) | $w + "\t" + .name'
Expected output
$ kubectl auth can-i list secrets --all-namespaces
no
payments/payments-api DB_PASSWORD # <- a value written into the workload spec, readable by anyone with view
payments/payments-api PAYMENT_PROVIDER_KEY
We never list secret objects, since the API returns their data whatever we print. Instead we read the workloads, which view can see, and print the names of environment variables that hold a literal value and look like a credential. A password written into a deployment is readable by every subject with view, every pipeline that renders the manifest, and the Git history behind it.
Negative result. No rows: credentials reach workloads through secretKeyRef, a mounted secret, or an external secrets operator.
Fix. Move literal values into Secrets or an external secret store, rotate each one found, and keep list and watch on secrets to the controllers that need them.
Does admission stop a privileged pod?
kubectl get namespaces -L pod-security.kubernetes.io/enforce
cat > privileged-test.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata: {name: atarus-admission-test}
spec:
containers:
- name: test
image: registry.example.com/pause:3.9
securityContext: {privileged: true}
EOF
kubectl apply --dry-run=server -n ops-tools -f privileged-test.yaml
Expected output
NAME STATUS AGE ENFORCE
kube-system Active 412d
ops-tools Active 230d # <- no enforce label
payments Active 412d baseline
pod/atarus-admission-test created (server dry run) # <- admission let a privileged pod through; nothing was stored
A server-side dry run passes through authentication, authorization and every admission controller, including policy webhooks that support dry runs, then stops before anything is written. It needs create on pods in that namespace; where the review identity should not hold that, the client runs the same two lines and sends us the result. A privileged pod shares the node's kernel without restriction, which is the step from a namespace to the node.
Negative result. violates PodSecurity "baseline:latest": privileged or a policy engine's denial in every namespace except kube-system.
Fix. Label every namespace with pod-security.kubernetes.io/enforce: baseline at least, restricted where workloads allow it, and set a cluster default in the admission configuration so a new namespace starts enforced.
The defender sees
With the API server audit log on, every request above is an event under atarus-review: create on selfsubjectreviews and selfsubjectrulesreviews for the identity checks, list on roles, bindings and workloads, and a create on pods whose request URI carries dryRun=All. At the Metadata level that is enough to see who read what. A review identity listing every role binding in the cluster is a pattern worth an alert, as is any dry run against a namespace the platform team did not expect. If the client cannot find these events, the missing audit log is the finding, and the pipeline review covers where the deploy identity's own trust comes from.
Done when
The identity and its rights are recorded, every cluster-admin binding and every non-system role with a wildcard, escalate, bind or impersonate verb is listed with its subjects, secret exposure is recorded by name only, and each namespace has its admission result.
Not covered
Container escapes, node and kubelet testing, image and registry review, and the cloud account under the cluster (see the cloud first hour); the outputs shown are representative examples on a placeholder cluster, not captured runs.