Skip to main content
In the previous lesson we created a role and a user mapped to a ServiceAccount. This lesson shows how to create a read-only user that can view pods (get, list, watch) but cannot modify cluster resources. Use case: you need an account that can inspect resources for reporting or audits without granting any write permissions.

Overview

Steps we’ll follow:
  1. Create the user with oc create user.
  2. Create a ClusterRole that grants read-only access to pods.
  3. Bind that ClusterRole to the user with a ClusterRoleBinding.
  4. Verify the binding and test the user’s permissions.

1) Create the user

Create a user named mikeuser and confirm it exists:

2) Create a ClusterRole and ClusterRoleBinding (single YAML)

Place both the ClusterRole and ClusterRoleBinding into one YAML file (for example role.yaml). This ClusterRole grants only read verbs (get, list, watch) on pods; the binding attaches that role to the mikeuser user.
Remember: subject kinds are case-sensitive. Use User, Group, or ServiceAccount exactly as shown.
Important: the kind field under subjects is case-sensitive. Using user (lowercase) will cause the ClusterRoleBinding to be rejected.

3) Apply the YAML

Apply the combined YAML to create the ClusterRole and ClusterRoleBinding:

4) Verify the binding and test permissions

  • In the OpenShift Console: go to Users → select mikeuser → RoleBindings. You should see mike-can-read-pods referencing mikesreaduser, which allows get, list, and watch on pods.
  • Example oc get / oc describe output for the ClusterRoleBinding (this mirrors what you might see in the console or from oc get clusterrolebinding -o yaml):
  • Optional quick permission test (run as a cluster-admin or a user who can impersonate):
Expected output: yes (if the binding is effective). Try a write verb to confirm denial:
Expected output: no

5) Restricting access to a single namespace

If you want the user limited to a single namespace instead of cluster-wide pod access, create a Role and a RoleBinding in that namespace (namespace-scoped). Replace kind: ClusterRole / ClusterRoleBinding with Role / RoleBinding and include the target metadata.namespace in both objects.

Quick reference

Now mikeuser can view pods cluster-wide (or, if you prefer, only in a namespace) without being able to modify resources.

Watch Video