blob: ef0ff00156ab41144be0dcfe5552c5111e69b7cb [file] [log] [blame]
Felipe Monteiroc4589322017-06-09 19:42:50 +01001Patrole - RBAC Integration Tempest Plugin
2=========================================
DavidPurcell663aedf2017-01-03 10:01:14 -05003
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +01004Patrole is a set of integration tests to be run against a live OpenStack
5cluster. It has a battery of tests dedicated to validating the correctness and
6integrity of the cloud's RBAC implementation.
7
8More importantly, Patrole is a security validation tool for verifying that
9Role-Based Access Control is correctly configured and enforced in an OpenStack
10cloud. It runs `Tempest`_-based API tests using specified RBAC roles, thus
11allowing deployments to verify that only intended roles have access to those
12APIs.
DavidPurcell663aedf2017-01-03 10:01:14 -050013
Felipe Monteiroc2873892017-11-15 06:09:02 +000014Patrole is currently undergoing heavy development. As more projects move
15toward policy in code, Patrole will align its testing with the appropriate
16documentation.
17
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010018* Free software: Apache license
19* Documentation: https://docs.openstack.org/patrole/latest
Masayuki Igawa94e6b182019-09-18 15:08:56 +090020* Source: https://opendev.org/openstack/patrole
Felipe Monteirob2ebe492018-06-18 21:39:28 +010021* Bugs: https://storyboard.openstack.org/#!/project/openstack/patrole
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010022* Release notes: https://docs.openstack.org/releasenotes/patrole/
Felipe Monteiro443d39c2018-04-08 17:05:33 -040023
Masayuki Igawa94e6b182019-09-18 15:08:56 +090024Team and repository tags
25------------------------
26
27.. image:: https://governance.openstack.org/tc/badges/patrole.svg
28 :target: https://governance.openstack.org/tc/reference/tags/index.html
29
Felipe Monteiroe9176552018-07-16 14:39:55 -040030.. _design-principles:
31
Felipe Monteiroc2873892017-11-15 06:09:02 +000032Design Principles
33-----------------
34
ghanshyam9ee07cf2018-08-16 08:15:42 +000035As a `Tempest plugin`_, Patrole borrows some design principles from `Tempest design principles`_,
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010036but not all, as its testing scope is confined to policies.
Felipe Monteiroc2873892017-11-15 06:09:02 +000037
38* *Stability*. Patrole uses OpenStack public interfaces. Tests in Patrole
39 should only touch public OpenStack APIs.
40* *Atomicity*. Patrole tests should be atomic: they should test policies in
41 isolation. Unlike Tempest, a Patrole test strives to only call a single
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010042 endpoint at a time. This is because it is important to validate each policy
43 is authorized correctly and the best way to do that is to validate each
44 policy alone, to avoid test contamination.
Felipe Monteiro543f7b92018-06-10 13:38:31 -040045* *Complete coverage*. Patrole should validate all policy in code defaults. For
46 testing, Patrole uses the API-to-policy mapping contained in each project's
47 `policy in code`_ documentation where applicable.
48
49 For example, Nova's policy in code documentation is located in the
50 `Nova repository`_ under ``nova/policies``. Likewise, Keystone's policy in
51 code documentation is located in the `Keystone repository`_ under
52 ``keystone/common/policies``. The other OpenStack services follow the same
53 directory layout pattern with respect to policy in code.
54
55 .. note::
56
57 Realistically this is not always possible because some services have
58 not yet moved to policy in code.
59
Felipe Monteiroe9176552018-07-16 14:39:55 -040060* *Customizable*. Patrole should be able to validate custom policy overrides to
61 ensure that those overrides enhance rather than undermine the cloud's RBAC
62 configuration. In addition, Patrole should be able to validate any role.
Felipe Monteiro543f7b92018-06-10 13:38:31 -040063* *Self-cleaning*. Patrole should attempt to clean up after itself; whenever
Felipe Monteiroc2873892017-11-15 06:09:02 +000064 possible we should tear down resources when done.
65
66 .. note::
67
68 Patrole modifies roles dynamically in the background, which affects
69 pre-provisioned credentials. Work is currently underway to clean up
70 modifications made to pre-provisioned credentials.
71
Felipe Monteiro543f7b92018-06-10 13:38:31 -040072* *Self-testing*. Patrole should be self-testing.
73
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010074.. _Tempest plugin: https://docs.openstack.org/tempest/latest/plugin.html
ghanshyam9ee07cf2018-08-16 08:15:42 +000075.. _Tempest design principles: https://docs.openstack.org/tempest/latest/overview.html#design-principles
Felipe Monteiro543f7b92018-06-10 13:38:31 -040076.. _policy in code: https://specs.openstack.org/openstack/oslo-specs/specs/newton/policy-in-code.html
Masayuki Igawa94e6b182019-09-18 15:08:56 +090077.. _Nova repository: https://opendev.org/openstack/nova/src/branch/master/nova/policies
78.. _Keystone repository: https://opendev.org/openstack/keystone/src/branch/master/keystone/common/policies
Felipe Monteiroc2873892017-11-15 06:09:02 +000079
DavidPurcell663aedf2017-01-03 10:01:14 -050080Features
Felipe Monteiro780210d2017-07-17 22:21:53 +010081--------
82* Validation of default policy definitions located in policy.json files.
83* Validation of in-code policy definitions.
84* Validation of custom policy file definitions that override default policy
85 definitions.
86* Built-in positive and negative testing. Positive and negative testing
87 are performed using the same tests and role-switching.
88* Valdation of custom roles as well as default OpenStack roles.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +010089
90.. note::
91
Felipe Monteiro780210d2017-07-17 22:21:53 +010092 Patrole does not yet support policy.yaml files, the new file format for
93 policy files in OpenStack.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +010094
95How It Works
Felipe Monteiro780210d2017-07-17 22:21:53 +010096------------
97Patrole leverages ``oslo.policy`` (OpenStack's policy enforcement engine) to
98determine whether a given role is allowed to perform a policy action, given a
99specific role and OpenStack service. The output from ``oslo.policy`` (the
100expected result) and the actual result from test execution are compared to
101each other: if both results match, then the test passes; else it fails.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100102
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100103Terminology
104^^^^^^^^^^^
105* Expected Result - The expected result of a given test.
106* Actual Result - The actual result of a given test.
107* Final Result - A match between both expected and actual results. A mismatch
108 in the expected result and the actual result will result in a test failure.
109
110 * Expected: Pass | Actual: Pass - Test Case Success
111 * Expected: Pass | Actual: Fail - Test Case Under-Permission Failure
112 * Expected: Fail | Actual: Pass - Test Case Over-Permission Failure
113 * Expected: Fail | Actual: Fail (Expected exception) - Test Case Success
114 * Expected: Fail | Actual: Fail (Unexpected exception) - Test Case Failure
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100115
Felipe Monteiro780210d2017-07-17 22:21:53 +0100116Quickstart
Felipe Monteiro7c7b5702017-07-21 01:43:42 +0100117----------
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100118To run Patrole, you must first have `Tempest`_ installed and configured
ghanshyam9ee07cf2018-08-16 08:15:42 +0000119properly. Please reference `Tempest_quickstart`_ guide to do so. Follow all
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100120the steps outlined therein. Afterward, proceed with the steps below.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100121
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100122#. You first need to install Patrole. This is done with pip after you check out
123 the Patrole repo::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100124
Masayuki Igawa94e6b182019-09-18 15:08:56 +0900125 $ git clone https://opendev.org/openstack/patrole
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100126 $ pip install patrole/
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100127
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100128 This can be done within a venv.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100129
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100130 .. note::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100131
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100132 You may also install Patrole from source code by running::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100133
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100134 pip install -e patrole/
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100135
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100136#. Next you must properly configure Patrole, which is relatively
137 straightforward. For details on configuring Patrole refer to the
ghanshyam9ee07cf2018-08-16 08:15:42 +0000138 `Patrole Configuration <https://docs.openstack.org/patrole/latest/configuration.html#patrole-configuration>`_.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100139
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100140#. Once the configuration is done you're now ready to run Patrole. This can
141 be done using the `tempest_run`_ command. This can be done by running::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100142
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100143 $ tempest run --regex '^patrole_tempest_plugin\.tests\.api'
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100144
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100145 There is also the option to use testr directly, or any `testr`_ based test
146 runner, like `ostestr`_. For example, from the workspace dir run::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100147
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100148 $ stestr --regex '(?!.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api))'
149
150 will run the same set of tests as the default gate jobs.
151
Felipe Monteiro0d3c7432018-10-28 02:14:22 +0000152 You can also run Patrole tests using `tox`_, but as Patrole needs access to
153 global packages use ``--sitepackages`` argument. To do so, ``cd`` into the
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100154 **Tempest** directory and run::
155
Felipe Monteiro0d3c7432018-10-28 02:14:22 +0000156 $ tox -eall --sitepackages -- patrole_tempest_plugin.tests.api
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100157
158 .. note::
159
160 It is possible to run Patrole via ``tox -eall`` in order to run Patrole
161 isolated from other plugins. This can be accomplished by including the
162 installation of services that currently use policy in code -- for example,
163 Nova and Keystone. For example::
164
165 $ tox -evenv-tempest -- pip install /opt/stack/patrole /opt/stack/keystone /opt/stack/nova
166 $ tox -eall -- patrole_tempest_plugin.tests.api
167
168#. Log information from tests is captured in ``tempest.log`` under the Tempest
169 repository. Some Patrole debugging information is captured in that log
zhufl17fc3332019-08-08 10:14:42 +0800170 related to expected test results and `Role Overriding <https://docs.openstack.org/patrole/latest/test_writing_guide.html#role-overriding>`_.
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100171
172 More detailed RBAC testing log output is emitted to ``patrole.log`` under
173 the Patrole repository. To configure Patrole's logging, see the
ghanshyam9ee07cf2018-08-16 08:15:42 +0000174 `Patrole Configuration Guide <https://docs.openstack.org/patrole/latest/configuration.html#patrole-configuration>`_.
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100175
Masayuki Igawa94e6b182019-09-18 15:08:56 +0900176.. _Tempest: https://opendev.org/openstack/tempest/
ghanshyam9ee07cf2018-08-16 08:15:42 +0000177.. _Tempest_quickstart: https://docs.openstack.org/tempest/latest/overview.html#quickstart
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100178.. _tempest_run: https://docs.openstack.org/tempest/latest/run.html
179.. _testr: https://testrepository.readthedocs.org/en/latest/MANUAL.html
180.. _ostestr: https://docs.openstack.org/os-testr/latest/
181.. _tox: https://tox.readthedocs.io/en/latest/
182
183RBAC Tests
184----------
185
Mykola Yakovlieve0f35502018-09-26 18:26:57 -0500186To change the roles that the patrole tests are being run as, edit
187``rbac_test_roles`` in the ``patrole`` section of tempest.conf: ::
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100188
189 [patrole]
Goutham Pratapad16ccfb2019-01-30 16:18:57 +0530190 rbac_test_roles = member,reader
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100191 ...
192
193.. note::
194
Mykola Yakovlieve0f35502018-09-26 18:26:57 -0500195 The ``rbac_test_roles`` is service-specific. member, for example,
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100196 is an arbitrary role, but by convention is used to designate the default
197 non-admin role in the system. Most Patrole tests should be run with
198 **admin** and **member** roles. However, other services may use entirely
Mykola Yakovlieve0f35502018-09-26 18:26:57 -0500199 different roles or role combinations.
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100200
Felipe Monteiro4d4cb1e2018-07-29 13:44:10 -0400201For more information about RBAC, reference the `rbac-overview`_
202documentation page.
203
Felipe Monteiroe36a9732018-11-16 17:28:52 +0000204For information regarding which projects Patrole offers RBAC testing for,
205reference the `HACKING`_ documentation page.
206
Felipe Monteiro4d4cb1e2018-07-29 13:44:10 -0400207.. _rbac-overview: https://docs.openstack.org/patrole/latest/rbac-overview.html
Felipe Monteiroe36a9732018-11-16 17:28:52 +0000208.. _HACKING: https://docs.openstack.org/patrole/latest/HACKING.html#supported-openstack-components
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100209
210Unit Tests
211----------
212
213Patrole also has a set of unit tests which test the Patrole code itself. These
214tests can be run by specifying the test discovery path::
215
216 $ stestr --test-path ./patrole_tempest_plugin/tests/unit run
217
218By setting ``--test-path`` option to ``./patrole_tempest_plugin/tests/unit``
219it specifies that test discovery should only be run on the unit test directory.
220
221Alternatively, there are the py27 and py35 tox jobs which will run the unit
222tests with the corresponding version of Python.
223
224One common activity is to just run a single test; you can do this with tox
225simply by specifying to just run py27 or py35 tests against a single test::
226
227 $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils.RBACUtilsTest.test_override_role_with_missing_admin_role
228
229Or all tests in the test_rbac_utils.py file::
230
231 $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils
232
233You may also use regular expressions to run any matching tests::
234
235 $ tox -e py27 -- test_rbac_utils
236
237For more information on these options and details about stestr, please see the
238`stestr documentation <http://stestr.readthedocs.io/en/latest/MANUAL.html>`_.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100239
Felipe Monteiro780210d2017-07-17 22:21:53 +0100240Release Versioning
Felipe Monteiro7c7b5702017-07-21 01:43:42 +0100241------------------
Felipe Monteiro780210d2017-07-17 22:21:53 +0100242`Patrole Release Notes <https://docs.openstack.org/releasenotes/patrole/>`_
243shows which changes have been released for each version.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100244
Felipe Monteiro780210d2017-07-17 22:21:53 +0100245Patrole's release versioning follows Tempest's conventions. Like Tempest,
246Patrole is branchless and uses versioning instead.
Felipe Monteirob2ebe492018-06-18 21:39:28 +0100247
248Storyboard
249----------
250Bugs and enhancements are tracked via Patrole's
ghanshyam9cd0a432019-03-25 16:54:55 +0000251`Storyboard Page <https://storyboard.openstack.org/#!/project/openstack/patrole>`_.