| 1 |
============================= |
| 2 |
Understanding Cyborg Policies |
| 3 |
============================= |
| 4 |
|
| 5 |
.. warning:: |
| 6 |
|
| 7 |
JSON formatted policy file is deprecated since Cyborg (Victoria). |
| 8 |
Use YAML formatted file. Use `oslopolicy-convert-json-to-yaml`__ tool |
| 9 |
to convert the existing JSON to YAML formatted policy file in backward |
| 10 |
compatible way. |
| 11 |
|
| 12 |
.. __: https://docs.openstack.org/oslo.policy/latest/cli/oslopolicy-convert-json-to-yaml.html |
| 13 |
|
| 14 |
Cyborg supports a rich policy system that has evolved significantly over its |
| 15 |
lifetime. Initially, cyborg policy defaults have been defined in the codebase, |
| 16 |
requiring the ``policy.json`` file only to override these defaults. Starting in |
| 17 |
the Victoria release, policy file has been changed from ``policy.json`` |
| 18 |
to ``policy.yaml``. |
| 19 |
|
| 20 |
The old default policy in Cyborg is incomplete and not good enough. Since |
| 21 |
Cyborg V2 API is newly implemented in Train, RBAC check for V2 API still |
| 22 |
remains incomplete. So in the Ussuri release, the specification of policy |
| 23 |
refresh was approved. In the Victoria release, Cyborg landed the new default |
| 24 |
roles to improve some issues that had been identified: |
| 25 |
|
| 26 |
#. No ``allow``. Old policy ``allow`` means any access will be passed. |
| 27 |
``allow`` rule was used by cyborg:arq:create, which is too slack. |
| 28 |
|
| 29 |
#. No global vs project admin. The old role ``is_admin`` is used for the global |
| 30 |
admin that is able to make almost any change to Cyborg, and see all details |
| 31 |
of the Cyborg system. The rule passes for any user with an admin role, it |
| 32 |
doesn’t matter which project is used. |
| 33 |
|
| 34 |
#. No ``admin_or_owner``. Old role ``admin_or_owner`` sounds like it checks if |
| 35 |
the user is a member of a project. However, for most APIs we use the default |
| 36 |
target which means this rule will pass for any authenticated user. |
| 37 |
|
| 38 |
#. Introduce ``scope_type`` and ``reader`` role. There still some cases which |
| 39 |
are not well covered. For example, it is impossible to allow a user to |
| 40 |
retrieve/update devices which are shared by multiple projects from a system |
| 41 |
level without being given the global admin role. In addition, cyborg now |
| 42 |
doesn’t have a ``reader`` role. |
| 43 |
|
| 44 |
Keystone comes with ``admin``, ``member`` and ``reader`` roles by default. |
| 45 |
Please refer to `keystone document <https://docs.openstack.org/keystone/latest//admin/service-api-protection.html>`__ |
| 46 |
for more information about these new defaults. In addition, keystone supports |
| 47 |
a new "system scope" concept that makes it easier to protect deployment level |
| 48 |
resources from project or system level resources. Please refer to |
| 49 |
`token scopes <https://docs.openstack.org/keystone/latest//admin/tokens-overview.html#authorization-scopes>`__ |
| 50 |
and `system scope specification <https://specs.openstack.org/openstack/keystone-specs/specs/keystone/queens/system-scope.html>`__ |
| 51 |
to understand the scope concept. |
| 52 |
|
| 53 |
In the Cyborg (Victoria) release, Cyborg policies implemented |
| 54 |
the scope concept and default roles provided by keystone (admin, member, |
| 55 |
and reader). Using common roles from keystone reduces the likelihood of |
| 56 |
similar, but different, roles implemented across projects or deployments. |
| 57 |
With the help of the new defaults it is easier to understand who can do |
| 58 |
what across projects, reduces divergence, and increases interoperability. |
| 59 |
|
| 60 |
The below sections explain how these new defaults in the Cyborg can solve the |
| 61 |
issues mentioned above and extend more functionality to end users in a safe |
| 62 |
and secure way. |
| 63 |
|
| 64 |
More information is provided in the `cyborg specification <https://specs.openstack.org/openstack/cyborg-specs/specs/ussuri/approved/policy-defaults-refresh.html>`__ |
| 65 |
|
| 66 |
Scope |
| 67 |
----- |
| 68 |
|
| 69 |
OpenStack Keystone supports different scopes in tokens. |
| 70 |
These are described `here <https://docs.openstack.org/keystone/latest//admin/tokens-overview.html#authorization-scopes>`__. |
| 71 |
Token scopes represent the layer of authorization. Policy ``scope_types`` |
| 72 |
represent the layer of authorization required to access an API. |
| 73 |
|
| 74 |
.. note:: |
| 75 |
|
| 76 |
The ``scope_type`` of each policy is hardcoded and is not |
| 77 |
overridable via the policy file. |
| 78 |
|
| 79 |
Cyborg policies have implemented the scope concept by defining the |
| 80 |
``scope_type`` in policies. To know each policy's ``scope_type``, please |
| 81 |
refer to the :doc:`Policy Reference <policy>` and look for |
| 82 |
``Scope Types`` or ``Intended scope(s)`` in |
| 83 |
:doc:`Policy Sample File <sample-policy>` as shown in below |
| 84 |
examples. |
| 85 |
|
| 86 |
.. rubric:: ``system`` scope |
| 87 |
|
| 88 |
Policies with a ``scope_type`` of ``system`` means a user with a |
| 89 |
``system-scoped`` token has permission to access the resource. This can be |
| 90 |
seen as a global role. All the system-level operation's policies |
| 91 |
have defaulted to ``scope_type`` of ``['system']``. |
| 92 |
|
| 93 |
For example, consider the ``POST /v2/device_profiles`` API. |
| 94 |
|
| 95 |
.. code:: |
| 96 |
|
| 97 |
# Create a device_profile |
| 98 |
# POST /v2/device_profiles |
| 99 |
# Intended scope(s): system |
| 100 |
#"cyborg:device_profile:create": "rule:system_admin_api" |
| 101 |
|
| 102 |
.. rubric:: ``project`` scope |
| 103 |
|
| 104 |
Policies with a ``scope_type`` of ``project`` means a user with a |
| 105 |
``project-scoped`` token has permission to access the resource. This can be |
| 106 |
seen as a project role. All the project-level operation's policies should be |
| 107 |
set to ``scope_type`` of ``['project']`` by default. |
| 108 |
|
| 109 |
.. rubric:: ``system and project`` scope |
| 110 |
|
| 111 |
Policies with a ``scope_type`` of ``system and project`` means a user with a |
| 112 |
``system-scoped`` or ``project-scoped`` token has permission to access the |
| 113 |
resource. All the system and project level operation's policies have defaulted |
| 114 |
to ``scope_type`` of ``['system', 'project']``. |
| 115 |
|
| 116 |
For example, consider the ``GET /v2/device_profiles/{device_profiles_uuid}`` |
| 117 |
API. |
| 118 |
|
| 119 |
.. code:: |
| 120 |
|
| 121 |
# Retrieve a specific device_profile |
| 122 |
# GET /v2/device_profiles/{device_profiles_uuid} |
| 123 |
# Intended scope(s): system, project |
| 124 |
#"cyborg:device_profile:get_one": "rule:system_or_project_reader" |
| 125 |
|
| 126 |
These scope types provide a way to differentiate between system-level and |
| 127 |
project-level access roles. You can control the information with scope of the |
| 128 |
users. |
| 129 |
|
| 130 |
Policy scope is disabled by default to allow operators to migrate from |
| 131 |
the old policy enforcement system in a graceful way. This can be |
| 132 |
enabled by configuring the :oslo.config:option:`oslo_policy.enforce_scope` |
| 133 |
option to ``True``. |
| 134 |
|
| 135 |
.. note:: |
| 136 |
|
| 137 |
[oslo_policy] |
| 138 |
enforce_scope=True |
| 139 |
|
| 140 |
|
| 141 |
Roles |
| 142 |
----- |
| 143 |
|
| 144 |
You can refer to `this <https://docs.openstack.org/keystone/latest//admin/service-api-protection.html>`__ |
| 145 |
document to know about all available defaults from Keystone. |
| 146 |
|
| 147 |
Along with the ``scope_type`` feature, Cyborg policy defines new |
| 148 |
defaults for each policy. |
| 149 |
|
| 150 |
.. rubric:: ``reader`` |
| 151 |
|
| 152 |
This provides read-only access to the resources within the ``system`` or |
| 153 |
``project``. Cyborg policies are defaulted to below rules: |
| 154 |
|
| 155 |
.. code:: |
| 156 |
|
| 157 |
system_reader_api |
| 158 |
Default |
| 159 |
role:reader and system_scope:all |
| 160 |
|
| 161 |
project_reader_api |
| 162 |
Default |
| 163 |
role:reader and project_id:%(project_id)s |
| 164 |
|
| 165 |
system_or_project_reader |
| 166 |
Default |
| 167 |
rule:system_reader_api or rule:project_reader_api |
| 168 |
|
| 169 |
.. rubric:: ``member`` |
| 170 |
|
| 171 |
This role is to perform the project level write operation with combination |
| 172 |
to the system admin. Cyborg policies are defaulted to below rules: |
| 173 |
|
| 174 |
.. code:: |
| 175 |
|
| 176 |
project_member_api |
| 177 |
Default |
| 178 |
role:member and project_id:%(project_id)s |
| 179 |
|
| 180 |
system_admin_or_owner |
| 181 |
Default |
| 182 |
rule:system_admin_api or rule:project_member_api |
| 183 |
|
| 184 |
.. rubric:: ``admin`` |
| 185 |
|
| 186 |
This role is to perform the admin level write operation at system as well |
| 187 |
as at project-level operations. Cyborg policies are defaulted to below rules: |
| 188 |
|
| 189 |
.. code:: |
| 190 |
|
| 191 |
system_admin_api |
| 192 |
Default |
| 193 |
role:admin and system_scope:all |
| 194 |
|
| 195 |
project_admin_api |
| 196 |
Default |
| 197 |
role:admin and project_id:%(project_id)s |
| 198 |
|
| 199 |
system_admin_or_owner |
| 200 |
Default |
| 201 |
rule:system_admin_api or rule:project_member_api |
| 202 |
|
| 203 |
With these new defaults, you can solve the problem of: |
| 204 |
|
| 205 |
#. Providing the read-only access to the user. Polices are made more granular |
| 206 |
and defaulted to reader rules. For example: If you need to let someone audit |
| 207 |
your deployment for security purposes. |
| 208 |
|
| 209 |
#. Customize the policy in better way. For example, you will be able |
| 210 |
to provide access to project level member to perform arq patch/post for |
| 211 |
instance boot with the project's token. |
| 212 |
|
| 213 |
Backward Compatibility |
| 214 |
---------------------- |
| 215 |
|
| 216 |
During the development period (Victoria and Wallaby releases), the new and old |
| 217 |
policy will both work for backward compatibility by supporting the old |
| 218 |
defaults and disabling the ``scope_type`` feature by default. This means the |
| 219 |
old defaults and deployments that use them will keep working as-is. However, |
| 220 |
we encourage every deployment to switch to new policy. ``scope_type`` will be |
| 221 |
enabled by default and the old defaults will be removed starting in the |
| 222 |
X release. |
| 223 |
|
| 224 |
To implement the new default reader roles, some policies needed to become |
| 225 |
granular. They have been renamed, with the old names still supported for |
| 226 |
backwards compatibility. |
| 227 |
|
| 228 |
Migration Plan |
| 229 |
-------------- |
| 230 |
|
| 231 |
To have a graceful migration, Cyborg provides two flags to switch to the new |
| 232 |
policy completely. You do not need to overwrite the policy file to adopt the |
| 233 |
new policy defaults. |
| 234 |
|
| 235 |
Here is step wise guide for migration: |
| 236 |
|
| 237 |
#. Create scoped token: |
| 238 |
|
| 239 |
You need to create the new token with scope knowledge via below CLI: |
| 240 |
|
| 241 |
- `Create System Scoped Token <https://docs.openstack.org/keystone/latest//admin/tokens-overview.html#operation_create_system_token>`__. |
| 242 |
- `Create Project Scoped Token <https://docs.openstack.org/keystone/latest//admin/tokens-overview.html#operation_create_project_scoped_token>`__. |
| 243 |
|
| 244 |
#. Create new default roles in keystone if not done: |
| 245 |
|
| 246 |
If you do not have new defaults in Keystone then you can create and re-run |
| 247 |
the `Keystone Bootstrap <https://docs.openstack.org/keystone/latest//admin/bootstrap.html>`__. |
| 248 |
Keystone added this support in 14.0.0 (Rocky) release. |
| 249 |
|
| 250 |
#. Enable Scope Checks |
| 251 |
|
| 252 |
The :oslo.config:option:`oslo_policy.enforce_scope` flag is to enable the |
| 253 |
``scope_type`` features. The scope of the token used in the request is |
| 254 |
always compared to the ``scope_type`` of the policy. If the scopes do not |
| 255 |
match, one of two things can happen. |
| 256 |
If :oslo.config:option:`oslo_policy.enforce_scope` is True, the request |
| 257 |
will be rejected. If :oslo.config:option:`oslo_policy.enforce_scope` is |
| 258 |
False, an warning will be logged, but the request will be accepted |
| 259 |
(assuming the rest of the policy passes). The default value of this flag |
| 260 |
is False. |
| 261 |
|
| 262 |
.. note:: Before you enable this flag, you need to audit your users and make |
| 263 |
sure everyone who needs system-level access has a system role |
| 264 |
assignment in keystone. |
| 265 |
|
| 266 |
#. Enable new defaults |
| 267 |
|
| 268 |
The ``oslo_policy.enforce_new_defaults`` flag switches |
| 269 |
the policy to new defaults-only. This flag controls whether or not to use |
| 270 |
old deprecated defaults when evaluating policies. If True, the old |
| 271 |
deprecated defaults are not evaluated. This means if any existing |
| 272 |
token is allowed for old defaults but is disallowed for new defaults, |
| 273 |
it will be rejected. The default value of this flag is False. |
| 274 |
|
| 275 |
.. note:: Before you enable this flag, you need to educate users about the |
| 276 |
different roles they need to use to continue using Cyborg APIs. |
| 277 |
|
| 278 |
|
| 279 |
#. Check for deprecated policies |
| 280 |
|
| 281 |
A few policies were made more granular to implement the reader roles. New |
| 282 |
policy names are available to use. If old policy names which are renamed |
| 283 |
are overwritten in policy file, then warning will be logged. Please migrate |
| 284 |
those policies to new policy names. |
| 285 |
|
| 286 |
We expect all deployments to migrate to new policy by X release so that |
| 287 |
we can remove the support of old policies. |