|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * masters/extending-api-with-crds.adoc |
| 4 | + |
| 5 | +[id='crd-creating-aggregated-cluster-role-{context}'] |
| 6 | += Creating cluster roles for Custom Resource Definitions |
| 7 | + |
| 8 | +After creating a cluster-scoped Custom Resource Definition (CRD), cluster |
| 9 | +administrators can grant permissions to it. If you use the `admin`, `edit`, and |
| 10 | +`view` default cluster roles, take advantage of cluster role aggregation for |
| 11 | +their rules. |
| 12 | + |
| 13 | +[IMPORTANT] |
| 14 | +==== |
| 15 | +You must explicitly assign permissions to each of these roles. The roles with |
| 16 | +more permissions do not inherit rules from roles with fewer permissions. If you |
| 17 | +assign a rule to a role, you must also assign that verb to roles that have more |
| 18 | +permissions. For example, if you grant the `get crontabs` permission to the view |
| 19 | +role, you must also grant it to the edit and admin roles. The admin or edit role |
| 20 | +is usually assigned to the user that created a project through the project |
| 21 | +template. |
| 22 | +==== |
| 23 | + |
| 24 | +.Prerequisites |
| 25 | + |
| 26 | +- Create a CRD. |
| 27 | + |
| 28 | +.Procedure |
| 29 | + |
| 30 | +. Create a cluster role definition file for the CRD. The cluster role definition |
| 31 | +is a YAML file that contains the rules that apply to each cluster role. The |
| 32 | +{product-title} controller adds the rules that you specify to the default |
| 33 | +cluster roles. |
| 34 | ++ |
| 35 | +.Example YAML file for a cluster role definition |
| 36 | +[source,yaml] |
| 37 | +---- |
| 38 | +kind: ClusterRole |
| 39 | +apiVersion: rbac.authorization.k8s.io/v1 <1> |
| 40 | +metadata: |
| 41 | + name: name: aggregate-cron-tabs-admin-edit <2> |
| 42 | + labels: |
| 43 | + rbac.authorization.k8s.io/aggregate-to-admin: "true" <3> |
| 44 | + rbac.authorization.k8s.io/aggregate-to-edit: "true" <4> |
| 45 | +rules: |
| 46 | +- apiGroups: ["stable.example.com"] <5> |
| 47 | + resources: ["crontabs"] <6> |
| 48 | + verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"] <7> |
| 49 | +--- |
| 50 | +kind: ClusterRole |
| 51 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 52 | +metadata: |
| 53 | + name: aggregate-cron-tabs-view <2> |
| 54 | + labels: |
| 55 | + # Add these permissions to the "view" default role. |
| 56 | + rbac.authorization.k8s.io/aggregate-to-view: "true" <8> |
| 57 | + rbac.authorization.k8s.io/aggregate-to-cluster-reader: "true" <9> |
| 58 | +rules: |
| 59 | +- apiGroups: ["stable.example.com"] <5> |
| 60 | + resources: ["crontabs"] <6> |
| 61 | + verbs: ["get", "list", "watch"] <7> |
| 62 | +---- |
| 63 | +<1> Use the `apiextensions.k8s.io/v1beta1` API. |
| 64 | +<2> Specify a name for the definition. |
| 65 | +<3> Specify this label to grant permissions to the admin default role. |
| 66 | +<4> Specify this label to grant permissions to the edit default role. |
| 67 | +<5> Specify the group name of the CRD. |
| 68 | +<6> Specify the plural name of the CRD that these rules apply to. |
| 69 | +<7> Specify the verbs that represent the permissions that are granted to the role. |
| 70 | +For example, apply read and write permissions to the `admin` and `edit` roles |
| 71 | +and only read permission to the `view` role. |
| 72 | +<8> Specify this label to grant permissions to the `view` default role. |
| 73 | +<9> Specify this label to grant permissions to the `cluster-reader` default role. |
| 74 | + |
| 75 | +. Create the cluster role: |
| 76 | ++ |
| 77 | +---- |
| 78 | +$ oc create -f <file_name>.yaml |
| 79 | +---- |
0 commit comments