RBAC: Who Can Do What
- Model: Role-Based Access Control (additive permissions only).
- Subjects: Users, Groups, and ServiceAccounts.
- Scope: Roles (Namespaced) vs. ClusterRoles (Global).
Kubernetes security follows the Principle of Least Privilege.
0. The "Default Deny" Philosophy
In Kubernetes, permissions are additive only. There are no "Deny" rules.
- Everything starts with Zero permissions.
- You add "Allow" rules via Roles.
- If a user has two Roles, and one allows "Delete" while the other doesn't, the user can delete.
Rule of Thumb: If you don't explicitly grant it, it is forbidden.
1. Namespaces: The Virtual Cluster
A Namespace allows you to partition a single physical cluster into multiple virtual clusters.
Why use them?
- Isolation: Separate
dev,staging, andprodenvironments. - Access Control: Give "Team A" full control over
namespace-abut no access tonamespace-b. - Resource Quotas: Limit how much CPU/RAM a namespace can consume.
Common Namespaces
default: Where things go if you don't specify a namespace.kube-system: System components (API server, DNS, etc.). Don't touch this.kube-public: Auto-readable by everyone (rarely used).
2. Role-Based Access Control (RBAC)
Security in Kubernetes is deny-by-default. No one (User or Pod) can do anything unless they are explicitly granted permission via RBAC.
Interactive RBAC Graph
Visualize the relationship: Subject (User) → RoleBinding → Role → Permissions.
User: alice
User: bob
- Users have no permissions by default.
- Roles define "what" can be done (Verbs) to "which" objects (Resources).
- RoleBindings connect a User to a Role.
Role vs ClusterRole
This distinction trips up everyone.
| Feature | Role | ClusterRole |
|---|---|---|
| Scope | Single Namespace | Entire Cluster |
| Binding | RoleBinding | ClusterRoleBinding |
| Use Case | App Developer, Team Member | Cluster Admin, CI/CD System |
Example Scenarios
Scenario A: "Alice is a developer on Team Frontend"
- Create Namespace
frontend. - Create
Roleinfrontendallowingcreate, get, listonpods, services. - Create
RoleBindinginfrontendconnectingUser: Aliceto thatRole. Result: Alice can manage pods infrontend, but can't seebackendor delete Nodes.
Scenario B: "Bob is the SRE Admin"
- Use built-in
cluster-adminClusterRole. - Create
ClusterRoleBindingconnectingUser: Bobtocluster-admin. Result: Bob can do anything.
Aggregated ClusterRoles
You can combine multiple ClusterRoles into one using labels.
- Use Case: Creating a default "view" role that automatically includes new CRD read permissions when you install a new Operator.
User Impersonation
"Can Alice really delete pods?" You can test permissions without logging in as the user:
kubectl auth can-i delete pods --as alice --as-group developers
Result: yes or no.
💬 Feedback & Comments
Have a question or found a bug? Leave a comment below using your GitHub account.