Kubernetes RBAC Explained: Roles, Bindings & Permissions

Kubernetes RBAC Explained: Roles, Bindings, and Least Privilege

Every request to the Kubernetes API carries an identity, and kubernetes rbac explained in one sentence is this: RBAC decides what each identity is allowed to do, and everything not explicitly granted is denied. Get it right and a leaked CI token can only read logs in one namespace. Get it wrong and that same token can delete your entire cluster. If you are still getting oriented, our practical Kubernetes guide covers the moving parts before permissions enter the picture.

RBAC stands for Role-Based Access Control. Instead of granting permissions directly to users, you define roles that bundle permissions and then bind those roles to identities. This article walks through each piece with real YAML you can apply.

kubernetes rbac explained in 30 seconds

The whole system rests on four objects plus the request it evaluates. A permission is a combination of a verb (get, list, create, delete, update, patch), an API group, and a resource (pods, deployments, secrets). The subject making the request is a User, a Group, or a ServiceAccount. And there is no permission by default: nothing is allowed until a binding says otherwise.

The four objects:

  • Role: a set of permissions limited to one namespace.
  • ClusterRole: a set of permissions that works cluster-wide, or across every namespace.
  • RoleBinding: attaches a Role (or a ClusterRole’s rules) to subjects within one namespace.
  • ClusterRoleBinding: attaches a ClusterRole to subjects across the whole cluster.

Rules define what; bindings define who. Keep that split in your head and RBAC stops being confusing.

Role vs ClusterRole

The role vs clusterrole decision comes down to scope. A Role lives inside a namespace and only grants access there. A ClusterRole lives at cluster level and can do two things a Role cannot: grant access to cluster-scoped resources such as nodes, namespaces, persistent volumes, and storage classes, and grant the same set of permissions across all namespaces at once.

Here is a ClusterRole that lets an admin read nodes:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: node-reader
rules:
- apiGroups: [""]
  resources: ["nodes"]
  verbs: ["get", "list", "watch"]

The common trap is reaching for a ClusterRole when a Role would do. If a deployment pipeline only touches the webshop namespace, it has no business holding cluster-wide power. Roles keep blast radius small, and pairing them with Kubernetes namespaces gives you a real multi-tenant boundary rather than a naming convention.

A useful habit from the production hardening checklist applies here too: define the smallest possible permission set first, then widen it only when something demonstrably breaks.

RoleBinding vs ClusterRoleBinding

The rolebinding vs clusterrolebinding distinction is the same scope question applied to the grant itself. A RoleBinding ties subjects to permissions inside one namespace. A ClusterRoleBinding ties them across the entire cluster, which is how identities like cluster-admin get their power.

One detail people miss: a RoleBinding can reference a ClusterRole. That is legal and useful, but the grant still applies to only the RoleBinding’s namespace. So referencing the built-in view ClusterRole from a RoleBinding in namespace billing gives a user read access in billing and nowhere else. Reuse the permission set, keep the narrow scope.

A hands-on example: deployer service account

Suppose a deployment script needs to update deployments and read pod logs in the webshop namespace, and nothing else. First create the identity:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: ci-deployer
  namespace: webshop

Then define the smallest Role that covers the job:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: deployer
  namespace: webshop
rules:
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: [""]
  resources: ["pods", "pods/log"]
  verbs: ["get", "list"]

Finally, bind them together:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: deployer-binding
  namespace: webshop
subjects:
- kind: ServiceAccount
  name: ci-deployer
  namespace: webshop
roleRef:
  kind: Role
  name: deployer
  apiGroup: rbac.authorization.k8s.io

Apply all three and the pipeline can deploy and debug without touching secrets, config maps, or anything outside webshop. Notice that secrets is deliberately absent from the resources list. If your workload needs secret access, grant that narrowly as well, and consider whether a dedicated secrets manager is a better home for credentials than etcd in the first place.

CI pipelines and the cluster-admin trap

The most common RBAC failure in the wild is handing cluster-admin to CI. It happens because the pipeline “just works” afterward, and nobody revisits the shortcut. Then one compromised token or one buggy script can wipe namespaces, read every secret in the cluster, and create new privileged accounts for persistence. Everything below follows the least privilege kubernetes admins expect from production systems: grant only the verbs and resources the job needs, in the namespaces it touches, to a dedicated service account per pipeline.

That means separate service accounts per environment: ci-deployer-staging and ci-deployer-production instead of one token for both. It also means the pipeline that deploys the app does not get permission to read secrets unless it genuinely needs them, and the pipeline that only runs tests gets even less.

Managing kubernetes service account permissions gets easier if you treat tokens like credentials with a lifecycle: rotate them on a schedule, store them in your CI system’s secret store rather than in the repo, and delete the service account when the pipeline is retired. If you are building the pipeline itself, our CI pipeline with GitHub Actions walkthrough covers how secrets and tokens flow through a typical setup.

Common RBAC mistakes to avoid

Beyond the cluster-admin shortcut, these keep showing up in audits:

  • Wildcard verbs and resources. verbs: ["*"] or resources: ["*"] turns a “limited” Role into a nearly-admin one. List each verb and resource explicitly.
  • Binding to broad groups. Granting permissions to system:authenticated gives them to every authenticated user in the cluster. Bind to named users or service accounts instead.
  • Reusing one service account for everything. The app, the CI job, and the backup cron should not share an identity. Shared identities make revocation and auditing impossible.
  • Forgotten bindings. Contractors leave, tools get replaced, and their bindings stay. Review kubectl get rolebindings,clusterrolebindings -A as part of offboarding.
  • Default service account with automounted tokens. Every pod gets the namespace’s default token unless you disable it. Set automountServiceAccountToken: false on pods that do not talk to the API.

Test access before trusting it

RBAC is easy to reason about wrong, so verify with kubectl auth can-i before shipping:

kubectl auth can-i update deployments 
  -n webshop 
  --as=system:serviceaccount:webshop:ci-deployer
# yes

kubectl auth can-i delete secrets 
  -n webshop 
  --as=system:serviceaccount:webshop:ci-deployer
# no

Run these from your workstation with the --as flag to impersonate the service account. If a “no” comes back “yes”, your Role is wider than you think. Make this a habit after every RBAC change, and you will catch misconfigurations before an attacker does.

Start with a deny-by-default mindset, use Roles over ClusterRoles wherever scope allows, and give CI the least privilege that still lets it deploy. Do that consistently and RBAC becomes boring infrastructure instead of an incident waiting to happen.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.