RBAC Basics
This section covers the four RBAC objects you will use every day - Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings - and how to compose them into least-privilege access.
Search across all documentation pages
This section covers the four RBAC objects you will use every day - Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings - and how to compose them into least-privilege access.
kubectl configured with an identity that can create RBAC objects.Quick check that RBAC is active and you can read your own permissions:
kubectl api-resources --api-group=rbac.authorization.k8s.io
kubectl auth can-i --listA Role grants verbs on resources inside a single namespace.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: payments
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]apiGroups: [""] is the core group, where pods, services, and configmaps live.payments namespace.create or delete.The RoleBinding connects the Role to a subject inside the namespace.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
namespace: payments
name: read-pods
subjects:
- kind: User
name: dev-alice
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.iosubjects lists who gets the access - here a single user.roleRef points to the Role granting the permissions.payments, so the grant is namespace-scoped.roleRef is immutable, so change bindings by replacing, not editing.A ClusterRole defines permissions that are not tied to one namespace.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: node-viewer
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list"]A ClusterRoleBinding grants a ClusterRole across the whole cluster.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: view-nodes
subjects:
- kind: Group
name: sre-team
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: node-viewer
apiGroup: rbac.authorization.k8s.iosre-team group can list nodes in every namespace.A namespaced RoleBinding can reference a ClusterRole to scope shared permissions.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
namespace: payments
name: payments-edit
subjects:
- kind: Group
name: payments-devs
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: edit
apiGroup: rbac.authorization.k8s.ioedit ClusterRole is defined once but bound per namespace.payments-devs get edit rights only inside payments.Workloads authenticate as a ServiceAccount, which is a valid subject.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
namespace: payments
name: app-config-reader
subjects:
- kind: ServiceAccount
name: checkout
namespace: payments
roleRef:
kind: Role
name: config-reader
apiGroup: rbac.authorization.k8s.iokind: ServiceAccount requires an explicit namespace.checkout pod inherits exactly these permissions.Ask the API server what a subject can do before shipping.
kubectl auth can-i get pods --namespace payments
kubectl auth can-i list secrets --namespace payments \
--as system:serviceaccount:payments:checkoutcan-i returns yes or no from the real authorizer.--as impersonates any user, group, or ServiceAccount.Compose a ClusterRole from smaller labeled pieces.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: monitoring-viewer
labels:
rbac.example.com/aggregate-to-monitoring: "true"
rules:
- apiGroups: ["monitoring.coreos.com"]
resources: ["prometheuses", "servicemonitors"]
verbs: ["get", "list", "watch"]aggregationRule selector absorbs these rules automatically.view, edit, and admin roles grow the same way.Restrict a rule to specific object names with resourceNames.
rules:
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["tls-cert"]
verbs: ["get"]tls-cert Secret, nothing else.resourceNames does not support list or watch, only name-addressable verbs.Trace what a subject can actually do.
kubectl auth can-i --list --namespace payments \
--as system:serviceaccount:payments:checkoutexec and secrets.Some capabilities live on subresources, not the parent object.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: payments
name: pod-logs-reader
rules:
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get"]pods/log is the log subresource, separate from pods itself.pods/exec, pods/portforward, and pods/status, each grantable independently.pods/exec out of routine developer Roles, since it is interactive shell access.A few habits keep grants tight as a cluster grows.
verbs: ["*"].view, edit, and admin ClusterRoles before writing your own.Stack versions: This page was written for Kubernetes 1.36.2, Docker Engine 29.6.1 (BuildKit default), containerd (CRI runtime on nodes), Helm 3, Compose v2, Argo CD (latest - verify at build), and Gateway API (GA - verify controller support at build).
Reviewed by Chris St. John·Last updated Jul 19, 2026