RBAC and ServiceAccounts: Who Can Do What Inside the Cluster
Kubernetes RBAC explained: Roles, ClusterRoles, bindings and ServiceAccounts, bound tokens, risky permissions and auditing access.

A CI pipeline needs to deploy one application into one namespace. The quickest way to make it work is to give its credentials cluster-admin. A year later, that pipeline’s token, stored in a CI system that dozens of people can configure, can read every Secret in the cluster, delete any namespace and create privileged pods on any node. Nobody decided that; it accumulated one convenient shortcut at a time.
RBAC (role-based access control) is the authorization mode used by virtually every Kubernetes cluster. It runs inside the API server, after authentication and before admission, as described in the control plane article. Every permission is additive: there are no deny rules, so an identity can do exactly the union of what its bindings allow.
Who is asking: users and ServiceAccounts
Kubernetes has no user objects. Human identities come from outside: client certificates, an OIDC provider such as Okta, Entra ID or Google, or the cloud provider’s IAM on managed clusters (for example EKS access entries or IAM mappings, GKE with Google accounts). The API server receives a username and group memberships and RBAC works with those names.
ServiceAccounts are real Kubernetes objects, namespaced, intended for workloads. Every namespace has a default ServiceAccount, and every pod runs as one. Since Kubernetes 1.22, pods receive bound tokens through a projected volume: short-lived (an hour by default, refreshed automatically by the kubelet), bound to the specific pod and invalid once it is deleted. Since 1.24, long-lived token Secrets are no longer created automatically, which removed a long-standing source of leaked credentials.
The four RBAC objects
| Object | Scope | Purpose |
|---|---|---|
Role |
One namespace | Allowed verbs on resources in that namespace |
ClusterRole |
Cluster | Allowed verbs on any resource, including cluster-scoped ones such as nodes; also a reusable template |
RoleBinding |
One namespace | Grants a Role, or a ClusterRole limited to this namespace, to subjects |
ClusterRoleBinding |
Cluster | Grants a ClusterRole across all namespaces |
A very useful pattern is to define a ClusterRole once and bind it per namespace with RoleBindings. The permissions apply only inside each bound namespace, and you avoid duplicating identical Roles everywhere.
Example: a deployer for one namespace
apiVersion: v1
kind: ServiceAccount
metadata:
name: ci-deployer
namespace: billing
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: deployer
namespace: billing
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["services", "configmaps"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ci-deployer
namespace: billing
subjects:
- kind: ServiceAccount
name: ci-deployer
namespace: billing
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: deployer
Rules combine an API group (the empty string "" is the core group for pods, services, secrets and config maps), resources and verbs. The common verbs are get, list, watch, create, update, patch and delete. Notice what is missing: no Secrets, no delete, no pods/exec. Secrets for this pipeline would come from an external secret manager, as discussed in ConfigMaps and Secrets.
For a CI system outside the cluster, prefer federating its identity (for example GitHub Actions OIDC to cloud IAM to cluster access) over exporting a token, so there is no long-lived credential to leak. When a token is genuinely needed, kubectl create token ci-deployer -n billing --duration=1h issues a short-lived one.
Built-in ClusterRoles for people
| ClusterRole | Grants |
|---|---|
view |
Read most objects in a namespace, but not Secrets |
edit |
Create and modify most objects, including reading Secrets, but not roles or bindings |
admin |
Full control of a namespace, including roles and bindings within it |
cluster-admin |
Everything, everywhere |
Bind these to groups from your identity provider with RoleBindings per namespace, for example view in production for every engineer and edit only in their team’s development namespaces. Keep cluster-admin for a small break-glass group.
ServiceAccounts for workloads
Most applications never call the Kubernetes API. For them, the safest setting is no token at all:
apiVersion: v1
kind: ServiceAccount
metadata:
name: billing-api
namespace: billing
automountServiceAccountToken: false
Give each application its own ServiceAccount rather than sharing default, so that permissions and cloud access can be granted per workload. Controllers and operators that do use the API should get Roles scoped to exactly the resources they manage.
Cloud access through workload identity
ServiceAccounts are also how pods get cloud permissions without static keys. EKS maps ServiceAccounts to IAM roles through IAM Roles for Service Accounts or the newer EKS Pod Identity, launched in late 2023; GKE uses Workload Identity; AKS uses Microsoft Entra Workload ID. A pod running as billing-api can read its S3 bucket and nothing else, and no access key ever sits in a Secret.
Permissions that are admin in disguise
createon pods (or Deployments, Jobs and other workload controllers) in a namespace: the pod can mount any Secret and use any ServiceAccount in that namespace, inheriting its permissions.getorliston Secrets:listreturns every value, and ServiceAccount tokens and cloud credentials may be among them.pods/execandpods/attach: a shell in any pod, with its credentials and network access.escalate,bindandimpersonate: create or assume permissions you do not have.nodes/proxy: direct access to the kubelet API, which can execute commands in pods.- Wildcards:
resources: ["*"]orverbs: ["*"]silently include resources and subresources added later.
Combine RBAC with Pod Security Standards, which limit what a pod is allowed to do on the node, so that pod creation rights cannot be turned into node access.
Auditing access
kubectl auth can-i delete deployments -n billing --as=system:serviceaccount:billing:ci-deployer
kubectl auth can-i --list -n billing --as=jane@acme.example
kubectl get rolebindings,clusterrolebindings -A -o wide | grep -i cluster-admin
Open-source tools such as rbac-tool and rakkess produce “who can do what” matrices. Review ClusterRoleBindings regularly, and enable API server audit logs, which managed providers offer as a setting, so you can see who actually used powerful permissions.
Frequently Asked Questions
What is the difference between a Role and a ClusterRole?
A Role grants permissions within one namespace. A ClusterRole is cluster-scoped and can grant permissions on cluster-wide resources such as nodes, or be bound in individual namespaces with RoleBindings as a reusable set of permissions.
What is a Kubernetes ServiceAccount?
A namespaced identity for workloads. Pods run as a ServiceAccount and receive a short-lived token for it, which RBAC uses to decide what the pod may do in the Kubernetes API. ServiceAccounts are also mapped to cloud IAM roles for workload identity.
Should pods mount ServiceAccount tokens?
Only if they call the Kubernetes API. Set automountServiceAccountToken: false on ServiceAccounts or pods that do not need a token, so a compromised application has no API credentials to use.
How do I check what permissions a user or ServiceAccount has?
Use kubectl auth can-i with –as, for example kubectl auth can-i –list -n NAMESPACE –as=system:serviceaccount:NAMESPACE:NAME, or tools such as rbac-tool for a cluster-wide view.
Narrow by default, broad by exception
Good RBAC is mostly restraint: namespace-scoped bindings to groups, one ServiceAccount per workload, no API token for apps that do not need one, workload identity instead of cloud keys, and a short, reviewed list of people with cluster-wide power. RBAC decides what identities can do through the API; Pod Security Standards covers what pods are allowed to do on the node itself. For the full reference, see the RBAC documentation and the RBAC good practices guide.
Originally posted on 16 July 2024 and post last modified on 16 July 2024