✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes ClusterRole Management

Kubernetes ClusterRole Management defines and controls permissions across a cluster, ensuring secure and efficient access to resources through role-based policies.

Kubernetes ClusterRole Management is the practice of authoring and maintaining ClusterRole objects — the cluster-scoped counterpart to Role that can express permissions over cluster-scoped resources, over non-resource URLs, or over namespaced resources intended to be reused across many namespaces. Because a single ClusterRole can be bound in dozens of different ways throughout a cluster, managing them carries a wider blast radius than managing a namespaced Role, and requires correspondingly more care.


What ClusterRoles Can Express That Roles Cannot

Cluster-Scoped Resources

Resources that have no namespace — Node, PersistentVolume, Namespace itself, ClusterRole and ClusterRoleBinding — can only be granted through a ClusterRole, since a Role is inherently confined to a single namespace and cannot reference objects that exist outside any namespace.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: node-viewer
rules:
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["get", "list", "watch"]

Non-Resource URLs

ClusterRole rules can also grant access to non-resource API paths, such as /healthz or /metrics, using nonResourceURLs instead of resources, which has no equivalent in a namespaced Role.

rules:
- nonResourceURLs: ["/metrics"]
  verbs: ["get"]

The Dual Nature of ClusterRole Binding

Cluster-Wide Grants via ClusterRoleBinding

Binding a ClusterRole with a ClusterRoleBinding grants the specified permissions across every namespace in the cluster, which is appropriate for genuinely cluster-wide responsibilities such as node maintenance, cluster-wide monitoring, or platform administration.

Namespace-Scoped Reuse via RoleBinding

The same ClusterRole can instead be bound with a RoleBinding inside a single namespace, in which case its permissions apply only within that namespace — this is the mechanism that makes the built-in view, edit, and admin roles reusable templates rather than requiring a separate object per namespace.

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: team-edit-access
  namespace: analytics
subjects:
- kind: Group
  name: analytics-team
roleRef:
  kind: ClusterRole
  name: edit
  apiGroup: rbac.authorization.k8s.io

Aggregated ClusterRoles

Composing Permissions by Label Selector

An aggregated ClusterRole declares an aggregationRule matching other ClusterRole objects by label, and the API server automatically merges their rules into the aggregating role's rules field. This is how the built-in admin, edit, and view roles are extended to cover custom resources without modifying the built-in objects.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: view
  labels:
    kubernetes.io/bootstrap-aggregate-to-view: "true"
aggregationRule:
  clusterRoleSelectors:
  - matchLabels:
      rbac.authorization.k8s.io/aggregate-to-view: "true"
rules: []

Any operator installing a custom resource should add a corresponding aggregated ClusterRole with the matching label, so that existing bindings to view, edit, or admin automatically extend to the new resource type.


Governance Practices

Restricting Who Can Create ClusterRoleBindings

Because a ClusterRoleBinding to cluster-admin grants unrestricted cluster access, the permission to create ClusterRole and ClusterRoleBinding objects should itself be tightly restricted, typically to a small platform-administration group, separate from the broader set of users who might manage namespaced Roles.

Escalation Protection

RBAC prevents a subject from creating a ClusterRoleBinding or ClusterRole that grants more than the subject itself already holds, unless explicitly given the escalate verb — a safeguard specifically relevant to ClusterRole management given its cluster-wide reach.

Naming and Discoverability

Because ClusterRole objects are not namespaced, a large cluster can accumulate many of them across teams; consistent naming conventions (a team or product prefix, for instance) and labels indicating ownership make it feasible to audit which team is responsible for which cluster-scoped role.


Auditing ClusterRole Usage

Finding Every Binding to a Role

Because a single ClusterRole may be referenced by many RoleBindings and ClusterRoleBindings scattered across namespaces, auditing its effective reach requires enumerating all bindings cluster-wide and filtering for the role name, rather than inspecting the ClusterRole object in isolation.

kubectl get rolebindings,clusterrolebindings --all-namespaces -o json | \
  jq '.items[] | select(.roleRef.name=="cluster-admin")'

Minimizing cluster-admin Exposure

Regularly listing every subject bound to cluster-admin and justifying each one individually is one of the highest-value periodic reviews in RBAC governance, since it is the single role capable of the broadest possible impact if misused.