blob: f3798599cddd07453baa0e373425f0b9ac3e6599 [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
Rick Bartraed950052017-06-29 17:20:33 -040045purpose of setting this flag to True is to verify that RBAC policy
46is in accordance to requirements. The idea is that the
Felipe Monteiro97117b02018-05-23 16:31:23 -070047``custom_requirements_file`` perfectly 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
70```
Felipe Monteiro97117b02018-05-23 16:31:23 -070071<service_foo>:
72 <api_action_x>:
73 - <allowed_role_a>
74 - <allowed_role_b>
75 - <allowed_role_c>
76 <api_action_y>:
77 - <allowed_role_d>
78 - <allowed_role_e>
79<service_bar>:
80 <api_action_z>:
81 - <allowed_role_b>
Rick Bartraed950052017-06-29 17:20:33 -040082```
Felipe Monteiro97117b02018-05-23 16:31:23 -070083
Rick Bartraed950052017-06-29 17:20:33 -040084Where:
Felipe Monteiro97117b02018-05-23 16:31:23 -070085
86service = the service that is being tested (Cinder, Nova, etc.)
Rick Bartraed950052017-06-29 17:20:33 -040087api_action = the policy action that is being tested. Examples:
88 - volume:create
89 - os_compute_api:servers:start
90 - add_image
Felipe Monteiro97117b02018-05-23 16:31:23 -070091allowed_role = the Keystone role that is allowed to perform the API.
Rick Bartraed950052017-06-29 17:20:33 -040092""")
DavidPurcell029d8c32017-01-06 15:27:41 -050093]
Felipe Monteirof6eb8622017-08-06 06:08:02 +010094
95
Sean Pryor7f8993f2017-08-14 12:53:17 -040096patrole_log_group = cfg.OptGroup(
97 name='patrole_log', title='Patrole Logging Options')
98
Felipe Monteiro739041f2018-03-25 00:24:03 -040099
Sean Pryor7f8993f2017-08-14 12:53:17 -0400100PatroleLogGroup = [
101 cfg.BoolOpt('enable_reporting',
102 default=False,
103 help="Enables reporting on RBAC expected and actual test "
104 "results for each Patrole test"),
105 cfg.StrOpt('report_log_name',
106 default='patrole.log',
107 help="Name of file where output from 'enable_reporting' is "
108 "logged. Note that this file is recreated on each "
109 "invocation of patrole"),
110 cfg.StrOpt('report_log_path',
111 default='.',
112 help="Path (relative or absolute) where the output from "
113 "'enable_reporting' is logged. This is combined with"
114 "report_log_name to generate the full path."),
115]
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100116
117
Felipe Monteiro739041f2018-03-25 00:24:03 -0400118policy_feature_enabled = cfg.OptGroup(
119 name='policy-feature-enabled',
120 title='Feature Flags for New or Changed Policies')
121
122
123PolicyFeatureEnabledGroup = [
124 # TODO(felipemonteiro): The 6 feature flags below should be removed after
125 # Pike is EOL.
126 cfg.BoolOpt('create_port_fixed_ips_ip_address_policy',
127 default=True,
128 help="""Is the Neutron policy
129"create_port:fixed_ips:ip_address" available in the cloud? This policy was
130changed in a backwards-incompatible way."""),
131 cfg.BoolOpt('update_port_fixed_ips_ip_address_policy',
132 default=True,
133 help="""Is the Neutron policy
134"update_port:fixed_ips:ip_address" available in the cloud? This policy was
135changed in a backwards-incompatible way."""),
136 cfg.BoolOpt('limits_extension_used_limits_policy',
137 default=True,
138 help="""Is the Cinder policy
139"limits_extension:used_limits" available in the cloud? This policy was
140changed in a backwards-incompatible way."""),
141 cfg.BoolOpt('volume_extension_volume_actions_attach_policy',
142 default=True,
143 help="""Is the Cinder policy
144"volume_extension:volume_actions:attach" available in the cloud? This policy
145was changed in a backwards-incompatible way."""),
146 cfg.BoolOpt('volume_extension_volume_actions_reserve_policy',
147 default=True,
148 help="""Is the Cinder policy
149"volume_extension:volume_actions:reserve" available in the cloud? This policy
150was changed in a backwards-incompatible way."""),
151 cfg.BoolOpt('volume_extension_volume_actions_unreserve_policy',
152 default=True,
153 help="""Is the Cinder policy
154"volume_extension:volume_actions:unreserve" available in the cloud? This policy
155was changed in a backwards-incompatible way.""")
156]
157
158
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100159def list_opts():
160 """Return a list of oslo.config options available.
161
162 The purpose of this is to allow tools like the Oslo sample config file
163 generator to discover the options exposed to users.
164 """
165 opt_list = [
166 (patrole_group, PatroleGroup),
Felipe Monteiro739041f2018-03-25 00:24:03 -0400167 (patrole_log_group, PatroleLogGroup),
168 (policy_feature_enabled, PolicyFeatureEnabledGroup)
169
Felipe Monteiro098a8cd2017-09-20 21:31:27 +0100170 ]
171
172 return opt_list