Sub topic 2
The RBAC Model: Additive, Deny-by-Default Permissions
This chapter assumes you know basic Kubernetes objects (pods, namespaces, secrets), can apply YAML with kubectl, and understand that the API server exposes resources and verbs over REST. It builds the working model that the later chapters on Roles, bindings, and service accounts rely on.
Two properties to remember
Role-based access control (RBAC) is the authorizer most clusters use to decide whether an already-authenticated request is allowed. It has two properties that shape everything else.
- Deny by default. If no rule allows a request, the request is rejected. You never write a rule that says "block this."
- Additive. Permissions only accumulate. A subject's effective access is the union of every rule reachable through every binding that names it. No rule can subtract from another.
The practical consequence is that you cannot grant broad access and then carve out an exception. To keep a user away from secrets, you must make sure that no binding gives them secrets access.
The four objects
RBAC is built from four API objects in the rbac.authorization.k8s.io/v1 group. Two define permissions, and two attach them to subjects.
| Object | Scope | Purpose |
|---|---|---|
| Role | One namespace | Lists allowed actions on resources in that namespace |
| ClusterRole | Cluster-wide | Lists allowed actions, usable cluster-wide or as a reusable template |
| RoleBinding | One namespace | Grants a Role or ClusterRole to subjects within that namespace |
| ClusterRoleBinding | Cluster-wide | Grants a ClusterRole to subjects in every namespace |
A subject is the identity receiving the permissions: a user, a group, or a service account. A rule names API groups, resources, and verbs. Roles hold rules, and bindings connect Roles to subjects.
A worked example of additivity
Suppose the user jane is bound to two roles in the default namespace.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: configmap-reader
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: jane-pods
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: jane-configmaps
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: configmap-reader
apiGroup: rbac.authorization.k8s.ioJane can now list pods and list config maps in default. She cannot delete pods, read secrets, or do anything in other namespaces, because no rule grants those actions.
Common errors
- Expecting a deny rule. RBAC has none. If someone has too much access, find the binding that grants it and remove or narrow it.
- Forgetting that access is a union. Fixing one over-broad Role does not help if another binding still grants the same access through a different path.
- Confusing 401 and 403. A 401 means authentication failed. A 403
Forbiddenmeans the user was identified but no rule allowed the action. - Assuming a binding's namespace limits a ClusterRole's rules. A RoleBinding that references a ClusterRole limits its effect to the binding's namespace. A ClusterRoleBinding applies it everywhere.
Exercise
A user is bound to Role A, which allows reading pods, and Role B, which allows reading secrets, both in namespace dev. You want to stop the user from reading secrets without touching Role B. Can you add a Role with a deny rule for secrets? What should you do instead?
Show answer
No. RBAC has only allow rules, and permissions are the union of all bound roles. Remove the RoleBinding that grants Role B to the user, or edit Role B so it no longer grants secrets access. Also check that no other binding gives the user secrets access.