Inspect existing ClusterRoles
Count all ClusterRoles in the cluster:ClusterRoles and ClusterRoleBindings are cluster-scoped resources. Use
kubectl get clusterroles and kubectl get clusterrolebindings to list them and kubectl describe to inspect specific objects.Inspect ClusterRoleBindings
Count ClusterRoleBindings:cluster-admin role:
cluster-admin ClusterRoleBinding to see its subjects:
cluster-admin ClusterRole is bound to the system:masters group, granting full privileges to that group.
Be careful when binding
cluster-admin. It grants unrestricted cluster access. Prefer creating minimal ClusterRoles for users that only need specific cluster-scoped permissions.What permissions does the cluster-admin ClusterRole grant?
Describe the cluster-admin ClusterRole to inspect its policy rules:
cluster-admin grants all verbs (*) for all resources and non-resource URLs across the cluster.
Grant node access to user “michelle”
Michelle needs read access to nodes (to inspect and monitor them). First, confirm Michelle does not currently have node-listing permission:get, list, and watch on nodes, and bind it to Michelle.
Create the ClusterRole:
michelle:
Grant storage-related access to Michelle
Michelle needs access to storage resources:PersistentVolumes and StorageClasses. First, confirm the resource names and API groups using kubectl api-resources:
list, create, get, and watch on persistentvolumes and storageclasses:
storage-admin ClusterRole to Michelle:
PersistentVolume and StorageClass) per the permissions granted.
Summary
- ClusterRoles and ClusterRoleBindings are cluster-scoped and control access across the entire cluster.
- Use minimal, purpose-specific ClusterRoles instead of broad roles like
cluster-adminwhen possible. - You can grant a non-privileged user access to specific cluster-scoped resources by creating a ClusterRole and binding it with a ClusterRoleBinding.
- Always verify permissions by attempting actions using
--as <user>.