RETIRED, Tempest plugin for testing and verifying RBAC policy enforcement.
Go to file
Felipe Monteiro a20add27cf Use admin creds for waiting
Use admin creds for waiting for all RBAC tests that use waiters after
rbac_utils has switched to RBAC role. It is not necessary (though not
detrimental either) to do this during tearDown.

The reason why this should be done is because "waiting" entails calling
a "show" API action in a loop, until the resource reaches a desired
status. In other words, a policy action related to the "show" API action
is enforced -- which is problematic within the context of RBAC testing.

Change-Id: Id4b896b3ad0dff33e70f46a8dda950f7c3b148bf
2017-06-22 19:28:41 +00:00
devstack Patrole devstack plugin 2017-05-31 16:17:58 +00:00
doc/source Update test/installation documentation 2017-06-01 20:54:59 +00:00
patrole_tempest_plugin Use admin creds for waiting 2017-06-22 19:28:41 +00:00
releasenotes Merge "Additional network router RBAC tests" 2017-06-21 20:03:22 +00:00
.coveragerc Initial Cookiecutter commit 2017-01-04 15:11:34 -05:00
.gitignore Initial Cookiecutter commit 2017-01-04 15:11:34 -05:00
.gitreview Added .gitreview 2016-12-21 08:20:20 +00:00
.mailmap Initial Cookiecutter commit 2017-01-04 15:11:34 -05:00
.testr.conf Initial Cookiecutter commit 2017-01-04 15:11:34 -05:00
babel.cfg Initial Cookiecutter commit 2017-01-04 15:11:34 -05:00
CONTRIBUTING.rst Optimize the link address 2017-06-05 18:45:16 +07:00
HACKING.rst Optimize the link address 2017-06-05 18:45:16 +07:00
LICENSE Initial Cookiecutter commit 2017-01-04 15:11:34 -05:00
README.rst Merge "Show team and repo badges on README" 2017-06-13 21:58:10 +00:00
requirements.txt Add oslo.policy requirement to requirements.txt 2017-05-22 15:31:25 +01:00
setup.cfg Remove support for py34 2017-06-08 22:40:08 +07:00
setup.py Fixed AT&T Copyright statements 2017-01-27 12:46:27 -05:00
test-requirements.txt Fix test coverage tox command for patrole. 2017-03-04 23:27:31 +00:00
test-whitelist.txt Changes tox to only run unit tests and moves unit tests to tests/unit. 2017-02-28 16:03:08 -05:00
tox.ini Hacking: enable extensions H106, H203 and H904 2017-05-17 15:36:16 +00:00

Team and repository tags

image

Patrole - RBAC Integration Tempest Plugin

Patrole is a tool for verifying that Role-Based Access Control is being correctly enforced.

Patrole allows users to run API tests using specified RBAC roles. This allows deployments to verify that only intended roles have access to those APIs. This is critical to ensure security, especially in large deployments with custom roles.

Features

Patrole offers RBAC testing for various OpenStack RBAC policies. It includes a decorator that wraps around tests which verifies that when the test calls the corresponding API endpoint, access is only granted for correct roles.

Currently, Patrole supports policies contained in code and in policy.json files. If both exist, the policy actions in the policy.json are prioritized.

Stable Interface

Patrole offers a stable interface that is guaranteed to be backwards compatible and can be directly consumed by other projects. Currently, rbac_exceptions.py and rbac_policy_parser.py are guaranteed to be stable.

Release Versioning

Patrole Release Notes show what changes have been released.

Test Flows

There are several possible test flows.

If the rbac_test_role is allowed to access the endpoint:

  • The test passes if no 403 Forbidden or RbacActionFailed exception is raised.

If the rbac_test_role is not allowed to access the endpoint:

  • If the endpoint returns a 403 Forbidden exception the test will pass.
  • If the endpoint returns successfully, then the test will fail with an RbacOverPermission exception.
  • If the endpoint returns something other than a 403 Forbidden to indicate that the role is not allowed, the test will raise an RbacActionFailed exception.

Note

Certain services like Neutron intentionally raise a 404 instead of a 403 for security concerns. Patrole accomodates this behavior by anticipating a 404 instead of a 403, using the expected_exception argument. For more information about Neutron's policy enforcement, see: https://docs.openstack.org/developer/neutron/devref/policy.html#request-authorization.

