cinder/cinder/tests/unit/policies
Gorka Eguileor 68fdc32336 Reject unsafe delete attachment calls
Due to how the Linux SCSI kernel driver works there are some storage
systems, such as iSCSI with shared targets, where a normal user can
access other projects' volume data connected to the same compute host
using the attachments REST API.

This affects both single and multi-pathed connections.

To prevent users from doing this, unintentionally or maliciously,
cinder-api will now reject some delete attachment requests that are
deemed unsafe.

Cinder will process the delete attachment request normally in the
following cases:

- The request comes from an OpenStack service that is sending the
  service token that has one of the roles in `service_token_roles`.
- Attachment doesn't have an instance_uuid value
- The instance for the attachment doesn't exist in Nova
- According to Nova the volume is not connected to the instance
- Nova is not using this attachment record

There are 3 operations in the actions REST API endpoint that can be used
for an attack:

- `os-terminate_connection`: Terminate volume attachment
- `os-detach`: Detach a volume
- `os-force_detach`: Force detach a volume

In this endpoint we just won't allow most requests not coming from a
service. The rules we apply are the same as for attachment delete
explained earlier, but in this case we may not have the attachment id
and be more restrictive.  This should not be a problem for normal
operations because:

- Cinder backup doesn't use the REST API but RPC calls via RabbitMQ
- Glance doesn't use this interface

Checking whether it's a service or not is done at the cinder-api level
by checking that the service user that made the call has at least one of
the roles in the `service_token_roles` configuration. These roles are
retrieved from keystone by the keystone middleware using the value of
the "X-Service-Token" header.

If Cinder is configured with `service_token_roles_required = true` and
an attacker provides non-service valid credentials the service will
return a 401 error, otherwise it'll return 409 as if a normal user had
made the call without the service token.

Closes-Bug: #2004555
Change-Id: I612905a1bf4a1706cce913c0d8a6df7a240d599a
(cherry picked from commit 6df1839bdf)
Conflicts:
        cinder/exception.py
(cherry picked from commit dd6010a9f7)
(cherry picked from commit cb4682fb83)
Conflicts:
        cinder/exception.py
(cherry picked from commit a66f4afa22)
Conflicts:
	cinder/compute/nova.py
	cinder/tests/unit/attachments/test_attachments_api.py
	cinder/volume/api.py
2023-05-10 20:01:48 +02:00
..
__init__.py Refactor on policy in code 2019-01-15 01:22:37 +00:00
base.py Add infrastructure for testing new RBAC policies 2021-08-31 15:41:17 -07:00
test_attachments.py Reject unsafe delete attachment calls 2023-05-10 20:01:48 +02:00
test_backups.py Implement project personas for backups API 2021-09-14 19:39:31 -07:00
test_base.py Default type overrides 2020-09-16 14:05:31 +00:00
test_default_volume_types.py Update project personas for default_types 2021-09-09 15:23:27 -04:00
test_group_actions.py Implement Xena project personas for group_actions 2021-09-13 22:18:55 -04:00
test_group_snapshots.py Implement Xena project personas for group snapshots 2021-09-15 08:44:31 -04:00
test_group_types.py Implement project personas group_types 2021-09-10 12:58:48 -04:00
test_groups.py Implement Xena personas for volume groups 2021-09-11 11:23:16 -04:00
test_limits.py Implement project personas for the limits API 2021-09-10 12:39:06 -07:00
test_messages.py Implement project personas for messages 2021-08-31 15:43:11 -07:00
test_quota_class.py Implement project personas for quotas and quota_classes 2021-09-08 16:35:54 -07:00
test_quotas.py Implement project personas for quotas and quota_classes 2021-09-08 16:35:54 -07:00
test_snapshot_actions.py Implement secure RBAC for snapshot actions 2021-09-10 12:55:46 -07:00
test_snapshot_metadata.py Implement project personas for snapshot metadata 2021-09-15 08:56:09 -04:00
test_snapshots.py Implement project personas for snapshots 2021-09-10 13:12:31 -07:00
test_type_extra_specs.py Update policies related to user visible extra specs 2021-09-15 14:47:00 -07:00
test_volume.py Implement project personas for volume API 2021-09-09 15:23:17 +00:00
test_volume_access.py Xena project personas for volume type access API 2021-09-10 17:33:38 -04:00
test_volume_actions.py Reject unsafe delete attachment calls 2023-05-10 20:01:48 +02:00
test_volume_metadata.py Implement project personas for volume metadata API 2021-09-10 12:46:23 -07:00
test_volume_transfers.py Implement project personas for volume transfers 2021-09-08 10:26:41 -04:00
test_volume_type.py Update policies related to user visible extra specs 2021-09-15 14:47:00 -07:00