Skip to content
Securityintermediate

What is Kubernetes RBAC?

Updated Nov 30, 20263 min readBased on official documentation
What is Kubernetes RBAC?

In short

Kubernetes RBAC is role-based access control, a way to decide who can do what in a Kubernetes cluster. You define roles that hold permissions, then bind those roles to users, groups or service accounts. Access is granted only when a rule explicitly allows it.

What RBAC means in Kubernetes

Role-based access control, or RBAC, is a method of limiting access to resources based on the job each person or program has. Instead of giving every user full control, you group permissions into roles and hand those roles out.

In Kubernetes, RBAC is one of the authorization steps the API server runs for each request. It uses the rbac.authorization.k8s.io API group, so the rules are stored as normal Kubernetes objects. You can create, read and change them with kubectl, just like pods or services.

RBAC must be switched on. The API server has to include the RBAC authorizer, either through an authorization configuration file or through the --authorization-mode flag. Most current clusters already have it enabled, but it is worth checking before you build on it.

The four RBAC objects

RBAC uses four object kinds, and they work as two pairs.

  • Role holds permission rules that apply inside one namespace.
  • ClusterRole holds permission rules that apply across the whole cluster.
  • RoleBinding connects a set of subjects to a role inside one namespace.
  • ClusterRoleBinding connects subjects to a ClusterRole for the entire cluster.

Subjects are users, groups or service accounts. A namespace is a named section of a cluster, used to separate workloads.

RBAC rules are only additive. There is no way to write a deny rule. If no rule allows an action, it is refused. Adding more rules can only widen access, so keep each role small.

How it works

A role lists rules. Each rule names the API groups, the resources and the verbs it allows. A verb is an action such as get, list, watch, create or delete.

A binding then links that role to subjects. Once the binding exists, each subject gets the permissions from the role. Roles and bindings are separate objects, so you can reuse one role for many people.

A RoleBinding can point at either a Role or a ClusterRole. When it points at a ClusterRole, the permissions apply only inside the namespace of the RoleBinding. This lets you define a common set of roles once and reuse them in several namespaces. A ClusterRoleBinding applies a ClusterRole to every namespace at once.

A simple example

Suppose a developer named jane should read pods in the default namespace. You first create a Role:

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

Then you bind it to jane:

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

Names are case sensitive, so jane and Jane are different subjects. The empty string in apiGroups refers to the core API group, which holds pods.

Common mistakes

The most common mistake is trying to change a binding's role. Once a RoleBinding or ClusterRoleBinding is created, its roleRef cannot be changed. You must delete the binding and create a new one. This is deliberate. It stops someone who can edit a binding's subjects from quietly receiving a different role.

Another mistake is using a Role when you need cluster-wide access. A Role only works in one namespace. For nodes, non-resource paths such as /healthz, or pods across all namespaces, you need a ClusterRole.

Resource names also need care. Use a slash to reach a subresource, such as pods/log. You can limit access to specific objects with resourceNames, but you cannot restrict deletecollection or top-level create requests this way. When you restrict list or watch by resource name, clients must add a matching metadata.name field selector to their request.

Finally, RBAC objects restrict you too. If you are changing a cluster while learning, you may be blocked from creating some roles. The official docs describe privilege escalation prevention and bootstrapping, which explain these limits.

RBAC is the standard authorization mode, but it is not the only one. Clusters can also use other authorizers, and some teams add policy engines on top. For most cases, RBAC with small, namespace-scoped roles is the simplest place to start.

To inspect or update RBAC objects, use kubectl like any other resource. The kubectl auth reconcile command can create or update a manifest of RBAC objects and handle the delete-and-recreate step for bindings when a roleRef must change.

For the full rules, field names and command examples, read the official RBAC documentation linked from this page.

FAQ

Can RBAC deny a specific user access to something?

No. RBAC rules only grant permissions, and there are no deny rules. If no rule allows an action, the request is refused. To restrict access, remove or avoid giving a permission.

What is the difference between a Role and a ClusterRole?

A Role applies within one namespace and must be created in that namespace. A ClusterRole is not tied to a namespace and can cover cluster-scoped resources like nodes, or be bound to one namespace or to all of them.

Can I change the role in an existing binding?

No. The roleRef of a binding is immutable. Delete the binding and create a new one that points at the role you want.

Do I need to restart the cluster to enable RBAC?

RBAC is turned on through the API server settings, using either an authorization configuration file or the --authorization-mode flag. Check your cluster setup, since the change applies to the API server itself.

Sources

This page is based on the official documentation below. Read it for full detail.

Kubernetes RBAC — official documentation ↗

Kubernetes RBAC in the news

blozhikDeveloper news from across the web, explained. Every story links to its original sources.