Skip to main content
Security & multi-tenancyLesson 1 of 13

Who Can Do What (RBAC)

Developer kim and a pod run by a deploy tool both work with pods in the shop-dev namespace. They call the same API server, yet some requests pass and some are rejected with 403. Let's follow where the paths split.

Requester—
Action—
Result—
Namespace · shop-devDeveloper kimHuman · kubectlDeploy toolSA · ci-botAPI serverEntry for all requestsAuthenticationWho are you?RBAC authzIs this allowed?etcdStored resourcesRoleBindingTo whomRoleWhatClusterRoleWhole clusterget podslist pods
RequestResponse / reportAppears in a later step

What you will learn

  • Authentication (who) vs. authorization (allowed?)
  • A Role sets "what", a RoleBinding sets "to whom"
  • Why login works but delete returns 403
  • Namespace scope vs. cluster scope

The four parts of RBAC​

NameWhat it doesScope
RoleA set of permissions: which actions (get·list·delete, etc.) are allowed on which resourcesOne namespace
ClusterRoleThe same kind of permission set, but can also cover cluster-scoped resources such as nodesCluster
RoleBindingBinds a permission set to users, groups, or ServiceAccountsOne namespace
ClusterRoleBindingBinds a ClusterRole across the whole clusterCluster

Try it yourself​

kubectl auth whoami # Who authentication says you are
kubectl get rolebindings -n <namespace> -o wide # Which Role is bound to whom
kubectl auth can-i delete pods -n <namespace> --as <user> # no means 403 Forbidden
kubectl auth can-i list pods -n <namespace> --as system:serviceaccount:<namespace>:<sa> # Same check for a ServiceAccount
kubectl auth can-i list nodes # Cluster-scoped, needs a ClusterRole

Check yourself

  1. kim can list Pods in shop-dev, but deleting a Pod returns 403 Forbidden. What is the problem?
  2. You create a Role that allows get and list on Pods, but nobody can use it. What is missing?
  3. kim needs to list nodes. Why can a Role in shop-dev not grant this?

Further reading: Using RBAC Authorization · Namespaces