blob: ee7a6c56692536f7cfb28ef76bb249f71cd342e8 [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."),
Rick Bartraed950052017-06-29 17:20:33 -040030 # TODO(rb560u): There needs to be support for reading these JSON files from
Felipe Monteiro3ab2c352017-07-05 22:25:34 +010031 # other hosts. It may be possible to leverage the v3 identity policy API.
32 cfg.ListOpt('custom_policy_files',
33 default=['/etc/%s/policy.json'],
34 help="""List of the paths to search for policy files. Each
35policy path assumes that the service name is included in the path once. Also
36assumes Patrole is on the same host as the policy files. The paths should be
37ordered by precedence, with high-priority paths before low-priority paths. The
38first path that is found to contain the service's policy file will be used.
39"""),
Rick Bartraed950052017-06-29 17:20:33 -040040 cfg.BoolOpt('test_custom_requirements',
41 default=False,
42 help="""
43This option determines whether Patrole should run against a
Felipe Monteiro97117b02018-05-23 16:31:23 -070044``custom_requirements_file`` which defines RBAC requirements. The
Felipe Monteiro66d54a92018-05-31 20:08:35 +010045purpose of setting this flag to ``True`` is to verify that RBAC policy
Rick Bartraed950052017-06-29 17:20:33 -040046is in accordance to requirements. The idea is that the
Felipe Monteiro66d54a92018-05-31 20:08:35 +010047``custom_requirements_file`` precisely defines what the RBAC requirements are.
Rick Bartraed950052017-06-29 17:20:33 -040048
49Here are the possible outcomes when running the Patrole tests against
Felipe Monteiro97117b02018-05-23 16:31:23 -070050a ``custom_requirements_file``:
Rick Bartraed950052017-06-29 17:20:33 -040051
52YAML definition: allowed
53test run: allowed
54test result: pass
55
56YAML definition: allowed
57test run: not allowed
Felipe Monteiro97117b02018-05-23 16:31:23 -070058test result: fail (under-permission, e.g. Forbidden exception)
Rick Bartraed950052017-06-29 17:20:33 -040059
60YAML definition: not allowed
61test run: allowed
62test result: fail (over-permission)
63"""),
64 cfg.StrOpt('custom_requirements_file',
65 help="""
Felipe Monteiro97117b02018-05-23 16:31:23 -070066File path of the YAML file that defines your RBAC requirements. This
67file must be located on the same host that Patrole runs on. The YAML
Rick Bartraed950052017-06-29 17:20:33 -040068file should be written as follows:
69
Felipe Monteiro66d54a92018-05-31 20:08:35 +010070.. code-block:: yaml
71
72 <service_foo>:
73 <api_action_a>:
74 - <allowed_role_1>
75 - <allowed_role_2>
76 - <allowed_role_3>
77 <api_action_b>:
78 - <allowed_role_2>
79 - <allowed_role_4>
80 <service_bar>:
81 <api_action_c>:
82 - <allowed_role_3>
Felipe Monteiro97117b02018-05-23 16:31:23 -070083
Rick Bartraed950052017-06-29 17:20:33 -040084Where:
Felipe Monteiro97117b02018-05-23 16:31:23 -070085
Felipe Monteiro66d54a92018-05-31 20:08:35 +010086service = the service that is being tested (Cinder, Nova, etc.).
87
Rick Bartraed950052017-06-29 17:20:33 -040088api_action = the policy action that is being tested. Examples:
Felipe Monteiro66d54a92018-05-31 20:08:35 +010089
90* volume:create
91* os_compute_api:servers:start
92* add_image
93
94allowed_role = the ``oslo.policy`` role that is allowed to perform the API.
Rick Bartraed950052017-06-29 17:20:33 -040095""")
DavidPurcell029d8c32017-01-06 15:27:41 -050096]
Felipe Monteirof6eb8622017-08-06 06:08:02 +010097
98
Sean Pryor7f8993f2017-08-14 12:53:17 -040099patrole_log_group = cfg.OptGroup(
100 name='patrole_log', title='Patrole Logging Options')
101
Felipe Monteiro739041f2018-03-25 00:24:03 -0400102
Sean Pryor7f8993f2017-08-14 12:53:17 -0400103PatroleLogGroup = [
104 cfg.BoolOpt('enable_reporting',
105 default=False,
106 help="Enables reporting on RBAC expected and actual test "
107 "results for each Patrole test"),
108 cfg.StrOpt('report_log_name',
109 default='patrole.log',
110 help="Name of file where output from 'enable_reporting' is "
111 "logged. Note that this file is recreated on each "
112 "invocation of patrole"),
113 cfg.StrOpt('report_log_path',
114 default='.',
115 help="Path (relative or absolute) where the output from "
116 "'enable_reporting' is logged. This is combined with"
117 "report_log_name to generate the full path."),
118]
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100119
120
Felipe Monteiro739041f2018-03-25 00:24:03 -0400121policy_feature_enabled = cfg.OptGroup(
122 name='policy-feature-enabled',
123 title='Feature Flags for New or Changed Policies')
124
125
126PolicyFeatureEnabledGroup = [
127 # TODO(felipemonteiro): The 6 feature flags below should be removed after
128 # Pike is EOL.
129 cfg.BoolOpt('create_port_fixed_ips_ip_address_policy',
130 default=True,
131 help="""Is the Neutron policy
132"create_port:fixed_ips:ip_address" available in the cloud? This policy was
133changed in a backwards-incompatible way."""),
134 cfg.BoolOpt('update_port_fixed_ips_ip_address_policy',
135 default=True,
136 help="""Is the Neutron policy
137"update_port:fixed_ips:ip_address" available in the cloud? This policy was
138changed in a backwards-incompatible way."""),
139 cfg.BoolOpt('limits_extension_used_limits_policy',
140 default=True,
141 help="""Is the Cinder policy
142"limits_extension:used_limits" available in the cloud? This policy was
143changed in a backwards-incompatible way."""),
144 cfg.BoolOpt('volume_extension_volume_actions_attach_policy',
145 default=True,
146 help="""Is the Cinder policy
147"volume_extension:volume_actions:attach" available in the cloud? This policy
148was changed in a backwards-incompatible way."""),
149 cfg.BoolOpt('volume_extension_volume_actions_reserve_policy',
150 default=True,
151 help="""Is the Cinder policy
152"volume_extension:volume_actions:reserve" available in the cloud? This policy
153was changed in a backwards-incompatible way."""),
154 cfg.BoolOpt('volume_extension_volume_actions_unreserve_policy',
155 default=True,
156 help="""Is the Cinder policy
157"volume_extension:volume_actions:unreserve" available in the cloud? This policy
158was changed in a backwards-incompatible way.""")
159]
160
161
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100162def list_opts():
163 """Return a list of oslo.config options available.
164
165 The purpose of this is to allow tools like the Oslo sample config file
166 generator to discover the options exposed to users.
167 """
168 opt_list = [
169 (patrole_group, PatroleGroup),
Felipe Monteiro739041f2018-03-25 00:24:03 -0400170 (patrole_log_group, PatroleLogGroup),
171 (policy_feature_enabled, PolicyFeatureEnabledGroup)
172
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100173 ]
174
175 return opt_list