Auditing Kubernetes RBAC Privilege Escalation
Legal Notice: This skill is for authorized security testing and educational purposes only. Enumerating and exercising RBAC permissions affects a live cluster's access posture. Only test clusters you own or are explicitly authorized in writing to assess.
Overview
Kubernetes Role-Based Access Control (RBAC, MITRE ATT&CK T1078 Valid Accounts) governs what every user and service account may do via Role/ClusterRole rules bound by RoleBinding/ClusterRoleBinding. Because workloads run with a mounted service-account token by default, an attacker who compromises one pod inherits that account's RBAC rights. Over-permissive bindings turn a single compromised pod into a cluster takeover: certain verbs and resources are "RBAC-equivalent to cluster-admin."
Per the Kubernetes "RBAC Good Practices" guidance and Unit 42 research, the dangerous primitives are:
escalate on roles — grant yourself any permission, even ones you do not hold.
bind on clusterroles — create a binding to cluster-admin.
impersonate on users/groups/serviceaccounts — act as any subject including system:masters.
create/update/patch on pods — schedule a privileged pod or mount the node, escaping to the host (T1611).
create on pods/exec, pods/attach, pods/ephemeralcontainers — run code in any existing pod.
get/list/watch on secrets — list returns full secret contents, including other service-account tokens.
create on serviceaccounts/token — mint tokens for more privileged accounts.
update/patch on validatingwebhookconfigurations/mutatingwebhookconfigurations, nodes/proxy, certificatesigningrequests/approval — admission/CSR abuse to cluster-admin.
- Wildcards (
verbs: ["*"], resources: ["*"]) — implicit super-privilege.
This skill systematically enumerates effective permissions for every subject, maps which subjects hold these escalation primitives, and produces remediation evidence. Source: Kubernetes RBAC Good Practices; Unit 42 Kubernetes RBAC research.
When to Use
- During an authorized Kubernetes security assessment or cluster penetration test
- After compromising a pod, to determine what its service-account token can reach
- When reviewing RBAC drift before a production go-live
- When validating least-privilege after a platform migration or Helm rollout
Prerequisites
Objectives
- Inventory all
Role, ClusterRole, RoleBinding, and ClusterRoleBinding objects
- Enumerate effective permissions per subject using
kubectl auth can-i --as
- Identify subjects holding RBAC-equivalent-to-admin primitives
- Trace token-mounting pods to over-privileged service accounts
- Demonstrate (in a lab) one escalation path end-to-end
- Output a prioritized findings report with least-privilege remediation
MITRE ATT&CK Mapping
| Technique ID |
Name |
Tactic |
| T1078 |
Valid Accounts |
Defense Evasion / Persistence / Privilege Escalation |
| T1098 |
Account Manipulation |
Persistence |
| T1528 |
Steal Application Access Token |
Credential Access |
| T1613 |
Container and Resource Discovery |
Discovery |
| T1611 |
Escape to Host |
Privilege Escalation |
Workflow
Step 1: Inventory RBAC Objects
# All roles and bindings, cluster-wide
kubectl get clusterroles,clusterrolebindings -o wide
kubectl get roles,rolebindings --all-namespaces -o wide
# Dump full RBAC for offline analysis
kubectl get clusterroles,clusterrolebindings,roles,rolebindings \
--all-namespaces -o yaml > rbac-dump.yaml
# Who is bound to cluster-admin?
kubectl get clusterrolebindings -o json | \
jq -r '.items[] | select(.roleRef.name=="cluster-admin") |
.metadata.name + " -> " + (.subjects // [] | map(.kind+"/"+.name) | join(","))'
Step 2: Enumerate Effective Permissions per Subject
kubectl auth can-i is the authoritative check because it evaluates the live authorizer (RBAC + webhooks). Use --as to impersonate a subject (requires impersonate rights for the audit identity).
# Full access matrix for a service account
kubectl auth can-i --list \
--as=system:serviceaccount:default:default
# Targeted dangerous-permission probes
kubectl auth can-i create pods --all-namespaces \
--as=system:serviceaccount:dev:builder
kubectl auth can-i get secrets --all-namespaces \
--as=system:serviceaccount:dev:builder
kubectl auth can-i create serviceaccounts/token -n kube-system \
--as=system:serviceaccount:dev:builder
kubectl auth can-i '*' '*' --all-namespaces \
--as=system:serviceaccount:dev:builder
# rakkess full verb x resource matrix for a subject
kubectl access-matrix --as system:serviceaccount:dev:builder
Step 3: Hunt the Escalation Primitives
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: auditing-kubernetes-rbac-privilege-escalation3description: "Audit Kubernetes RBAC privilege escalation. Signals: cloud privilege escalation, IAM privilege escalation, container privilege escalation."4zh-signals: "Auditing Kubernetes RBAC Privilege Escalation 信号:云提权,iam提权,容器提权。"5when-to-use: >-6 Finds over-permissive RBAC roles and service-account token abuse paths in a Kubernetes7 cluster using kubectl auth can-i, rbac-police, kubectl-who-can, and rakkess, tracing which8 subjects can escalate toward cluster-admin. Use when reviewing who can escalate privileges9 in a cluster, hunting exploitable RoleBindings during an authorized review, or validating10 least privilege after an RBAC change. Keywords: RBAC, ClusterRoleBinding, service account11 token, auth can-i, rbac-police, escalate, bind, impersonate. Do not use for designing and12 applying hardened RBAC - use implementing-rbac-hardening-for-kubernetes.13domain: cybersecurity14subdomain: container-security15tags:16- kubernetes17- rbac18- privilege-escalation19- service-account20- least-privilege21- kubectl22- access-control23- attack-paths24version: '1.0'25author: mahipal26license: Apache-2.027nist_csf:28- PR.AA-0529mitre_attack:30- T107831metadata:32 source: https://skillmd.com/skills/dangeroussong/auditing-kubernetes-rbac-privilege-escalation33---3435# Auditing Kubernetes RBAC Privilege Escalation3637> **Legal Notice:** This skill is for authorized security testing and educational purposes only. Enumerating and exercising RBAC permissions affects a live cluster's access posture. Only test clusters you own or are explicitly authorized in writing to assess.3839## Overview4041Kubernetes Role-Based Access Control (RBAC, MITRE ATT&CK T1078 Valid Accounts) governs what every user and service account may do via `Role`/`ClusterRole` rules bound by `RoleBinding`/`ClusterRoleBinding`. Because workloads run with a mounted service-account token by default, an attacker who compromises one pod inherits that account's RBAC rights. Over-permissive bindings turn a single compromised pod into a cluster takeover: certain verbs and resources are "RBAC-equivalent to cluster-admin."4243Per the Kubernetes "RBAC Good Practices" guidance and Unit 42 research, the dangerous primitives are:4445- **`escalate` on roles** — grant yourself any permission, even ones you do not hold.46- **`bind` on clusterroles** — create a binding to `cluster-admin`.47- **`impersonate`** on users/groups/serviceaccounts — act as any subject including `system:masters`.48- **`create`/`update`/`patch` on `pods`** — schedule a privileged pod or mount the node, escaping to the host (T1611).49- **`create` on `pods/exec`, `pods/attach`, `pods/ephemeralcontainers`** — run code in any existing pod.50- **`get`/`list`/`watch` on `secrets`** — list returns full secret contents, including other service-account tokens.51- **`create` on `serviceaccounts/token`** — mint tokens for more privileged accounts.52- **`update`/`patch` on `validatingwebhookconfigurations`/`mutatingwebhookconfigurations`, `nodes/proxy`, `certificatesigningrequests/approval`** — admission/CSR abuse to cluster-admin.53- **Wildcards** (`verbs: ["*"]`, `resources: ["*"]`) — implicit super-privilege.5455This skill systematically enumerates effective permissions for every subject, maps which subjects hold these escalation primitives, and produces remediation evidence. Source: Kubernetes RBAC Good Practices; Unit 42 Kubernetes RBAC research.5657## When to Use5859- During an authorized Kubernetes security assessment or cluster penetration test60- After compromising a pod, to determine what its service-account token can reach61- When reviewing RBAC drift before a production go-live62- When validating least-privilege after a platform migration or Helm rollout6364## Prerequisites6566- `kubectl` configured against the target cluster (your own credentials, or a captured service-account token)67- Read access to RBAC objects (most audits run with a cluster-reader or admin context)68- Audit tooling:69 ```bash70 # rbac-police - find escalation paths (Cymulate)71 curl -L https://github.com/PaloAltoNetworks/rbac-police/releases/latest/download/rbac-police-linux-amd64 -o rbac-police72 chmod +x rbac-police7374 # kubectl-who-can - which subjects can perform an action (Aqua)75 kubectl krew install who-can7677 # rakkess - access matrix of resources x verbs for the current/another subject78 kubectl krew install access-matrix7980 # rbac-lookup - which roles a subject has (FairwindsOps)81 kubectl krew install rbac-lookup82 ```8384## Objectives8586- Inventory all `Role`, `ClusterRole`, `RoleBinding`, and `ClusterRoleBinding` objects87- Enumerate effective permissions per subject using `kubectl auth can-i --as`88- Identify subjects holding RBAC-equivalent-to-admin primitives89- Trace token-mounting pods to over-privileged service accounts90- Demonstrate (in a lab) one escalation path end-to-end91- Output a prioritized findings report with least-privilege remediation9293## MITRE ATT&CK Mapping9495| Technique ID | Name | Tactic |96|--------------|------|--------|97| T1078 | Valid Accounts | Defense Evasion / Persistence / Privilege Escalation |98| T1098 | Account Manipulation | Persistence |99| T1528 | Steal Application Access Token | Credential Access |100| T1613 | Container and Resource Discovery | Discovery |101| T1611 | Escape to Host | Privilege Escalation |102103## Workflow104105### Step 1: Inventory RBAC Objects106107```bash108# All roles and bindings, cluster-wide109kubectl get clusterroles,clusterrolebindings -o wide110kubectl get roles,rolebindings --all-namespaces -o wide111112# Dump full RBAC for offline analysis113kubectl get clusterroles,clusterrolebindings,roles,rolebindings \114 --all-namespaces -o yaml > rbac-dump.yaml115116# Who is bound to cluster-admin?117kubectl get clusterrolebindings -o json | \118 jq -r '.items[] | select(.roleRef.name=="cluster-admin") |119 .metadata.name + " -> " + (.subjects // [] | map(.kind+"/"+.name) | join(","))'120```121122### Step 2: Enumerate Effective Permissions per Subject123124`kubectl auth can-i` is the authoritative check because it evaluates the live authorizer (RBAC + webhooks). Use `--as` to impersonate a subject (requires impersonate rights for the audit identity).125126```bash127# Full access matrix for a service account128kubectl auth can-i --list \129 --as=system:serviceaccount:default:default130131# Targeted dangerous-permission probes132kubectl auth can-i create pods --all-namespaces \133 --as=system:serviceaccount:dev:builder134kubectl auth can-i get secrets --all-namespaces \135 --as=system:serviceaccount:dev:builder136kubectl auth can-i create serviceaccounts/token -n kube-system \137 --as=system:serviceaccount:dev:builder138kubectl auth can-i '*' '*' --all-namespaces \139 --as=system:serviceaccount:dev:builder140141# rakkess full verb x resource matrix for a subject142kubectl access-matrix --as system:serviceaccount:dev:builder143```144145### Step 3: Hunt the Escalation Primitives146147```bash148149> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.