blob: e9c03c8e9b6886954140dcbd30a8c24a3a9e5140 [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 Monteiro780210d2017-07-17 22:21:53 +010021Patrole currently offers testing for the following OpenStack services: Nova,
22Neutron, Glance, Cinder and Keystone.
DavidPurcell663aedf2017-01-03 10:01:14 -050023
Felipe Monteiroc2873892017-11-15 06:09:02 +000024Patrole is currently undergoing heavy development. As more projects move
25toward policy in code, Patrole will align its testing with the appropriate
26documentation.
27
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010028* Free software: Apache license
29* Documentation: https://docs.openstack.org/patrole/latest
30* Source: https://git.openstack.org/cgit/openstack/patrole
31* Bugs: https://bugs.launchpad.net/patrole
32* Release notes: https://docs.openstack.org/releasenotes/patrole/
Felipe Monteiro443d39c2018-04-08 17:05:33 -040033
Felipe Monteiroc2873892017-11-15 06:09:02 +000034Design Principles
35-----------------
36
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010037As a `Tempest plugin`_, Patrole borrows some `design principles`_ from Tempest,
38but not all, as its testing scope is confined to policies.
Felipe Monteiroc2873892017-11-15 06:09:02 +000039
40* *Stability*. Patrole uses OpenStack public interfaces. Tests in Patrole
41 should only touch public OpenStack APIs.
42* *Atomicity*. Patrole tests should be atomic: they should test policies in
43 isolation. Unlike Tempest, a Patrole test strives to only call a single
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010044 endpoint at a time. This is because it is important to validate each policy
45 is authorized correctly and the best way to do that is to validate each
46 policy alone, to avoid test contamination.
Felipe Monteiro543f7b92018-06-10 13:38:31 -040047* *Complete coverage*. Patrole should validate all policy in code defaults. For
48 testing, Patrole uses the API-to-policy mapping contained in each project's
49 `policy in code`_ documentation where applicable.
50
51 For example, Nova's policy in code documentation is located in the
52 `Nova repository`_ under ``nova/policies``. Likewise, Keystone's policy in
53 code documentation is located in the `Keystone repository`_ under
54 ``keystone/common/policies``. The other OpenStack services follow the same
55 directory layout pattern with respect to policy in code.
56
57 .. note::
58
59 Realistically this is not always possible because some services have
60 not yet moved to policy in code.
61
62* *Self-cleaning*. Patrole should attempt to clean up after itself; whenever
Felipe Monteiroc2873892017-11-15 06:09:02 +000063 possible we should tear down resources when done.
64
65 .. note::
66
67 Patrole modifies roles dynamically in the background, which affects
68 pre-provisioned credentials. Work is currently underway to clean up
69 modifications made to pre-provisioned credentials.
70
Felipe Monteiro543f7b92018-06-10 13:38:31 -040071* *Self-testing*. Patrole should be self-testing.
72
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +010073.. _Tempest plugin: https://docs.openstack.org/tempest/latest/plugin.html
74.. _design principles: https://docs.openstack.org/tempest/latest/overview.html#design-principles
Felipe Monteiro543f7b92018-06-10 13:38:31 -040075.. _policy in code: https://specs.openstack.org/openstack/oslo-specs/specs/newton/policy-in-code.html
76.. _Nova repository: https://github.com/openstack/nova/tree/master/nova/policies
77.. _Keystone repository: https://github.com/openstack/keystone/tree/master/keystone/common/policies
Felipe Monteiroc2873892017-11-15 06:09:02 +000078
DavidPurcell663aedf2017-01-03 10:01:14 -050079Features
Felipe Monteiro780210d2017-07-17 22:21:53 +010080--------
81* Validation of default policy definitions located in policy.json files.
82* Validation of in-code policy definitions.
83* Validation of custom policy file definitions that override default policy
84 definitions.
85* Built-in positive and negative testing. Positive and negative testing
86 are performed using the same tests and role-switching.
87* Valdation of custom roles as well as default OpenStack roles.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +010088
89.. note::
90
Felipe Monteiro780210d2017-07-17 22:21:53 +010091 Patrole does not yet support policy.yaml files, the new file format for
92 policy files in OpenStack.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +010093
94How It Works
Felipe Monteiro780210d2017-07-17 22:21:53 +010095------------
96Patrole leverages ``oslo.policy`` (OpenStack's policy enforcement engine) to
97determine whether a given role is allowed to perform a policy action, given a
98specific role and OpenStack service. The output from ``oslo.policy`` (the
99expected result) and the actual result from test execution are compared to
100each other: if both results match, then the test passes; else it fails.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100101
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100102Terminology
103^^^^^^^^^^^
104* Expected Result - The expected result of a given test.
105* Actual Result - The actual result of a given test.
106* Final Result - A match between both expected and actual results. A mismatch
107 in the expected result and the actual result will result in a test failure.
108
109 * Expected: Pass | Actual: Pass - Test Case Success
110 * Expected: Pass | Actual: Fail - Test Case Under-Permission Failure
111 * Expected: Fail | Actual: Pass - Test Case Over-Permission Failure
112 * Expected: Fail | Actual: Fail (Expected exception) - Test Case Success
113 * Expected: Fail | Actual: Fail (Unexpected exception) - Test Case Failure
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100114
Felipe Monteiro780210d2017-07-17 22:21:53 +0100115Quickstart
Felipe Monteiro7c7b5702017-07-21 01:43:42 +0100116----------
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100117To run Patrole, you must first have `Tempest`_ installed and configured
118properly. Please reference Tempest's `Quickstart`_ guide to do so. Follow all
119the steps outlined therein. Afterward, proceed with the steps below.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100120
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100121#. You first need to install Patrole. This is done with pip after you check out
122 the Patrole repo::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100123
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100124 $ git clone https://git.openstack.org/openstack/patrole
125 $ pip install patrole/
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100126
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100127 This can be done within a venv.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100128
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100129 .. note::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100130
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100131 You may also install Patrole from source code by running::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100132
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100133 pip install -e patrole/
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100134
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100135#. Next you must properly configure Patrole, which is relatively
136 straightforward. For details on configuring Patrole refer to the
137 :ref:`patrole-configuration`.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100138
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100139#. Once the configuration is done you're now ready to run Patrole. This can
140 be done using the `tempest_run`_ command. This can be done by running::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100141
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100142 $ tempest run --regex '^patrole_tempest_plugin\.tests\.api'
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100143
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100144 There is also the option to use testr directly, or any `testr`_ based test
145 runner, like `ostestr`_. For example, from the workspace dir run::
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100146
Felipe Monteiroe5ee4be2018-06-18 21:39:28 +0100147 $ stestr --regex '(?!.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api))'
148
149 will run the same set of tests as the default gate jobs.
150
151 You can also run Patrole tests using `tox`_. To do so, ``cd`` into the
152 **Tempest** directory and run::
153
154 $ tox -eall-plugin -- patrole_tempest_plugin.tests.api
155
156 .. note::
157
158 It is possible to run Patrole via ``tox -eall`` in order to run Patrole
159 isolated from other plugins. This can be accomplished by including the
160 installation of services that currently use policy in code -- for example,
161 Nova and Keystone. For example::
162
163 $ tox -evenv-tempest -- pip install /opt/stack/patrole /opt/stack/keystone /opt/stack/nova
164 $ tox -eall -- patrole_tempest_plugin.tests.api
165
166#. Log information from tests is captured in ``tempest.log`` under the Tempest
167 repository. Some Patrole debugging information is captured in that log
168 related to expected test results and :ref:`role-overriding`.
169
170 More detailed RBAC testing log output is emitted to ``patrole.log`` under
171 the Patrole repository. To configure Patrole's logging, see the
172 :ref:`patrole-configuration` guide.
173
174.. _Tempest: https://github.com/openstack/tempest
175.. _Quickstart: https://docs.openstack.org/tempest/latest/overview.html#quickstart
176.. _tempest_run: https://docs.openstack.org/tempest/latest/run.html
177.. _testr: https://testrepository.readthedocs.org/en/latest/MANUAL.html
178.. _ostestr: https://docs.openstack.org/os-testr/latest/
179.. _tox: https://tox.readthedocs.io/en/latest/
180
181RBAC Tests
182----------
183
184To change the role that the patrole tests are being run as, edit
185``rbac_test_role`` in the ``patrole`` section of tempest.conf: ::
186
187 [patrole]
188 rbac_test_role = member
189 ...
190
191.. note::
192
193 The ``rbac_test_role`` is service-specific. member, for example,
194 is an arbitrary role, but by convention is used to designate the default
195 non-admin role in the system. Most Patrole tests should be run with
196 **admin** and **member** roles. However, other services may use entirely
197 different roles.
198
199For more information about the member role and its nomenclature,
200please see: `<https://ask.openstack.org/en/question/4759/member-vs-_member_/>`__.
201
202Unit Tests
203----------
204
205Patrole also has a set of unit tests which test the Patrole code itself. These
206tests can be run by specifying the test discovery path::
207
208 $ stestr --test-path ./patrole_tempest_plugin/tests/unit run
209
210By setting ``--test-path`` option to ``./patrole_tempest_plugin/tests/unit``
211it specifies that test discovery should only be run on the unit test directory.
212
213Alternatively, there are the py27 and py35 tox jobs which will run the unit
214tests with the corresponding version of Python.
215
216One common activity is to just run a single test; you can do this with tox
217simply by specifying to just run py27 or py35 tests against a single test::
218
219 $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils.RBACUtilsTest.test_override_role_with_missing_admin_role
220
221Or all tests in the test_rbac_utils.py file::
222
223 $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils
224
225You may also use regular expressions to run any matching tests::
226
227 $ tox -e py27 -- test_rbac_utils
228
229For more information on these options and details about stestr, please see the
230`stestr documentation <http://stestr.readthedocs.io/en/latest/MANUAL.html>`_.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100231
Felipe Monteiro780210d2017-07-17 22:21:53 +0100232Release Versioning
Felipe Monteiro7c7b5702017-07-21 01:43:42 +0100233------------------
Felipe Monteiro780210d2017-07-17 22:21:53 +0100234`Patrole Release Notes <https://docs.openstack.org/releasenotes/patrole/>`_
235shows which changes have been released for each version.
Felipe Monteiro7bc35dc2017-04-19 21:11:46 +0100236
Felipe Monteiro780210d2017-07-17 22:21:53 +0100237Patrole's release versioning follows Tempest's conventions. Like Tempest,
238Patrole is branchless and uses versioning instead.