How to list users with role cluster-admin in OpenShift?

15,305

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'
Share:
15,305

Related videos on Youtube

tlo
Author by

tlo

Twitter: @sengaya https://twitter.com/sengaya

Updated on September 18, 2022

Comments

  • tlo
    tlo over 1 year

    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