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