|
| 1 | +[id='proc-rbac-config-conditional-policy-file_{context}'] |
| 2 | += Configuring conditional policies defined in an external file |
| 3 | + |
| 4 | +You can configure and manage conditional policies that are defined in an external file. To define conditional policies, you can directly edit the configuration files and pass them to {product-short}, instead of using the {product-short} web UI or API. You can configure {product-short} to use these files instead of the default files. |
| 5 | + |
| 6 | +.Prerequisites |
| 7 | +* You are logged in to your {ocp-short} account using the {ocp-short} web console. |
| 8 | +* You have defined roles and associated policies in a CSV file that serves as a basis for creating roles and permissions. Ensure that you mount the CSV file to {product-short}. |
| 9 | ++ |
| 10 | +For more information, see xref:ref-rbac-conditional-policy-definition_title-authorization[] and xref:con-rbac-config-permission-policies-external-file_title-authorization[]. |
| 11 | + |
| 12 | +.Procedure |
| 13 | + |
| 14 | +. Define conditional policies in a YAML file, which includes role references, permission mappings, and conditions. |
| 15 | ++ |
| 16 | +-- |
| 17 | +The following is an example of a YAML file defining conditional policies: |
| 18 | + |
| 19 | +.Example YAML file defining conditional policies |
| 20 | +[source,yaml] |
| 21 | +---- |
| 22 | +--- |
| 23 | +result: CONDITIONAL |
| 24 | +roleEntityRef: 'role:default/test' |
| 25 | +pluginId: catalog |
| 26 | +resourceType: catalog-entity |
| 27 | +permissionMapping: |
| 28 | + - read |
| 29 | + - update |
| 30 | +conditions: |
| 31 | + rule: IS_ENTITY_OWNER |
| 32 | + resourceType: catalog-entity |
| 33 | + params: |
| 34 | + claims: |
| 35 | + - 'group:default/team-a' |
| 36 | + - 'group:default/team-b' |
| 37 | +--- |
| 38 | +result: CONDITIONAL |
| 39 | +roleEntityRef: 'role:default/test' |
| 40 | +pluginId: catalog |
| 41 | +resourceType: catalog-entity |
| 42 | +permissionMapping: |
| 43 | + - delete |
| 44 | +conditions: |
| 45 | + rule: IS_ENTITY_OWNER |
| 46 | + resourceType: catalog-entity |
| 47 | + params: |
| 48 | + claims: |
| 49 | + - 'group:default/team-a' |
| 50 | +---- |
| 51 | +-- |
| 52 | +. In {ocp-short}, create a ConfigMap to hold the policies as shown in the following example: |
| 53 | ++ |
| 54 | +-- |
| 55 | +.Example ConfigMap |
| 56 | +[source, yaml] |
| 57 | +---- |
| 58 | +kind: ConfigMap |
| 59 | +apiVersion: v1 |
| 60 | +metadata: |
| 61 | + name: rbac-conditional-policy |
| 62 | + namespace: rhdh |
| 63 | +data: |
| 64 | + rbac-policy.yaml: | |
| 65 | + p, role:default/guests, catalog-entity, read, allow |
| 66 | +
|
| 67 | + result: CONDITIONAL |
| 68 | + roleEntityRef: 'role:default/test' |
| 69 | + pluginId: catalog |
| 70 | + resourceType: catalog-entity |
| 71 | + permissionMapping: |
| 72 | + - read |
| 73 | + - update |
| 74 | + conditions: |
| 75 | + rule: IS_ENTITY_OWNER |
| 76 | + resourceType: catalog-entity |
| 77 | + params: |
| 78 | + claims: |
| 79 | + - 'group:default/team-a' |
| 80 | + - 'group:default/team-b' |
| 81 | +---- |
| 82 | +-- |
| 83 | + |
| 84 | +. Open `app-config.yaml` file and specify the path to `conditionalPoliciesFile` as shown in the following example: |
| 85 | ++ |
| 86 | +-- |
| 87 | +.Example `app-config.yaml` file |
| 88 | +[source,yaml] |
| 89 | +---- |
| 90 | +permission: |
| 91 | + enabled: true |
| 92 | + rbac: |
| 93 | + conditionalPoliciesFile: /some/path/conditional-policies.yaml |
| 94 | +---- |
| 95 | +-- |
| 96 | + |
| 97 | +. To enable automatic reloading of the policy file without restarting the application, add the `policyFileReload` option and set it to `true`: |
| 98 | ++ |
| 99 | +-- |
| 100 | +.Example `app-config.yaml` file |
| 101 | +[source,yaml] |
| 102 | +---- |
| 103 | +permission: |
| 104 | + enabled: true |
| 105 | + rbac: |
| 106 | + conditionalPoliciesFile: /some/path/conditional-policies.yaml |
| 107 | + policies-csv-file: /some/path/rbac-policy.csv |
| 108 | + policyFileReload: true |
| 109 | +---- |
| 110 | +-- |
| 111 | + |
| 112 | +. Optional: Define nested conditional policies in the YAML file as needed. |
| 113 | ++ |
| 114 | +-- |
| 115 | +.Example for nested conditional policies |
| 116 | +[source,yaml] |
| 117 | +---- |
| 118 | +{ |
| 119 | + "result": "CONDITIONAL", |
| 120 | + "roleEntityRef": "role:default/developer", |
| 121 | + "pluginId": "catalog", |
| 122 | + "resourceType": "catalog-entity", |
| 123 | + "permissionMapping": ["delete"], |
| 124 | + "conditions": { |
| 125 | + "allOf": [ |
| 126 | + { |
| 127 | + "anyOf": [ |
| 128 | + { |
| 129 | + "rule": "IS_ENTITY_KIND", |
| 130 | + "resourceType": "catalog-entity", |
| 131 | + "params": { |
| 132 | + "kinds": [ |
| 133 | + "group" |
| 134 | + ] |
| 135 | + } |
| 136 | + }, |
| 137 | + { |
| 138 | + "rule": "IS_ENTITY_OWNER", |
| 139 | + "resourceType": "catalog-entity", |
| 140 | + "params": { |
| 141 | + "claims": [ |
| 142 | + "$ownerRefs" |
| 143 | + ] |
| 144 | + } |
| 145 | + } |
| 146 | + ] |
| 147 | + }, |
| 148 | + { |
| 149 | + "not": { |
| 150 | + "rule": "IS_ENTITY_KIND", |
| 151 | + "resourceType": "catalog-entity", |
| 152 | + "params": { |
| 153 | + "kinds": [ |
| 154 | + "api" |
| 155 | + ] |
| 156 | + } |
| 157 | + } |
| 158 | + } |
| 159 | + ] |
| 160 | +} |
| 161 | +} |
| 162 | +---- |
| 163 | + |
| 164 | +In the previous example, the `role:default/developer` is granted the condition to delete catalog entities only if they are the entity owner or if the catalog entity belongs to a group. However, this condition does not apply if the catalog entity is an API. |
| 165 | +-- |
| 166 | + |
0 commit comments