From 3ab2c357e8510e3d1aa562c29d4b72e9f24e1477 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Wed, 5 Jul 2017 22:25:34 +0100 Subject: [PATCH] Dynamic policy file discovery Patrole should eventually support other services like Heat and Murano, not just the Big Tent services included in Tempest. Patrole then should be able to dynamically discover custom policy files. While the solution this commit implements is not perfect, it will allow more services' policy file to be discovered by Patrole. The policy files will still have to be located on the same host as Patrole. This commit removes the service-specific policy path CONF options in favor of a new CONF option called ``[rbac] custom_policy_files`` which is a ListOpt that includes paths for each custom policy file. Each policy path assumes that the service name is included in the path. The paths should be ordered by precedence, with high-priority paths before low-priority paths. The first path that is found to contain the service's policy file will be used. This commit refactors unit tests and rbac_policy_parser as needed to work with the changes. Change-Id: Ia929b77223b54906888af6cd324f0cfa0fafda8f Implements blueprint: dynamic-policy-file-discovery --- patrole_tempest_plugin/config.py | 50 ++++++-- patrole_tempest_plugin/rbac_policy_parser.py | 53 +++++--- .../tests/unit/test_rbac_policy_parser.py | 113 +++++++----------- ...olicy-file-discovery-104cbfc64b55d605.yaml | 22 ++++ 4 files changed, 136 insertions(+), 102 deletions(-) create mode 100644 releasenotes/notes/dynamic-policy-file-discovery-104cbfc64b55d605.yaml diff --git a/patrole_tempest_plugin/config.py b/patrole_tempest_plugin/config.py index 11808368..a6f30e7e 100644 --- a/patrole_tempest_plugin/config.py +++ b/patrole_tempest_plugin/config.py @@ -21,33 +21,61 @@ rbac_group = cfg.OptGroup(name='rbac', RbacGroup = [ cfg.StrOpt('rbac_test_role', default='admin', - help="The current RBAC role against which to run" - " Patrole tests."), + help="""The current RBAC role against which to run Patrole +tests."""), cfg.BoolOpt('enable_rbac', default=True, help="Enables RBAC tests."), cfg.BoolOpt('strict_policy_check', default=False, - help="If true, throws RbacParsingException for" - " policies which don't exist. If false, " - "throws skipException."), + help="""If true, throws RbacParsingException for policies which +don't exist or are not included in the service's policy file. If false, throws +skipException."""), # TODO(rb560u): There needs to be support for reading these JSON files from - # other hosts. It may be possible to leverage the v3 identity policy API + # other hosts. It may be possible to leverage the v3 identity policy API. + cfg.ListOpt('custom_policy_files', + default=['/etc/%s/policy.json'], + help="""List of the paths to search for policy files. Each +policy path assumes that the service name is included in the path once. Also +assumes Patrole is on the same host as the policy files. The paths should be +ordered by precedence, with high-priority paths before low-priority paths. The +first path that is found to contain the service's policy file will be used. +"""), cfg.StrOpt('cinder_policy_file', default='/etc/cinder/policy.json', - help="Location of the neutron policy file."), + help="""Location of the Cinder policy file. Assumed to be on +the same host as Patrole.""", + deprecated_for_removal=True, + deprecated_reason="It is better to use `custom_policy_files` " + "which supports any OpenStack service."), cfg.StrOpt('glance_policy_file', default='/etc/glance/policy.json', - help="Location of the glance policy file."), + help="""Location of the Glance policy file. Assumed to be on +the same host as Patrole.""", + deprecated_for_removal=True, + deprecated_reason="It is better to use `custom_policy_files` " + "which supports any OpenStack service."), cfg.StrOpt('keystone_policy_file', default='/etc/keystone/policy.json', - help="Location of the keystone policy file."), + help="""Location of the custom Keystone policy file. Assumed to +be on the same host as Patrole.""", + deprecated_for_removal=True, + deprecated_reason="It is better to use `custom_policy_files` " + "which supports any OpenStack service."), cfg.StrOpt('neutron_policy_file', default='/etc/neutron/policy.json', - help="Location of the neutron policy file."), + help="""Location of the Neutron policy file. Assumed to be on +the same host as Patrole.""", + deprecated_for_removal=True, + deprecated_reason="It is better to use `custom_policy_files` " + "which supports any OpenStack service."), cfg.StrOpt('nova_policy_file', default='/etc/nova/policy.json', - help="Location of the nova policy file."), + help="""Location of the custom Nova policy file. Assumed to be +on the same host as Patrole.""", + deprecated_for_removal=True, + deprecated_reason="It is better to use `custom_policy_files` " + "which supports any OpenStack service."), cfg.BoolOpt('test_custom_requirements', default=False, help=""" diff --git a/patrole_tempest_plugin/rbac_policy_parser.py b/patrole_tempest_plugin/rbac_policy_parser.py index 17a626c2..41871cf4 100644 --- a/patrole_tempest_plugin/rbac_policy_parser.py +++ b/patrole_tempest_plugin/rbac_policy_parser.py @@ -58,26 +58,27 @@ class RbacPolicyParser(RbacAuthority): the custom policy file over the default policy implementation is prioritized. - :param project_id: type uuid - :param user_id: type uuid - :param service: type string - :param path: type string + :param uuid project_id: project_id of object performing API call + :param uuid user_id: user_id of object performing API call + :param string service: service of the policy file + :param dict extra_target_data: dictionary containing additional object + data needed by oslo.policy to validate generic checks """ if extra_target_data is None: extra_target_data = {} - # First check if the service is valid. self.validate_service(service) - # Use default path in /etc/