DavidPurcell | b25f93d | 2017-01-27 12:46:27 -0500 | [diff] [blame] | 1 | # Copyright 2017 AT&T Corporation. |
DavidPurcell | 663aedf | 2017-01-03 10:01:14 -0500 | [diff] [blame] | 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from oslo_config import cfg |
| 17 | |
DavidPurcell | 029d8c3 | 2017-01-06 15:27:41 -0500 | [diff] [blame] | 18 | |
Felipe Monteiro | f6eb862 | 2017-08-06 06:08:02 +0100 | [diff] [blame] | 19 | patrole_group = cfg.OptGroup(name='patrole', title='Patrole Testing Options') |
| 20 | |
| 21 | |
| 22 | PatroleGroup = [ |
DavidPurcell | 029d8c3 | 2017-01-06 15:27:41 -0500 | [diff] [blame] | 23 | cfg.StrOpt('rbac_test_role', |
| 24 | default='admin', |
Felipe Monteiro | 8390341 | 2018-07-09 16:33:55 +0100 | [diff] [blame] | 25 | help="""The current RBAC role against which to run |
| 26 | Patrole tests."""), |
Felipe Monteiro | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 27 | cfg.ListOpt('custom_policy_files', |
| 28 | default=['/etc/%s/policy.json'], |
| 29 | help="""List of the paths to search for policy files. Each |
| 30 | policy path assumes that the service name is included in the path once. Also |
| 31 | assumes Patrole is on the same host as the policy files. The paths should be |
Sergey Vilgelm | 062fb15 | 2018-09-06 20:51:57 -0500 | [diff] [blame] | 32 | ordered by precedence, with high-priority paths before low-priority paths. All |
| 33 | the paths that are found to contain the service's policy file will be used and |
Sergey Vilgelm | ef7047d | 2018-09-11 14:48:55 -0500 | [diff] [blame] | 34 | all policy files will be merged. Allowed ``json`` or ``yaml`` formats. |
Felipe Monteiro | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 35 | """), |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 36 | cfg.BoolOpt('test_custom_requirements', |
| 37 | default=False, |
| 38 | help=""" |
| 39 | This option determines whether Patrole should run against a |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 40 | ``custom_requirements_file`` which defines RBAC requirements. The |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 41 | purpose of setting this flag to ``True`` is to verify that RBAC policy |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 42 | is in accordance to requirements. The idea is that the |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 43 | ``custom_requirements_file`` precisely defines what the RBAC requirements are. |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 44 | |
| 45 | Here are the possible outcomes when running the Patrole tests against |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 46 | a ``custom_requirements_file``: |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 47 | |
| 48 | YAML definition: allowed |
| 49 | test run: allowed |
| 50 | test result: pass |
| 51 | |
| 52 | YAML definition: allowed |
| 53 | test run: not allowed |
Felipe Monteiro | f16b6b3 | 2018-06-28 19:32:59 -0400 | [diff] [blame] | 54 | test result: fail (under-permission) |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 55 | |
| 56 | YAML definition: not allowed |
| 57 | test run: allowed |
| 58 | test result: fail (over-permission) |
| 59 | """), |
| 60 | cfg.StrOpt('custom_requirements_file', |
| 61 | help=""" |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 62 | File path of the YAML file that defines your RBAC requirements. This |
| 63 | file must be located on the same host that Patrole runs on. The YAML |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 64 | file should be written as follows: |
| 65 | |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 66 | .. code-block:: yaml |
| 67 | |
| 68 | <service_foo>: |
| 69 | <api_action_a>: |
| 70 | - <allowed_role_1> |
| 71 | - <allowed_role_2> |
| 72 | - <allowed_role_3> |
| 73 | <api_action_b>: |
| 74 | - <allowed_role_2> |
| 75 | - <allowed_role_4> |
| 76 | <service_bar>: |
| 77 | <api_action_c>: |
| 78 | - <allowed_role_3> |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 79 | |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 80 | Where: |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 81 | |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 82 | service = the service that is being tested (Cinder, Nova, etc.). |
| 83 | |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 84 | api_action = the policy action that is being tested. Examples: |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 85 | |
| 86 | * volume:create |
| 87 | * os_compute_api:servers:start |
| 88 | * add_image |
| 89 | |
| 90 | allowed_role = the ``oslo.policy`` role that is allowed to perform the API. |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 91 | """) |
DavidPurcell | 029d8c3 | 2017-01-06 15:27:41 -0500 | [diff] [blame] | 92 | ] |
Felipe Monteiro | f6eb862 | 2017-08-06 06:08:02 +0100 | [diff] [blame] | 93 | |
| 94 | |
Sean Pryor | 7f8993f | 2017-08-14 12:53:17 -0400 | [diff] [blame] | 95 | patrole_log_group = cfg.OptGroup( |
| 96 | name='patrole_log', title='Patrole Logging Options') |
| 97 | |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 98 | |
Sean Pryor | 7f8993f | 2017-08-14 12:53:17 -0400 | [diff] [blame] | 99 | PatroleLogGroup = [ |
| 100 | cfg.BoolOpt('enable_reporting', |
| 101 | default=False, |
| 102 | help="Enables reporting on RBAC expected and actual test " |
| 103 | "results for each Patrole test"), |
| 104 | cfg.StrOpt('report_log_name', |
| 105 | default='patrole.log', |
| 106 | help="Name of file where output from 'enable_reporting' is " |
| 107 | "logged. Note that this file is recreated on each " |
| 108 | "invocation of patrole"), |
| 109 | cfg.StrOpt('report_log_path', |
| 110 | default='.', |
| 111 | help="Path (relative or absolute) where the output from " |
| 112 | "'enable_reporting' is logged. This is combined with" |
| 113 | "report_log_name to generate the full path."), |
| 114 | ] |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 115 | |
| 116 | |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 117 | policy_feature_enabled = cfg.OptGroup( |
| 118 | name='policy-feature-enabled', |
| 119 | title='Feature Flags for New or Changed Policies') |
| 120 | |
| 121 | |
| 122 | PolicyFeatureEnabledGroup = [ |
| 123 | # TODO(felipemonteiro): The 6 feature flags below should be removed after |
| 124 | # Pike is EOL. |
| 125 | cfg.BoolOpt('create_port_fixed_ips_ip_address_policy', |
| 126 | default=True, |
| 127 | help="""Is the Neutron policy |
| 128 | "create_port:fixed_ips:ip_address" available in the cloud? This policy was |
| 129 | changed in a backwards-incompatible way."""), |
| 130 | cfg.BoolOpt('update_port_fixed_ips_ip_address_policy', |
| 131 | default=True, |
| 132 | help="""Is the Neutron policy |
| 133 | "update_port:fixed_ips:ip_address" available in the cloud? This policy was |
| 134 | changed in a backwards-incompatible way."""), |
| 135 | cfg.BoolOpt('limits_extension_used_limits_policy', |
| 136 | default=True, |
| 137 | help="""Is the Cinder policy |
| 138 | "limits_extension:used_limits" available in the cloud? This policy was |
| 139 | changed in a backwards-incompatible way."""), |
| 140 | cfg.BoolOpt('volume_extension_volume_actions_attach_policy', |
| 141 | default=True, |
| 142 | help="""Is the Cinder policy |
| 143 | "volume_extension:volume_actions:attach" available in the cloud? This policy |
| 144 | was changed in a backwards-incompatible way."""), |
| 145 | cfg.BoolOpt('volume_extension_volume_actions_reserve_policy', |
| 146 | default=True, |
| 147 | help="""Is the Cinder policy |
| 148 | "volume_extension:volume_actions:reserve" available in the cloud? This policy |
| 149 | was changed in a backwards-incompatible way."""), |
| 150 | cfg.BoolOpt('volume_extension_volume_actions_unreserve_policy', |
| 151 | default=True, |
| 152 | help="""Is the Cinder policy |
| 153 | "volume_extension:volume_actions:unreserve" available in the cloud? This policy |
Felipe Monteiro | 6bffc5c | 2018-08-19 22:54:33 +0100 | [diff] [blame] | 154 | was changed in a backwards-incompatible way."""), |
| 155 | # *** Include feature flags for groups of policies below. *** |
| 156 | # Best practice is to capture new policies, removed policies, renamed |
| 157 | # policies in a group, per release. |
| 158 | # |
| 159 | # TODO(felipemonteiro): Remove these feature flags once Stein is EOL. |
| 160 | cfg.BoolOpt('removed_nova_policies_stein', |
| 161 | default=True, |
| 162 | help="""Are the Nova API extension policies available in the |
| 163 | cloud (e.g. os_compute_api:os-extended-availability-zone)? These policies were |
| 164 | removed in Stein because Nova API extension concept was removed in Pike."""), |
Chi Lo | 8c04bd8 | 2018-06-01 16:21:50 -0500 | [diff] [blame] | 165 | cfg.BoolOpt('added_cinder_policies_stein', |
| 166 | default=True, |
| 167 | help="""Are the Cinder API extension policies available in the |
| 168 | cloud (e.g. [create|update|get|delete]_encryption_policy)? These policies are |
| 169 | added in Stein.""") |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 170 | ] |
| 171 | |
| 172 | |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 173 | def list_opts(): |
| 174 | """Return a list of oslo.config options available. |
| 175 | |
| 176 | The purpose of this is to allow tools like the Oslo sample config file |
| 177 | generator to discover the options exposed to users. |
| 178 | """ |
| 179 | opt_list = [ |
| 180 | (patrole_group, PatroleGroup), |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 181 | (patrole_log_group, PatroleLogGroup), |
| 182 | (policy_feature_enabled, PolicyFeatureEnabledGroup) |
| 183 | |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 184 | ] |
| 185 | |
| 186 | return opt_list |