Repository navigation
feat(driver): add validation for RWX block volume attachments - #403
Conversation
3c201f2 to
52ab015
Compare
Add custom linstor-csi image build to packages/system/linstor: - Add Dockerfile based on upstream linstor-csi - Import patch from upstream PR #403 for RWX block volume validation (prevents misuse of allow-two-primaries in KubeVirt live migration) - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods The RWX validation patch ensures that RWX block volumes with allow-two-primaries are only used by pods belonging to the same KubeVirt VM during live migration. Upstream PR: piraeusdatastore/linstor-csi#403 Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
d3d1393 to
991a9da
Compare
Add custom linstor-csi image build to packages/system/linstor: - Add Dockerfile based on upstream linstor-csi - Import patch from upstream PR #403 for RWX block volume validation (prevents misuse of allow-two-primaries in KubeVirt live migration) - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods The RWX validation patch ensures that RWX block volumes with allow-two-primaries are only used by pods belonging to the same KubeVirt VM during live migration. Upstream PR: piraeusdatastore/linstor-csi#403 Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
Add custom linstor-csi image build to packages/system/linstor: - Add Dockerfile based on upstream linstor-csi - Import patch from upstream PR #403 for RWX block volume validation (prevents misuse of allow-two-primaries in KubeVirt live migration) - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods The RWX validation patch ensures that RWX block volumes with allow-two-primaries are only used by pods belonging to the same KubeVirt VM during live migration. Upstream PR: piraeusdatastore/linstor-csi#403 Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
Add custom linstor-csi image build to packages/system/linstor: - Add Dockerfile based on upstream linstor-csi - Import patch from upstream PR #403 for RWX block volume validation (prevents misuse of allow-two-primaries in KubeVirt live migration) - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods The RWX validation patch ensures that RWX block volumes with allow-two-primaries are only used by pods belonging to the same KubeVirt VM during live migration. Upstream PR: piraeusdatastore/linstor-csi#403 Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
Add custom linstor-csi image build to packages/system/linstor: - Add Dockerfile based on upstream linstor-csi - Import patch from upstream PR #403 for RWX block volume validation (prevents misuse of allow-two-primaries in KubeVirt live migration) - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods The RWX validation patch ensures that RWX block volumes with allow-two-primaries are only used by pods belonging to the same KubeVirt VM during live migration. Upstream PR: piraeusdatastore/linstor-csi#403 Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
## What this PR does This PR adds custom linstor-csi image build to the linstor package with an important upstream patch for RWX block volume validation. **Changes:** - Add linstor-csi Dockerfile based on upstream linstor-csi master - Import patch from upstream PR piraeusdatastore/linstor-csi#403 for RWX block volume validation - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods **RWX Validation Patch:** The imported patch prevents misuse of DRBD allow-two-primaries by ensuring RWX block volumes are only used by pods belonging to the same KubeVirt VM during live migration. This prevents data corruption when multiple non-related pods attempt to use the same RWX block volume. **Upstream PR:** piraeusdatastore/linstor-csi#403 ### Release note ```release-note [linstor] Add custom linstor-csi image build with RWX block volume validation patch that prevents data corruption during KubeVirt live migration ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Integrated LINSTOR CSI with deployable CSI components and node init helpers; packaged as a production-ready image. * **Updates** * Added build/publish flow for Piraeus server and LINSTOR CSI images; chart values updated with new image references and tags. * **Behavior changes** * Node-side RWX block-volume pre-validation to prevent conflicting multi-node/multi-writer access. * **Tests** * Comprehensive RWX validation tests covering multi-pod and VM scenarios. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
## What this PR does This PR adds custom linstor-csi image build to the linstor package with an important upstream patch for RWX block volume validation. **Changes:** - Add linstor-csi Dockerfile based on upstream linstor-csi master - Import patch from upstream PR piraeusdatastore/linstor-csi#403 for RWX block volume validation - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods **RWX Validation Patch:** The imported patch prevents misuse of DRBD allow-two-primaries by ensuring RWX block volumes are only used by pods belonging to the same KubeVirt VM during live migration. This prevents data corruption when multiple non-related pods attempt to use the same RWX block volume. **Upstream PR:** piraeusdatastore/linstor-csi#403 ### Release note ```release-note [linstor] Add custom linstor-csi image build with RWX block volume validation patch that prevents data corruption during KubeVirt live migration ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Integrated LINSTOR CSI with deployable CSI components and node init helpers; packaged as a production-ready image. * **Updates** * Added build/publish flow for Piraeus server and LINSTOR CSI images; chart values updated with new image references and tags. * **Behavior changes** * Node-side RWX block-volume pre-validation to prevent conflicting multi-node/multi-writer access. * **Tests** * Comprehensive RWX validation tests covering multi-pod and VM scenarios. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
00fd08c to
a514193
Compare
Add controller-side validation to prevent misuse of allow-two-primaries for RWX block volumes. Controller-side validation (ControllerPublishVolume): - Query K8s API for all pods using the target PVC - Extract VM names from virt-launcher pods or via ownerReferences for hotplug disks - Validate all pods belong to the same VM - Block attachment if pods from different VMs are found Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
a514193 to
acf1719
Compare
|
Hey @WanzenBug I decided to remove node-level validation because it is blocking KubeVirt logic for hotplug volumes, at least this patch protects from misuse of PR description updated |
| } | ||
|
|
||
| // Get PV to find PVC reference (volumeID == PV name in CSI) | ||
| pv, err := d.kubeClient.Resource(pvGVR).Get(ctx, volumeID, metav1.GetOptions{}) |
There was a problem hiding this comment.
Strictly speaking, this is not always true. You need to check spec.csi.volumeHandle instead. I guess its not really worth to fully check for that, but we should at least check the PV that it has the correct volumeHandle.
| continue | ||
| } | ||
|
|
||
| claimName, _, _ := unstructured.NestedString(pvc, "claimName") |
There was a problem hiding this comment.
I think you can combine this with the line above, no need to unpack the pvc part?
There was a problem hiding this comment.
Perhaps move the added validation to a seperate package/file? There is already a pkg/utils, where we could have a free-standing function ValidateRWXBlockAttachment(), which takes the necessary kube client, logs etc...
There was a problem hiding this comment.
RWX Block validation moved to pkg/utils/rwx_validation.go
| rwxBlock := req.VolumeCapability.AccessMode.GetMode() == csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER && req.VolumeCapability.GetBlock() != nil | ||
|
|
||
| // Validate RWX block attachment to prevent misuse of allow-two-primaries | ||
| if rwxBlock { |
There was a problem hiding this comment.
Can we have a switch/option that disables this check? I don't think there would be any valid use cases outside of kubevirt, but perhaps there is some obscure custom virtualization-on-k8s platform that would be stopped by this patch.
There was a problem hiding this comment.
Added new flag --disable-rwx-block-validation=false
Add custom linstor-csi image build to packages/system/linstor: - Add Dockerfile based on upstream linstor-csi - Import patch from upstream PR #403 for RWX block volume validation (prevents misuse of allow-two-primaries in KubeVirt live migration) - Update Makefile to build both piraeus-server and linstor-csi images - Configure LinstorCluster CR to use custom linstor-csi image in CSI controller and node pods The RWX validation patch ensures that RWX block volumes with allow-two-primaries are only used by pods belonging to the same KubeVirt VM during live migration. Upstream PR: piraeusdatastore/linstor-csi#403 Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
b42eada to
4a6e0c6
Compare
…able RWX block validation Move RWX block validation logic to a separate package as requested in code review. Also addressed other review comments: - Add volumeHandle check to verify PV matches the requested volumeID - Simplify claimName extraction by combining nested calls Add --disable-rwx-block-validation CLI flag and DisableRWXBlockValidation() driver option. This allows administrators to disable the KubeVirt VM ownership validation for RWX block volumes in environments where the validation causes issues or when using RWX block volumes outside of KubeVirt. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
4a6e0c6 to
28d809e
Compare
<!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does upstream PR piraeusdatastore/linstor-csi#403 ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [linstor] Refactor node-level RWX validation ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a command-line option to disable strict RWX block volume validation for specialized deployments. * Centralized RWX validation into a shared utility used by the driver. * **Improvements** * Improved VM identification and pod/PV handling for RWX block attachments, including hotplug scenarios. * **Tests** * Added comprehensive unit tests covering RWX validation and related pod/PV scenarios. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Summary
Add controller-side validation to prevent misuse of
allow-two-primariesfor RWX block volumes:Note: This validation applies ONLY to RWX block volumes (
volumeMode: Block). Filesystem RWX volumes (including NFS) are not affected.Implementation Details
Controller-Side Validation (ControllerPublishVolume)
When attaching a RWX block volume:
vm.kubevirt.io/namelabel from virt-launcher podsownerReferencesfrom hotplug-disk pods to virt-launcher podError example:
Why Controller-Only Validation?
Node-side validation was considered but rejected because:
publish_contextdoesn't work for existing VolumeAttachmentsController validation is sufficient because:
ControllerPublishVolumeis called for each new VolumeAttachmentKnown Limitations
No Node-Level Validation
Node-side validation is not implemented. This means the driver does not protect against multi-attach of RWX block volumes to different VMs on the same node when VolumeAttachment already exists.
However, this implementation does protect against misuse of
allow-two-primariesin DRBD - the controller validation ensures that the DRBD option is only enabled when all pods belong to the same VM (live migration scenario).Migration Blocked by Failed Pods
If VM2 attempts to start but is blocked by controller validation (because VM1 is using the volume), VM2 will remain in
Pendingstate withFailedAttachVolume. If VM1 then attempts to migrate to the same node as VM2, the migration will also be blocked because:nodeNameset (already scheduled)Workaround: Delete the blocked VM2 pod before migrating VM1.
Test plan
go test ./pkg/driver/... --run TestValidateRWX -v