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