|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * extensions/ce/user-access-resources.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | + |
| 7 | +[id="olmv1-granting-user-access-binding_{context}"] |
| 8 | += Granting user access to extension resources by using custom role bindings |
| 9 | + |
| 10 | +As a cluster administrator, you can manually create and configure role-based access control (RBAC) policies to grant user access to extension resources by using custom role bindings. |
| 11 | + |
| 12 | +.Prerequisites |
| 13 | + |
| 14 | +* A cluster extension has been installed on your cluster. |
| 15 | +* You have a list of API groups and resource names, as described in "Finding API groups and resources exposed by a cluster extension". |
| 16 | + |
| 17 | +.Procedure |
| 18 | + |
| 19 | +. If the installed cluster extension does not provide default cluster roles, manually create one or more roles: |
| 20 | + |
| 21 | +.. Consider the use cases for the set of roles described in "Common default cluster roles for users". |
| 22 | ++ |
| 23 | +For example, create one or more of the following `ClusterRole` object definitions, replacing `<cluster_extension_api_group>` and `<cluster_extension_custom_resource>` with the actual API group and resource names provided by the installed cluster extension: |
| 24 | ++ |
| 25 | +.Example `view-custom-resource.yaml` file |
| 26 | +[source,yaml] |
| 27 | +---- |
| 28 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 29 | +kind: ClusterRole |
| 30 | +metadata: |
| 31 | + name: view-custom-resource |
| 32 | +rules: |
| 33 | +- apiGroups: |
| 34 | + - <cluster_extension_api_group> |
| 35 | + resources: |
| 36 | + - <cluster_extension_custom_resources> |
| 37 | + verbs: |
| 38 | + - get |
| 39 | + - list |
| 40 | + - watch |
| 41 | +---- |
| 42 | ++ |
| 43 | +.Example `edit-custom-resource.yaml` file |
| 44 | +[source,yaml] |
| 45 | +---- |
| 46 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 47 | +kind: ClusterRole |
| 48 | +metadata: |
| 49 | + name: edit-custom-resource |
| 50 | +rules: |
| 51 | +- apiGroups: |
| 52 | + - <cluster_extension_api_group> |
| 53 | + resources: |
| 54 | + - <cluster_extension_custom_resources> |
| 55 | + verbs: |
| 56 | + - get |
| 57 | + - list |
| 58 | + - watch |
| 59 | + - create |
| 60 | + - update |
| 61 | + - patch |
| 62 | + - delete |
| 63 | +---- |
| 64 | ++ |
| 65 | +.Example `admin-custom-resource.yaml` file |
| 66 | +[source,yaml] |
| 67 | +---- |
| 68 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 69 | +kind: ClusterRole |
| 70 | +metadata: |
| 71 | + name: admin-custom-resource |
| 72 | +rules: |
| 73 | +- apiGroups: |
| 74 | + - <cluster_extension_api_group> |
| 75 | + resources: |
| 76 | + - <cluster_extension_custom_resources> |
| 77 | + verbs: |
| 78 | + - '*' <1> |
| 79 | +---- |
| 80 | +<1> Setting a wildcard (`*`) in `verbs` allows all actions on the specified resources. |
| 81 | + |
| 82 | +.. Create the cluster roles by running the following command for any YAML files you created: |
| 83 | ++ |
| 84 | +[source,terminal] |
| 85 | +---- |
| 86 | +$ oc create -f <filename>.yaml |
| 87 | +---- |
| 88 | + |
| 89 | +. Associate a cluster role to specific users or groups to grant them the necessary permissions for the resource by binding the cluster roles to individual user or group names: |
| 90 | + |
| 91 | +.. Create an object definition for either a _cluster role binding_ to grant access across all namespaces or a _role binding_ to grant access within a specific namespace: |
| 92 | ++ |
| 93 | +-- |
| 94 | +*** The following example cluster role bindings grant read-only `view` access to the custom resource across all namespaces: |
| 95 | ++ |
| 96 | +.Example `ClusterRoleBinding` object for a user |
| 97 | +[source,yaml] |
| 98 | +---- |
| 99 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 100 | +kind: ClusterRoleBinding |
| 101 | +metadata: |
| 102 | + name: view-custom-resource-binding |
| 103 | +subjects: |
| 104 | +- kind: User |
| 105 | + name: <user_name> |
| 106 | +roleRef: |
| 107 | + kind: ClusterRole |
| 108 | + name: view-custom-resource |
| 109 | + apiGroup: rbac.authorization.k8s.io |
| 110 | +---- |
| 111 | ++ |
| 112 | +.Example `ClusterRoleBinding` object for a user |
| 113 | +[source,yaml] |
| 114 | +---- |
| 115 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 116 | +kind: ClusterRoleBinding |
| 117 | +metadata: |
| 118 | + name: view-custom-resource-binding |
| 119 | +subjects: |
| 120 | +- kind: Group |
| 121 | + name: <group_name> |
| 122 | +roleRef: |
| 123 | + kind: ClusterRole |
| 124 | + name: view-custom-resource |
| 125 | + apiGroup: rbac.authorization.k8s.io |
| 126 | +---- |
| 127 | + |
| 128 | +*** The following role binding restricts `edit` permissions to a specific namespace: |
| 129 | ++ |
| 130 | +.Example `RoleBinding` object for a user |
| 131 | +[source,yaml] |
| 132 | +---- |
| 133 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 134 | +kind: RoleBinding |
| 135 | +metadata: |
| 136 | + name: edit-custom-resource-edit-binding |
| 137 | + namespace: <namespace> |
| 138 | +subjects: |
| 139 | +- kind: User |
| 140 | + name: <username> |
| 141 | +roleRef: |
| 142 | + kind: Role |
| 143 | + name: custom-resource-edit |
| 144 | + apiGroup: rbac.authorization.k8s.io |
| 145 | +---- |
| 146 | +-- |
| 147 | + |
| 148 | +.. Save your object definition to a YAML file. |
| 149 | + |
| 150 | +.. Create the object by running the following command: |
| 151 | ++ |
| 152 | +[source,terminal] |
| 153 | +---- |
| 154 | +$ oc create -f <filename>.yaml |
| 155 | +---- |
0 commit comments