RBAC
Roles, ClusterRoles and bindings: how requests are authorized, namespace scoping, escalation prevention, aggregation, and permissions that are secretly admin.
Authentication, users and service accountsLabels, selectors, annotations and namespaces
RBAC
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- RBAC is allow-only. A request is permitted if any rule bound to the user, one of their groups or their ServiceAccount matches its verb, API group, resource (or subresource) and, optionally, resource name. There are no deny rules.
- A Role grants within one namespace. A ClusterRole defines rules usable anywhere. Bound by a RoleBinding it applies in that binding's namespace, and by a ClusterRoleBinding in all namespaces and for cluster-scoped resources.
- You can't grant what you don't hold. The API server rejects a Role or binding that would give permissions the creator lacks, unless they have the escalate or bind verbs.
- Built-in view, edit and admin are aggregated ClusterRoles. A ClusterRole labelled aggregate-to-edit (or view, admin) merges into them, which is how CRDs join the standard roles.
- Some permissions are quietly powerful: creating Pods, reading Secrets, impersonate, escalate, bind, and create on serviceaccounts/token. Treat them like admin.
- kubectl auth can-i, with --as and --list, asks the real authorizer what a subject may do. Use it to check grants instead of reading YAML.
Identity isn’t permission
Authentication turns every request into a username and some groups. The next question is whether that identity may do this thing: list Pods in shop, delete a Deployment, read a Secret. In almost every cluster the answer comes from RBAC, role-based access control, enabled on the API server with --authorization-mode=Node,RBAC.
The core problem RBAC solves is the same as in any multi-person system. Granting permissions person by person is unmanageable, so you name sets of permissions (roles) and attach people and programs to them (bindings). Think of it as a building’s access system: badges are identities, access profiles are roles, and the assignment table links them.
Four objects, two scopes
RBAC has four API kinds:
| Defines rules | Grants them | |
|---|---|---|
| Namespaced | Role |
RoleBinding |
| Cluster-wide | ClusterRole |
ClusterRoleBinding |
A rule names API groups, resources (and subresources like pods/log), optional resourceNames, and verbs: get, list, watch, create, update, patch, delete, deletecollection, plus special ones like impersonate, bind and escalate. A binding names subjects, which are users, groups or ServiceAccounts, and points at one role.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: deployer
namespace: shop
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["shop-config"]
verbs: ["get", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: dev-deployers
namespace: shop
subjects:
- kind: Group
name: dev
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: deployer
apiGroup: rbac.authorization.k8s.io
The scoping rule that confuses people: a ClusterRole bound with a RoleBinding applies only in that RoleBinding’s namespace. That’s how the built-in admin, edit and view ClusterRoles are meant to be used. Define once, grant per namespace. Only a ClusterRoleBinding grants across all namespaces, and only a ClusterRole can cover cluster-scoped resources like Nodes or non-resource URLs like /healthz.
Asking the authorizer
Reading YAML to work out what someone can do is error-prone. kubectl auth can-i asks the real authorizer. With the binding above, impersonating jane in group dev on a lab API server:
create deployments.apps -n shop yes
delete deployments.apps -n shop no
get pods/log -n shop yes
create pods/exec -n shop no
get configmaps/shop-config -n shop yes
get configmaps/other -n shop no
list configmaps -n shop no
get secrets -n shop no
create deployments.apps -n default no
Each line shows a property of the model. Verbs are listed explicitly, so delete isn’t implied by update. Subresources are separate: logs yes, exec no. resourceNames restricts to named objects, which is why list (which has no single name) is denied. RBAC only allows, so anything unmatched is denied, and permissions in shop mean nothing in default. kubectl auth can-i --list -n shop --as=jane --as-group=dev prints the whole effective rule set.
Escalation prevention
If you can create Roles and RoleBindings, why not write yourself a Role with everything? Because the API server checks. I gave jane permission to create Roles and RoleBindings in shop and nothing else new:
$ kubectl -n shop create role secret-reader --verb=get --resource=secrets --as=jane --as-group=dev
Error from server (Forbidden): roles.rbac.authorization.k8s.io "secret-reader" is forbidden:
user "jane" (groups=["dev" "system:authenticated"]) is attempting to grant RBAC permissions not currently held:
{APIGroups:[""], Resources:["secrets"], Verbs:["get"]}
A Role within her own permissions (get,list on pods) was created without complaint. Binding herself to the admin ClusterRole failed the same way, with a list of every permission in admin she lacked, dozens of lines long. The rule, from pkg/registry/rbac: you may create or update a role only if you already hold all its permissions, or have escalate on roles. You may bind a role only if you hold its permissions, or have bind on it. Delegation can never exceed what the delegator has.
Aggregated roles
The default ClusterRoles view, edit and admin aren’t fixed lists. Each has an aggregationRule:
{"clusterRoleSelectors":[{"matchLabels":{"rbac.authorization.k8s.io/aggregate-to-edit":"true"}}]}
A controller merges the rules of every ClusterRole carrying that label into edit. After I applied a ClusterRole for Karpenter’s nodepools with aggregate-to-edit and aggregate-to-admin labels, edit grew to 28 rules, the last one granting nodepools in karpenter.sh. That’s how operators make their custom resources part of the standard roles without anyone editing them.
Permissions that are secretly admin
Some grants look modest and aren’t. From the RBAC good-practices guide:
- create Pods (or any workload: Deployments, Jobs, DaemonSets) in a namespace gives access to every Secret and ServiceAccount there, since a Pod can mount them. Combined with a permissive Pod Security level it can mean the node.
- get/list/watch secrets:
listreturns the contents, not just names. - impersonate users, groups or ServiceAccounts. The built-in
editandadminroles include impersonating ServiceAccounts in their namespace. - escalate, bind, and create on
serviceaccounts/token. - Write access to webhook configurations,
nodes/proxy, orpersistentvolumeswithhostPath.
Habits that keep RBAC sane
- Bind roles to groups from your identity provider, not to individual users.
- Prefer namespaced
RoleBindingsto built-in ClusterRoles. ReserveClusterRoleBindingsfor platform teams and controllers. - Give each workload its own ServiceAccount with exactly the verbs it calls.
- Avoid wildcards (
*) in resources and verbs. They silently grant future resources too. - Audit with
kubectl auth can-i --list --as=..., and with tools that list “who can” for a verb and resource.
About the video
The embed is Anton Putra’s “Kubernetes RBAC Explained”, April 2024, 23 minutes. Its chapters build the model first (decoupling users from permissions, identities, modelling access to resources, granting permissions), then demo four scenarios: Role and RoleBinding in the same namespace, in different namespaces, a ClusterRole with a RoleBinding, and a ClusterRole with a ClusterRoleBinding, plus a tip on writing concise policies. It doesn’t cover escalation prevention or aggregation, which this lesson ran for real. I judged it from chapters and description only, since transcripts couldn’t be fetched. English was judged from its “English (US) original” audio track. That DevOps Guy’s longer 2021 walkthrough is in deeper.
What was run: the Role and RoleBinding, every can-i answer, the escalation rejections, the aggregation rule and the 28-rule edit role are real output from a local Kubernetes v1.37.3 API server, impersonating jane with --as. The escalation logic is in pkg/registry/rbac in the v1.37.3 source. The list of dangerous permissions is from the RBAC good-practices docs, checked 2026-11-28.
Where this fits
RBAC decides who may create a Pod. The next lesson decides what that Pod may do on the node: security contexts and Pod Security Standards.
Check yourself
A ClusterRole grants get on secrets. It is bound to the group dev with a RoleBinding in namespace shop. Can dev read secrets in namespace billing?
No. A RoleBinding limits whatever role it references to its own namespace, so dev reads secrets only in shop. A ClusterRoleBinding would grant it in every namespace.
Jane can create Roles in shop but can't read Secrets. She creates a Role granting get on secrets and binds it to herself. What happens?
The API server rejects the Role with 'attempting to grant RBAC permissions not currently held'. RBAC's escalation check requires the creator to already hold every permission in a Role (or have the escalate verb), and to hold a role's permissions before binding it (or have bind).
Why is permission to create Pods in a namespace close to permission to read all its Secrets?
A Pod can mount any Secret in its namespace as a volume or environment variable, and can run as any ServiceAccount there, so whoever can create Pods can read those Secrets and act with those accounts' permissions.
You install a CRD and want everyone with the edit role to manage its objects. What do you do?
Create a ClusterRole with rules for the CRD's resources and the label rbac.authorization.k8s.io/aggregate-to-edit: "true" (and aggregate-to-admin). The aggregation controller copies its rules into edit and admin.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.