blob: 5eefa5cc92d74b893df54032535f475ea06789bc [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,
60wherever possible.
61
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
88capable of dynamically determining expected test behavior. See
89:ref:`rbac-validation` for more details.
90
91Note that support for custom policies is limited. This is because custom
92policies can be arbitrarily complex, requiring that tests be very robust
93in order to handle all edge cases.
94
95.. _multiple-policies:
96
97Multiple Policies
98-----------------
99
100Behind the scenes, many APIs enforce multiple policies, for many reasons,
101including:
102
103* to control complex cross-service workflows;
104* to control whether a server is booted from an image or booted from a volume
105 (for example);
106* to control whether a response body should contain additional information
107 conditioned upon successful policy authorization.
108
109This makes `policy in code`_ especially important for policy validation: it
110is difficult to keep track of all the policies being enforced across all the
111individual APIs, without policy in code documentation.
112
113Multi-Policy Validation
114^^^^^^^^^^^^^^^^^^^^^^^
115
116Patrole offers support for validating APIs that enforce multiple policies.
117Perhaps in an ideal world each API endpoint would enforce only one policy,
118but in reality some API endpoints enforce multiple policies. Thus, to offer
119accurate validation, Patrole handles multiple policies:
120
121* for services *with* policy in code documentation: this documentation
122 indicates that a single API endpoint enforces multiple policy actions.
123* for services *without* policy in code documentation: the API code clearly
124 shows multiple policy actions being validated. Note that in this case some
125 degree of log tracing is required by developers to confirm that the expected
126 policies are getting enforced, prior to the tests getting merged.
127
128.. todo::
129
130 Link to multi-policy validation documentation section once it has been
131 written.
132
133.. _error-codes:
134
135Error Codes
136-----------
137
138Most OpenStack services raise a ``403 Forbidden`` following failed
139:term:`hard authorization`. Neutron, however, can raise a ``404 NotFound``
140as well. See Neutron's `authorization policy enforcement`_ documentation
141for more details.
142
143Glossary
144--------
145
146The following nomenclature is used throughout Patrole documentation so it is
147important to understand what each term means in order to understand concepts
148related to RBAC in Patrole.
149
150.. glossary::
151
152 authorize
153
154 The act of ``oslo.policy`` determining whether a user can perform a
155 :term:`policy` given his or her :term:`role`.
156
157 enforce
158
159 See :term:`authorize`.
160
161 hard authorization
162
163 The `do_raise`_ flag controls whether policy authorization should result
164 in an exception getting raised or a boolean value getting returned.
165 Hard authorization results in an exception getting raised. Usually, this
166 results in a ``403 Forbidden`` getting returned for unauthorized requests.
167 (See :ref:`error-codes` for further details.)
168
169 Related term: :term:`soft authorization`.
170
171 oslo.policy
172
173 The OpenStack library providing support for RBAC policy enforcement across
174 all OpenStack services. See the `official documentation`_ for more
175 information.
176
177 policy
178
179 Defines an RBAC rule. Each policy is defined by a one-line statement in
180 the form "<target>" : "<rule>". For more information, reference OpenStack's
181 `policy documentation`_.
182
183 policy action
184
185 See :term:`policy target`.
186
187 policy file
188
189 Prior to `governance goal`_ used by all OpenStack services to define
190 policy defaults. Still used by some services, which is why Patrole
191 needs to read the policy files to derive policy information for testing.
192
193 policy in code
194
195 Registers default OpenStack policies for a service in the service's code
196 base.
197
198 Beginning with the Queens release, policy in code became a
199 `governance goal`_.
200
201 policy rule
202
203 The policy rule determines under which circumstances the API call is
204 permitted.
205
206 policy target
207
208 The name of a policy.
209
210 requirements file
211
212 Requirements-driven approach to declaring the expected RBAC test results
213 referenced by Patrole. Uses a high-level YAML syntax to crystallize policy
214 requirements concisely and unambiguously. See :ref:`requirements-authority`
215 for more information.
216
217 role
218
219 A designation for the set of actions that describe what a user can do in
220 the system. Roles are managed through the `Keystone Roles API`_.
221
222 Role-Based Access Control (RBAC)
223
224 May be formally defined as "an approach to restricting system access to
225 authorized users."
226
227 rule
228
229 See :term:`policy rule`. Note that currently the Patrole code base
230 conflates "rule" with :term:`policy target` in some places.
231
232 soft authorization
233
234 The `do_raise`_ flag controls whether policy authorization should result
235 in an exception getting raised or a boolean value getting returned.
236 Soft authorization results in a boolean value getting returned. When policy
237 authorization evaluates to true, additional operations are performed as a
238 part of the API request or additional information is included in the
239 response body (see `response filtering`_ for an example).
240
241 Related term: :term:`hard authorization`.
242
243.. _Nova repository: https://github.com/openstack/nova/tree/master/nova/policies
244.. _Keystone repository: https://github.com/openstack/keystone/tree/master/keystone/common/policies
245.. _governance goal: https://governance.openstack.org/tc/goals/queens/policy-in-code.html
246.. _scope types: https://docs.openstack.org/keystone/latest/admin/identity-tokens.html#authorization-scopes
247.. _policy.yaml: https://docs.openstack.org/ocata/config-reference/policy-yaml-file.html
248.. _oslo.policy: https://docs.openstack.org/oslo.policy/latest/
249.. _policy documentation: https://docs.openstack.org/kilo/config-reference/content/policy-json-file.html
250.. _do_raise: https://docs.openstack.org/oslo.policy/latest/reference/api/oslo_policy.policy.html#oslo_policy.policy.Enforcer.enforce
251.. _authorization policy enforcement: https://docs.openstack.org/neutron/latest/contributor/internals/policy.html
252.. _official documentation: https://docs.openstack.org/oslo.policy/latest/
253.. _Keystone Roles API: https://developer.openstack.org/api-ref/identity/v3/#roles
254.. _response filtering: https://docs.openstack.org/neutron/latest/contributor/internals/policy.html#response-filtering