blob: becc0789726b181eb05422065ac975f3fac6bdbf [file] [log] [blame]
Felipe Monteiroc4589322017-06-09 19:42:50 +01001========================
2Team and repository tags
3========================
4
shangxiaobj11b02322017-08-14 22:45:11 -07005.. image:: https://governance.openstack.org/tc/badges/patrole.svg
6 :target: https://governance.openstack.org/tc/reference/tags/index.html
Felipe Monteiroc4589322017-06-09 19:42:50 +01007
Felipe Monteiroc4589322017-06-09 19:42:50 +01008Patrole - RBAC Integration Tempest Plugin
9=========================================
DavidPurcell663aedf2017-01-03 10:01:14 -050010
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010011Patrole is a set of integration tests to be run against a live OpenStack
12cluster. It has a battery of tests dedicated to validating the correctness and
13integrity of the cloud's RBAC implementation.
14
15More importantly, Patrole is a security validation tool for verifying that
16Role-Based Access Control is correctly configured and enforced in an OpenStack
17cloud. It runs `Tempest`_-based API tests using specified RBAC roles, thus
18allowing deployments to verify that only intended roles have access to those
19APIs.
DavidPurcell663aedf2017-01-03 10:01:14 -050020
Felipe Monteiroc2873892017-11-15 06:09:02 +000021Patrole is currently undergoing heavy development. As more projects move
22toward policy in code, Patrole will align its testing with the appropriate
23documentation.
24
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010025* Free software: Apache license
26* Documentation: https://docs.openstack.org/patrole/latest
27* Source: https://git.openstack.org/cgit/openstack/patrole
28* Bugs: https://bugs.launchpad.net/patrole
29* Release notes: https://docs.openstack.org/releasenotes/patrole/
Felipe Monteiro443d39c2018-04-08 17:05:33 -040030
Felipe Monteiroe9176552018-07-16 14:39:55 -040031.. _design-principles:
32
Felipe Monteiroc2873892017-11-15 06:09:02 +000033Design Principles
34-----------------
35
ghanshyam9ee07cf2018-08-16 08:15:42 +000036As a `Tempest plugin`_, Patrole borrows some design principles from `Tempest design principles`_,
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010037but not all, as its testing scope is confined to policies.
Felipe Monteiroc2873892017-11-15 06:09:02 +000038
39* *Stability*. Patrole uses OpenStack public interfaces. Tests in Patrole
40 should only touch public OpenStack APIs.
41* *Atomicity*. Patrole tests should be atomic: they should test policies in
42 isolation. Unlike Tempest, a Patrole test strives to only call a single
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010043 endpoint at a time. This is because it is important to validate each policy
44 is authorized correctly and the best way to do that is to validate each
45 policy alone, to avoid test contamination.
Felipe Monteiro543f7b92018-06-10 13:38:31 -040046* *Complete coverage*. Patrole should validate all policy in code defaults. For
47 testing, Patrole uses the API-to-policy mapping contained in each project's
48 `policy in code`_ documentation where applicable.
49
50 For example, Nova's policy in code documentation is located in the
51 `Nova repository`_ under ``nova/policies``. Likewise, Keystone's policy in
52 code documentation is located in the `Keystone repository`_ under
53 ``keystone/common/policies``. The other OpenStack services follow the same
54 directory layout pattern with respect to policy in code.
55
56 .. note::
57
58 Realistically this is not always possible because some services have
59 not yet moved to policy in code.
60
Felipe Monteiroe9176552018-07-16 14:39:55 -040061* *Customizable*. Patrole should be able to validate custom policy overrides to
62 ensure that those overrides enhance rather than undermine the cloud's RBAC
63 configuration. In addition, Patrole should be able to validate any role.
Felipe Monteiro543f7b92018-06-10 13:38:31 -040064* *Self-cleaning*. Patrole should attempt to clean up after itself; whenever
Felipe Monteiroc2873892017-11-15 06:09:02 +000065 possible we should tear down resources when done.
66
67 .. note::
68
69 Patrole modifies roles dynamically in the background, which affects
70 pre-provisioned credentials. Work is currently underway to clean up
71 modifications made to pre-provisioned credentials.
72
Felipe Monteiro543f7b92018-06-10 13:38:31 -040073* *Self-testing*. Patrole should be self-testing.
74
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010075.. _Tempest plugin: https://docs.openstack.org/tempest/latest/plugin.html
ghanshyam9ee07cf2018-08-16 08:15:42 +000076.. _Tempest design principles: https://docs.openstack.org/tempest/latest/overview.html#design-principles
Felipe Monteiro543f7b92018-06-10 13:38:31 -040077.. _policy in code: https://specs.openstack.org/openstack/oslo-specs/specs/newton/policy-in-code.html
Luigi Toscano6da06ed2019-01-07 17:50:41 +010078.. _Nova repository: https://git.openstack.org/cgit/openstack/nova/tree/nova/policies
79.. _Keystone repository: https://git.openstack.org/cgit/openstack/keystone/tree/keystone/common/policies
Felipe Monteiroc2873892017-11-15 06:09:02 +000080
DavidPurcell663aedf2017-01-03 10:01:14 -050081Features
Felipe Monteiro780210d2017-07-17 22:21:53 +010082--------
83* Validation of default policy definitions located in policy.json files.
84* Validation of in-code policy definitions.
85* Validation of custom policy file definitions that override default policy
86 definitions.
87* Built-in positive and negative testing. Positive and negative testing
88 are performed using the same tests and role-switching.
89* Valdation of custom roles as well as default OpenStack roles.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +010090
91.. note::
92
Felipe Monteiro780210d2017-07-17 22:21:53 +010093 Patrole does not yet support policy.yaml files, the new file format for
94 policy files in OpenStack.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +010095
96How It Works
Felipe Monteiro780210d2017-07-17 22:21:53 +010097------------
98Patrole leverages ``oslo.policy`` (OpenStack's policy enforcement engine) to
99determine whether a given role is allowed to perform a policy action, given a
100specific role and OpenStack service. The output from ``oslo.policy`` (the
101expected result) and the actual result from test execution are compared to
102each other: if both results match, then the test passes; else it fails.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100103
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100104Terminology
105^^^^^^^^^^^
106* Expected Result - The expected result of a given test.
107* Actual Result - The actual result of a given test.
108* Final Result - A match between both expected and actual results. A mismatch
109 in the expected result and the actual result will result in a test failure.
110
111 * Expected: Pass | Actual: Pass - Test Case Success
112 * Expected: Pass | Actual: Fail - Test Case Under-Permission Failure
113 * Expected: Fail | Actual: Pass - Test Case Over-Permission Failure
114 * Expected: Fail | Actual: Fail (Expected exception) - Test Case Success
115 * Expected: Fail | Actual: Fail (Unexpected exception) - Test Case Failure
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100116
Felipe Monteiro780210d2017-07-17 22:21:53 +0100117Quickstart
Felipe Monteiro7c7b5702017-07-21 01:43:42 +0100118----------
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100119To run Patrole, you must first have `Tempest`_ installed and configured
ghanshyam9ee07cf2018-08-16 08:15:42 +0000120properly. Please reference `Tempest_quickstart`_ guide to do so. Follow all
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100121the steps outlined therein. Afterward, proceed with the steps below.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100122
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100123#. You first need to install Patrole. This is done with pip after you check out
124 the Patrole repo::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100125
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100126 $ git clone https://git.openstack.org/openstack/patrole
127 $ pip install patrole/
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100128
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100129 This can be done within a venv.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100130
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100131 .. note::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100132
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100133 You may also install Patrole from source code by running::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100134
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100135 pip install -e patrole/
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100136
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100137#. Next you must properly configure Patrole, which is relatively
138 straightforward. For details on configuring Patrole refer to the
ghanshyam9ee07cf2018-08-16 08:15:42 +0000139 `Patrole Configuration <https://docs.openstack.org/patrole/latest/configuration.html#patrole-configuration>`_.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100140
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100141#. Once the configuration is done you're now ready to run Patrole. This can
142 be done using the `tempest_run`_ command. This can be done by running::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100143
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100144 $ tempest run --regex '^patrole_tempest_plugin\.tests\.api'
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100145
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100146 There is also the option to use testr directly, or any `testr`_ based test
147 runner, like `ostestr`_. For example, from the workspace dir run::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100148
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100149 $ stestr --regex '(?!.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api))'
150
151 will run the same set of tests as the default gate jobs.
152
Felipe Monteiro0d3c7432018-10-28 02:14:22 +0000153 You can also run Patrole tests using `tox`_, but as Patrole needs access to
154 global packages use ``--sitepackages`` argument. To do so, ``cd`` into the
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100155 **Tempest** directory and run::
156
Felipe Monteiro0d3c7432018-10-28 02:14:22 +0000157 $ tox -eall --sitepackages -- patrole_tempest_plugin.tests.api
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100158
159 .. note::
160
161 It is possible to run Patrole via ``tox -eall`` in order to run Patrole
162 isolated from other plugins. This can be accomplished by including the
163 installation of services that currently use policy in code -- for example,
164 Nova and Keystone. For example::
165
166 $ tox -evenv-tempest -- pip install /opt/stack/patrole /opt/stack/keystone /opt/stack/nova
167 $ tox -eall -- patrole_tempest_plugin.tests.api
168
169#. Log information from tests is captured in ``tempest.log`` under the Tempest
170 repository. Some Patrole debugging information is captured in that log
ghanshyam9ee07cf2018-08-16 08:15:42 +0000171 related to expected test results and `Role Overriding <https://docs.openstack.org/patrole/latest/framework/rbac_utils.html#role-overriding>`_.
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100172
173 More detailed RBAC testing log output is emitted to ``patrole.log`` under
174 the Patrole repository. To configure Patrole's logging, see the
ghanshyam9ee07cf2018-08-16 08:15:42 +0000175 `Patrole Configuration Guide <https://docs.openstack.org/patrole/latest/configuration.html#patrole-configuration>`_.
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100176
Luigi Toscano6da06ed2019-01-07 17:50:41 +0100177.. _Tempest: https://git.openstack.org/cgit/openstack/tempest
ghanshyam9ee07cf2018-08-16 08:15:42 +0000178.. _Tempest_quickstart: https://docs.openstack.org/tempest/latest/overview.html#quickstart
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100179.. _tempest_run: https://docs.openstack.org/tempest/latest/run.html
180.. _testr: https://testrepository.readthedocs.org/en/latest/MANUAL.html
181.. _ostestr: https://docs.openstack.org/os-testr/latest/
182.. _tox: https://tox.readthedocs.io/en/latest/
183
184RBAC Tests
185----------
186
Mykola Yakovlieve0f35502018-09-26 18:26:57 -0500187To change the roles that the patrole tests are being run as, edit
188``rbac_test_roles`` in the ``patrole`` section of tempest.conf: ::
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100189
190 [patrole]
Goutham Pratapad16ccfb2019-01-30 16:18:57 +0530191 rbac_test_roles = member,reader
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100192 ...
193
194.. note::
195
Mykola Yakovlieve0f35502018-09-26 18:26:57 -0500196 The ``rbac_test_roles`` is service-specific. member, for example,
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100197 is an arbitrary role, but by convention is used to designate the default
198 non-admin role in the system. Most Patrole tests should be run with
199 **admin** and **member** roles. However, other services may use entirely
Mykola Yakovlieve0f35502018-09-26 18:26:57 -0500200 different roles or role combinations.
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100201
Felipe Monteiro4d4cb1e2018-07-29 13:44:10 -0400202For more information about RBAC, reference the `rbac-overview`_
203documentation page.
204
Felipe Monteiroe36a9732018-11-16 17:28:52 +0000205For information regarding which projects Patrole offers RBAC testing for,
206reference the `HACKING`_ documentation page.
207
Felipe Monteiro4d4cb1e2018-07-29 13:44:10 -0400208.. _rbac-overview: https://docs.openstack.org/patrole/latest/rbac-overview.html
Felipe Monteiroe36a9732018-11-16 17:28:52 +0000209.. _HACKING: https://docs.openstack.org/patrole/latest/HACKING.html#supported-openstack-components
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100210
211Unit Tests
212----------
213
214Patrole also has a set of unit tests which test the Patrole code itself. These
215tests can be run by specifying the test discovery path::
216
217 $ stestr --test-path ./patrole_tempest_plugin/tests/unit run
218
219By setting ``--test-path`` option to ``./patrole_tempest_plugin/tests/unit``
220it specifies that test discovery should only be run on the unit test directory.
221
222Alternatively, there are the py27 and py35 tox jobs which will run the unit
223tests with the corresponding version of Python.
224
225One common activity is to just run a single test; you can do this with tox
226simply by specifying to just run py27 or py35 tests against a single test::
227
228 $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils.RBACUtilsTest.test_override_role_with_missing_admin_role
229
230Or all tests in the test_rbac_utils.py file::
231
232 $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils
233
234You may also use regular expressions to run any matching tests::
235
236 $ tox -e py27 -- test_rbac_utils
237
238For more information on these options and details about stestr, please see the
239`stestr documentation <http://stestr.readthedocs.io/en/latest/MANUAL.html>`_.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100240
Felipe Monteiro780210d2017-07-17 22:21:53 +0100241Release Versioning
Felipe Monteiro7c7b5702017-07-21 01:43:42 +0100242------------------
Felipe Monteiro780210d2017-07-17 22:21:53 +0100243`Patrole Release Notes <https://docs.openstack.org/releasenotes/patrole/>`_
244shows which changes have been released for each version.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100245
Felipe Monteiro780210d2017-07-17 22:21:53 +0100246Patrole's release versioning follows Tempest's conventions. Like Tempest,
247Patrole is branchless and uses versioning instead.