Felipe Monteiro | c458932 | 2017-06-09 19:42:50 +0100 | [diff] [blame] | 1 | ======================== |
| 2 | Team and repository tags |
| 3 | ======================== |
| 4 | |
shangxiaobj | 11b0232 | 2017-08-14 22:45:11 -0700 | [diff] [blame] | 5 | .. image:: https://governance.openstack.org/tc/badges/patrole.svg |
| 6 | :target: https://governance.openstack.org/tc/reference/tags/index.html |
Felipe Monteiro | c458932 | 2017-06-09 19:42:50 +0100 | [diff] [blame] | 7 | |
Felipe Monteiro | c458932 | 2017-06-09 19:42:50 +0100 | [diff] [blame] | 8 | Patrole - RBAC Integration Tempest Plugin |
| 9 | ========================================= |
DavidPurcell | 663aedf | 2017-01-03 10:01:14 -0500 | [diff] [blame] | 10 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 11 | Patrole is a set of integration tests to be run against a live OpenStack |
| 12 | cluster. It has a battery of tests dedicated to validating the correctness and |
| 13 | integrity of the cloud's RBAC implementation. |
| 14 | |
| 15 | More importantly, Patrole is a security validation tool for verifying that |
| 16 | Role-Based Access Control is correctly configured and enforced in an OpenStack |
| 17 | cloud. It runs `Tempest`_-based API tests using specified RBAC roles, thus |
| 18 | allowing deployments to verify that only intended roles have access to those |
| 19 | APIs. |
DavidPurcell | 663aedf | 2017-01-03 10:01:14 -0500 | [diff] [blame] | 20 | |
Felipe Monteiro | c287389 | 2017-11-15 06:09:02 +0000 | [diff] [blame] | 21 | Patrole is currently undergoing heavy development. As more projects move |
| 22 | toward policy in code, Patrole will align its testing with the appropriate |
| 23 | documentation. |
| 24 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 25 | * Free software: Apache license |
| 26 | * Documentation: https://docs.openstack.org/patrole/latest |
| 27 | * Source: https://git.openstack.org/cgit/openstack/patrole |
Felipe Monteiro | b2ebe49 | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 28 | * Bugs: https://storyboard.openstack.org/#!/project/openstack/patrole |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 29 | * Release notes: https://docs.openstack.org/releasenotes/patrole/ |
Felipe Monteiro | 443d39c | 2018-04-08 17:05:33 -0400 | [diff] [blame] | 30 | |
Felipe Monteiro | e917655 | 2018-07-16 14:39:55 -0400 | [diff] [blame] | 31 | .. _design-principles: |
| 32 | |
Felipe Monteiro | c287389 | 2017-11-15 06:09:02 +0000 | [diff] [blame] | 33 | Design Principles |
| 34 | ----------------- |
| 35 | |
ghanshyam | 9ee07cf | 2018-08-16 08:15:42 +0000 | [diff] [blame] | 36 | As a `Tempest plugin`_, Patrole borrows some design principles from `Tempest design principles`_, |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 37 | but not all, as its testing scope is confined to policies. |
Felipe Monteiro | c287389 | 2017-11-15 06:09:02 +0000 | [diff] [blame] | 38 | |
| 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 Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 43 | 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 Monteiro | 543f7b9 | 2018-06-10 13:38:31 -0400 | [diff] [blame] | 46 | * *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 Monteiro | e917655 | 2018-07-16 14:39:55 -0400 | [diff] [blame] | 61 | * *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 Monteiro | 543f7b9 | 2018-06-10 13:38:31 -0400 | [diff] [blame] | 64 | * *Self-cleaning*. Patrole should attempt to clean up after itself; whenever |
Felipe Monteiro | c287389 | 2017-11-15 06:09:02 +0000 | [diff] [blame] | 65 | 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 Monteiro | 543f7b9 | 2018-06-10 13:38:31 -0400 | [diff] [blame] | 73 | * *Self-testing*. Patrole should be self-testing. |
| 74 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 75 | .. _Tempest plugin: https://docs.openstack.org/tempest/latest/plugin.html |
ghanshyam | 9ee07cf | 2018-08-16 08:15:42 +0000 | [diff] [blame] | 76 | .. _Tempest design principles: https://docs.openstack.org/tempest/latest/overview.html#design-principles |
Felipe Monteiro | 543f7b9 | 2018-06-10 13:38:31 -0400 | [diff] [blame] | 77 | .. _policy in code: https://specs.openstack.org/openstack/oslo-specs/specs/newton/policy-in-code.html |
Luigi Toscano | 6da06ed | 2019-01-07 17:50:41 +0100 | [diff] [blame] | 78 | .. _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 Monteiro | c287389 | 2017-11-15 06:09:02 +0000 | [diff] [blame] | 80 | |
DavidPurcell | 663aedf | 2017-01-03 10:01:14 -0500 | [diff] [blame] | 81 | Features |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 82 | -------- |
| 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 Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 90 | |
| 91 | .. note:: |
| 92 | |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 93 | Patrole does not yet support policy.yaml files, the new file format for |
| 94 | policy files in OpenStack. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 95 | |
| 96 | How It Works |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 97 | ------------ |
| 98 | Patrole leverages ``oslo.policy`` (OpenStack's policy enforcement engine) to |
| 99 | determine whether a given role is allowed to perform a policy action, given a |
| 100 | specific role and OpenStack service. The output from ``oslo.policy`` (the |
| 101 | expected result) and the actual result from test execution are compared to |
| 102 | each other: if both results match, then the test passes; else it fails. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 103 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 104 | Terminology |
| 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 Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 116 | |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 117 | Quickstart |
Felipe Monteiro | 7c7b570 | 2017-07-21 01:43:42 +0100 | [diff] [blame] | 118 | ---------- |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 119 | To run Patrole, you must first have `Tempest`_ installed and configured |
ghanshyam | 9ee07cf | 2018-08-16 08:15:42 +0000 | [diff] [blame] | 120 | properly. Please reference `Tempest_quickstart`_ guide to do so. Follow all |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 121 | the steps outlined therein. Afterward, proceed with the steps below. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 122 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 123 | #. You first need to install Patrole. This is done with pip after you check out |
| 124 | the Patrole repo:: |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 125 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 126 | $ git clone https://git.openstack.org/openstack/patrole |
| 127 | $ pip install patrole/ |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 128 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 129 | This can be done within a venv. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 130 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 131 | .. note:: |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 132 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 133 | You may also install Patrole from source code by running:: |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 134 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 135 | pip install -e patrole/ |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 136 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 137 | #. Next you must properly configure Patrole, which is relatively |
| 138 | straightforward. For details on configuring Patrole refer to the |
ghanshyam | 9ee07cf | 2018-08-16 08:15:42 +0000 | [diff] [blame] | 139 | `Patrole Configuration <https://docs.openstack.org/patrole/latest/configuration.html#patrole-configuration>`_. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 140 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 141 | #. 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 Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 143 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 144 | $ tempest run --regex '^patrole_tempest_plugin\.tests\.api' |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 145 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 146 | 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 Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 148 | |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 149 | $ 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 Monteiro | 0d3c743 | 2018-10-28 02:14:22 +0000 | [diff] [blame] | 153 | 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 Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 155 | **Tempest** directory and run:: |
| 156 | |
Felipe Monteiro | 0d3c743 | 2018-10-28 02:14:22 +0000 | [diff] [blame] | 157 | $ tox -eall --sitepackages -- patrole_tempest_plugin.tests.api |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 158 | |
| 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 |
zhufl | 17fc333 | 2019-08-08 10:14:42 +0800 | [diff] [blame] | 171 | related to expected test results and `Role Overriding <https://docs.openstack.org/patrole/latest/test_writing_guide.html#role-overriding>`_. |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 172 | |
| 173 | More detailed RBAC testing log output is emitted to ``patrole.log`` under |
| 174 | the Patrole repository. To configure Patrole's logging, see the |
ghanshyam | 9ee07cf | 2018-08-16 08:15:42 +0000 | [diff] [blame] | 175 | `Patrole Configuration Guide <https://docs.openstack.org/patrole/latest/configuration.html#patrole-configuration>`_. |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 176 | |
Luigi Toscano | 6da06ed | 2019-01-07 17:50:41 +0100 | [diff] [blame] | 177 | .. _Tempest: https://git.openstack.org/cgit/openstack/tempest |
ghanshyam | 9ee07cf | 2018-08-16 08:15:42 +0000 | [diff] [blame] | 178 | .. _Tempest_quickstart: https://docs.openstack.org/tempest/latest/overview.html#quickstart |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 179 | .. _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 | |
| 184 | RBAC Tests |
| 185 | ---------- |
| 186 | |
Mykola Yakovliev | e0f3550 | 2018-09-26 18:26:57 -0500 | [diff] [blame] | 187 | To change the roles that the patrole tests are being run as, edit |
| 188 | ``rbac_test_roles`` in the ``patrole`` section of tempest.conf: :: |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 189 | |
| 190 | [patrole] |
Goutham Pratapa | d16ccfb | 2019-01-30 16:18:57 +0530 | [diff] [blame] | 191 | rbac_test_roles = member,reader |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 192 | ... |
| 193 | |
| 194 | .. note:: |
| 195 | |
Mykola Yakovliev | e0f3550 | 2018-09-26 18:26:57 -0500 | [diff] [blame] | 196 | The ``rbac_test_roles`` is service-specific. member, for example, |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 197 | 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 Yakovliev | e0f3550 | 2018-09-26 18:26:57 -0500 | [diff] [blame] | 200 | different roles or role combinations. |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 201 | |
Felipe Monteiro | 4d4cb1e | 2018-07-29 13:44:10 -0400 | [diff] [blame] | 202 | For more information about RBAC, reference the `rbac-overview`_ |
| 203 | documentation page. |
| 204 | |
Felipe Monteiro | e36a973 | 2018-11-16 17:28:52 +0000 | [diff] [blame] | 205 | For information regarding which projects Patrole offers RBAC testing for, |
| 206 | reference the `HACKING`_ documentation page. |
| 207 | |
Felipe Monteiro | 4d4cb1e | 2018-07-29 13:44:10 -0400 | [diff] [blame] | 208 | .. _rbac-overview: https://docs.openstack.org/patrole/latest/rbac-overview.html |
Felipe Monteiro | e36a973 | 2018-11-16 17:28:52 +0000 | [diff] [blame] | 209 | .. _HACKING: https://docs.openstack.org/patrole/latest/HACKING.html#supported-openstack-components |
Felipe Monteiro | e5ee4be | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 210 | |
| 211 | Unit Tests |
| 212 | ---------- |
| 213 | |
| 214 | Patrole also has a set of unit tests which test the Patrole code itself. These |
| 215 | tests can be run by specifying the test discovery path:: |
| 216 | |
| 217 | $ stestr --test-path ./patrole_tempest_plugin/tests/unit run |
| 218 | |
| 219 | By setting ``--test-path`` option to ``./patrole_tempest_plugin/tests/unit`` |
| 220 | it specifies that test discovery should only be run on the unit test directory. |
| 221 | |
| 222 | Alternatively, there are the py27 and py35 tox jobs which will run the unit |
| 223 | tests with the corresponding version of Python. |
| 224 | |
| 225 | One common activity is to just run a single test; you can do this with tox |
| 226 | simply 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 | |
| 230 | Or all tests in the test_rbac_utils.py file:: |
| 231 | |
| 232 | $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils |
| 233 | |
| 234 | You may also use regular expressions to run any matching tests:: |
| 235 | |
| 236 | $ tox -e py27 -- test_rbac_utils |
| 237 | |
| 238 | For more information on these options and details about stestr, please see the |
| 239 | `stestr documentation <http://stestr.readthedocs.io/en/latest/MANUAL.html>`_. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 240 | |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 241 | Release Versioning |
Felipe Monteiro | 7c7b570 | 2017-07-21 01:43:42 +0100 | [diff] [blame] | 242 | ------------------ |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 243 | `Patrole Release Notes <https://docs.openstack.org/releasenotes/patrole/>`_ |
| 244 | shows which changes have been released for each version. |
Felipe Monteiro | 7bc35dc | 2017-04-19 21:11:46 +0100 | [diff] [blame] | 245 | |
Felipe Monteiro | 780210d | 2017-07-17 22:21:53 +0100 | [diff] [blame] | 246 | Patrole's release versioning follows Tempest's conventions. Like Tempest, |
| 247 | Patrole is branchless and uses versioning instead. |
Felipe Monteiro | b2ebe49 | 2018-06-18 21:39:28 +0100 | [diff] [blame] | 248 | |
| 249 | Storyboard |
| 250 | ---------- |
| 251 | Bugs and enhancements are tracked via Patrole's |
ghanshyam | 9cd0a43 | 2019-03-25 16:54:55 +0000 | [diff] [blame] | 252 | `Storyboard Page <https://storyboard.openstack.org/#!/project/openstack/patrole>`_. |