Give a team just enough access with RBAC

DevOps, Hands On30 minutesFreeSteps checked 23 November 2026By Cloud Hands On

In this task you'll let a team manage its own apps in one namespace and nothing else.

Kubernetes RBAC has four objects. A Role lists allowed verbs (get, list, watch, create, update, patch, delete) on resources in one namespace; a ClusterRole does the same cluster-wide or for reuse. A RoleBinding gives a Role (or a ClusterRole, limited to one namespace) to users, groups or service accounts; a ClusterRoleBinding gives it everywhere.

Start small and add what's missing: errors say exactly which verb and resource were refused. kubectl auth can-i checks any identity's permissions before you hand them out. Watch for powerful verbs that look harmless: create on pods lets someone run anything with the namespace's service accounts, and get on secrets reads every password in the namespace.

Example. Quayhurst Health gives its appointments team the built-in edit ClusterRole through a RoleBinding in the appointments namespace only. The team can deploy and debug its apps, but can't read other teams' namespaces or change RBAC itself.

Before you start

You need: Docker Desktop, kind and kubectl on your computer (all free), and a cluster from Run a practice cluster on your computer. Time: 30 minutes.

Where to look

  1. Terminal
  2. kubectl

Steps

  1. Create a namespace appointments and a service account deployer in it.
  2. Create a Role allowing get, list, watch, create, update, patch and delete on deployments and pods (see Commands).
  3. Bind it to the service account with a RoleBinding.
  4. Check with kubectl auth can-i create deployments -n appointments --as=system:serviceaccount:appointments:deployer (yes) and the same in default (no).
  5. Check get secrets is refused, and that reading logs is refused too: kubectl auth can-i get pods --subresource=log says no, because pods/log is a separate resource.Don't write get pods/log: kubectl reads that as a pod named log and can wrongly answer yes.
  6. Add a second Role with get on pods/log, bind it, check the subresource again (yes), then list everything with kubectl auth can-i --list.
  7. Swap your Role for the built-in edit ClusterRole in a RoleBinding and compare the lists.

Commands

kubectl create namespace appointments
kubectl create serviceaccount deployer -n appointments
kubectl create role app-deployer -n appointments --verb=get,list,watch,create,update,patch,delete --resource=deployments,pods
kubectl create rolebinding app-deployer -n appointments --role=app-deployer --serviceaccount=appointments:deployer
kubectl auth can-i create deployments -n appointments --as=system:serviceaccount:appointments:deployer
kubectl auth can-i get secrets -n appointments --as=system:serviceaccount:appointments:deployer
# Subresources: use --subresource (get pods/log would mean a pod named log)
kubectl auth can-i get pods --subresource=log -n appointments --as=system:serviceaccount:appointments:deployer
kubectl create role log-reader -n appointments --verb=get --resource=pods/log
kubectl create rolebinding log-reader -n appointments --role=log-reader --serviceaccount=appointments:deployer
kubectl auth can-i --list -n appointments --as=system:serviceaccount:appointments:deployer

Watch out for

Cost
Free.
Security
Avoid cluster-admin for people and pipelines, avoid wildcards (*), and review who can read secrets or create pods.
Common mistakes
Using a ClusterRoleBinding when a RoleBinding would do, forgetting that pods/log and pods/exec are separate resources, and checking them with can-i get pods/log instead of --subresource=log.

Clean up

kubectl delete namespace appointments (it removes the Role, binding and service account).

Words to know

Role
A list of allowed actions on resources in one namespace.
RoleBinding
Gives a Role or ClusterRole to people or service accounts in one namespace.
Service account
An identity for software running in pods.
Verb
An action such as get, list, create or delete.

Tick off each step and track your progress in the guide.

Open this task in DevOps, Hands On

Keep going