Course contentsShow
← Cloud and Infrastructure
Lesson 1386 of 2,98928. Kubernetes SecurityFree lesson

Aggregated ClusterRoles

Learn how ClusterRoles can aggregate permissions from other ClusterRoles using labels.

Aggregated ClusterRoles

What you'll learn: How to build composite ClusterRoles by aggregating permissions from multiple labeled ClusterRoles automatically.

The Core Idea

An aggregated ClusterRole is a special ClusterRole that doesn't define its own rules directly. Instead, it automatically collects and combines permissions from other ClusterRoles based on label selectors. When any ClusterRole matching the selector is created, updated, or deleted, Kubernetes automatically updates the aggregated ClusterRole's permissions.

Think of it like a smart playlist that automatically includes songs matching certain criteria—you don't manually add each song; the playlist updates itself when new matching songs appear.

How It Works

You define an aggregated ClusterRole using the aggregationRule field with a clusterRoleSelectors list. Kubernetes watches for ClusterRoles whose labels match your selectors and merges all their rules together.

Why Use Aggregation?

This pattern is powerful for:

  • Extensibility: Add-ons can extend existing permission sets without modifying core ClusterRoles
  • Modularity: Break complex permissions into manageable, labeled pieces
  • Maintainability: Update permissions by adding/removing labeled ClusterRoles rather than editing monolithic rules

Real-World Pattern

Kubernetes itself uses this for built-in roles like admin, edit, and view. For example, the edit ClusterRole aggregates all ClusterRoles labeled with rbac.authorization.k8s.io/aggregate-to-edit: "true". When you install a CustomResourceDefinition, you can create a companion ClusterRole with this label, and users with edit automatically get those new permissions—no manual updates needed.

Key Takeaway: Aggregated ClusterRoles use label selectors to automatically combine permissions from multiple ClusterRoles, enabling modular and extensible RBAC configurations without manual rule management.