How It Works

Patrole leverages oslo_policy (OpenStack's policy enforcement engine) to determine whether a given role is allowed to perform a policy action given a specific rule and OpenStack service. This is done before test execution inside the rbac_rule_validation.action decorator. Then, inside the test, the API that does policy enforcement for the same rule is called. The outcome is compared against the result from oslo_policy and a pass or fail is determined as outlined above: Test Flows.

Note

Currently, Patrole does not support checking multiple rules against a single API call. Even though some APIs enforce multiple rules (some indirectly), it is increasingly difficult to maintain the tests if multiple policy actions are expected to be called.

Test Execution Workflow

The workflow is as follows:

  1. Each test uses the rbac_rule_validation.action decorator, like below: :

    @rbac_rule_validation.action(
        service="nova",
        rule="os_compute_api:servers:stop")
    @decorators.idempotent_id('ab4a17d2-166f-4a6d-9944-f17baa576cf2')
    def test_stop_server(self):
        # Set the primary credential's role to "rbac_test_role".
        self.rbac_utils.switch_role(self, toggle_rbac_role=True)
        # Call the API that enforces the policy action specified by "rule".
        self._test_stop_server()

    The service attribute accepts an OpenStack service and the rule attribute accepts a valid OpenStack policy action, like "os_compute_api:servers:stop".

  2. The rbac_rule_validation.action decorator passes these attributes, along with user_id and project_id information derived from the primary Tempest credential (self.os.credentials.user_id and self.os.credentials.project_id), to the rbac_policy_parser.

  3. The logic in rbac_policy_parser then passes all this information along and the role in CONF.rbac.rbac_test_role to oslo_policy to determine whether the rbac_test_role is authorized to perform the policy action for the given service.

  4. After all of the logic above has executed inside the rbac decorator, the test is executed. The test then sets up test-level resources, if necessary, with admin credentials implicitly. This is accomplished through rbac_utils.switch_role(toggle_rbac_role=False), which is done as part of client setup (inside the call to rbac_utils.RbacUtils): :

    @classmethod
    def setup_clients(cls):
        super(BaseV2ComputeRbacTest, cls).setup_clients()
        cls.auth_provider = cls.os_primary.auth_provider
        cls.rbac_utils = rbac_utils.RbacUtils(cls)
        ...

    This code has already executed when the test class is instantiated, because it is located in the base rbac test class. Whenever cls.rbac_utils.switch_role is called, one of two behaviors are possible:

    1. The primary credential's role is changed to admin if toggle_rbac_role=False
    2. The primary credential's role is changed to rbac_test_role if toggle_rbac_role=True

    Thus, at the beginning of every test and during resource_setup and resource_cleanup, the primary credential has the admin role.

  5. After preliminary test-level setup is performed, like creating a server, a second call to self.rbac_utils.switch_role is done: :

    self.rbac_utils.switch_role(cls, toggle_rbac_role=True)

    Now the primary credential has the role specified by rbac_test_role.

  6. The API endpoint in which policy enforcement of "os_compute_api:servers:stop" is performed can now be called.

    To determine whether a policy action is enforced, refer to the relevant controller code to make sure that the policy action is indeed enforced.

  7. Now that a call is made to "stop_server" with the primary credentials having the role specified by rbac_test_role, either the nova contoller will allow or disallow the action to be performed. Since the "stop_server" policy action in nova is defined as "base.RULE_ADMIN_OR_OWNER", the API will most likely return a successful status code. For more information about this policy action, see https://github.com/openstack/nova/blob/master/nova/policies/servers.py.

  8. As mentioned above, the result from the API call and the result from oslo_policy are compared for consistency.

  9. Finally, after the test has executed, but before tearDown or resource_cleanup is called, self.rbac_utils.switch_role(cls, toggle_rbac_role=False) is called, so that the primary credential yet again has admin permissions for test clean up. This call is always performed in the "finally" block inside the rbac_rule_validation decorator.

Warning

Failure to call self.rbac_utils.switch_role(cls, toggle_rbac_role=True) inside a test with the rbac_rule_validation decorator applied results in a RbacResourceSetupFailed being raised, causing the test to fail.