blob: 9eed5ab0bf5de54cc835d537c9a6d0e4ad4ce9da [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 Monteiro3ab2c352017-07-05 22:25:34 +010025 help="""The current RBAC role against which to run Patrole
26tests."""),
Samantha Blanco0d880082017-03-23 18:14:37 -040027 cfg.BoolOpt('enable_rbac',
Felipe Monteiro2c0c55a2017-03-06 17:22:10 -050028 default=True,
Samantha Blanco0d880082017-03-23 18:14:37 -040029 help="Enables RBAC tests."),
Felipe Monteiro3ab2c352017-07-05 22:25:34 +010030 cfg.ListOpt('custom_policy_files',
31 default=['/etc/%s/policy.json'],
32 help="""List of the paths to search for policy files. Each
33policy path assumes that the service name is included in the path once. Also
34assumes Patrole is on the same host as the policy files. The paths should be
35ordered by precedence, with high-priority paths before low-priority paths. The
36first path that is found to contain the service's policy file will be used.
37"""),
Rick Bartraed950052017-06-29 17:20:33 -040038 cfg.BoolOpt('test_custom_requirements',
39 default=False,
40 help="""
41This option determines whether Patrole should run against a
Felipe Monteiro97117b02018-05-23 16:31:23 -070042``custom_requirements_file`` which defines RBAC requirements. The
Felipe Monteiro66d54a92018-05-31 20:08:35 +010043purpose of setting this flag to ``True`` is to verify that RBAC policy
Rick Bartraed950052017-06-29 17:20:33 -040044is in accordance to requirements. The idea is that the
Felipe Monteiro66d54a92018-05-31 20:08:35 +010045``custom_requirements_file`` precisely defines what the RBAC requirements are.
Rick Bartraed950052017-06-29 17:20:33 -040046
47Here are the possible outcomes when running the Patrole tests against
Felipe Monteiro97117b02018-05-23 16:31:23 -070048a ``custom_requirements_file``:
Rick Bartraed950052017-06-29 17:20:33 -040049
50YAML definition: allowed
51test run: allowed
52test result: pass
53
54YAML definition: allowed
55test run: not allowed
Felipe Monteirof16b6b32018-06-28 19:32:59 -040056test result: fail (under-permission)
Rick Bartraed950052017-06-29 17:20:33 -040057
58YAML definition: not allowed
59test run: allowed
60test result: fail (over-permission)
61"""),
62 cfg.StrOpt('custom_requirements_file',
63 help="""
Felipe Monteiro97117b02018-05-23 16:31:23 -070064File path of the YAML file that defines your RBAC requirements. This
65file must be located on the same host that Patrole runs on. The YAML
Rick Bartraed950052017-06-29 17:20:33 -040066file should be written as follows:
67
Felipe Monteiro66d54a92018-05-31 20:08:35 +010068.. code-block:: yaml
69
70 <service_foo>:
71 <api_action_a>:
72 - <allowed_role_1>
73 - <allowed_role_2>
74 - <allowed_role_3>
75 <api_action_b>:
76 - <allowed_role_2>
77 - <allowed_role_4>
78 <service_bar>:
79 <api_action_c>:
80 - <allowed_role_3>
Felipe Monteiro97117b02018-05-23 16:31:23 -070081
Rick Bartraed950052017-06-29 17:20:33 -040082Where:
Felipe Monteiro97117b02018-05-23 16:31:23 -070083
Felipe Monteiro66d54a92018-05-31 20:08:35 +010084service = the service that is being tested (Cinder, Nova, etc.).
85
Rick Bartraed950052017-06-29 17:20:33 -040086api_action = the policy action that is being tested. Examples:
Felipe Monteiro66d54a92018-05-31 20:08:35 +010087
88* volume:create
89* os_compute_api:servers:start
90* add_image
91
92allowed_role = the ``oslo.policy`` role that is allowed to perform the API.
Rick Bartraed950052017-06-29 17:20:33 -040093""")
DavidPurcell029d8c32017-01-06 15:27:41 -050094]
Felipe Monteirof6eb8622017-08-06 06:08:02 +010095
96
Sean Pryor7f8993f2017-08-14 12:53:17 -040097patrole_log_group = cfg.OptGroup(
98 name='patrole_log', title='Patrole Logging Options')
99
Felipe Monteiro739041f2018-03-25 00:24:03 -0400100
Sean Pryor7f8993f2017-08-14 12:53:17 -0400101PatroleLogGroup = [
102 cfg.BoolOpt('enable_reporting',
103 default=False,
104 help="Enables reporting on RBAC expected and actual test "
105 "results for each Patrole test"),
106 cfg.StrOpt('report_log_name',
107 default='patrole.log',
108 help="Name of file where output from 'enable_reporting' is "
109 "logged. Note that this file is recreated on each "
110 "invocation of patrole"),
111 cfg.StrOpt('report_log_path',
112 default='.',
113 help="Path (relative or absolute) where the output from "
114 "'enable_reporting' is logged. This is combined with"
115 "report_log_name to generate the full path."),
116]
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100117
118
Felipe Monteiro739041f2018-03-25 00:24:03 -0400119policy_feature_enabled = cfg.OptGroup(
120 name='policy-feature-enabled',
121 title='Feature Flags for New or Changed Policies')
122
123
124PolicyFeatureEnabledGroup = [
125 # TODO(felipemonteiro): The 6 feature flags below should be removed after
126 # Pike is EOL.
127 cfg.BoolOpt('create_port_fixed_ips_ip_address_policy',
128 default=True,
129 help="""Is the Neutron policy
130"create_port:fixed_ips:ip_address" available in the cloud? This policy was
131changed in a backwards-incompatible way."""),
132 cfg.BoolOpt('update_port_fixed_ips_ip_address_policy',
133 default=True,
134 help="""Is the Neutron policy
135"update_port:fixed_ips:ip_address" available in the cloud? This policy was
136changed in a backwards-incompatible way."""),
137 cfg.BoolOpt('limits_extension_used_limits_policy',
138 default=True,
139 help="""Is the Cinder policy
140"limits_extension:used_limits" available in the cloud? This policy was
141changed in a backwards-incompatible way."""),
142 cfg.BoolOpt('volume_extension_volume_actions_attach_policy',
143 default=True,
144 help="""Is the Cinder policy
145"volume_extension:volume_actions:attach" available in the cloud? This policy
146was changed in a backwards-incompatible way."""),
147 cfg.BoolOpt('volume_extension_volume_actions_reserve_policy',
148 default=True,
149 help="""Is the Cinder policy
150"volume_extension:volume_actions:reserve" available in the cloud? This policy
151was changed in a backwards-incompatible way."""),
152 cfg.BoolOpt('volume_extension_volume_actions_unreserve_policy',
153 default=True,
154 help="""Is the Cinder policy
155"volume_extension:volume_actions:unreserve" available in the cloud? This policy
156was changed in a backwards-incompatible way.""")
157]
158
159
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100160def list_opts():
161 """Return a list of oslo.config options available.
162
163 The purpose of this is to allow tools like the Oslo sample config file
164 generator to discover the options exposed to users.
165 """
166 opt_list = [
167 (patrole_group, PatroleGroup),
Felipe Monteiro739041f2018-03-25 00:24:03 -0400168 (patrole_log_group, PatroleLogGroup),
169 (policy_feature_enabled, PolicyFeatureEnabledGroup)
170
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100171 ]
172
173 return opt_list