| name | auditing-kubernetes-rbac-permissions |
| description | Kubernetes Role-Based Access Control (RBAC) auditing systematically reviews roles, cluster roles, bindings, and service account permissions to identify overly permissive access, privilege escalation p |
| domain | cybersecurity |
| subdomain | container-security |
| tags | ["containers","kubernetes","security","RBAC","access-control"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
Auditing Kubernetes RBAC Permissions
Overview
Kubernetes Role-Based Access Control (RBAC) auditing systematically reviews roles, cluster roles, bindings, and service account permissions to identify overly permissive access, privilege escalation paths, and violations of least-privilege principles. Tools like rbac-tool, KubiScan, and rakkess automate discovery of dangerous permission combinations.
Prerequisites
- Kubernetes cluster with RBAC enabled (default since 1.6)
- kubectl with cluster-admin access for full audit
- rbac-tool, rakkess, or KubiScan installed
Core Concepts
RBAC Components
| Resource | Scope | Purpose |
|---|
| Role | Namespace | Grants permissions within a namespace |
| ClusterRole | Cluster | Grants permissions cluster-wide |
| RoleBinding | Namespace | Binds Role/ClusterRole to subjects in namespace |
| ClusterRoleBinding | Cluster | Binds ClusterRole to subjects cluster-wide |
Dangerous Permission Combinations
| Permission | Risk | Impact |
|---|
* on * resources | Critical | Equivalent to cluster-admin |
| create pods | High | Can deploy privileged pods |
| create pods/exec | High | Can exec into any pod |
| get secrets | High | Can read all secrets |
| create clusterrolebindings | Critical | Can escalate to cluster-admin |
| impersonate users | Critical | Can act as any user |
| escalate on roles | Critical | Can grant permissions beyond own |
| bind on roles | High | Can create new role bindings |
Implementation Steps
Step 1: Enumerate All RBAC Resources
kubectl get clusterroles -o name | wc -l
kubectl get clusterroles --no-headers | grep -v "system:"
kubectl get clusterrolebindings -o wide
kubectl get roles -A
kubectl get rolebindings -A -o wide
kubectl get clusterroles,clusterrolebindings,roles,rolebindings -A -o yaml > rbac-export.yaml
Step 2: Identify Wildcard Permissions
kubectl get clusterroles -o json | jq -r '
.items[] |
select(.rules[]? |
(.verbs | index("*")) and
(.resources | index("*"))
) |
.metadata.name'
kubectl get clusterroles -o json | jq -r '
.items[] |
select(.rules[]? |
(.verbs | index("create") or index("*")) and
(.resources | index("pods") or index("*"))
) |
.metadata.name'
kubectl get clusterroles -o json | jq -r '
.items[] |
select(.rules[]? |
(.verbs | index("get") or index("list") or index("*")) and
(.resources | index("secrets") or index("*"))
) |
.metadata.name'
Step 3: Check Service Account Permissions
kubectl get serviceaccounts -A
for ns in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do
echo "=== $ns/default ==="
kubectl auth can-i --list --as=system:serviceaccount:$ns:default 2>/dev/null | grep -v "no"
done
kubectl get clusterrolebindings -o json | jq -r '
.items[] |
select(.roleRef.name == "cluster-admin") |
{binding: .metadata.name, subjects: [.subjects[]? | {kind, name, namespace}]}'
Step 4: Use rbac-tool for Automated Analysis
kubectl krew install rbac-tool
kubectl rbac-tool viz --outformat dot | dot -Tpng > rbac-graph.png
kubectl rbac-tool who-can get secrets -A
kubectl rbac-tool who-can create pods -A
kubectl rbac-tool who-can '*' '*'
kubectl rbac-tool analysis
kubectl rbac-tool auditgen > rbac-audit.yaml
Step 5: Check for Privilege Escalation Paths
kubectl get clusterroles -o json | jq -r '
.items[] |
select(.rules[]? |
(.verbs | index("escalate") or index("bind") or index("impersonate")) and
(.resources | index("clusterroles") or index("roles") or index("clusterrolebindings") or index("rolebindings") or index("users") or index("groups") or index("serviceaccounts"))
) |
.metadata.name'
kubectl get clusterroles -o json | jq -r '
.items[] |
select(.rules[]? |
(.verbs | index("impersonate"))
) |
{name: .metadata.name, rules: .rules}'
Step 6: Audit with KubiScan
pip install kubiscan
kubiscan --risky-roles
kubiscan --risky-clusterroles
kubiscan --risky-subjects
kubiscan --risky-pods
kubiscan --all
Validation Commands
kubectl auth can-i create pods --as=system:serviceaccount:default:myapp
kubectl auth can-i --list --as=developer@example.com
kubescape scan framework nsa --controls-config rbac-controls.json
kubectl auth can-i delete nodes --as=system:serviceaccount:app:web-server
References