How to list users with role cluster-admin in OpenShift?
I can add users to the cluster-role "cluster-admin" with:
oc adm policy add-cluster-role-to-user cluster-admin <user>
But how can I list all users with the role cluster-admin?
Environment: OpenShift 3.x
Solution 1:
Found it myself:
It's in the RoleBinding[cluster-admins]:
section of:
oc describe clusterPolicyBindings :default
With jq
you can get the list of users in one command:
oc get --all-namespaces --output json clusterPolicyBindings | jq '.items[].roleBindings[] | select(.name=="cluster-admins") | .roleBinding.userNames'
For OpenShift 3.7 and newer:
oc get clusterrolebindings -o json | jq '.items[] | select(.metadata.name=="cluster-admins") | .userNames'
Solution 2:
in openshift 3.9 the cluster admins are located in different dictionaries(cluster-admin-0,cluster-admin-1, and so on). To list them:
oc get clusterrolebinding -o json | jq '.items[] | select(.metadata.name | startswith("cluster-admin")) | .userNames'