Managing Role-based Access Control (RBAC)

    You are viewing documentation for a release that is no longer supported. The latest supported version of version 3 is [3.11]. For the most recent version 4, see

    You can use the CLI to view and the administrator CLI to manage the roles and bindings.

    Viewing roles and bindings

    Roles can be used to grant various levels of access both as well as at the project-scope. can be associated with, or bound to, multiple roles at the same time. You can view details about the roles and their bindings using the command.

    Users with the cluster-admin default cluster role bound cluster-wide can perform any action on any resource. Users with the bound locally can manage roles and bindings in that project.

    To view the cluster roles and their associated rule sets:

    To view the current set of cluster role bindings, which show the users and groups that are bound to various roles:

    1. $ oc describe clusterrolebinding.rbac
    2. Name: admin
    3. Labels: <none>
    4. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    5. Role:
    6. Kind: ClusterRole
    7. Name: admin
    8. Subjects:
    9. Kind Name Namespace
    10. ---- ---- ---------
    11. ServiceAccount template-instance-controller openshift-infra
    12. Name: basic-users
    13. Labels: <none>
    14. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    15. Role:
    16. Kind: ClusterRole
    17. Name: basic-user
    18. Subjects:
    19. Kind Name Namespace
    20. ---- ---- ---------
    21. Group system:authenticated
    22. Name: cluster-admin
    23. Labels: kubernetes.io/bootstrapping=rbac-defaults
    24. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    25. Role:
    26. Kind: ClusterRole
    27. Name: cluster-admin
    28. Subjects:
    29. Kind Name Namespace
    30. ---- ---- ---------
    31. ServiceAccount pvinstaller default
    32. Group system:masters
    33. Name: cluster-admins
    34. Labels: <none>
    35. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    36. Role:
    37. Kind: ClusterRole
    38. Name: cluster-admin
    39. Subjects:
    40. Kind Name Namespace
    41. ---- ---- ---------
    42. Group system:cluster-admins
    43. User system:admin
    44. Name: cluster-readers
    45. Labels: <none>
    46. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    47. Role:
    48. Kind: ClusterRole
    49. Name: cluster-reader
    50. Subjects:
    51. Kind Name Namespace
    52. ---- ---- ---------
    53. Group system:cluster-readers
    54. Name: cluster-status-binding
    55. Labels: <none>
    56. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    57. Role:
    58. Kind: ClusterRole
    59. Name: cluster-status
    60. Subjects:
    61. Kind Name Namespace
    62. ---- ---- ---------
    63. Group system:authenticated
    64. Group system:unauthenticated
    65. Name: registry-registry-role
    66. Labels: <none>
    67. Annotations: <none>
    68. Role:
    69. Kind: ClusterRole
    70. Name: system:registry
    71. Subjects:
    72. ---- ---- ---------
    73. ServiceAccount registry default
    74. Name: router-router-role
    75. Labels: <none>
    76. Annotations: <none>
    77. Role:
    78. Kind: ClusterRole
    79. Name: system:router
    80. Subjects:
    81. Kind Name Namespace
    82. ---- ---- ---------
    83. Name: self-access-reviewers
    84. Labels: <none>
    85. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    86. Role:
    87. Kind: ClusterRole
    88. Name: self-access-reviewer
    89. Subjects:
    90. Kind Name Namespace
    91. ---- ---- ---------
    92. Group system:authenticated
    93. Group system:unauthenticated
    94. Name: self-provisioners
    95. Labels: <none>
    96. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    97. Role:
    98. Kind: ClusterRole
    99. Name: self-provisioner
    100. Subjects:
    101. Kind Name Namespace
    102. ---- ---- ---------
    103. Group system:authenticated:oauth
    104. Name: system:basic-user
    105. Labels: kubernetes.io/bootstrapping=rbac-defaults
    106. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    107. Role:
    108. Kind: ClusterRole
    109. Name: system:basic-user
    110. Subjects:
    111. Kind Name Namespace
    112. ---- ---- ---------
    113. Group system:authenticated
    114. Group system:unauthenticated
    115. Name: system:build-strategy-docker-binding
    116. Labels: <none>
    117. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    118. Role:
    119. Kind: ClusterRole
    120. Name: system:build-strategy-docker
    121. Subjects:
    122. Kind Name Namespace
    123. ---- ---- ---------
    124. Group system:authenticated
    125. Name: system:build-strategy-jenkinspipeline-binding
    126. Labels: <none>
    127. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    128. Role:
    129. Kind: ClusterRole
    130. Name: system:build-strategy-jenkinspipeline
    131. Subjects:
    132. Kind Name Namespace
    133. ---- ---- ---------
    134. Group system:authenticated
    135. Name: system:build-strategy-source-binding
    136. Labels: <none>
    137. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    138. Role:
    139. Kind: ClusterRole
    140. Name: system:build-strategy-source
    141. Subjects:
    142. Kind Name Namespace
    143. ---- ---- ---------
    144. Group system:authenticated
    145. Name: system:controller:attachdetach-controller
    146. Labels: kubernetes.io/bootstrapping=rbac-defaults
    147. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    148. Kind: ClusterRole
    149. Name: system:controller:attachdetach-controller
    150. Subjects:
    151. Kind Name Namespace
    152. ---- ---- ---------
    153. ServiceAccount attachdetach-controller kube-system
    154. Name: system:controller:certificate-controller
    155. Labels: kubernetes.io/bootstrapping=rbac-defaults
    156. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    157. Role:
    158. Kind: ClusterRole
    159. Name: system:controller:certificate-controller
    160. Subjects:
    161. Kind Name Namespace
    162. ---- ---- ---------
    163. Name: system:controller:cronjob-controller
    164. Labels: kubernetes.io/bootstrapping=rbac-defaults
    165. Annotations: rbac.authorization.kubernetes.io/autoupdate=true
    166. ...

    All of the default cluster roles can be bound locally to users or groups.

    can be created.

    The local role bindings are also viewable.

    To view the current set of local role bindings, which show the users and groups that are bound to various roles:

    1. $ oc describe rolebinding.rbac

    By default, the current project is used when viewing local role bindings. Alternatively, a project can be specified with the -n flag. This is useful for viewing the local role bindings of another project, if the user already has the admin default cluster role in it.

    1. $ oc describe rolebinding.rbac -n joe-project
    2. Name: admin
    3. Labels: <none>
    4. Annotations: <none>
    5. Role:
    6. Kind: ClusterRole
    7. Name: admin
    8. Subjects:
    9. Kind Name Namespace
    10. ---- ---- ---------
    11. User joe
    12. Name: system:deployers
    13. Labels: <none>
    14. Annotations: <none>
    15. Role:
    16. Kind: ClusterRole
    17. Name: system:deployer
    18. Subjects:
    19. Kind Name Namespace
    20. ---- ---- ---------
    21. ServiceAccount deployer joe-project
    22. Name: system:image-builders
    23. Labels: <none>
    24. Annotations: <none>
    25. Role:
    26. Kind: ClusterRole
    27. Name: system:image-builder
    28. Subjects:
    29. Kind Name Namespace
    30. ---- ---- ---------
    31. ServiceAccount builder joe-project
    32. Name: system:image-pullers
    33. Labels: <none>
    34. Annotations: <none>
    35. Role:
    36. Kind: ClusterRole
    37. Name: system:image-puller
    38. Subjects:
    39. Kind Name Namespace
    40. ---- ---- ---------
    41. Group system:serviceaccounts:joe-project

    Adding, or binding, a to users or groups gives the user or group the relevant access granted by the role. You can add and remove roles to and from users and groups using oc adm policy commands.

    When managing a user or group’s associated roles for local role bindings using the following operations, a project may be specified with the -n flag. If it is not specified, then the current project is used.

    Table 1. Local role binding operations
    CommandDescription

    $ oc adm policy who-can <verb> <resource>

    Indicates which users can perform an action on a resource.

    $ oc adm policy add-role-to-user <role> <username>

    Binds a given role to specified users in the current project.

    $ oc adm policy remove-role-from-user <role> <username>

    Removes a given role from specified users in the current project.

    $ oc adm policy remove-user <username>

    $ oc adm policy add-role-to-group <role> <groupname>

    Binds a given role to specified groups in the current project.

    $ oc adm policy remove-role-from-group <role> <groupname>

    Removes a given role from specified groups in the current project.

    $ oc adm policy remove-group <groupname>

    Removes specified groups and all of their roles in the current project.

    —rolebinding-name=

    Can be used with oc adm policy commands to retain the rolebinding name assigned to a user or group.

    You can also manage cluster role bindings using the following operations. The -n flag is not used for these operations because cluster role bindings use non-namespaced resources.

    For example, you can add the admin role to the alice user in joe-project by running:

    1. $ oc adm policy add-role-to-user admin alice -n joe-project

    You can then view the local role bindings and verify the addition in the output:

    1The alice user has been added to the admins RoleBinding.

    Creating a local role

    1. To create a local role for a project, run the following command:

      1. $ oc create role <name> --verb=<verb> --resource=<resource> -n <project>

      In this command, specify: * <name>, the local role’s name * <verb>, a comma-separated list of the verbs to apply to the role * <resource>, the resources that the role applies to * <project>, the project name

      + For example, to create a local role that allows a user to view pods in the blue project, run the following command:

      +

      1. $ oc create role podview --verb=get --resource=pod -n blue
    2. To bind the new role to a user, run the following command:

    1. $ oc adm policy add-role-to-user podview user2 --role-namespace=blue -n blue

    To create a cluster role, run the following command:

    1. $ oc create clusterrole <name> --verb=<verb> --resource=<resource>

    In this command, specify:

    • <name>, the local role’s name

    • <verb>, a comma-separated list of the verbs to apply to the role

    • <resource>, the resources that the role applies to

    For example, to create a cluster role that allows a user to view pods, run the following command:

    Cluster and local role bindings

    A cluster role binding is a binding that exists at the cluster level. A role binding exists at the project level. The cluster role view must be bound to a user using a local role binding for that user to view the project. Create local roles only if a cluster role does not provide the set of permissions needed for a particular situation.

    Some cluster role names are initially confusing. You can bind the cluster-admin to a user, using a local role binding, making it appear that this user has the privileges of a cluster administrator. This is not the case. Binding the cluster-admin to a certain project is more like a super administrator for that project, granting the permissions of the cluster role admin, plus a few additional permissions like the ability to edit rate limits. This can appear confusing especially via the web console UI, which does not list cluster role bindings that are bound to true cluster administrators. However, it does list local role bindings that you can use to locally bind cluster-admin.

    During a cluster upgrade, and on every restart of any master, the are automatically reconciled to restore any missing permissions.

    If you customized default cluster roles and want to ensure a role reconciliation does not modify them:

    1. Protect each role from reconciliation:

      1. $ oc annotate clusterrole.rbac <role_name> --overwrite rbac.authorization.kubernetes.io/autoupdate=false
    2. Generate a default bootstrap policy template file:

      1. $ oc adm create-bootstrap-policy-file --filename=policy.json

      The contents of the file vary based on the OKD version, but the file contains only the default policies.

    3. Update the policy.json file to include any cluster role customizations.

    4. Use the policy file to automatically reconcile roles and role bindings that are not reconcile protected:

      1. $ oc auth reconcile -f policy.json
      1. # oc adm policy reconcile-sccs \
      2. --additive-only=true \