-
Notifications
You must be signed in to change notification settings - Fork 29
feat(driver): add validation for RWX block volume attachments #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kvaps
wants to merge
2
commits into
master
Choose a base branch
from
feat/rwx-block-validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add validation to prevent misuse of allow-two-primaries for RWX block volumes. The driver now checks that multiple pods using the same RWX block volume belong to the same KubeVirt VM (identified by the vm.kubevirt.io/name label). This allows live migration (where source and target pods have the same VM label) while preventing incorrect usage where different VMs try to share the same block device. The validation is performed in ControllerPublishVolume before calling Attach, using the existing dynamic Kubernetes client. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
3c201f2 to
52ab015
Compare
kvaps
added a commit
to cozystack/cozystack
that referenced
this pull request
Jan 7, 2026
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]>
c61d278 to
d3d1393
Compare
Add two-tier validation to prevent misuse of allow-two-primaries for RWX block volumes. This ensures volumes are only shared during live migration of a single VM, not between different VMs. Controller-side validation (ControllerPublishVolume): - Query Kubernetes API for all pods using the PVC - Extract VM names from pods (supports both virt-launcher and hotplug disks) - Validate all pods belong to the same VM - Reject if different VMs are detected Node-side validation (NodePublishVolume): - Check local publish directory for existing mounts - Block second pod from mounting on the same node - Protects edge case where ControllerPublishVolume is skipped (CSI calls ControllerPublishVolume once per node, not per pod) Design decisions: - Controller uses K8s API for VM identification - Node uses filesystem check (no K8s API access on node pods) - Simple, maintainer-friendly, no external dependencies - Only affects RWX block volumes (volumeMode: Block) Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
d3d1393 to
991a9da
Compare
kvaps
added a commit
to cozystack/cozystack
that referenced
this pull request
Jan 7, 2026
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]>
kvaps
added a commit
to cozystack/cozystack
that referenced
this pull request
Jan 7, 2026
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]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Add two-tier 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 (different VMs on different nodes):
Node-Side Validation (NodePublishVolume)
When mounting a RWX block volume:
/var/lib/kubelet/plugins/kubernetes.io/csi/volumeDevices/publish/<volumeID>/Error example (same node):
Why node-side validation is needed:
CSI protocol calls
ControllerPublishVolumeonce per(volumeID, nodeID)pair, NOT per pod. This means:Without node-side validation, VM2 from a different VM could mount the same volume on node1.
Design Decisions
Why filesystem check instead of alternatives?
Alternative 1: Kubernetes API on node
Alternative 2: LINSTOR API with Aux properties
Chosen solution: Local filesystem check
The node validation blocks ALL same-node multi-pod scenarios for block volumes, which is correct behavior:
Why Two-Tier Validation?
Controller validation (K8s API):
Node validation (filesystem check):
Known Limitations
Migration Blocked by Failed Pods
If VM2 attempts to start on node2 but is blocked by controller validation (because VM1 is running on node1), VM2 will remain in
Pendingstate withFailedAttachVolume. If VM1 then attempts to migrate to node2, the migration will also be blocked because:nodeName: node2(already scheduled)Workaround: Delete the blocked VM2 pod before migrating VM1 to the same node.
Why this happens: Kubernetes keeps pods in Pending state even after repeated attach failures. The CSI controller has no way to distinguish between a "legitimately pending" pod and a "permanently failed to attach" pod.
Test plan
go test ./pkg/driver/... --run TestValidateRWX -v