Role-Based Access Control (RBAC) is the modern standard for Kubernetes authorization. It replaces legacy ABAC with four declarative API objects — Role, ClusterRole, RoleBinding, and ClusterRoleBinding — that grant fine-grained permissions to users, groups, and ServiceAccounts.Source: CKA Day 22Source: CKA Day 23Source: CKA Day 24Source: CKA Day 25
The Four RBAC Objects
Object
Scope
Purpose
Role
Namespace
Defines a set of permissions (rules) within a single Namespace
ClusterRole
Cluster-wide
Defines a set of permissions across all Namespaces or on cluster-scoped resources
RoleBinding
Namespace
Binds a Role (or ClusterRole) to subjects within a single Namespace
ClusterRoleBinding
Cluster-wide
Binds a ClusterRole to subjects across the entire cluster
A critical distinction: ClusterRoles can be bound with RoleBindings to grant cluster-level permissions inside a single Namespace. However, Roles cannot be bound with ClusterRoleBindings — a ClusterRoleBinding requires a ClusterRole.
API Groups: Core vs Named — Every Kubernetes resource belongs to an API group. The “core” group (e.g., v1 for Pods, Services, ConfigMaps) has no group suffix and is referenced in RBAC rules as "" (empty string). Named groups include apps (Deployments, ReplicaSets), rbac.authorization.k8s.io (Roles, Bindings), networking.k8s.io (Ingress, NetworkPolicies), and batch (Jobs, CronJobs). When writing a Role, always specify the correct apiGroups field — a blank value targets only core resources, not Deployments or other named-group objects. Source: CKA Day 23
Wildcard caution:verbs: ["*"] and resources: ["*"] grant broad permissions. In production, enumerate exact verbs and resources.
Subjects: Who Gets Access
A subject can be one of three kinds:
Kind
Example
Use Case
User
name: alice
Human operators authenticated via client certs or OIDC
Group
name: developers
OIDC groups or certificate Organization fields
ServiceAccount
name: prometheus, namespace: monitoring
In-cluster workloads that call the API server
ServiceAccount namespace trap: When binding a ServiceAccount, you must specify its Namespace in the subjects block, even if the Binding is in the same Namespace. Source: CKA Day 22
Built-in ClusterRoles
Kubernetes ships with several default ClusterRoles:
ClusterRole
Purpose
cluster-admin
Full control over every resource in the cluster
admin
Full control within a Namespace, including RBAC management
edit
Read/write access to most namespace resources (cannot manage RBAC)
view
Read-only access to most namespace resources
These are designed to be bound with RoleBindings for namespace-level delegation or ClusterRoleBindings for cluster-wide access.
A common CKA exam pattern: granting a user the ability to create Namespaces requires a ClusterRole with create on namespaces, bound via ClusterRoleBinding. Source: CKA Day 22
ClusterRole Deep-Dive
Non-Resource URLs
ClusterRoles uniquely support permissions on API server paths that do not map to Kubernetes objects. This is essential for health probes and metrics scraping:
Important:nonResourceURLs can only appear in ClusterRoles, not Roles. They are typically bound with ClusterRoleBindings to monitoring ServiceAccounts. Source: CKA Day 24
ClusterRole Aggregation Rules
Kubernetes supports aggregated ClusterRoles that dynamically combine rules from other ClusterRoles matching a label selector. This is how the built-in admin, edit, and view roles are composed:
apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: aggregated-monitoring labels: rbac.example.com/aggregate-to-monitoring: "true"aggregationRule: clusterRoleSelectors: - matchLabels: rbac.example.com/aggregate-to-monitoring: "true"rules: [] # Populated automatically by the controller
Any ClusterRole with the matching label will have its rules merged into the aggregated role. This pattern is used by Helm charts and operators to extend default roles without modifying them. Source: CKA Day 24
The RoleBinding + ClusterRole Pattern
The most flexible and DRY pattern in Kubernetes RBAC is binding a ClusterRole with a RoleBinding. This grants cluster-level permissions (as defined in the ClusterRole) but restricts them to a single Namespace:
apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: dev-edit namespace: devsubjects:- kind: User name: alice apiGroup: rbac.authorization.k8s.ioroleRef: kind: ClusterRole name: edit apiGroup: rbac.authorization.k8s.io
Pattern
Binding
Role Type
Scope of Permissions
Role + RoleBinding
RoleBinding
Role
One Namespace
ClusterRole + RoleBinding
RoleBinding
ClusterRole
One Namespace (the Binding’s namespace)
ClusterRole + ClusterRoleBinding
ClusterRoleBinding
ClusterRole
Entire cluster
Production use case: Define team permissions once in a custom ClusterRole, then create a RoleBinding in each team’s Namespace. This avoids duplicating Role YAML across namespaces while maintaining isolation. Source: CKA Day 24
Critical restriction: A RoleBinding can reference a ClusterRole, but a ClusterRoleBinding cannot reference a Role. ClusterRoleBindings always require ClusterRoles.
Imperative RBAC Generation
For exam speed, generate roles and bindings without hand-editing YAML:
Namespace-Scoped (Role + RoleBinding)
# Create a Role imperativelykubectl create role pod-reader --verb=get,list,watch --resource=pods --dry-run=client -o yaml# Create a RoleBinding imperativelykubectl create rolebinding read-pods --role=pod-reader --user=krishna --dry-run=client -o yaml# Bind a ClusterRole to a namespace (common for admin/edit/view delegation)kubectl create rolebinding dev-edit --clusterrole=edit --user=dev1 --namespace=default --dry-run=client -o yaml
Exam trap:kubectl create rolebinding requires --role for Roles and --clusterrole for ClusterRoles. Mixing them produces an invalid binding. Similarly, kubectl create clusterrolebinding only accepts --clusterrole; using --role errors because ClusterRoleBindings must reference ClusterRoles. Source: CKA Day 23Source: CKA Day 24
Testing and Debugging Permissions
kubectl auth can-i
The fastest way to verify RBAC without switching users is impersonation:
# Check if user "krishna" can get pods in a namespacekubectl auth can-i get pods --as krishna --namespace default# Check if user can create deployments (useful after editing a Role)kubectl auth can-i create deployments --as krishna --namespace default# Check cluster-scoped permissions (omit --namespace for cluster-wide resources)kubectl auth can-i list nodes --as alicekubectl auth can-i get persistentvolumes --as alicekubectl auth can-i create namespaces --as alice# List all permissions for the current userkubectl auth can-i --list# List all permissions for a specific userkubectl auth can-i --list --as alice
Cluster admin advantage: Users with impersonate rights (e.g., cluster-admin) can test any user’s permissions without logging in as them. This is the standard CKA exam debugging pattern. For cluster-scoped checks, omit the --namespace flag to verify true cluster-wide access. Source: CKA Day 23Source: CKA Day 24
Counting RBAC Objects (Exam Task Pattern)
When the exam asks “how many roles exist in the cluster?”, suppress headers and count lines:
kubectl get roles --no-headers --all-namespaces | wc -lkubectl get rolebindings --no-headers --all-namespaces | wc -l
Inspecting Role and Binding Details
# Describe a Role to see its ruleskubectl describe role pod-reader --namespace default# Describe a RoleBinding to see which subjects are boundkubectl describe rolebinding read-pods --namespace default# List all bindings referencing a specific rolekubectl get rolebindings -o json | jq '.items[] | select(.roleRef.name=="pod-reader")'
CKA Speed Patterns
Namespace-Scoped
Generate manifest:kubectl create role pod-reader --verb=get,list,watch --resource=pods --dry-run=client -o yaml
Exam-style hands-on tasks for this topic. Complete each task before reviewing the solution. Time yourself — CKA tasks average 5–7 minutes.
Task 1: Create a Namespace-Scoped Role
You are asked to create a Role named pod-reader in namespace dev with permissions to get, list, and watch Pods.
Requirements: Use imperative generation; target only core resources.
Verification:kubectl describe role pod-reader -n devSolution:
kubectl create role pod-reader --verb=get,list,watch --resource=pods -n dev --dry-run=client -o yaml | kubectl apply -f -
Task 2: Bind a Role to a User
You are asked to bind the Role pod-reader in namespace dev to user jane.
Requirements: Create a RoleBinding named jane-pod-reader.
Verification:kubectl auth can-i get pods --as jane --namespace devSolution:
kubectl create rolebinding jane-pod-reader --role=pod-reader --user=jane -n dev --dry-run=client -o yaml | kubectl apply -f -kubectl auth can-i get pods --as jane --namespace dev
Task 3: Create a ClusterRole for Nodes
You are asked to create a ClusterRole named node-reader with permissions to get and list nodes.
Requirements: Must be cluster-scoped.
Verification:kubectl describe clusterrole node-readerSolution:
Task 4: Test Permissions with Impersonation
You are asked to verify whether user jane can create Deployments in namespace dev.
Requirements: Do not log in as jane; use impersonation.
Verification: Command should return no (or yes if granted).
Solution:
kubectl auth can-i create deployments --as jane --namespace dev