Kubernetes RBAC Notes
Kubernetes RBAC Notes
With RBAC:
2. Allow only specific actions (e.g., view pods, but not delete
them)
Decision
These providers handle who you are, then Kubernetes uses RBAC to
decide what you can do.
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: dev
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list"]
2. ClusterRole
3. RoleBinding
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: bind-alice
namespace: dev
subjects:
- kind: User
name: alice@example.com
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
4. ClusterRoleBinding
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: admin-binding
subjects:
- kind: User
name: bob@example.com
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
Real-World Example
Scenario: You want to allow a CI/CD pipeline (viaServiceAccount)
to only create and delete Deployments in the dev namespace.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: dev
name: cicd-deploy
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["create", "delete"]
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: bind-cicd-sa
namespace: dev
subjects:
- kind: ServiceAccount
name: cicd-pipeline
namespace: dev
roleRef:
kind: Role
name: cicd-deploy
apiGroup: rbac.authorization.k8s.io
Advantages of RBAC in Kubernetes
Advantage Description
Least Privilege Enforce fine-grained, minimal permissions
Extensible Integrates with Identity Providers
Auditable Easy to track who can do what
Separation of Users, teams, apps, and environments
Concerns isolated
Protects Critical
Avoid accidental damage
Resources
Define and manage using YAML (GitOps-
Declarative
friendly)
Easily restrict users to environments (dev,
Namespace Scoped
staging, prod)
Limitations / Considerations
Limitation Workaround
No built-in user management Use external IdPs
Debugging access issues can
Use kubectl auth can-i
be hard
Complex in large teams Use RBAC generators, policies
Use tools like OPA/Gatekeeper for
Static rules
dynamic policies
RBAC = Authorization framework in K8s