Skip to main content

Role‑Based Access Control

Why RBAC Was Born

Picture a giant library. Thousands of books, multiple reading rooms, and countless visitors. Without rules, anyone could wander into restricted archives or borrow rare manuscripts. Chaos would follow. Kubernetes faced the same challenge: clusters host sensitive workloads, and not every user or service should have full access.

RBAC (Role‑Based Access Control) was born as the library card system of Kubernetes, ensuring that only authorized users can perform specific actions.


RBAC in Kubernetes

  • Users and Service Accounts: Represent people or applications interacting with the cluster.
  • Roles: Define sets of permissions (verbs like get, list, create, delete).
  • RoleBindings: Attach roles to users or service accounts within a namespace.
  • ClusterRoles and ClusterRoleBindings: Extend permissions across the entire cluster.

Analogy: RBAC is like library cards - some allow reading, some allow borrowing, and some grant access to restricted archives.


Global Context

  • Enterprises: Use RBAC to enforce compliance and prevent unauthorized access.
  • Cloud Providers: Managed Kubernetes services integrate RBAC with cloud IAM systems.
  • Community: RBAC is a universal best practice, taught as the foundation of Kubernetes security.

Hands‑On Exercise

  1. Test Access:
    • As dev-user, try listing pods in dev-team.
    • Reflect: How does RBAC enforce least privilege by limiting actions to only what’s necessary?

Bind the Role to a User:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-pods
  namespace: dev-team
subjects:
- kind: User
  name: dev-user
roleRef:
  kind: Role
  name: pod-reader
  apiGroup: rbac.authorization.k8s.io

Create a Role:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: dev-team
  name: pod-reader
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch"]

The Hacker’s Notebook

  • Roles are rulebooks - defining what actions are allowed.
  • RoleBindings are library cards - granting permissions to users.
  • ClusterRoles extend rulebooks across the entire library (cluster).
  • Lesson for engineers: Don’t give everyone admin rights - use RBAC to enforce boundaries.
  • Hacker’s mindset: Treat RBAC as your guardrails. With it, you can run secure, compliant workloads across teams and tenants.

Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥

Updated on Dec 29, 2025