patrole_tempest_plugin.rbac_utils.
RbacUtilsMixin
(*args, **kwargs)[source]¶Bases: object
Utility mixin responsible for switching os_primary
role.
Should be used as a mixin class alongside an instance of
tempest.test.BaseTestCase
to perform Patrole class setup for a
base RBAC class. Child classes should not use this mixin.
Example:
class BaseRbacTest(rbac_utils.RbacUtilsMixin, base.BaseV2ComputeTest):
@classmethod
def setup_clients(cls):
super(BaseRbacTest, cls).setup_clients()
cls.hosts_client = cls.os_primary.hosts_client
...
This class is responsible for overriding the value of the primary Tempest
credential’s role (i.e. os_primary
role). By doing so, it is possible
to seamlessly swap between admin credentials, needed for setup and clean
up, and primary credentials, needed to perform the API call which does
policy enforcement. The primary credentials always cycle between roles
defined by CONF.identity.admin_role
and
CONF.patrole.rbac_test_roles
.
admin_roles_client
= None¶get_all_needed_roles
(roles)[source]¶Extending given roles with roles from mapping
Parameters: | roles – list of roles |
---|---|
Returns: | extended list of roles |
get_auth_providers
()[source]¶Returns list of auth_providers used within test.
Tests may redefine this method to include their own or third party client auth_providers.
override_role
()[source]¶Override the role used by os_primary
Tempest credentials.
Temporarily change the role used by os_primary
credentials to:
[patrole] rbac_test_roles
before test execution[identity] admin_role
after test executionAutomatically switches to admin role after test execution.
Returns: | None |
---|
Warning
This function can alter user roles for pre-provisioned credentials. Work is underway to safely clean up after this function.
Example:
@rbac_rule_validation.action(service='test',
rules=['a:test:rule'])
def test_foo(self):
# Allocate test-level resources here.
with self.override_role():
# The role for `os_primary` has now been overridden. Within
# this block, call the API endpoint that enforces the
# expected policy specified by "rule" in the decorator.
self.foo_service.bar_api_call()
# The role is switched back to admin automatically. Note that
# if the API call above threw an exception, any code below this
# point in the test is not executed.
override_role_and_validate_list
(admin_resources=None, admin_resource_id=None)[source]¶Call override_role
and validate RBAC for a list API action.
List actions usually do soft authorization: partial or empty response bodies are returned instead of exceptions. This helper validates that unauthorized roles only return a subset of the available resources. Should only be used for validating list API actions.
Parameters: |
|
---|---|
Returns: | py:class:_ValidateListContext object. |
Example:
# the resource created by admin
admin_resource_id = (
self.ntp_client.create_dscp_marking_rule()
["dscp_marking_rule"]["id'])
with self.override_role_and_validate_list(
admin_resource_id=admin_resource_id) as ctx:
# the list of resources available for member role
ctx.resources = self.ntp_client.list_dscp_marking_rules(
policy_id=self.policy_id)["dscp_marking_rules"]
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.