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 | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 25 | help="""The current RBAC role against which to run Patrole |
| 26 | 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, |
Samantha Blanco | 0d88008 | 2017-03-23 18:14:37 -0400 | [diff] [blame] | 29 | help="Enables RBAC tests."), |
| 30 | cfg.BoolOpt('strict_policy_check', |
Felipe Monteiro | f71def8 | 2017-11-07 03:27:13 +0000 | [diff] [blame] | 31 | default=True, |
Felipe Monteiro | f71def8 | 2017-11-07 03:27:13 +0000 | [diff] [blame] | 32 | deprecated_for_removal=True, |
| 33 | deprecated_reason="""This option allows for the possibility |
| 34 | of false positives. As a testing framework, Patrole should fail any test that |
| 35 | passes in an invalid policy.""", |
Felipe Monteiro | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 36 | help="""If true, throws RbacParsingException for policies which |
| 37 | don't exist or are not included in the service's policy file. If false, throws |
| 38 | skipException."""), |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 39 | # TODO(rb560u): There needs to be support for reading these JSON files from |
Felipe Monteiro | 3ab2c35 | 2017-07-05 22:25:34 +0100 | [diff] [blame] | 40 | # other hosts. It may be possible to leverage the v3 identity policy API. |
| 41 | cfg.ListOpt('custom_policy_files', |
| 42 | default=['/etc/%s/policy.json'], |
| 43 | help="""List of the paths to search for policy files. Each |
| 44 | policy path assumes that the service name is included in the path once. Also |
| 45 | assumes Patrole is on the same host as the policy files. The paths should be |
| 46 | ordered by precedence, with high-priority paths before low-priority paths. The |
| 47 | first path that is found to contain the service's policy file will be used. |
| 48 | """), |
Rick Bartra | ed95005 | 2017-06-29 17:20:33 -0400 | [diff] [blame] | 49 | cfg.BoolOpt('test_custom_requirements', |
| 50 | default=False, |
| 51 | help=""" |
| 52 | This option determines whether Patrole should run against a |
| 53 | `custom_requirements_file` which defines RBAC requirements. The |
| 54 | purpose of setting this flag to True is to verify that RBAC policy |
| 55 | is in accordance to requirements. The idea is that the |
| 56 | `custom_requirements_file` perfectly defines what the RBAC requirements are. |
| 57 | |
| 58 | Here are the possible outcomes when running the Patrole tests against |
| 59 | a `custom_requirements_file`: |
| 60 | |
| 61 | YAML definition: allowed |
| 62 | test run: allowed |
| 63 | test result: pass |
| 64 | |
| 65 | YAML definition: allowed |
| 66 | test run: not allowed |
| 67 | test result: fail (under-permission) |
| 68 | |
| 69 | YAML definition: not allowed |
| 70 | test run: allowed |
| 71 | test result: fail (over-permission) |
| 72 | """), |
| 73 | cfg.StrOpt('custom_requirements_file', |
| 74 | help=""" |
| 75 | File path of the yaml file that defines your RBAC requirements. This |
| 76 | file must be located on the same host that Patrole runs on. The yaml |
| 77 | file should be written as follows: |
| 78 | |
| 79 | ``` |
| 80 | <service>: |
| 81 | <api_action>: |
| 82 | - <allowed_role> |
| 83 | - <allowed_role> |
| 84 | - <allowed_role> |
| 85 | <api_action>: |
| 86 | - <allowed_role> |
| 87 | - <allowed_role> |
| 88 | <service> |
| 89 | <api_action>: |
| 90 | - <allowed_role> |
| 91 | ``` |
| 92 | Where: |
| 93 | service = the service that is being tested (cinder, nova, etc) |
| 94 | api_action = the policy action that is being tested. Examples: |
| 95 | - volume:create |
| 96 | - os_compute_api:servers:start |
| 97 | - add_image |
| 98 | allowed_role = the Keystone role that is allowed to perform the API |
| 99 | """) |
DavidPurcell | 029d8c3 | 2017-01-06 15:27:41 -0500 | [diff] [blame] | 100 | ] |
Felipe Monteiro | f6eb862 | 2017-08-06 06:08:02 +0100 | [diff] [blame] | 101 | |
| 102 | |
Sean Pryor | 7f8993f | 2017-08-14 12:53:17 -0400 | [diff] [blame] | 103 | patrole_log_group = cfg.OptGroup( |
| 104 | name='patrole_log', title='Patrole Logging Options') |
| 105 | |
| 106 | PatroleLogGroup = [ |
| 107 | cfg.BoolOpt('enable_reporting', |
| 108 | default=False, |
| 109 | help="Enables reporting on RBAC expected and actual test " |
| 110 | "results for each Patrole test"), |
| 111 | cfg.StrOpt('report_log_name', |
| 112 | default='patrole.log', |
| 113 | help="Name of file where output from 'enable_reporting' is " |
| 114 | "logged. Note that this file is recreated on each " |
| 115 | "invocation of patrole"), |
| 116 | cfg.StrOpt('report_log_path', |
| 117 | default='.', |
| 118 | help="Path (relative or absolute) where the output from " |
| 119 | "'enable_reporting' is logged. This is combined with" |
| 120 | "report_log_name to generate the full path."), |
| 121 | ] |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 122 | |
| 123 | |
| 124 | def list_opts(): |
| 125 | """Return a list of oslo.config options available. |
| 126 | |
| 127 | The purpose of this is to allow tools like the Oslo sample config file |
| 128 | generator to discover the options exposed to users. |
| 129 | """ |
| 130 | opt_list = [ |
| 131 | (patrole_group, PatroleGroup), |
Felipe Monteiro | b58c119 | 2017-11-20 01:50:24 +0000 | [diff] [blame] | 132 | (patrole_log_group, PatroleLogGroup) |
Felipe Monteiro | 098a8cd | 2017-09-20 21:31:27 +0100 | [diff] [blame] | 133 | ] |
| 134 | |
| 135 | return opt_list |