diff --git a/cloud/blockstore/tests/csi_driver/e2e_tests_part2/test.py b/cloud/blockstore/tests/csi_driver/e2e_tests_part2/test.py index b023802b7a3..b410931953f 100644 --- a/cloud/blockstore/tests/csi_driver/e2e_tests_part2/test.py +++ b/cloud/blockstore/tests/csi_driver/e2e_tests_part2/test.py @@ -1,6 +1,8 @@ import pytest import subprocess +from pathlib import Path + import cloud.blockstore.tests.csi_driver.lib.csi_runner as csi @@ -57,3 +59,71 @@ def test_readonly_volume(mount_path, access_type, vm_mode, gid): raise finally: csi.cleanup_after_test(env, volume_name, access_type, [pod_id]) + + +def test_mount_volume_group(): + # Scenario + # 1. create volume and publish volume without mount volume group + # 2. create directory and file + # 3. unpublish volume + # 4. create new group with specified GID + # 5. publish volume with mount volume group GID + # 6. check that mounted dir and existing files have specified GID + # 7. create new directory and file + # 8. check that new directory and file have specified GID + env, run = csi.init() + try: + volume_name = "example-disk" + volume_size = 1024 ** 3 + pod_name = "example-pod" + pod_id = "deadbeef1" + access_type = "mount" + env.csi.create_volume(name=volume_name, size=volume_size) + env.csi.stage_volume(volume_name, access_type) + + gid = 1013 + result = subprocess.run( + ["groupadd", "-g", str(gid), "test_group_" + str(gid)], + capture_output=True, + ) + assert result.returncode == 0 + + env.csi.publish_volume( + pod_id, + volume_name, + pod_name, + access_type + ) + + mount_path = Path("/var/lib/kubelet/pods") / pod_id / "volumes/kubernetes.io~csi" / volume_name / "mount" + test_dir1 = mount_path / "testdir1" + test_dir1.mkdir() + test_file1 = test_dir1 / "testfile1" + test_file1.touch() + + env.csi.unpublish_volume(pod_id, volume_name, access_type) + env.csi.publish_volume( + pod_id, + volume_name, + pod_name, + access_type, + volume_mount_group=str(gid) + ) + + assert gid == mount_path.stat().st_gid + assert gid == test_dir1.stat().st_gid + assert gid == test_file1.stat().st_gid + + test_file2 = mount_path / "testfile2" + test_file2.touch() + assert gid == test_file2.stat().st_gid + + test_dir2 = mount_path / "testdir2" + test_dir2.mkdir() + assert gid == test_dir2.stat().st_gid + + except subprocess.CalledProcessError as e: + csi.log_called_process_error(e) + raise + finally: + csi.cleanup_after_test(env, volume_name, access_type, [pod_id]) diff --git a/cloud/blockstore/tools/csi_driver/internal/driver/node.go b/cloud/blockstore/tools/csi_driver/internal/driver/node.go index 6bbbb251cf2..c863eeae741 100644 --- a/cloud/blockstore/tools/csi_driver/internal/driver/node.go +++ b/cloud/blockstore/tools/csi_driver/internal/driver/node.go @@ -780,7 +780,7 @@ func (s *nodeService) nodeStageDiskAsFilesystem( return fmt.Errorf("failed to create staging directory: %w", err) } - mountOptions := []string{} + mountOptions := []string{"grpid"} if mnt != nil { for _, flag := range mnt.MountFlags { mountOptions = append(mountOptions, flag) diff --git a/cloud/blockstore/tools/csi_driver/internal/driver/node_test.go b/cloud/blockstore/tools/csi_driver/internal/driver/node_test.go index 13c294182c6..1785840b4a6 100644 --- a/cloud/blockstore/tools/csi_driver/internal/driver/node_test.go +++ b/cloud/blockstore/tools/csi_driver/internal/driver/node_test.go @@ -482,7 +482,7 @@ func TestPublishUnpublishDiskForInfrakuber(t *testing.T) { mockCallIsMountPoint := mounter.On("IsMountPoint", stagingTargetPath).Return(false, nil) - mounter.On("Mount", nbdDeviceFile, stagingTargetPath, "ext4", []string{}).Return(nil) + mounter.On("Mount", nbdDeviceFile, stagingTargetPath, "ext4", []string{"grpid"}).Return(nil) _, err = nodeService.NodeStageVolume(ctx, &csi.NodeStageVolumeRequest{ VolumeId: diskId,