Kubernetes RBAC Basics
How Role-Based Access Control decides who may do what inside a cluster, so that people and programs get exactly the keys they need and nothing more, explained step by step from zero.
Picture a large office building. There is a main door, a reception desk, a server room, a finance office and a canteen. Now imagine that on the first day everyone is handed one master key that opens every door. The new intern can walk into the finance office. The cleaner can unplug the servers. A visitor can take files from any cabinet. Nothing bad may happen today, but it is only a matter of time.
A Kubernetes cluster is just like that building. It holds your applications, your passwords, your customer data and the machines that run them. Many people and many programs need to work inside it. The question is never “should they get in?” but “which doors should each one be able to open?”. The answer in Kubernetes is called RBAC, short for Role-Based Access Control.
In this guide you will learn what RBAC is, why it exists, the four objects it is built from, how Kubernetes makes a decision each time someone asks to do something, how to design safe permissions, which permissions are secretly dangerous, and how professionals keep access tidy over time. Every new word will be explained the first time it appears.
1The Problem: Everybody Has the Master Key
Before we meet the solution, let us feel the trouble it removes. A safety tool only makes sense once you imagine the accident.
A quick look at Kubernetes
A container is a small sealed box holding a program and everything it needs. Kubernetes is the free, open-source system that starts, stops, moves and repairs thousands of these boxes across many computers. A group of computers managed together is a cluster. Containers run inside small wrappers called Pods. Everything you do to a cluster, such as creating a Pod or reading a password, is done by sending a request to its front door, the API server.
Why unlimited access is dangerous
If every person and every program could ask the API server for anything, small mistakes and small attacks would become huge.
- A developer who only meant to look at one app’s Pods accidentally deletes the whole production database.
- A tool that only needs to read the list of Pods is hacked, and the attacker uses its unlimited power to steal every password in the cluster.
- A former employee’s account still works months after they left, and it can do everything.
- Two teams share one cluster, and one team can read the other team’s private data.
The fix is a rule that has been used in security for decades: the principle of least privilege. It means every person and every program should have only the permissions they need to do their job, and no more.
A hotel does not give every guest a master key. A guest’s key card opens only their own room, the gym and the front door. A cleaner’s card opens the rooms they clean but not the safe. The manager’s card opens more. RBAC is the hotel’s key card system for your cluster.
RBAC is not about distrusting people. It is about limiting the damage that any single mistake or any single stolen password can cause.
2Building Blocks You Need First
Eight small ideas carry this whole topic. Learn them once and everything else will feel natural.
API Server
The front door and front desk of the cluster. Every request from every person and every program goes through it.
Resource
A kind of thing stored in the cluster, such as Pods, Secrets, Deployments or Nodes. Permissions are given per kind of resource.
Verb
An action you can perform on a resource: look at one, list them all, create, change or delete. Permissions are given per verb.
Namespace
A named room inside a cluster that keeps one team’s things apart from another’s. Many permissions can be limited to a single room.
Subject
The one asking. It can be a person (a user), a group of people, or a program (a service account).
Service account
An identity made for a program running inside the cluster, so that the program can talk to the API server with its own limited permissions.
Authentication
Proving who you are, like showing your ID card. The cluster asks: “Who is this?”
Authorization
Deciding what a known person may do, like checking the list at the door. The cluster asks: “Is this person allowed to do that?” RBAC lives here.
Think of a library. Resources are the kinds of items: books, rare manuscripts, the cash box. Verbs are actions: read, borrow, write in, remove. Namespaces are the different sections. Subjects are the members and staff. RBAC is the rulebook that says which member may do which action on which items in which section.
3The Three Gates Every Request Passes
RBAC is only one gate in a row of three. Knowing the other two prevents a lot of confusion.
When you send a request to the API server, it does not simply obey. The request must pass three gates, one after another. If it fails any gate, it stops there.
| Gate | Question asked | Example of failure | Result |
|---|---|---|---|
| 1. Authentication | Who are you? | An expired certificate or a wrong token | Refused with an “unauthorized” answer |
| 2. Authorization (RBAC) | Are you allowed to do this? | A developer trying to read Secrets without permission | Refused with a “forbidden” answer |
| 3. Admission control | Does this request follow the cluster’s rules and defaults? | A Pod asking for dangerous settings that a policy bans | Refused, or quietly changed to fit the rules |
Think of boarding a plane. First, the desk checks your passport to see who you are (authentication). Next, the agent checks that your ticket allows you on this flight and seat class (authorization). Finally, security checks that your bag contains nothing forbidden (admission). Having a valid passport does not give you a seat, and having a ticket does not let you bring anything you like.
Important: Kubernetes does not store your users
Beginners are often surprised to learn that Kubernetes has no built-in list of human users. There is no place to “create a user” and give them a password. Instead, the cluster trusts outside systems to prove identities: signed certificates, tokens from a company login service, or the cloud provider’s identity system. RBAC then works with the name and groups that these systems report. Programs inside the cluster are different: they use service accounts, which are real objects that Kubernetes manages.
“Unauthorized” means the cluster does not know who you are. “Forbidden” means it knows who you are but you are not allowed. The difference tells you which gate to look at first.
4What RBAC Really Is
Let us define it in plain words and then note the three facts that shape everything else.
RBAC is the part of Kubernetes that decides, for every request, whether the person or program asking is allowed to do it. Instead of giving permissions directly to each person, you gather permissions into named bundles called roles, and then connect people to roles. Roles describe “what can be done”. Bindings describe “who gets it”. Keeping these two ideas apart makes access easy to manage.
RBAC has been a stable, standard feature of Kubernetes since 2017, and nearly every real cluster uses it. It is normally switched on by starting the API server with RBAC as one of its authorization modes.
Three facts to remember
- Everything is denied by default. If no rule allows a request, it is refused. A brand new person with no bindings can do nothing.
- RBAC only adds permissions. There is no “deny” rule. The full set of permissions someone has is the sum of every rule from every role they are bound to.
- Permissions can be checked, listed and changed at any time. A change to a role takes effect quickly for everyone bound to it.
RBAC works like a guest list at a private party. Nobody gets in unless their name is on a list. You can put someone on several lists, and they may enter through any of them. But you cannot write “do not admit” under a name: you can only remove the name from the lists.
5The Four RBAC Objects
Everything in RBAC is built from four simple objects. They come in two pairs.
Role
A bundle of permissions that applies inside one namespace. For example, “may read Pods and their logs in the shop namespace”.
ClusterRole
A bundle of permissions that is not tied to a namespace. It can cover things that belong to the whole cluster, such as Nodes, or be reused in many namespaces.
RoleBinding
Connects people or programs to a role inside one namespace. The permissions apply only in that namespace.
ClusterRoleBinding
Connects people or programs to a ClusterRole across the entire cluster. The permissions apply in every namespace.
| Object | Belongs to a namespace? | Job | Can point to |
|---|---|---|---|
| Role | Yes | Lists permissions | Rules only |
| ClusterRole | No | Lists permissions | Rules only |
| RoleBinding | Yes | Grants a role to subjects in one namespace | A Role or a ClusterRole |
| ClusterRoleBinding | No | Grants a ClusterRole to subjects everywhere | A ClusterRole only |
Imagine a job description and a name badge. The role is the job description: “Can open the storeroom and read the stock sheet”. The binding is the badge with a person’s name that says “this person has that job”. You can write one job description and hand out many badges. When you update the description, everyone holding the badge gets the change at once.
A binding cannot be re-pointed to a different role once it is created. If you need a different role, delete the binding and create a new one. This small rule prevents accidental silent upgrades of access.
6Architecture and Components
Here is the whole picture in one drawing. Follow the arrows from the people on the left to the resources on the right.
flowchart LR
subgraph WHO["Subjects: who is asking"]
U["User"]
G["Group"]
SA["ServiceAccount"]
end
subgraph BIND["Bindings: the links"]
RB["RoleBinding: one namespace"]
CRB["ClusterRoleBinding: whole cluster"]
end
subgraph WHAT["Roles: what is allowed"]
R["Role: one namespace"]
CR["ClusterRole: cluster wide"]
end
U --> RB
G --> RB
SA --> RB
U --> CRB
G --> CRB
SA --> CRB
RB --> R
RB --> CR
CRB --> CR
R --> RULE["Rules: verbs on resources"]
CR --> RULE
RULE --> RES["Kubernetes resources such as Pods, Secrets and Nodes"]
Reading the diagram
Read it from left to right as a chain of trust. On the far left are the subjects: the people, groups and programs that make requests. In the middle are the bindings, which connect each subject to a role. Next come the roles, which hold rules. And on the right are the resources that the rules talk about. To find out what someone can do, you follow the arrows from them to the end and collect every rule you meet.
Notice that a RoleBinding can point to either a Role or a ClusterRole. That is a clever trick we will explore later. It lets you write a permission bundle once and hand it out room by room.
Meet each component
User
A human identity supplied by an outside system. Kubernetes only sees a name, such as “ravi@example.com”.
Group
A named set of users, also supplied by the outside system. Giving access to a group is easier than to each person.
ServiceAccount
An identity for a program, created and managed inside the cluster, living in a namespace.
Rule
One line inside a role saying “these actions on these resources are allowed”.
RBAC authorizer
The part of the API server that reads all roles and bindings and answers “yes” or “no” for each request.
Resources
The things being protected: Pods, Secrets, Deployments, Nodes, and even custom resource types added later.
7How Kubernetes Makes an Access Decision
What actually happens between pressing Enter and getting an answer? Let us walk through it slowly.
sequenceDiagram
participant U as You
participant A as API Server
participant N as Authentication
participant R as RBAC Authorizer
participant M as Admission Control
participant S as Cluster Storage
U->>A: Send a request
A->>N: Who is this
N-->>A: This is Ravi in group team-a
A->>R: May Ravi do this action here
R-->>A: Yes, a rule allows it
A->>M: Check policies and defaults
M-->>A: Accepted
A->>S: Save the change
A-->>U: Success
A request arrives
Someone or something asks the API server to do a thing, for example “list the Pods in the shop namespace”. The request carries proof of identity, such as a certificate or a token.
Authentication names the asker
The API server checks the proof and works out a username and a list of groups. If it cannot tell who is asking, the request stops here.
The request is turned into a question
The API server rewrites the request as four facts: who is asking, which verb (action), which resource, and which namespace. For example: “Ravi, list, pods, shop”.
RBAC searches for a matching rule
The authorizer looks at every binding that includes Ravi or one of his groups, opens the linked roles, and searches their rules for one that matches all four facts.
The first match wins: allow
As soon as one rule allows the action, the answer is “yes”. No further searching is needed, and no other rule can take it back.
No match means deny
If the search ends without finding an allowing rule, the request is refused with a “forbidden” message that names the user, the verb and the resource. That message is very helpful for debugging.
Admission control gets its turn
If allowed, the request moves on to admission control, which can still refuse or adjust it according to cluster policies. Only then is the change saved.
The authorizer is like a security guard holding a stack of guest lists. When you arrive, the guard looks for your name on any list that gives access to the room you are asking about. The moment they find your name, you are in. If they get to the bottom of the stack without finding it, you are turned away.
The authorizer checks every request, including those from the cluster’s own components. Kubelets, the helpers on each node, use a separate specialized authorizer for their own narrow tasks, and RBAC handles nearly everything else.
8Anatomy of a Rule
A role is just a list of rules. Each rule answers three questions: which kind of thing, which actions, and optionally which named items.
The parts of a rule
API groups
Kubernetes sorts its resource kinds into families called API groups. Pods and Secrets are in the “core” group, which is written as an empty name. Deployments are in the “apps” group.
Resources
The kinds of things the rule covers, such as pods, secrets or deployments. Special sub-parts like pod logs and pod shell access are listed separately.
Verbs
The actions allowed. Keep this list as short as possible, since each verb adds power.
Resource names
Narrows the rule to specific named items, such as one particular Secret, instead of all of them.
The verbs, in plain words
| Verb | Meaning | Risk level |
|---|---|---|
get | Read one named item | Low to medium. Depends on what it reveals. |
list | Read the whole collection of items | Medium. On Secrets it reveals every secret’s contents. |
watch | Follow changes as they happen | Medium. Like list, but live. |
create | Make a new item | Medium to high. Creating a Pod can be very powerful. |
update and patch | Change an existing item | High. Can alter running workloads. |
delete and deletecollection | Remove one item or many | High. Can cause outages. |
escalate, bind, impersonate | Special verbs about changing or borrowing permissions | Very high. Treat as admin-level. |
Sub-resources: the hidden doors
Some resources have hidden parts with their own permissions. Reading a Pod’s logs is one permission, and opening a shell inside a Pod is another. Being able to look at a Pod does not mean you can see its logs, and being able to see logs does not mean you can step inside it. This lets you grant “read-only debugging” without granting “get inside and change things”.
A rule is like a line in a museum staff handbook: “Curators may view, clean and move paintings in the east wing, but only view the storage room’s rare manuscripts”. It names the kind of item, the allowed actions and sometimes a particular named item. A handbook line that just said “curators may do anything to anything” would be a serious risk, just as a wildcard rule in Kubernetes is.
Rules may use a star, meaning “all”, for resources or verbs. It is quick to write and dangerous to keep, because it silently covers new resource types added later. Prefer explicit lists.
9Who Is Asking? Users, Groups and Service Accounts
A permission is only useful when it is attached to a subject. There are three kinds, and each has its own habits.
Users
A user is a human being, identified by a name that an outside system supplies. This might come from a signed certificate, from your company’s login service using a standard called OpenID Connect, or from the cloud provider’s identity system. Kubernetes does not store passwords for users. It only trusts the identity that it is told about.
Groups
Groups come from the same outside systems. A person’s request may carry several group names, such as “team-a” and “developers”. Binding a role to a group means that new team members get the right access automatically when they join the group, and lose it when they leave. Kubernetes also adds a few special groups of its own. Everyone who has proved their identity belongs to the group “system:authenticated”, and a group called “system:masters” is hard-wired to have unlimited power that RBAC cannot take away.
Service accounts
A service account is the identity of a program running in a Pod. Each namespace gets a default service account, and Pods use it automatically unless told otherwise. When a program inside the cluster needs to call the API server, for example a tool that watches for new Deployments, it does so as its service account. Its full name looks like “system:serviceaccount:” followed by the namespace and the account name. Modern clusters give each Pod a short-lived, automatically rotated token instead of a permanent password.
| Subject | Who it represents | Where it is defined | Typical use |
|---|---|---|---|
| User | A person | Outside identity system | Developers, operators, auditors |
| Group | A set of people | Outside identity system | Teams and departments |
| ServiceAccount | A program in a Pod | Inside the cluster, in a namespace | Automation, controllers, CI tools, apps that call the API |
Users are like employees with personal ID cards issued by the company’s HR system. Groups are departments. Service accounts are like the badges given to robots working in the building: the security office issues a robot badge, and it opens only the doors that robot’s task requires.
If a Pod does not need to talk to the API server at all, do not give it a token. Most application Pods never need one, and turning off the automatic token removes an attractive target for attackers.
10Scope: Namespace or Whole Cluster?
The same role can behave very differently depending on how you bind it. This is the most useful trick in RBAC.
flowchart LR
CR["ClusterRole: view"] --> RB1["RoleBinding in namespace shop"]
CR --> RB2["RoleBinding in namespace blog"]
CR --> CRB["ClusterRoleBinding"]
RB1 --> S1["Read access in shop only"]
RB2 --> S2["Read access in blog only"]
CRB --> S3["Read access in every namespace"]
Suppose you write a ClusterRole called “view” that allows reading most things. If you attach it with a RoleBinding in the shop namespace, the person can read only inside the shop. Attach the same ClusterRole with a RoleBinding in the blog namespace and they can read only in the blog. Attach it with a ClusterRoleBinding and they can read everywhere. The bundle is the same; only the reach changes.
When you truly need a ClusterRole
- Some resources do not belong to any namespace, such as Nodes, PersistentVolumes and Namespaces themselves. Permissions on these need a ClusterRole and a ClusterRoleBinding.
- Some web addresses of the API server are not resources at all, such as health checks. Rules for those also live in a ClusterRole.
- When you want one shared bundle reused in many namespaces, define it once as a ClusterRole and bind it room by room.
flowchart TB
Q["What access do you need to give"] --> A["One namespace only"]
Q --> B["Every namespace"]
Q --> C["Cluster-level things such as Nodes"]
A --> A1["Role plus RoleBinding, or a ClusterRole plus a RoleBinding"]
B --> B1["ClusterRole plus ClusterRoleBinding"]
C --> C1["ClusterRole plus ClusterRoleBinding"]
A ClusterRole is a company-wide job description: “Auditor: can read financial records”. A RoleBinding says “Sara is an Auditor in the Paris office only”. A ClusterRoleBinding says “Sara is an Auditor in every office”. Same job description, different reach.
Start with the smallest reach that works. A RoleBinding in one namespace is almost always safer than a ClusterRoleBinding. Widen only when there is a clear reason.
11Built-in Roles You Get for Free
You do not have to write every role from scratch. Kubernetes ships with a handful of ready-made ClusterRoles, and understanding them saves a lot of work.
| Role | What it allows | Good for |
|---|---|---|
| cluster-admin | Everything, everywhere | A very small number of trusted administrators |
| admin | Almost everything inside one namespace, including managing roles and bindings there | The owner of a team’s namespace |
| edit | Read and change most objects in a namespace, but not roles or bindings | Developers deploying their apps |
| view | Read most objects in a namespace, but not Secrets, roles or bindings | Read-only observers, support staff, auditors |
How they combine with bindings
These are ClusterRoles, so you choose their reach with the kind of binding. Attach “edit” to a group with a RoleBinding in one namespace and the whole team can deploy apps there and nowhere else. Attach “cluster-admin” with a ClusterRoleBinding and you have created a super administrator. The built-in “cluster-admin” role is already linked to the special group “system:masters”.
System roles
You will also see many roles whose names start with “system:”. Kubernetes creates them for its own components, such as the scheduler and the controller manager, so that each part of the cluster has only the access it needs. It is best not to edit or delete them, since the cluster relies on them.
Roles that grow automatically
The admin, edit and view roles are built by aggregation. Extension authors can attach labels to their own ClusterRoles, and Kubernetes merges those permissions into the built-in ones. That way, when you install a new kind of resource, the familiar view and edit roles learn about it without manual work.
The built-in roles are like the standard job titles on a company’s org chart: Owner, Manager, Staff and Visitor. Most people fit one of them. You only design a special title when someone’s job truly does not match any of the standard ones.
Because “cluster-admin” can do anything, handing it out “just to make things work” is the single most common RBAC mistake. If you find yourself doing this, stop and work out which specific permission was missing.
12A Complete Walkthrough: Giving a Team the Right Access
Let us put the pieces together with a story. No commands, just the thinking, so you can see how the decisions flow.
The situation
An online shop runs one cluster with three namespaces: shop (the live store), payments (money handling) and staging (testing). Three groups need access. Developers must deploy and debug in shop and staging. Support staff must look at Pods and logs in shop but change nothing. A deployment robot must update the shop’s apps after each release. Nobody outside a small platform team should touch payments.
List the people and programs
Write down who needs access and what for. Here: the developers group, the support group, and one service account for the deployment robot.
Start from the built-in roles
Developers fit the built-in “edit” role. Support staff fit “view”, which already lets them read Pods and their logs but not Secrets. Nobody in these groups needs “admin” or “cluster-admin”. A custom role is only added if support later needs something “view” does not cover.
Write a small custom role for the robot
The deployment robot only needs to update Deployments and read Pods in the shop namespace. A custom Role lists exactly those verbs on exactly those resources. It has no access to Secrets or to roles.
Bind in the smallest scope
Create RoleBindings inside the shop and staging namespaces, not cluster-wide ones. The developers group gets “edit” in both. Support gets “view” in shop only. The robot’s service account gets its custom role in shop only.
Leave payments closed
Since there are no bindings in the payments namespace for these groups, they get no access there. Default deny does the work without any extra rule.
Test as each subject
Use the permission check tool to ask, on behalf of each group and the robot, “can you do this?” for a few allowed and a few forbidden actions. Confirm that forbidden ones are really forbidden.
Store the definitions in version control
Keep all roles and bindings as files in a repository so that changes are reviewed, dated and reversible. Apply them from there instead of typing them by hand.
This is like setting up access to a new office. First you decide who works there and why. Then you use standard key card types for most people, make one special card for the delivery robot that opens only the loading door, and record the whole plan in a shared document so the next person knows why each card exists.
13Testing and Troubleshooting Access
Sooner or later you will see a “forbidden” message. Knowing how to read it and test the fix is a core skill.
Reading a forbidden message
A refusal usually tells you four things in plain words: who was refused, which action, which kind of resource, and in which namespace. For instance, it may say that a certain user cannot list Pods in a certain namespace. Those four facts are exactly what RBAC checked, so they point straight to the missing rule.
Confirm who you are
Make sure the identity in the message is the one you expect. Using the wrong saved login is a very common cause.
Ask the cluster directly
The “auth can-i” check answers “may this action be done?” with yes or no. You can ask on behalf of another user, group or service account by using impersonation, if you have permission to do so. There is also a way to list everything a subject may do in a namespace.
Find the bindings
Look at which RoleBindings and ClusterRoleBindings name that user, one of their groups, or the service account. If none do, that explains the refusal.
Read the linked role
Open each role and check the exact resource name, API group and verb. A missing sub-resource such as pod logs is a frequent culprit, as is a typo in the resource name.
Check the namespace of the binding
A RoleBinding in the wrong namespace gives access in the wrong place. The permission exists, just not where you need it.
Add the smallest missing permission
Grant only what is missing, test again as the same subject, and record the change. Never fix a small gap by handing out an administrator role.
Helpful community tools
Several open-source tools make access easier to inspect. Some show a matrix of what a subject can do across all resources, and others answer “who can delete Secrets in this namespace?” or “which roles does this person hold?”. Names you may meet include rakkess, kubectl-who-can and rbac-lookup.
Do not confuse a “forbidden” message with an application bug. When a program running in a Pod cannot list or change something, first suspect its service account’s permissions, not the program’s code.
14RBAC and Your Company’s Login System
Real teams do not create user accounts in Kubernetes. They connect the cluster to an identity system they already trust.
OpenID Connect
A common sign-in standard. Users log in to the company’s identity provider, receive a signed token, and the API server trusts it. The token carries the person’s name and groups, which RBAC then uses.
Amazon EKS
People sign in with AWS identities. EKS maps those identities to Kubernetes users or groups, and RBAC decides what they may do inside the cluster.
Google Kubernetes Engine
Google account identities are recognized by the cluster. Google Cloud permissions control access to the cluster itself, and RBAC controls what happens inside it.
Azure Kubernetes Service
Integrates with Microsoft Entra ID, formerly called Azure Active Directory. Groups in the directory can be bound to Kubernetes roles, and Azure also offers its own role system for cluster access.
Two layers of doors
On managed clouds there are usually two separate sets of permissions. One decides who can reach and manage the cluster as a cloud resource, such as creating or deleting the whole cluster. The other, RBAC, decides what they can do inside it, such as deleting a Pod. You must set up both. Being an administrator in the cloud account does not always give the same power inside the cluster, and the reverse is true too.
Think of a shopping mall. The mall’s management decides who can enter the building at all. Each shop inside decides who may go into its stockroom. Getting through the mall entrance does not open the stockroom of every shop, and the shop owners cannot decide who gets into the mall.
Bind roles to groups in your identity system, not to individual people. When someone joins or leaves a team, you update the group in one place and Kubernetes access follows without touching the cluster.
15Advantages, Disadvantages and Trade-offs
Every design has strengths and costs. Knowing both helps you decide well.
Advantages
- Built into Kubernetes, with no extra software to install.
- Secure by default: everything is denied until allowed.
- Roles are reusable, so you write a bundle once and hand it out many times.
- Works at namespace level or cluster level.
- Fully controlled through normal Kubernetes objects, which can be stored in version control.
- Applies to people, groups and programs alike.
Disadvantages
- No deny rules, so exceptions are hard to express.
- Rules can be verbose and hard to read as they grow.
- Hard to see the full picture: what someone can do is spread across many bindings.
- Cannot express conditions such as “only during work hours” or “only for objects with this label”.
- Some permissions are more powerful than they look.
- Needs regular review, since access tends to accumulate.
The trade-offs behind the choices
Safety versus convenience. Giving broad roles makes life easy today and risky tomorrow. Narrow roles take more design and testing, but limit the damage from any mistake.
Few roles versus many roles. A small set of well-known roles is easy to understand and audit. A huge collection of tiny custom roles is precise but hard to keep track of. Most teams settle on the built-in roles for common needs and a few custom ones for special cases.
Cluster-wide versus namespace-level. Cluster-wide bindings are simple to manage but expose everything. Namespace-level bindings need more objects but contain any problem to one room.
RBAC alone versus extra policy tools. Because RBAC cannot express conditions, larger organizations add policy engines that check requests against extra rules. This gives more control at the cost of more moving parts.
16Security: Permissions That Are More Powerful Than They Look
Some permissions sound harmless but can be turned into full control. Learning to spot them is what separates careful teams from careless ones.
Reading Secrets
Secrets hold passwords, keys and tokens. Even the “list” action returns every secret’s contents. Whoever can read Secrets can often impersonate services and reach other systems.
Creating Pods
A person who can create a Pod can make it run as any service account in that namespace, mount its secrets, and use its token. Creating Pods can therefore be a path to every permission in the room.
Opening a shell in a Pod
The “exec” sub-resource lets you run commands inside a running container. From there you can read its files, environment and service account token.
Changing roles and bindings
Anyone who can edit roles or bindings can give themselves more power. Kubernetes blocks direct self-promotion by default, but the special verbs escalate and bind lift that block, so they must be guarded closely.
Impersonation
The impersonate verb lets a subject act as someone else, including a powerful administrator. It should be given to almost nobody.
Creating service account tokens
Being able to mint tokens for a privileged service account is the same as being that account.
Node access
Permissions that touch Nodes or their proxy paths can lead to reading data from every Pod on that node.
Stars and cluster-admin
A rule with a star for everything, or a binding to cluster-admin, is a master key. Keep both extremely rare.
Guards built into RBAC
Kubernetes includes protection against a person quietly raising their own power. You can create or change a role only if you already hold every permission that role contains, unless you have been granted the special escalate verb. In the same way, you can create a binding only if you already hold the permissions being handed out, unless you have the bind verb. These guards are why the special verbs are so sensitive.
Habits that reduce risk
- Turn off the automatic token for Pods that never call the API server.
- Give each application its own service account instead of sharing the default one.
- Do not bind roles to the groups of anonymous or unauthenticated users.
- Avoid using the powerful “system:masters” group for everyday work. It bypasses RBAC completely and cannot be limited.
- Use short-lived credentials instead of permanent ones wherever possible.
A role that says “may create Pods” in a namespace that also contains a powerful service account is quietly a role that says “may become that powerful service account”. Always judge a permission by what it can lead to, not only by its name.
Think of a bank. A clerk who can only view accounts is low risk. A clerk who can print blank cheques, issue new staff cards or edit the rules of who may open the vault is really a bank manager in disguise. The name of the permission matters less than what it lets you do next.
17Monitoring, Auditing and Regular Reviews
Access is not a set-it-and-forget-it job. Permissions tend to grow silently, so you need to keep looking at them.
Turn on audit logging
The API server can record who did what and when, and whether it was allowed. These records answer “who deleted that?” and “who read that secret?”. Choose a policy that captures sensitive actions without recording secret contents.
Watch changes to RBAC objects
Raise an alarm whenever a new ClusterRoleBinding, especially one to cluster-admin, is created or a role is edited. These are the moments when access grows.
Watch refusals
A sudden rise in “forbidden” answers can mean a broken deployment, a misconfigured tool, or someone probing for weaknesses.
Review access on a schedule
Every few months, list who holds powerful roles and confirm that each one still needs them. Remove people who changed teams or left the company.
Scan for risky roles
Security scanners such as Kubescape and Trivy can check a cluster for risky role settings, wildcards and over-broad bindings, and report them in a list.
Find unused service accounts
Programs come and go. Old service accounts with strong permissions but no owner are attractive targets and should be removed.
Alarms worth setting
- Any new binding that grants cluster-admin.
- Any edit to a built-in or system role.
- Any use of impersonation, escalation or the bind verb.
- A large jump in refused requests from one identity.
- Reading of Secrets by identities that normally never do.
Send audit records to your central log system, not just to a file on the control plane. That way an attacker who takes over the cluster cannot easily erase the trail.
18Design Patterns and Anti-patterns
Patterns are solutions that many teams found reliable. Anti-patterns are traps many teams fell into.
Patterns that work
Pattern: Bind to groups, not to people
Roles are attached to groups that come from the company’s identity system. Onboarding and offboarding happen there, and Kubernetes access follows automatically.
Pattern: Namespace per team with edit and view
Each team gets its own namespace. Team members get “edit” there, and a wider audience gets “view”. Nobody needs cluster-wide power for daily work.
Pattern: One service account per application
Each program gets its own identity with only the permissions it needs. If one is compromised, the others are unaffected.
Pattern: Break-glass access
Powerful roles are not held all the time. They are granted temporarily during an emergency, with approval and logging, then removed. Normal work uses low-power roles.
Pattern: Access defined as files in version control
Roles and bindings live in a repository. Every change is reviewed and dated, and an automated tool applies them. Drift from the approved state is easy to detect.
Pattern: Read-only by default for humans
People normally have view access in production. Changes are made by a pipeline whose service account has narrow, well-tested permissions. This reduces mistakes made by hand.
Traps to avoid
What it looks like
Binding cluster-admin to everyone, or to the default service account, “so that things work”.
Why it hurts
Any mistake or any stolen credential now has full control of the whole cluster. You have removed the very protection RBAC exists to provide.
Better approach
Find the exact missing permission and grant only that, in the smallest scope.
What it looks like
Using wildcards for resources and verbs in custom roles.
Why it hurts
The role silently grows as new resource types are added, and nobody notices the extra power.
Better approach
List the exact resources and verbs. It is longer to write but easy to review.
What it looks like
Sharing one administrator certificate or token among the whole team.
Why it hurts
You cannot tell who did what, you cannot remove one person’s access, and a leak exposes everything.
Better approach
Give every person their own identity from the company login system, and bind roles to groups.
What it looks like
Letting every Pod use the default service account and automatically receive its token.
Why it hurts
If any container is compromised, the attacker gets a ready-made credential. If someone later adds permissions to the default account, every Pod inherits them.
Better approach
Create dedicated service accounts, and disable automatic tokens for Pods that do not need the API.
19Best Practices and Common Mistakes
Small habits make the difference between tidy, safe access and a tangle nobody dares to touch.
Habits that pay off
- Apply least privilege. Start with no access and add only what is proven necessary.
- Prefer namespace-level bindings. Reach for cluster-wide bindings only when a resource truly needs it.
- Use the built-in roles first. Admin, edit and view cover most human needs.
- Name roles clearly. A name like “deployment-updater-shop” explains itself. A name like “role1” does not.
- Document why. Add a note on each custom role saying who asked for it and for what purpose.
- Test as the subject. Verify that allowed actions work and forbidden ones fail, before and after each change.
- Keep access in version control. Review changes just like code.
- Review regularly. Remove stale bindings, old service accounts and departed people.
- Protect the special verbs. Treat escalate, bind, impersonate and token creation like administrator powers.
Mistakes beginners make
Confusing Role and ClusterRole
Creating a Role in one namespace and expecting it to work in another, or trying to grant access to Nodes with a namespaced Role.
Forgetting sub-resources
Granting “get” on Pods and wondering why logs or shell access still fail. They are separate permissions.
Binding in the wrong namespace
The RoleBinding exists, but in a different room from the one where the person works.
Wrong subject name
A typo in the user, group or service account name, or a missing namespace for a service account, means the binding matches nobody.
Expecting deny rules
Trying to block one action while allowing the rest in the same role. RBAC cannot subtract. Build a role that lists only what is allowed.
Never cleaning up
Leaving old bindings around after a project ends, until nobody knows who holds what.
20Real-World and Industry Examples
Here is how RBAC shows up in everyday practice across popular tools and common team setups.
Kubernetes itself
The cluster’s own components use RBAC. The scheduler, the controller manager and other system parts each receive a purpose-built role, so that even the cluster’s own machinery follows least privilege.
Monitoring tools
Popular monitoring tools such as Prometheus and kube-state-metrics ship with read-only ClusterRoles. They need to list and watch many objects to build charts, but they never need to change anything, so their roles contain only read verbs.
GitOps tools
Argo CD and Flux, two widely used tools that keep a cluster in sync with a Git repository, run as service accounts with permissions to create and update the objects they manage. Teams typically limit them to specific namespaces so that one project’s automation cannot touch another’s.
Lessons from Helm
In the second major version of the Helm package manager, a server component called Tiller commonly ran with cluster-admin powers. That was convenient but risky, since anyone who could reach it gained full control. Helm 3 removed Tiller and now acts with the permissions of the person running it, a clear example of least privilege winning over convenience.
A typical online shop
Picture a store on a managed cluster. Developers sign in through the company identity provider and belong to a group. That group has the edit role in the shop and staging namespaces only. Support staff have view access. The deployment pipeline uses a service account limited to updating Deployments in the shop namespace. Only two platform engineers can reach the payments namespace, and their powerful access is granted temporarily and logged. Audit records flow to a central store, and every quarter the team reviews who holds which roles.
Multi-tenant platforms
Companies that share one cluster among many teams or customers give each tenant a namespace and bind only namespace-level roles. Combined with network rules and resource limits, RBAC becomes one of the walls between neighbors.
21Frequently Asked Questions
Quick answers to the questions beginners ask most often.
22Summary and Key Takeaways
You began with a building where everyone held the master key. Now you know how to issue the right key card to the right person.
Key Takeaways
- The purpose: RBAC decides who may do what in a cluster, so that every person and program has only the access it needs.
- The four objects: Role and ClusterRole describe permissions, while RoleBinding and ClusterRoleBinding connect them to users, groups and service accounts.
- The rules of the game: Everything is denied by default, permissions only add up, and there are no deny rules.
- The decision: A request passes authentication, then RBAC authorization, then admission control, and the first allowing rule wins.
- Scope matters: Prefer RoleBindings in a single namespace, and reuse ClusterRoles through RoleBindings. Use cluster-wide bindings only when truly needed.
- Beware hidden power: Reading Secrets, creating Pods, opening shells, editing roles and impersonation can each lead to full control.
- Keep it healthy: Bind to groups, use dedicated service accounts, store access as reviewed files, audit changes, alarm on new cluster-admin grants, and review access on a regular schedule.