Grant least privilege with Roles and bindings

  • 14 min
  • 5 steps
  • Security

Steps

0 of 5 done

Read a forbidden error, grant a workload exactly one resource, give a support identity in another namespace read access, and move a binding to a different role.

  1. Step 1 of 5

    The reporter Deployment in shop is crash-looping. Find the request the API server refused it, and the username it saw.

    Checked against what your commands print.

  2. Step 2, not started: Let reporter read ConfigMaps in shop, and nothing else. It needs to get, list and watch them.

  3. Step 3, not started: The support ServiceAccount lives in ops. In shop it must be able to list pods and read their logs, and must not be able to exec into them. Name the Role log-reader and the RoleBinding support-logs.

  4. Step 4, not started: Support needs read-only access to everything ordinary in shop, without Secrets and without anything in other namespaces. The built-in view ClusterRole covers that, pod logs included. Make support-logs grant view instead of log-reader, then remove the Role nobody uses.

  5. Step 5, not started: List the bindings in shop with the role and the subjects of each, the view you would start from when asked who has access to the namespace.

Lab terminal

Cluster time 1 minute
kind cluster kx, Kubernetes 1.37.
Each step is checked as you work.
​
Tab completes. Up and Down recall.
Type help for more.
Terminal keys

Enter runs the command. Tab completes, and the arrow keys recall earlier commands. Control C stops a watch. On an empty line, or after Escape, Tab moves focus out of the terminal.