Felipe Monteiro | 543f7b9 | 2018-06-10 13:38:31 -0400 | [diff] [blame^] | 1 | ======================== |
| 2 | Team and repository tags |
| 3 | ======================== |
| 4 | |
| 5 | .. image:: https://governance.openstack.org/tc/badges/patrole.svg |
| 6 | :target: https://governance.openstack.org/tc/reference/tags/index.html |
| 7 | |
| 8 | Patrole - The OpenStack RBAC Validation Test Suite |
| 9 | ================================================== |
| 10 | |
| 11 | The documentation for Patrole is officially hosted at: |
| 12 | https://docs.openstack.org/patrole/latest/ |
| 13 | |
| 14 | This is a set of integration tests to be run against a live OpenStack |
| 15 | cluster. Patrole has a battery of tests dedicated to validating the correctness |
| 16 | and security of the cloud's RBAC implementation. |
| 17 | |
| 18 | Design Principles |
| 19 | ----------------- |
| 20 | |
| 21 | As a `Tempest plugin`_, Patrole borrows some `design principles`_ from Tempest, |
| 22 | but not all, as its testing scope is confined to policies. |
| 23 | |
| 24 | * Patrole uses OpenStack public interfaces. Tests in Patrole should only touch |
| 25 | public OpenStack APIs. |
| 26 | * Patrole tests should be atomic: they should test policies in isolation. |
| 27 | Unlike Tempest, a Patrole test strives to only call a single endpoint at a |
| 28 | time. This is because it is important to validate each policy is authorized |
| 29 | correctly and the best way to do that is to validate the policy alone. |
| 30 | * Patrole should validate all policy in code defaults. For testing, Patrole |
| 31 | uses the API-to-policy mapping contained in each project's `policy in code`_ |
| 32 | documentation where applicable. |
| 33 | |
| 34 | For example, Nova's policy in code documentation is located in the |
| 35 | `Nova repository`_ under ``nova/policies``. Likewise, Keystone's policy in |
| 36 | code documentation is located in the `Keystone repository`_ under |
| 37 | ``keystone/common/policies``. The other OpenStack services follow the same |
| 38 | directory layout pattern with respect to policy in code. |
| 39 | |
| 40 | .. note:: |
| 41 | |
| 42 | Realistically this is not always possible because some services have |
| 43 | not yet moved to policy in code. |
| 44 | |
| 45 | * Patrole should attempt to clean up after itself; whenever possible it should |
| 46 | tear down resources when done. |
| 47 | |
| 48 | .. note:: |
| 49 | |
| 50 | Patrole modifies roles dynamically in the background, which affects |
| 51 | pre-provisioned credentials. Work is currently underway to clean up |
| 52 | modifications made to pre-provisioned credentials. |
| 53 | |
| 54 | * Patrole should be self-testing. |
| 55 | |
| 56 | .. _Tempest plugin: https://docs.openstack.org/tempest/latest/plugin.html |
| 57 | .. _design principles: https://docs.openstack.org/tempest/latest/overview.html#design-principles |
| 58 | .. _policy in code: https://specs.openstack.org/openstack/oslo-specs/specs/newton/policy-in-code.html |
| 59 | .. _Nova repository: https://github.com/openstack/nova/tree/master/nova/policies |
| 60 | .. _Keystone repository: https://github.com/openstack/keystone/tree/master/keystone/common/policies |
| 61 | |
| 62 | Quickstart |
| 63 | ---------- |
| 64 | |
| 65 | To run Patrole, you must first have `Tempest`_ installed and configured |
| 66 | properly. Please reference Tempest's `Quickstart`_ guide to do so. Follow all |
| 67 | the steps outlined therein. Afterward, proceed with the steps below. |
| 68 | |
| 69 | #. You first need to install Patrole. This is done with pip after you check out |
| 70 | the Patrole repo:: |
| 71 | |
| 72 | $ git clone https://git.openstack.org/openstack/patrole |
| 73 | $ pip install patrole/ |
| 74 | |
| 75 | This can be done within a venv. |
| 76 | |
| 77 | .. note:: |
| 78 | |
| 79 | You may also install Patrole from source code by running:: |
| 80 | |
| 81 | pip install -e patrole/ |
| 82 | |
| 83 | #. Next you must properly configure Patrole, which is relatively |
| 84 | straightforward. For details on configuring Patrole refer to the |
| 85 | :ref:`patrole-configuration`. |
| 86 | |
| 87 | #. Once the configuration is done you're now ready to run Patrole. This can |
| 88 | be done using the `tempest_run`_ command. This can be done by running:: |
| 89 | |
| 90 | $ tempest run --regex '^patrole_tempest_plugin\.tests\.api' |
| 91 | |
| 92 | There is also the option to use testr directly, or any `testr`_ based test |
| 93 | runner, like `ostestr`_. For example, from the workspace dir run:: |
| 94 | |
| 95 | $ stestr --regex '(?!.*\[.*\bslow\b.*\])(^patrole_tempest_plugin\.tests\.api))' |
| 96 | |
| 97 | will run the same set of tests as the default gate jobs. |
| 98 | |
| 99 | You can also run Patrole tests using `tox`_. To do so, ``cd`` into the |
| 100 | **Tempest** directory and run:: |
| 101 | |
| 102 | $ tox -eall-plugin -- patrole_tempest_plugin.tests.api |
| 103 | |
| 104 | .. note:: |
| 105 | |
| 106 | It is possible to run Patrole via ``tox -eall`` in order to run Patrole |
| 107 | isolated from other plugins. This can be accomplished by including the |
| 108 | installation of services that currently use policy in code -- for example, |
| 109 | Nova and Keystone. For example:: |
| 110 | |
| 111 | $ tox -evenv-tempest -- pip install /opt/stack/patrole /opt/stack/keystone /opt/stack/nova |
| 112 | $ tox -eall -- patrole_tempest_plugin.tests.api |
| 113 | |
| 114 | #. Log information from tests is captured in ``tempest.log`` under the Tempest |
| 115 | repository. Some Patrole debugging information is captured in that log |
| 116 | related to expected test results and :ref:`role-overriding`. |
| 117 | |
| 118 | More detailed RBAC testing log output is emitted to ``patrole.log`` under |
| 119 | the Patrole repository. To configure Patrole's logging, see the |
| 120 | :ref:`patrole-configuration` guide. |
| 121 | |
| 122 | .. _Tempest: https://github.com/openstack/tempest |
| 123 | .. _Quickstart: https://docs.openstack.org/tempest/latest/overview.html#quickstart |
| 124 | .. _tempest_run: https://docs.openstack.org/tempest/latest/run.html |
| 125 | .. _testr: https://testrepository.readthedocs.org/en/latest/MANUAL.html |
| 126 | .. _ostestr: https://docs.openstack.org/os-testr/latest/ |
| 127 | .. _tox: https://tox.readthedocs.io/en/latest/ |
| 128 | |
| 129 | RBAC Tests |
| 130 | ---------- |
| 131 | |
| 132 | To change the role that the patrole tests are being run as, edit |
| 133 | ``rbac_test_role`` in the ``patrole`` section of tempest.conf: :: |
| 134 | |
| 135 | [patrole] |
| 136 | rbac_test_role = member |
| 137 | ... |
| 138 | |
| 139 | .. note:: |
| 140 | |
| 141 | The ``rbac_test_role`` is service-specific. member, for example, |
| 142 | is an arbitrary role, but by convention is used to designate the default |
| 143 | non-admin role in the system. Most Patrole tests should be run with |
| 144 | **admin** and **member** roles. However, other services may use entirely |
| 145 | different roles. |
| 146 | |
| 147 | For more information about the member role and its nomenclature, |
| 148 | please see: `<https://ask.openstack.org/en/question/4759/member-vs-_member_/>`__. |
| 149 | |
| 150 | Unit Tests |
| 151 | ---------- |
| 152 | |
| 153 | Patrole also has a set of unit tests which test the Patrole code itself. These |
| 154 | tests can be run by specifying the test discovery path:: |
| 155 | |
| 156 | $ stestr --test-path ./patrole_tempest_plugin/tests/unit run |
| 157 | |
| 158 | By setting ``--test-path`` option to ``./patrole_tempest_plugin/tests/unit`` |
| 159 | it specifies that test discovery should only be run on the unit test directory. |
| 160 | |
| 161 | Alternatively, there are the py27 and py35 tox jobs which will run the unit |
| 162 | tests with the corresponding version of Python. |
| 163 | |
| 164 | One common activity is to just run a single test; you can do this with tox |
| 165 | simply by specifying to just run py27 or py35 tests against a single test:: |
| 166 | |
| 167 | $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils.RBACUtilsTest.test_override_role_with_missing_admin_role |
| 168 | |
| 169 | Or all tests in the test_rbac_utils.py file:: |
| 170 | |
| 171 | $ tox -e py27 -- -n patrole_tempest_plugin.tests.unit.test_rbac_utils |
| 172 | |
| 173 | You may also use regular expressions to run any matching tests:: |
| 174 | |
| 175 | $ tox -e py27 -- test_rbac_utils |
| 176 | |
| 177 | For more information on these options and details about stestr, please see the |
| 178 | `stestr documentation <http://stestr.readthedocs.io/en/latest/MANUAL.html>`_. |