liveBook · Manning

Role-based access control

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

Role-based access control is an authorization model that grants permissions according to assigned roles.

Role-based access control (RBAC) determines which actions an authenticated identity may perform through the Kubernetes API. Authentication establishes who is making a request; authorization checks whether that user or Service Account may perform the requested action. A valid client certificate proves a user's identity, but does not by itself define their RBAC permissions. section 3.1 section 3.4

Choose RBAC objects by permission scope and recipient:

  • A Role defines allowed verbs, such as get, list, and delete, for resources in a particular namespace. A ClusterRole defines permissions at cluster scope, including permissions for resources such as nodes. section 3.1.1
  • A RoleBinding assigns permissions within a namespace; a ClusterRoleBinding assigns cluster-wide permissions. Bindings can grant permissions to users, groups, or Service Accounts. A ClusterRoleBinding cannot bind a namespaced Role. section 3.1.1 section 9.3.2

Grant and test pod-reading access

In the default namespace, run `kubectl create role pod-reader --verb=get,list,watch --resource=pods`, then `kubectl create rolebinding pod-reader-binding --role=pod-reader --user=carol`. Inspect the result with `kubectl get role pod-reader -o yaml` and `kubectl get rolebinding pod-reader-binding -o yaml`. Finally, test the authorization decision: `kubectl auth can-i get pods -n default --as carol` returns `yes`, while `kubectl auth can-i delete pods -n default --as carol` returns `no`. For a manifest you can retain and edit, generate the Role YAML with a dry run instead of creating it immediately. section 3.1.1

$ kubectl auth can-i get pods -n default --as carol
yes
$ kubectl auth can-i delete pods -n default --as carol
no

Compare the two permission checks: the same user can get pods but cannot delete them in the default namespace. section 3.1.1

For an access problem, check the identity used for the request, the binding's subject and scope, then the referenced Role or ClusterRole's resources and verbs. Use `kubectl auth can-i` to verify the specific action rather than assuming that successful authentication permits it. Pods commonly access the API through Service Accounts, while human users commonly authenticate with client certificates. section 3.1 section 3.4

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through scoped permission objects, kubectl creation, YAML inspection, and allowed-versus-denied checks; does not develop authorization internals.
Examples
Uses a pod-reader Role, a user RoleBinding, YAML output, and kubectl auth can-i checks for getting versus deleting pods.
What it assumes
Assumes basic familiarity with kubectl and the Kubernetes API; distinguishes authentication from authorization and introduces the RBAC object types.
What you can do after
Apply it via kubectl to assign scoped permissions and verify whether a user or Service Account can perform an action.
How it connects
Connects authentication, X.509 client certificates, Service Accounts, Kubernetes API verbs, and namespaces to authorization decisions.

Also explained in

Compare how 16 books explain role-based access control →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.