Free tech learning for everyone, from basics to pro

Kubernetes SecurityCloud SecurityIntermediate

Kubernetes RBAC: roles, cluster roles, bindings and service accounts

In short: Kubernetes RBAC grants permissions by binding users, groups or service accounts to roles that list allowed verbs on resources. Roles are namespaced; ClusterRoles can apply across the cluster. Least privilege means namespace-scoped bindings, no wildcards, careful handling of powerful verbs and dedicated service accounts per workload.

The building blocks

Kubernetes RBAC is additive: there are no deny rules, so a subject can do only what some binding allows. Four object types are involved:

Role and binding scopeRolerules in one namespaceClusterRolecluster-wide or reusableRoleBindinggrants in one namespaceClusterRoleBindinggrants everywhere
Figure 1. Roles and bindings exist at namespace and cluster level; a RoleBinding can reuse a ClusterRole inside one namespace.

A subject is a user, a group or a service account. Kubernetes does not store human users itself; they come from client certificates or, more commonly in the cloud, an OIDC identity provider or the cloud's IAM. Service accounts are Kubernetes objects used by pods.

How Kubernetes RBAC links upSubjectuser, group,SABindingRoleBindingRolelist of rulesResourcespods, secretsVerbsget, list,create
Figure 2. A binding connects a subject to a role, and the role lists allowed verbs on resources.

A least-privilege example

This gives a deployment pipeline permission to manage Deployments in one namespace only, and nothing else:

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"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: deployer-binding
  namespace: shop
subjects:
- kind: ServiceAccount
  name: ci-deployer
  namespace: shop
roleRef:
  kind: Role
  name: deployer
  apiGroup: rbac.authorization.k8s.io

You can test what a subject can do with kubectl auth can-i:

kubectl auth can-i create deployments -n shop --as system:serviceaccount:shop:ci-deployer
kubectl auth can-i get secrets -n shop --as system:serviceaccount:shop:ci-deployer
kubectl auth can-i --list -n shop --as system:serviceaccount:shop:ci-deployer

Dangerous permissions

PermissionWhy it is risky
cluster-admin bindingFull control of everything; keep to a tiny break-glass group
Wildcards * in resources or verbsGrants future resource types you have not thought about
get/list on secretsReveals passwords and tokens, often leading to wider access
create podsA pod can mount any secret or service account in its namespace, and may be privileged if pod security allows
escalate, bind, impersonateLet a subject grant itself or act as more powerful identities
nodes/proxy, pods/execDirect access into nodes or running containers

Service accounts done well

  • Give each application its own service account rather than using default.
  • Set automountServiceAccountToken: false for pods that never call the Kubernetes API.
  • Modern clusters issue short-lived, audience-bound projected tokens; avoid creating long-lived token Secrets.
  • Link service accounts to cloud IAM through workload identity (for example EKS Pod Identity or IRSA, AKS Workload Identity, GKE Workload Identity Federation) instead of storing cloud keys.

Tip: review all ClusterRoleBindings regularly. Tools such as kubectl get clusterrolebindings -o wide or open-source RBAC analysers help spot unexpected cluster-admin grants.

Practice

What is the difference between a Role and a ClusterRole?
A Role holds rules for one namespace. A ClusterRole can cover cluster-scoped resources or be reused across namespaces through RoleBindings.
Why can permission to create pods lead to privilege escalation?
The new pod can mount any service account or secret in the namespace, and may run privileged if pod security does not stop it, giving access the creator did not directly have.
How do you check whether a service account can read secrets in a namespace?
Run kubectl auth can-i get secrets -n NAMESPACE --as system:serviceaccount:NAMESPACE:NAME.

Key takeaways

  • RBAC is additive: subjects get only what bindings allow.
  • Roles and RoleBindings are namespaced; Cluster versions span the cluster.
  • Avoid wildcards, cluster-admin and broad access to secrets.
  • Watch powerful verbs such as escalate, bind, impersonate and pod creation.
  • Use one service account per app and disable token mounting when unused.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.