RBAC Auditing Workflow
Advanced15 min
Audit Role-Based Access Control (RBAC) permissions to identify overly permissive roles and verify least-privilege access.
Prerequisites
- -kubectl configured
- -Cluster admin access
Steps
1
List all ClusterRoles and their rules
View all cluster-level roles and what permissions they grant.
$ kubectl get clusterroles -o custom-columns='NAME:.metadata.name,RULES:.rules[*].verbs'
2
Check what a specific user or service account can do
Test whether a subject has permission to perform specific actions.
$ kubectl auth can-i --list --as=system:serviceaccount:default:my-sa
Use --as to impersonate any user or service account to audit their effective permissions.
3
Find all RoleBindings for a specific subject
See which roles are bound to a specific user or service account.
$ kubectl get rolebindings,clusterrolebindings --all-namespaces -o json | jq -r '.items[] | select(.subjects[]?.name=="my-sa") | .metadata.name + " (" + .metadata.namespace + ")"'
4
Identify cluster-admin bindings
Find all subjects that have cluster-admin access, which should be minimized.
$ kubectl get clusterrolebindings -o json | jq -r '.items[] | select(.roleRef.name=="cluster-admin") | .metadata.name + ": " + (.subjects[]? | .kind + "/" + .name)'
Any subject with cluster-admin has full unrestricted access. Minimize these bindings.
5
Test a specific permission
Check if the current user can perform a specific action.
$ kubectl auth can-i create deployments --namespace=production
Full Script
FAQ
Discussion
Loading comments...