ceph-csi/internal
Prasanna Kumar Kalever 3686b6da8b rbd: utilize cookie support from rbd for nbd
Problem:
On remap/attach of device (i.e. nodeplugin restart), there is no way
for rbd-nbd to defend if the backend storage is matching with the initial
backend storage.

Say, if an initial map request for backend "pool1/image1" got mapped to
/dev/nbd0 and the userspace process is terminated (on nodeplugin restart).
A next remap/attach (nodeplugin start) request within reattach-timeout is
allowed to use /dev/nbd0 for a different backend "pool1/image2"

For example, an operation like below could be dangerous:

$ sudo rbd-nbd map --try-netlink rbd-pool/ext4-image
/dev/nbd0
$ sudo blkid /dev/nbd0
/dev/nbd0: UUID="bfc444b4-64b1-418f-8b36-6e0d170cfc04" TYPE="ext4"
$ sudo pkill -15 rbd-nbd   <-- nodeplugin terminate
$ sudo rbd-nbd attach --try-netlink --device /dev/nbd0 rbd-pool/xfs-image
/dev/nbd0
$ sudo blkid /dev/nbd0
/dev/nbd0: UUID="d29bf343-6570-4069-a9ea-2fa156ced908" TYPE="xfs"

Solution:
rbd-nbd/kernel now provides a way to keep some metadata in sysfs to identify
between the device and the backend, so that when a remap/attach request is
made, rbd-nbd can compare and avoid such dangerous operations.

With the provided solution, as part of the initial map request, backend
cookie (ceph-csi VOLID) can be stored in the sysfs per device config, so
that on a remap/attach request rbd-nbd will check and validate if the
backend per device cookie matches with the initial map backend with the help
of cookie.

At Ceph-csi we use VOLID as device cookie, which will be unique, we pass
the VOLID as cookie at map and use the same at the time of attach, that
way rbd-nbd can identify backends and their matching devices.

Requires:
https://github.com/ceph/ceph/pull/41323
https://lkml.org/lkml/2021/4/29/274

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
2021-11-04 03:20:59 +00:00
..
cephfs cleanup: move mount functions to new pkg 2021-09-23 06:39:37 +00:00
controller cleanup: simplify checkStaticVolume function and remove unwanted vars 2021-09-07 12:51:30 +00:00
csi-common util: NodeGetVolumeStatsResponse.Usage may not contain negative values 2021-10-20 07:18:48 +00:00
journal cleanup: replace parentName to snapParentName in checkReservation 2021-09-14 05:32:54 +00:00
kms util: set defaults for Vault config before converting 2021-10-28 14:41:53 +00:00
liveness cleanup: move log functions to new internal/util/log package 2021-08-26 09:34:05 +00:00
rbd rbd: utilize cookie support from rbd for nbd 2021-11-04 03:20:59 +00:00
util rbd: add unittests for IsMigrationSecret and ParseAndSetSecretMapFromMigSecret 2021-10-27 18:35:00 +00:00