Felipe Monteiro | e917655 | 2018-07-16 14:39:55 -0400 | [diff] [blame] | 1 | ================================== |
| 2 | Role-Based Access Control Overview |
| 3 | ================================== |
| 4 | |
| 5 | Introduction |
| 6 | ------------ |
| 7 | |
| 8 | Role-Based Access Control (RBAC) is used by most OpenStack services to control |
| 9 | user access to resources. Authorization is granted if a user has the necessary |
| 10 | role to perform an action. Patrole is concerned with validating that each of |
| 11 | these resources *can* be accessed by authorized users and *cannot* be accessed |
| 12 | by unauthorized users. |
| 13 | |
| 14 | OpenStack services use `oslo.policy`_ as the library for RBAC authorization. |
| 15 | Patrole relies on the same library for deriving expected test results. |
| 16 | |
| 17 | .. _policy-in-code: |
| 18 | |
| 19 | Policy in Code |
| 20 | -------------- |
| 21 | |
| 22 | Services publish their policy-to-API mapping via policy in code documentation. |
| 23 | This mapping includes the list of APIs that authorize a policy, for each |
| 24 | policy declared within a service. |
| 25 | |
| 26 | For example, Nova's policy in code documentation is located in the |
| 27 | `Nova repository`_ under ``nova/policies``. Likewise, Keystone's policy in |
| 28 | code documentation is located in the `Keystone repository`_ under |
| 29 | ``keystone/common/policies``. The other OpenStack services follow the same |
| 30 | directory layout pattern with respect to policy in code. |
| 31 | |
| 32 | The policy in code `governance goal`_ enumerates many advantages with following |
| 33 | this RBAC design approach. A so-called library of in-code policies offers the |
| 34 | following advantages, with respect to facilitating validation: |
| 35 | |
| 36 | * includes every policy enforced by an OpenStack service, enabling the |
| 37 | possibility of complete Patrole test coverage for that service (otherwise |
| 38 | one has to read the source code to discover all the policies) |
| 39 | * provides the policy-to-API mapping for each policy which can be used |
| 40 | to write correct Patrole tests (otherwise reading source code and |
| 41 | experimentation are required to derive this mapping) |
| 42 | * by extension, the policy-to-API mapping facilitates writing multi-policy |
| 43 | Patrole tests (otherwise even more experimentation and code reading is |
| 44 | required to arrive at all the policies enforced by an API) |
| 45 | * policy in code documentation includes additional information, like |
| 46 | descriptions and (in the case of some services, like Keystone) |
| 47 | `scope types`_, which help with understanding how to correctly write |
| 48 | Patrole tests |
| 49 | * by extension, such information helps to determine whether a Patrole test |
| 50 | should assume :term:`hard authorization` or :term:`soft authorization` |
| 51 | |
| 52 | Policy in Code (Default) Validation |
| 53 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 54 | |
| 55 | By default, Patrole validates default OpenStack policies. This is so that |
| 56 | the out-of-the-box defaults are sanity-checked, to ensure that OpenStack |
| 57 | services are secure, from an RBAC perspective, for each release. |
| 58 | |
| 59 | Patrole strives to validate RBAC by using the policy in code documentation, |
Felipe Monteiro | 0170c99 | 2018-07-31 20:10:05 -0400 | [diff] [blame] | 60 | wherever possible. See :ref:`validation-workflow-overview` for more details. |
Felipe Monteiro | e917655 | 2018-07-16 14:39:55 -0400 | [diff] [blame] | 61 | |
| 62 | .. _custom-policies: |
| 63 | |
| 64 | Custom Policies |
| 65 | --------------- |
| 66 | |
| 67 | Operators can override policy in code defaults using `policy.yaml`_. While |
| 68 | this allows operators to offer more fine-grained RBAC control to their tenants, |
| 69 | it opens the door to misconfiguration and bugs. Patrole can be used to validate |
| 70 | that custom policy overrides don't break anything and work as expected. |
| 71 | |
| 72 | Custom Policy Validation |
| 73 | ^^^^^^^^^^^^^^^^^^^^^^^^ |
| 74 | |
| 75 | While testing default policy behavior is a valid use case, oftentimes default |
| 76 | policies are modified with custom overrides in production. OpenStack's |
| 77 | `policy.yaml`_ documentation claims that "modifying policy can have unexpected |
| 78 | side effects", which is why Patrole was created: to ensure that custom |
| 79 | overrides allow the principle of least privilege to be tailor-made to exact |
| 80 | specifications via policy overrides, without: |
| 81 | |
| 82 | * causing unintended side effects (breaking API endpoints, breaking |
| 83 | cross-service workflows, breaking the policy file itself); or |
| 84 | * resulting in poor RBAC configuration, promoting security vulnerabilities |
| 85 | |
| 86 | This has implications on Patrole's :ref:`design-principles`: validating custom |
| 87 | overrides requires the ability to handle arbitrary roles, which requires logic |
Felipe Monteiro | 0170c99 | 2018-07-31 20:10:05 -0400 | [diff] [blame] | 88 | capable of dynamically determining expected test behavior. |
Felipe Monteiro | e917655 | 2018-07-16 14:39:55 -0400 | [diff] [blame] | 89 | |
| 90 | Note that support for custom policies is limited. This is because custom |
| 91 | policies can be arbitrarily complex, requiring that tests be very robust |
| 92 | in order to handle all edge cases. |
| 93 | |
| 94 | .. _multiple-policies: |
| 95 | |
| 96 | Multiple Policies |
| 97 | ----------------- |
| 98 | |
| 99 | Behind the scenes, many APIs enforce multiple policies, for many reasons, |
| 100 | including: |
| 101 | |
| 102 | * to control complex cross-service workflows; |
| 103 | * to control whether a server is booted from an image or booted from a volume |
| 104 | (for example); |
| 105 | * to control whether a response body should contain additional information |
| 106 | conditioned upon successful policy authorization. |
| 107 | |
| 108 | This makes `policy in code`_ especially important for policy validation: it |
| 109 | is difficult to keep track of all the policies being enforced across all the |
| 110 | individual APIs, without policy in code documentation. |
| 111 | |
| 112 | Multi-Policy Validation |
| 113 | ^^^^^^^^^^^^^^^^^^^^^^^ |
| 114 | |
| 115 | Patrole offers support for validating APIs that enforce multiple policies. |
| 116 | Perhaps in an ideal world each API endpoint would enforce only one policy, |
| 117 | but in reality some API endpoints enforce multiple policies. Thus, to offer |
| 118 | accurate validation, Patrole handles multiple policies: |
| 119 | |
| 120 | * for services *with* policy in code documentation: this documentation |
| 121 | indicates that a single API endpoint enforces multiple policy actions. |
| 122 | * for services *without* policy in code documentation: the API code clearly |
| 123 | shows multiple policy actions being validated. Note that in this case some |
| 124 | degree of log tracing is required by developers to confirm that the expected |
| 125 | policies are getting enforced, prior to the tests getting merged. |
| 126 | |
| 127 | .. todo:: |
| 128 | |
| 129 | Link to multi-policy validation documentation section once it has been |
| 130 | written. |
| 131 | |
| 132 | .. _error-codes: |
| 133 | |
| 134 | Error Codes |
| 135 | ----------- |
| 136 | |
| 137 | Most OpenStack services raise a ``403 Forbidden`` following failed |
| 138 | :term:`hard authorization`. Neutron, however, can raise a ``404 NotFound`` |
| 139 | as well. See Neutron's `authorization policy enforcement`_ documentation |
| 140 | for more details. |
| 141 | |
Felipe Monteiro | 0170c99 | 2018-07-31 20:10:05 -0400 | [diff] [blame] | 142 | Admin Context Policy |
| 143 | -------------------- |
| 144 | |
| 145 | The so-called "admin context" policy refers to the following policy definition |
| 146 | (using the legacy policy file syntax): |
| 147 | |
| 148 | .. code-block:: javascript |
| 149 | |
| 150 | { |
| 151 | "context_is_admin": "role:admin" |
| 152 | ... |
| 153 | } |
| 154 | |
| 155 | Which is unfortunately used to bypass ``oslo.policy`` authorization checks, |
| 156 | for example: |
| 157 | |
| 158 | .. code-block:: python |
| 159 | |
| 160 | # This function is responsible for calling oslo.policy to check whether |
| 161 | # requests are authorized to perform an API action. |
| 162 | def enforce(context, action, target, [...]): |
| 163 | # Here this condition, if True, skips over the enforce call below which |
| 164 | # is what calls oslo.policy. |
| 165 | if context.is_admin: |
| 166 | return True |
| 167 | _ENFORCER.enforce([...]) # This is what can be skipped over. |
| 168 | [...] |
| 169 | |
| 170 | This type of behavior is currently present in many services. Unless such |
| 171 | logic is removed in the future for services that implement it, Patrole |
| 172 | won't really be able to validate that admin role works from an ``oslo.policy`` |
| 173 | perspective. |
| 174 | |
Felipe Monteiro | e917655 | 2018-07-16 14:39:55 -0400 | [diff] [blame] | 175 | Glossary |
| 176 | -------- |
| 177 | |
| 178 | The following nomenclature is used throughout Patrole documentation so it is |
| 179 | important to understand what each term means in order to understand concepts |
| 180 | related to RBAC in Patrole. |
| 181 | |
| 182 | .. glossary:: |
| 183 | |
| 184 | authorize |
| 185 | |
| 186 | The act of ``oslo.policy`` determining whether a user can perform a |
| 187 | :term:`policy` given his or her :term:`role`. |
| 188 | |
| 189 | enforce |
| 190 | |
| 191 | See :term:`authorize`. |
| 192 | |
| 193 | hard authorization |
| 194 | |
| 195 | The `do_raise`_ flag controls whether policy authorization should result |
| 196 | in an exception getting raised or a boolean value getting returned. |
| 197 | Hard authorization results in an exception getting raised. Usually, this |
| 198 | results in a ``403 Forbidden`` getting returned for unauthorized requests. |
| 199 | (See :ref:`error-codes` for further details.) |
| 200 | |
| 201 | Related term: :term:`soft authorization`. |
| 202 | |
| 203 | oslo.policy |
| 204 | |
| 205 | The OpenStack library providing support for RBAC policy enforcement across |
| 206 | all OpenStack services. See the `official documentation`_ for more |
| 207 | information. |
| 208 | |
| 209 | policy |
| 210 | |
| 211 | Defines an RBAC rule. Each policy is defined by a one-line statement in |
| 212 | the form "<target>" : "<rule>". For more information, reference OpenStack's |
| 213 | `policy documentation`_. |
| 214 | |
| 215 | policy action |
| 216 | |
| 217 | See :term:`policy target`. |
| 218 | |
| 219 | policy file |
| 220 | |
| 221 | Prior to `governance goal`_ used by all OpenStack services to define |
| 222 | policy defaults. Still used by some services, which is why Patrole |
| 223 | needs to read the policy files to derive policy information for testing. |
| 224 | |
| 225 | policy in code |
| 226 | |
| 227 | Registers default OpenStack policies for a service in the service's code |
| 228 | base. |
| 229 | |
| 230 | Beginning with the Queens release, policy in code became a |
| 231 | `governance goal`_. |
| 232 | |
| 233 | policy rule |
| 234 | |
| 235 | The policy rule determines under which circumstances the API call is |
| 236 | permitted. |
| 237 | |
| 238 | policy target |
| 239 | |
| 240 | The name of a policy. |
| 241 | |
| 242 | requirements file |
| 243 | |
| 244 | Requirements-driven approach to declaring the expected RBAC test results |
| 245 | referenced by Patrole. Uses a high-level YAML syntax to crystallize policy |
| 246 | requirements concisely and unambiguously. See :ref:`requirements-authority` |
| 247 | for more information. |
| 248 | |
| 249 | role |
| 250 | |
| 251 | A designation for the set of actions that describe what a user can do in |
| 252 | the system. Roles are managed through the `Keystone Roles API`_. |
| 253 | |
| 254 | Role-Based Access Control (RBAC) |
| 255 | |
| 256 | May be formally defined as "an approach to restricting system access to |
| 257 | authorized users." |
| 258 | |
| 259 | rule |
| 260 | |
| 261 | See :term:`policy rule`. Note that currently the Patrole code base |
| 262 | conflates "rule" with :term:`policy target` in some places. |
| 263 | |
| 264 | soft authorization |
| 265 | |
| 266 | The `do_raise`_ flag controls whether policy authorization should result |
| 267 | in an exception getting raised or a boolean value getting returned. |
| 268 | Soft authorization results in a boolean value getting returned. When policy |
| 269 | authorization evaluates to true, additional operations are performed as a |
| 270 | part of the API request or additional information is included in the |
| 271 | response body (see `response filtering`_ for an example). |
| 272 | |
| 273 | Related term: :term:`hard authorization`. |
| 274 | |
| 275 | .. _Nova repository: https://github.com/openstack/nova/tree/master/nova/policies |
| 276 | .. _Keystone repository: https://github.com/openstack/keystone/tree/master/keystone/common/policies |
| 277 | .. _governance goal: https://governance.openstack.org/tc/goals/queens/policy-in-code.html |
| 278 | .. _scope types: https://docs.openstack.org/keystone/latest/admin/identity-tokens.html#authorization-scopes |
| 279 | .. _policy.yaml: https://docs.openstack.org/ocata/config-reference/policy-yaml-file.html |
| 280 | .. _oslo.policy: https://docs.openstack.org/oslo.policy/latest/ |
| 281 | .. _policy documentation: https://docs.openstack.org/kilo/config-reference/content/policy-json-file.html |
| 282 | .. _do_raise: https://docs.openstack.org/oslo.policy/latest/reference/api/oslo_policy.policy.html#oslo_policy.policy.Enforcer.enforce |
| 283 | .. _authorization policy enforcement: https://docs.openstack.org/neutron/latest/contributor/internals/policy.html |
| 284 | .. _official documentation: https://docs.openstack.org/oslo.policy/latest/ |
| 285 | .. _Keystone Roles API: https://developer.openstack.org/api-ref/identity/v3/#roles |
| 286 | .. _response filtering: https://docs.openstack.org/neutron/latest/contributor/internals/policy.html#response-filtering |