blob: df05eaaf638d31aa181cbdffa7e57f5e05913f5c [file] [log] [blame]
DavidPurcellb25f93d2017-01-27 12:46:27 -05001# Copyright 2017 AT&T Corporation.
DavidPurcell663aedf2017-01-03 10:01:14 -05002# 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
16from oslo_config import cfg
17
DavidPurcell029d8c32017-01-06 15:27:41 -050018
Felipe Monteirof6eb8622017-08-06 06:08:02 +010019patrole_group = cfg.OptGroup(name='patrole', title='Patrole Testing Options')
20
21
22PatroleGroup = [
DavidPurcell029d8c32017-01-06 15:27:41 -050023 cfg.StrOpt('rbac_test_role',
24 default='admin',
Felipe Monteiro83903412018-07-09 16:33:55 +010025 help="""The current RBAC role against which to run
26Patrole tests."""),
Felipe Monteiro3ab2c352017-07-05 22:25:34 +010027 cfg.ListOpt('custom_policy_files',
28 default=['/etc/%s/policy.json'],
29 help="""List of the paths to search for policy files. Each
30policy path assumes that the service name is included in the path once. Also
31assumes Patrole is on the same host as the policy files. The paths should be
32ordered by precedence, with high-priority paths before low-priority paths. The
33first path that is found to contain the service's policy file will be used.
34"""),
Rick Bartraed950052017-06-29 17:20:33 -040035 cfg.BoolOpt('test_custom_requirements',
36 default=False,
37 help="""
38This option determines whether Patrole should run against a
Felipe Monteiro97117b02018-05-23 16:31:23 -070039``custom_requirements_file`` which defines RBAC requirements. The
Felipe Monteiro66d54a92018-05-31 20:08:35 +010040purpose of setting this flag to ``True`` is to verify that RBAC policy
Rick Bartraed950052017-06-29 17:20:33 -040041is in accordance to requirements. The idea is that the
Felipe Monteiro66d54a92018-05-31 20:08:35 +010042``custom_requirements_file`` precisely defines what the RBAC requirements are.
Rick Bartraed950052017-06-29 17:20:33 -040043
44Here are the possible outcomes when running the Patrole tests against
Felipe Monteiro97117b02018-05-23 16:31:23 -070045a ``custom_requirements_file``:
Rick Bartraed950052017-06-29 17:20:33 -040046
47YAML definition: allowed
48test run: allowed
49test result: pass
50
51YAML definition: allowed
52test run: not allowed
Felipe Monteirof16b6b32018-06-28 19:32:59 -040053test result: fail (under-permission)
Rick Bartraed950052017-06-29 17:20:33 -040054
55YAML definition: not allowed
56test run: allowed
57test result: fail (over-permission)
58"""),
59 cfg.StrOpt('custom_requirements_file',
60 help="""
Felipe Monteiro97117b02018-05-23 16:31:23 -070061File path of the YAML file that defines your RBAC requirements. This
62file must be located on the same host that Patrole runs on. The YAML
Rick Bartraed950052017-06-29 17:20:33 -040063file should be written as follows:
64
Felipe Monteiro66d54a92018-05-31 20:08:35 +010065.. code-block:: yaml
66
67 <service_foo>:
68 <api_action_a>:
69 - <allowed_role_1>
70 - <allowed_role_2>
71 - <allowed_role_3>
72 <api_action_b>:
73 - <allowed_role_2>
74 - <allowed_role_4>
75 <service_bar>:
76 <api_action_c>:
77 - <allowed_role_3>
Felipe Monteiro97117b02018-05-23 16:31:23 -070078
Rick Bartraed950052017-06-29 17:20:33 -040079Where:
Felipe Monteiro97117b02018-05-23 16:31:23 -070080
Felipe Monteiro66d54a92018-05-31 20:08:35 +010081service = the service that is being tested (Cinder, Nova, etc.).
82
Rick Bartraed950052017-06-29 17:20:33 -040083api_action = the policy action that is being tested. Examples:
Felipe Monteiro66d54a92018-05-31 20:08:35 +010084
85* volume:create
86* os_compute_api:servers:start
87* add_image
88
89allowed_role = the ``oslo.policy`` role that is allowed to perform the API.
Rick Bartraed950052017-06-29 17:20:33 -040090""")
DavidPurcell029d8c32017-01-06 15:27:41 -050091]
Felipe Monteirof6eb8622017-08-06 06:08:02 +010092
93
Sean Pryor7f8993f2017-08-14 12:53:17 -040094patrole_log_group = cfg.OptGroup(
95 name='patrole_log', title='Patrole Logging Options')
96
Felipe Monteiro739041f2018-03-25 00:24:03 -040097
Sean Pryor7f8993f2017-08-14 12:53:17 -040098PatroleLogGroup = [
99 cfg.BoolOpt('enable_reporting',
100 default=False,
101 help="Enables reporting on RBAC expected and actual test "
102 "results for each Patrole test"),
103 cfg.StrOpt('report_log_name',
104 default='patrole.log',
105 help="Name of file where output from 'enable_reporting' is "
106 "logged. Note that this file is recreated on each "
107 "invocation of patrole"),
108 cfg.StrOpt('report_log_path',
109 default='.',
110 help="Path (relative or absolute) where the output from "
111 "'enable_reporting' is logged. This is combined with"
112 "report_log_name to generate the full path."),
113]
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100114
115
Felipe Monteiro739041f2018-03-25 00:24:03 -0400116policy_feature_enabled = cfg.OptGroup(
117 name='policy-feature-enabled',
118 title='Feature Flags for New or Changed Policies')
119
120
121PolicyFeatureEnabledGroup = [
122 # TODO(felipemonteiro): The 6 feature flags below should be removed after
123 # Pike is EOL.
124 cfg.BoolOpt('create_port_fixed_ips_ip_address_policy',
125 default=True,
126 help="""Is the Neutron policy
127"create_port:fixed_ips:ip_address" available in the cloud? This policy was
128changed in a backwards-incompatible way."""),
129 cfg.BoolOpt('update_port_fixed_ips_ip_address_policy',
130 default=True,
131 help="""Is the Neutron policy
132"update_port:fixed_ips:ip_address" available in the cloud? This policy was
133changed in a backwards-incompatible way."""),
134 cfg.BoolOpt('limits_extension_used_limits_policy',
135 default=True,
136 help="""Is the Cinder policy
137"limits_extension:used_limits" available in the cloud? This policy was
138changed in a backwards-incompatible way."""),
139 cfg.BoolOpt('volume_extension_volume_actions_attach_policy',
140 default=True,
141 help="""Is the Cinder policy
142"volume_extension:volume_actions:attach" available in the cloud? This policy
143was changed in a backwards-incompatible way."""),
144 cfg.BoolOpt('volume_extension_volume_actions_reserve_policy',
145 default=True,
146 help="""Is the Cinder policy
147"volume_extension:volume_actions:reserve" available in the cloud? This policy
148was changed in a backwards-incompatible way."""),
149 cfg.BoolOpt('volume_extension_volume_actions_unreserve_policy',
150 default=True,
151 help="""Is the Cinder policy
152"volume_extension:volume_actions:unreserve" available in the cloud? This policy
Felipe Monteiro6bffc5c2018-08-19 22:54:33 +0100153was changed in a backwards-incompatible way."""),
154 # *** Include feature flags for groups of policies below. ***
155 # Best practice is to capture new policies, removed policies, renamed
156 # policies in a group, per release.
157 #
158 # TODO(felipemonteiro): Remove these feature flags once Stein is EOL.
159 cfg.BoolOpt('removed_nova_policies_stein',
160 default=True,
161 help="""Are the Nova API extension policies available in the
162cloud (e.g. os_compute_api:os-extended-availability-zone)? These policies were
163removed in Stein because Nova API extension concept was removed in Pike."""),
Felipe Monteiro739041f2018-03-25 00:24:03 -0400164]
165
166
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100167def list_opts():
168 """Return a list of oslo.config options available.
169
170 The purpose of this is to allow tools like the Oslo sample config file
171 generator to discover the options exposed to users.
172 """
173 opt_list = [
174 (patrole_group, PatroleGroup),
Felipe Monteiro739041f2018-03-25 00:24:03 -0400175 (patrole_log_group, PatroleLogGroup),
176 (policy_feature_enabled, PolicyFeatureEnabledGroup)
177
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100178 ]
179
180 return opt_list