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."""), |
Samantha Blanco | 0d88008 | 2017-03-23 18:14:37 -0400 | [diff] [blame] | 27 | cfg.BoolOpt('enable_rbac', |
Felipe Monteiro | 2c0c55a | 2017-03-06 17:22:10 -0500 | [diff] [blame] | 28 | default=True, |
Felipe Monteiro | 8390341 | 2018-07-09 16:33:55 +0100 | [diff] [blame] | 29 | deprecated_for_removal=True, |
| 30 | deprecated_reason="""This is a legacy option that was |
| 31 | meaningful when Patrole existed downstream as a suite of tests inside Tempest. |
| 32 | Installing the Patrole plugin necessarily means that RBAC tests should be run. |
| 33 | This option is paradoxical with the Tempest plugin architecture. |
| 34 | """, |
| 35 | deprecated_since='R', |
| 36 | help="Enables Patrole RBAC tests."), |
Felipe Monteiro | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 37 | cfg.ListOpt('custom_policy_files', |
| 38 | default=['/etc/%s/policy.json'], |
| 39 | help="""List of the paths to search for policy files. Each |
| 40 | policy path assumes that the service name is included in the path once. Also |
| 41 | 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^] | 42 | ordered by precedence, with high-priority paths before low-priority paths. All |
| 43 | the paths that are found to contain the service's policy file will be used and |
| 44 | all policy files will be merged. |
Felipe Monteiro | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 45 | """), |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 46 | cfg.BoolOpt('test_custom_requirements', |
| 47 | default=False, |
| 48 | help=""" |
| 49 | This option determines whether Patrole should run against a |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 50 | ``custom_requirements_file`` which defines RBAC requirements. The |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 51 | 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] | 52 | is in accordance to requirements. The idea is that the |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 53 | ``custom_requirements_file`` precisely defines what the RBAC requirements are. |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 54 | |
| 55 | Here are the possible outcomes when running the Patrole tests against |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 56 | a ``custom_requirements_file``: |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 57 | |
| 58 | YAML definition: allowed |
| 59 | test run: allowed |
| 60 | test result: pass |
| 61 | |
| 62 | YAML definition: allowed |
| 63 | test run: not allowed |
Felipe Monteiro | f16b6b3 | 2018-06-28 19:32:59 -0400 | [diff] [blame] | 64 | test result: fail (under-permission) |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 65 | |
| 66 | YAML definition: not allowed |
| 67 | test run: allowed |
| 68 | test result: fail (over-permission) |
| 69 | """), |
| 70 | cfg.StrOpt('custom_requirements_file', |
| 71 | help=""" |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 72 | File path of the YAML file that defines your RBAC requirements. This |
| 73 | 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] | 74 | file should be written as follows: |
| 75 | |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 76 | .. code-block:: yaml |
| 77 | |
| 78 | <service_foo>: |
| 79 | <api_action_a>: |
| 80 | - <allowed_role_1> |
| 81 | - <allowed_role_2> |
| 82 | - <allowed_role_3> |
| 83 | <api_action_b>: |
| 84 | - <allowed_role_2> |
| 85 | - <allowed_role_4> |
| 86 | <service_bar>: |
| 87 | <api_action_c>: |
| 88 | - <allowed_role_3> |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 89 | |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 90 | Where: |
Felipe Monteiro | 97117b0 | 2018-05-23 16:31:23 -0700 | [diff] [blame] | 91 | |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 92 | service = the service that is being tested (Cinder, Nova, etc.). |
| 93 | |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 94 | api_action = the policy action that is being tested. Examples: |
Felipe Monteiro | 66d54a9 | 2018-05-31 20:08:35 +0100 | [diff] [blame] | 95 | |
| 96 | * volume:create |
| 97 | * os_compute_api:servers:start |
| 98 | * add_image |
| 99 | |
| 100 | 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] | 101 | """) |
DavidPurcell | 029d8c3 | 2017-01-06 15:27:41 -0500 | [diff] [blame] | 102 | ] |
Felipe Monteiro | f6eb862 | 2017-08-06 06:08:02 +0100 | [diff] [blame] | 103 | |
| 104 | |
Sean Pryor | 7f8993f | 2017-08-14 12:53:17 -0400 | [diff] [blame] | 105 | patrole_log_group = cfg.OptGroup( |
| 106 | name='patrole_log', title='Patrole Logging Options') |
| 107 | |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 108 | |
Sean Pryor | 7f8993f | 2017-08-14 12:53:17 -0400 | [diff] [blame] | 109 | PatroleLogGroup = [ |
| 110 | cfg.BoolOpt('enable_reporting', |
| 111 | default=False, |
| 112 | help="Enables reporting on RBAC expected and actual test " |
| 113 | "results for each Patrole test"), |
| 114 | cfg.StrOpt('report_log_name', |
| 115 | default='patrole.log', |
| 116 | help="Name of file where output from 'enable_reporting' is " |
| 117 | "logged. Note that this file is recreated on each " |
| 118 | "invocation of patrole"), |
| 119 | cfg.StrOpt('report_log_path', |
| 120 | default='.', |
| 121 | help="Path (relative or absolute) where the output from " |
| 122 | "'enable_reporting' is logged. This is combined with" |
| 123 | "report_log_name to generate the full path."), |
| 124 | ] |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 125 | |
| 126 | |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 127 | policy_feature_enabled = cfg.OptGroup( |
| 128 | name='policy-feature-enabled', |
| 129 | title='Feature Flags for New or Changed Policies') |
| 130 | |
| 131 | |
| 132 | PolicyFeatureEnabledGroup = [ |
| 133 | # TODO(felipemonteiro): The 6 feature flags below should be removed after |
| 134 | # Pike is EOL. |
| 135 | cfg.BoolOpt('create_port_fixed_ips_ip_address_policy', |
| 136 | default=True, |
| 137 | help="""Is the Neutron policy |
| 138 | "create_port:fixed_ips:ip_address" available in the cloud? This policy was |
| 139 | changed in a backwards-incompatible way."""), |
| 140 | cfg.BoolOpt('update_port_fixed_ips_ip_address_policy', |
| 141 | default=True, |
| 142 | help="""Is the Neutron policy |
| 143 | "update_port:fixed_ips:ip_address" available in the cloud? This policy was |
| 144 | changed in a backwards-incompatible way."""), |
| 145 | cfg.BoolOpt('limits_extension_used_limits_policy', |
| 146 | default=True, |
| 147 | help="""Is the Cinder policy |
| 148 | "limits_extension:used_limits" available in the cloud? This policy was |
| 149 | changed in a backwards-incompatible way."""), |
| 150 | cfg.BoolOpt('volume_extension_volume_actions_attach_policy', |
| 151 | default=True, |
| 152 | help="""Is the Cinder policy |
| 153 | "volume_extension:volume_actions:attach" available in the cloud? This policy |
| 154 | was changed in a backwards-incompatible way."""), |
| 155 | cfg.BoolOpt('volume_extension_volume_actions_reserve_policy', |
| 156 | default=True, |
| 157 | help="""Is the Cinder policy |
| 158 | "volume_extension:volume_actions:reserve" available in the cloud? This policy |
| 159 | was changed in a backwards-incompatible way."""), |
| 160 | cfg.BoolOpt('volume_extension_volume_actions_unreserve_policy', |
| 161 | default=True, |
| 162 | help="""Is the Cinder policy |
| 163 | "volume_extension:volume_actions:unreserve" available in the cloud? This policy |
Felipe Monteiro | 6bffc5c | 2018-08-19 22:54:33 +0100 | [diff] [blame] | 164 | was changed in a backwards-incompatible way."""), |
| 165 | # *** Include feature flags for groups of policies below. *** |
| 166 | # Best practice is to capture new policies, removed policies, renamed |
| 167 | # policies in a group, per release. |
| 168 | # |
| 169 | # TODO(felipemonteiro): Remove these feature flags once Stein is EOL. |
| 170 | cfg.BoolOpt('removed_nova_policies_stein', |
| 171 | default=True, |
| 172 | help="""Are the Nova API extension policies available in the |
| 173 | cloud (e.g. os_compute_api:os-extended-availability-zone)? These policies were |
| 174 | removed in Stein because Nova API extension concept was removed in Pike."""), |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 175 | ] |
| 176 | |
| 177 | |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 178 | def list_opts(): |
| 179 | """Return a list of oslo.config options available. |
| 180 | |
| 181 | The purpose of this is to allow tools like the Oslo sample config file |
| 182 | generator to discover the options exposed to users. |
| 183 | """ |
| 184 | opt_list = [ |
| 185 | (patrole_group, PatroleGroup), |
Felipe Monteiro | 739041f | 2018-03-25 00:24:03 -0400 | [diff] [blame] | 186 | (patrole_log_group, PatroleLogGroup), |
| 187 | (policy_feature_enabled, PolicyFeatureEnabledGroup) |
| 188 | |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 189 | ] |
| 190 | |
| 191 | return opt_list |