cinder/cinder
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
..
api Remove multiatttach request parameter 2023-04-14 08:49:07 +09:00
backup Don't destroy existing backup by mistake on import 2022-05-25 22:00:00 +00:00
brick LVM: Retry lvextend commands on code 139 2021-08-18 12:29:01 -04:00
cmd Merge "db: Vendor 'oslo_db.sqlalchemy.migration'" 2021-09-10 18:11:04 +00:00
common Merge "Change 'host' option from HostAddressOpt to StrOpt" 2021-09-08 18:27:48 +00:00
compute Reject unsafe delete attachment calls 2023-05-10 20:01:48 +02:00
db Fix: Race between attachment and volume deletion 2022-01-17 16:24:27 +01:00
group db: Remove 'db_driver' option 2021-08-27 15:13:21 +01:00
image Merge "Check VMDK subformat against an allowed list" into stable/xena 2023-01-25 16:07:11 +00:00
interface Replace getargspec with getfullargspec 2021-05-13 09:22:14 +08:00
keymgr Introduce flake8-import-order extension 2020-01-06 09:59:35 -06:00
locale Imported Translations from Zanata 2021-03-24 06:25:01 +00:00
message Add user messages for backup operations 2021-08-27 05:44:42 -04:00
objects Fix: nfs format info limitation 2022-05-26 10:20:15 +00:00
policies Fix typo in message policy deprecations 2021-10-14 17:19:38 +00:00
privsep Enable flake8-logging-format extension 2020-01-09 14:35:20 -06:00
scheduler Remove multiatttach request parameter 2023-04-14 08:49:07 +09:00
tests Reject unsafe delete attachment calls 2023-05-10 20:01:48 +02:00
transfer db: Remove 'db_driver' option 2021-08-27 15:13:21 +01:00
volume Reject unsafe delete attachment calls 2023-05-10 20:01:48 +02:00
wsgi Introduce flake8-import-order extension 2020-01-06 09:59:35 -06:00
zonemanager Brocade: Fix lookup UnboundLocalError 2020-08-07 15:24:44 +02:00
__init__.py
context.py Merge "Add infrastructure for testing new RBAC policies" 2021-09-06 17:44:47 +00:00
coordination.py Remove file locks once we delete a resource 2021-08-04 10:41:33 -04:00
exception.py Reject unsafe delete attachment calls 2023-05-10 20:01:48 +02:00
flow_utils.py mypy: create_volume flows 2021-08-10 10:26:39 -04:00
i18n.py
manager.py mypy: Fix unused type: ignore in manager.py 2021-09-16 10:25:39 -04:00
opts.py Merge "db: Remove 'db_driver' option" 2021-09-15 21:32:03 +00:00
policy.py Add infrastructure for testing new RBAC policies 2021-08-31 15:41:17 -07:00
quota_utils.py Modify/Move project validation methods to api_utils 2021-04-05 08:00:40 -04:00
quota.py Merge "Remove six from quota.py" 2021-04-20 07:49:02 +00:00
rpc.py mypy: continued manager, scheduler, rpcapi 2021-08-11 08:36:09 -04:00
service_auth.py
service.py Fix typo on service cluster change method 2020-05-06 19:36:07 -05:00
ssh_utils.py Remove six in files under cinder/* 2020-10-08 14:00:14 +08:00
utils.py Fix and unify capacity calculations 2023-01-19 10:33:18 -08:00
version.py