Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Auditing Kubernetes cluster RBAC configurations to identify overly permissive roles, wildcard permissions, dangerous ClusterRoleBindings, service account abuse, and privilege escalation paths using kubectl, rbac-tool, KubiScan, and Kubeaudit.
.claude/skills/auditing-kubernetes-cluster-rbac/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | — | — |
| case-16 | ✗→✓ | ▲ Improved | — | — |
| case-12 | ✗→✓ | ▲ Improved | — | — |
| case-13 | ✗→✓ | ▲ Improved | — | — |
| case-09 | ✗→✓ | ▲ Improved | — | — |
Do not use for network policy auditing (use Cilium or Calico network policy tools), for container image scanning (use Trivy or Grype), or for runtime security monitoring (use Falco or Sysdig Secure).
kubectl krew install rbac-tool or binary from GitHub)pip install kubiscan)brew install kubeaudit or from GitHub releases)Identify roles with wildcard permissions, secret access, pod exec, or escalation capabilities.
bash# List all ClusterRoles with wildcard verb access kubectl get clusterroles -o json | python3 -c " import json, sys data = json.load(sys.stdin) for role in data['items']: name = role['metadata']['name'] for rule in role.get('rules', []): verbs = rule.get('verbs', []) resources = rule.get('resources', []) if '*' in verbs or '*' in resources: print(f'ClusterRole: {name}') print(f' Verbs: {verbs}') print(f' Resources: {resources}') print(f' API Groups: {rule.get(\"apiGroups\", [])}') print() " # Find roles that can read secrets kubectl get clusterroles -o json | python3 -c " import json, sys data = json.load(sys.stdin) for role in data['items']: name = role['metadata']['name'] for rule in role.get('rules', []): resources = rule.get('resources', []) verbs = rule.get('verbs', []) if ('secrets' in resources or '*' in resources) and ('get' in verbs or 'list' in verbs or '*' in verbs): if not name.startswith('system:'): print(f'ClusterRole: {name} -> can access secrets (verbs: {verbs})') " # Find roles with pod/exec permissions (container escape risk) kubectl get clusterroles -o json | python3 -c " import json, sys data = json.load(sys.stdin) for role in data['items']: name = role['metadata']['name'] for rule in role.get('rules', []): resources = rule.get('resources', []) if 'pods/exec' in resources or 'pods/*' in resources: print(f'ClusterRole: {name} -> has pods/exec access') "
Review bindings to identify who has elevated access and detect overly broad group assignments.
bash# List all ClusterRoleBindings with the subjects kubectl get clusterrolebindings -o json | python3 -c " import json, sys data = json.load(sys.stdin) for binding in data['items']: name = binding['metadata']['name'] role = binding['roleRef']['name'] subjects = binding.get('subjects', []) for subject in subjects: kind = subject.get('kind', '') subj_name = subject.get('name', '') ns = subject.get('namespace', 'cluster-wide') print(f'{name} -> Role: {role} | {kind}: {subj_name} ({ns})') " | sort # Find bindings to cluster-admin kubectl get clusterrolebindings -o json | python3 -c " import json, sys data = json.load(sys.stdin) for binding in data['items']: if binding['roleRef']['name'] == 'cluster-admin': print(f\"Binding: {binding['metadata']['name']}\") for subject in binding.get('subjects', []): print(f\" {subject.get('kind')}: {subject.get('name')} (ns: {subject.get('namespace', 'N/A')})\") " # Find bindings granting access to all authenticated users kubectl get clusterrolebindings -o json | python3 -c " import json, sys data = json.load(sys.stdin) for binding in data['items']: for subject in binding.get('subjects', []): if subject.get('name') in ['system:authenticated', 'system:unauthenticated']: print(f\"WARNING: {binding['metadata']['name']} grants {binding['roleRef']['name']} to {subject['name']}\") "
Use rbac-tool for automated RBAC analysis including who-can queries and policy generation.
bash# Who can get secrets across all namespaces kubectl rbac-tool who-can get secrets # Who can create pods (potential for container escape) kubectl rbac-tool who-can create pods # Who can exec into pods kubectl rbac-tool who-can create pods/exec # Who can escalate privileges (bind/escalate verbs) kubectl rbac-tool who-can bind clusterroles kubectl rbac-tool who-can escalate clusterroles # Generate RBAC policy report kubectl rbac-tool analysis # Visualize RBAC relationships kubectl rbac-tool viz --outformat dot > rbac-graph.dot dot -Tpng rbac-graph.dot -o rbac-graph.png
Use KubiScan to automatically identify risky service accounts, pods, and RBAC configurations.
bash# Run KubiScan to find risky roles python3 -m kubiscan -rroles # List risky Roles python3 -m kubiscan -rcr # List risky ClusterRoles python3 -m kubiscan -rrb # List risky RoleBindings python3 -m kubiscan -rcrb # List risky ClusterRoleBindings # Find risky service accounts python3 -m kubiscan -rs # Risky service accounts # Find pods running with risky service accounts python3 -m kubiscan -rp # Risky pods # Check for privilege escalation paths python3 -m kubiscan -pe # Privilege escalation vectors # Generate full report python3 -m kubiscan -a # All checks
Check for unnecessary service account token mounts that could enable lateral movement from compromised pods.
bash# Find pods with automounted service account tokens kubectl get pods --all-namespaces -o json | python3 -c " import json, sys data = json.load(sys.stdin) for pod in data['items']: name = pod['metadata']['name'] ns = pod['metadata']['namespace'] sa = pod['spec'].get('serviceAccountName', 'default') automount = pod['spec'].get('automountServiceAccountToken', True) if automount and sa != 'default': print(f'{ns}/{name} -> SA: {sa} (token auto-mounted)') " # Find service accounts with non-default token secrets kubectl get serviceaccounts --all-namespaces -o json | python3 -c " import json, sys data = json.load(sys.stdin) for sa in data['items']: name = sa['metadata']['name'] ns = sa['metadata']['namespace'] secrets = sa.get('secrets', []) if name != 'default' and len(secrets) > 0: print(f'{ns}/{name}: {len(secrets)} secret(s) bound') " # Check for pods running as privileged or with host access kubectl get pods --all-namespaces -o json | python3 -c " import json, sys data = json.load(sys.stdin) for pod in data['items']: name = pod['metadata']['name'] ns = pod['metadata']['namespace'] for container in pod['spec'].get('containers', []): sc = container.get('securityContext', {}) if sc.get('privileged', False) or sc.get('runAsUser', 1) == 0: print(f'RISK: {ns}/{name}/{container[\"name\"]} - privileged={sc.get(\"privileged\",False)} runAsRoot={sc.get(\"runAsUser\",\"not set\")==0}') "
Execute Kubeaudit for comprehensive security checks including RBAC-related findings.
bash# Run all kubeaudit checks kubeaudit all --kubeconfig ~/.kube/config # Run specific RBAC-related checks kubeaudit privesc # Check for allowPrivilegeEscalation kubeaudit rootfs # Check for readOnlyRootFilesystem kubeaudit nonroot # Check for runAsNonRoot kubeaudit capabilities # Check for dangerous capabilities # Output as JSON for processing kubeaudit all --kubeconfig ~/.kube/config -f json > kubeaudit-results.json
| Term | Definition | |------|------------| | RBAC | Role-Based Access Control in Kubernetes, a method for regulating access to cluster resources based on the roles of individual users or service accounts | | ClusterRole | Cluster-wide role definition that specifies permissions (verbs on resources) applicable across all namespaces | | ClusterRoleBinding | Associates a ClusterRole with subjects (users, groups, service accounts) at the cluster scope | | Service Account | Identity associated with pods for authenticating to the Kubernetes API server, automatically mounted unless disabled | | automountServiceAccountToken | Pod spec field controlling whether the service account token is automatically mounted into the pod filesystem | | Privilege Escalation | RBAC verbs (bind, escalate, impersonate) that allow a user to grant themselves or others elevated permissions |
Context: A shared EKS cluster serves four development teams. RBAC was configured during initial setup but has not been reviewed in 12 months. Teams report being able to access other teams' namespaces.
Approach:
kubectl rbac-tool who-can get secrets to find subjects that can read secrets across namespacesedit to system:authenticated, giving all users write access cluster-widePitfalls: Removing ClusterRoleBindings can break CI/CD pipelines and operators that rely on cluster-wide access. Always audit which workloads use the bindings before removing them. EKS maps IAM roles to Kubernetes groups via aws-auth ConfigMap, so RBAC changes must be coordinated with IAM role mappings.
Kubernetes RBAC Audit Report
===============================
Cluster: production-eks (EKS 1.28)
Audit Date: 2026-02-23
Namespaces: 12
RBAC INVENTORY:
ClusterRoles: 48 (18 custom, 30 system)
ClusterRoleBindings: 32 (12 custom, 20 system)
Roles (namespaced): 24
RoleBindings (namespaced): 36
Service Accounts: 67
CRITICAL FINDINGS:
[RBAC-001] ClusterRoleBinding Grants edit to system:authenticated
Binding: authenticated-edit
Effect: ALL authenticated users have edit access across ALL namespaces
Risk: Any user can modify resources in any namespace
Remediation: Replace with namespace-scoped RoleBindings per team
[RBAC-002] Custom ClusterRole with Wildcard Permissions
ClusterRole: developer-admin
Rules: verbs=["*"], resources=["*"], apiGroups=["*"]
Bindings: 4 users via developer-admin-binding
Risk: Equivalent to cluster-admin without the name
Remediation: Scope to specific resources and verbs needed
SUMMARY:
Principals with cluster-admin: 6 (recommended: <= 3)
Roles with wildcard permissions: 4
Service accounts with secret access: 12
Pods with auto-mounted tokens: 45 / 67
Privileged containers: 8| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +23 percentage points is the difference between those two pass rates over the 22 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.