Role-Based Access Control (RBAC) Fundamentals
What you'll learn: How Kubernetes uses Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings to enforce least privilege access across your cluster.
The Core Idea
After authenticating to the Kubernetes API Server, users and service accounts need permissions to perform actions. RBAC answers "what can you do?" by defining roles (sets of permissions) and bindings (who gets those roles).
Think of it like a hotel: authentication is proving you're a guest, but RBAC determines whether you can access the pool, gym, or penthouse suite.
The Four RBAC Primitives
Role and ClusterRole
Roles define permissions within a specific namespace—like "can read Pods in the dev namespace." ClusterRoles work across the entire cluster or for cluster-wide resources (like nodes).
Both specify verbs (get, list, create, delete) on resources (Pods, Secrets, Services).
RoleBinding and ClusterRoleBinding
These attach roles to subjects (users, groups, or service accounts).
- RoleBinding grants a Role's permissions within one namespace
- ClusterRoleBinding grants a ClusterRole's permissions cluster-wide
Least Privilege in Action
RBAC lets you implement least privilege by:
- Granting only necessary verbs (read-only users get
get/list, notdelete) - Scoping to specific namespaces when possible
- Avoiding cluster-admin unless absolutely required
- Creating service accounts per application with tailored permissions
For example, a monitoring service account might have a ClusterRole to get and list Pods everywhere, but no create or delete permissions.
Why This Matters for Container Security
Without proper RBAC, a compromised container with a powerful service account token can pivot to control the entire cluster—reading secrets, deploying malicious workloads, or modifying security policies.
Key Takeaway: RBAC enforces least privilege by separating permission definitions (Roles/ClusterRoles) from assignments (RoleBindings/ClusterRoleBindings), ensuring each identity has only the access it needs within defined scopes.