Skip to content

Commit 5d9d386

Browse files
YashwantGohokarl-technicore
authored andcommitted
Support ReadWriteOnceWithFSType fsGroupPolicy in CSI Driver for non-root user
1 parent a972d2d commit 5d9d386

File tree

7 files changed

+67
-17
lines changed

7 files changed

+67
-17
lines changed

pkg/csi/driver/fss_node.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
)
3737

3838
const (
39-
mountPath = "mount"
4039
FipsEnabled = "1"
4140
fssMountSemaphoreTimeout = time.Second * 30
4241
fssUnmountSemaphoreTimeout = time.Second * 30
@@ -91,7 +90,7 @@ func (d FSSNodeDriver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVo
9190
return nil, status.Errorf(codes.InvalidArgument, "EncryptInTransit must be a boolean value")
9291
}
9392

94-
mounter := mount.New(mountPath)
93+
mounter := mount.New("")
9594

9695
if encryptInTransit {
9796
isPackageInstalled, err := csi_util.IsInTransitEncryptionPackageInstalled()
@@ -223,7 +222,7 @@ func (d FSSNodeDriver) NodePublishVolume(ctx context.Context, req *csi.NodePubli
223222

224223
var fsType = ""
225224

226-
mounter := mount.New(mountPath)
225+
mounter := mount.New("")
227226

228227
targetPath := req.GetTargetPath()
229228
readOnly := req.GetReadonly()
@@ -302,7 +301,7 @@ func (d FSSNodeDriver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnp
302301

303302
logger := d.logger.With("volumeID", req.VolumeId, "targetPath", req.TargetPath)
304303

305-
mounter := mount.New(mountPath)
304+
mounter := mount.New("")
306305
targetPath := req.GetTargetPath()
307306

308307
// Use mount.IsNotMountPoint because mounter.IsLikelyNotMountPoint can't detect bind mounts
@@ -402,7 +401,7 @@ func (d FSSNodeDriver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnsta
402401
}
403402

404403
func (d FSSNodeDriver) unmountAndCleanup(logger *zap.SugaredLogger, targetPath string, exportPath string, mountTargetIP string) error {
405-
mounter := mount.New(mountPath)
404+
mounter := mount.New("")
406405
// Use mount.IsNotMountPoint because mounter.IsLikelyNotMountPoint can't detect bind mounts
407406
isNotMountPoint, err := mount.IsNotMountPoint(mounter, targetPath)
408407
if err != nil {

pkg/csi/driver/lustre_node.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
const (
20+
mountPath = "mount"
2021
SetupLnet = "setupLnet"
2122
LustreSubnetCidr = "lustreSubnetCidr"
2223
)

test/e2e/cloud-provider-oci/fss_dynamic.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
)
2828

2929
const (
30-
defaultExportOptionsJsonString = "[{\"source\":\"10.0.0.0/16\",\"requirePrivilegedSourcePort\":true,\"access\":\"READ_WRITE\",\"identitySquash\":\"NONE\",\"anonymousUid\":0,\"anonymousGid\":0},{\"source\":\"2603:c020:4015:2100::/56\",\"requirePrivilegedSourcePort\":false,\"access\":\"READ_WRITE\",\"identitySquash\":\"NONE\"},{\"source\":\"2603:c020:11:1500::/56\",\"requirePrivilegedSourcePort\":false,\"access\":\"READ_WRITE\",\"identitySquash\":\"NONE\"}]"
30+
defaultExportOptionsJsonString = "[{\"source\":\"10.0.0.0/16\",\"requirePrivilegedSourcePort\":false,\"access\":\"READ_WRITE\",\"identitySquash\":\"NONE\",\"anonymousUid\":0,\"anonymousGid\":0},{\"source\":\"2603:c020:4015:2100::/56\",\"requirePrivilegedSourcePort\":false,\"access\":\"READ_WRITE\",\"identitySquash\":\"NONE\"},{\"source\":\"2603:c020:11:1500::/56\",\"requirePrivilegedSourcePort\":false,\"access\":\"READ_WRITE\",\"identitySquash\":\"NONE\"}]"
3131
)
3232

3333
var _ = Describe("Dynamic FSS test in cluster compartment", func() {
@@ -685,3 +685,20 @@ var _ = Describe("Dynamic FSS test with immediate binding mode", func() {
685685
})
686686
})
687687
})
688+
689+
var _ = Describe("Dynamic FSS test with ReadWriteOnce access mode", func() {
690+
f := framework.NewDefaultFramework("fss-dynamic")
691+
692+
Context("[cloudprovider][storage][csi][fss][mtexist][rwo]", func() {
693+
It("Create PVC and POD for CSI-FSS with RWO AccessMode ", func() {
694+
scParameters := map[string]string{"availabilityDomain": setupF.AdLabel, "mountTargetOcid": setupF.MntTargetOcid, "exportOptions": defaultExportOptionsJsonString}
695+
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-rwo-fss-dyn-e2e-test")
696+
scName := f.CreateStorageClassOrFail(f.Namespace.Name, framework.FssProvisionerType, scParameters, pvcJig.Labels, "Immediate", false, "Delete", nil)
697+
f.StorageClasses = append(f.StorageClasses, scName)
698+
pvcObject := pvcJig.CreateAndAwaitPVCOrFailDynamicFSS(f.Namespace.Name, "50Gi", scName, v1.ClaimBound, func(pvc *v1.PersistentVolumeClaim) {
699+
pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{"ReadWriteOnce"}
700+
})
701+
pvcJig.CheckSinglePodReadWrite(f.Namespace.Name, pvcObject.Name, false, []string{})
702+
})
703+
})
704+
})

test/e2e/cloud-provider-oci/fss_static.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ package e2e
1616

1717
import (
1818
"context"
19+
1920
. "github.com/onsi/ginkgo"
2021
"github.com/oracle/oci-cloud-controller-manager/test/e2e/framework"
22+
v1 "k8s.io/api/core/v1"
2123
v12 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
)
2325

@@ -26,7 +28,7 @@ var _ = Describe("Basic Static FSS test", func() {
2628
Context("[cloudprovider][storage][csi][fss][static]", func() {
2729
It("Create PVC and POD for CSI-FSS", func() {
2830
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-fss-e2e-test")
29-
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", []string{})
31+
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", "ReadWriteMany", "", []string{})
3032
pvc := pvcJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, pv.Name, "50Gi", nil)
3133
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
3234
pvcJig.CheckSinglePodReadWrite(f.Namespace.Name, pvc.Name, false, []string{})
@@ -50,7 +52,7 @@ var _ = Describe("Mount Options Static FSS test", func() {
5052
It("Create PV PVC and POD for CSI-FSS with mount options", func() {
5153
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-fss-e2e-test")
5254
mountOptions := []string{"sync", "hard", "noac", "nolock"}
53-
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", mountOptions)
55+
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", "ReadWriteMany", "", mountOptions)
5456
pvc := pvcJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, pv.Name, "50Gi", nil)
5557
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
5658
pvcJig.CheckSinglePodReadWrite(f.Namespace.Name, pvc.Name, false, mountOptions)
@@ -69,7 +71,7 @@ var _ = Describe("Mount Options Static FSS test", func() {
6971

7072
func TestEncryptionType(f *framework.CloudProviderFramework, mountOptions []string) {
7173
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-fss-e2e-test-intransit")
72-
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "true", mountOptions)
74+
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "true", "ReadWriteMany", "", mountOptions)
7375
pvc := pvcJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, pv.Name, "50Gi", nil)
7476
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
7577
pvcJig.CheckSinglePodReadWrite(f.Namespace.Name, pvc.Name, true, mountOptions)
@@ -80,7 +82,7 @@ var _ = Describe("Multiple Pods Static FSS test", func() {
8082
Context("[cloudprovider][storage][csi][fss][static]", func() {
8183
It("Multiple Pods should be able to read write same file", func() {
8284
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-fss-e2e-test")
83-
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", []string{})
85+
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", "ReadWriteMany", "", []string{})
8486
pvc := pvcJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, pv.Name, "50Gi", nil)
8587
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
8688
pvcJig.CheckMultiplePodReadWrite(f.Namespace.Name, pvc.Name, false)
@@ -89,7 +91,7 @@ var _ = Describe("Multiple Pods Static FSS test", func() {
8991
It("Multiple Pods should be able to read write same file with InTransit encryption enabled", func() {
9092
checkNodeAvailability(f)
9193
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-fss-e2e-test")
92-
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "true", []string{})
94+
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "true", "ReadWriteMany", "", []string{})
9395
pvc := pvcJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, pv.Name, "50Gi", nil)
9496
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
9597
pvcJig.CheckMultiplePodReadWrite(f.Namespace.Name, pvc.Name, true)
@@ -114,3 +116,19 @@ func checkNodeAvailability(f *framework.CloudProviderFramework) {
114116
Skip("Skipping test due to non-availability of nodes with label \"oke.oraclecloud.com/e2e.oci-fss-util\"")
115117
}
116118
}
119+
120+
var _ = Describe("Static FSS RWO Tests", func() {
121+
f := framework.NewDefaultFramework("fss-rwo")
122+
Context("[cloudprovider][storage][csi][fss][static][rwo]", func() {
123+
It("Verify volume group ownership change for RWO volume when fsType and fsGroup are defined", func() {
124+
pvcJig := framework.NewPVCTestJig(f.ClientSet, "csi-rwo-fss-e2e-test")
125+
pv := pvcJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", "ReadWriteOnce", "nfs", []string{})
126+
pvc := pvcJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, pv.Name, "50Gi", func(pvc *v1.PersistentVolumeClaim) {
127+
pvc.Spec.AccessModes = []v1.PersistentVolumeAccessMode{"ReadWriteOnce"}
128+
})
129+
f.VolumeIds = append(f.VolumeIds, pvc.Spec.VolumeName)
130+
pod := pvcJig.CreateAndAwaitNginxPodOrFail(f.Namespace.Name, pvc, WriteCommand)
131+
pvcJig.CheckVolumeOwnership(f.Namespace.Name, pod, "/usr/share/nginx/html/", "1000")
132+
})
133+
})
134+
})

test/e2e/cloud-provider-oci/lustre_static.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ var _ = Describe("Lustre Static", func() {
4444

4545
//FSS
4646
fssPVCJig := framework.NewPVCTestJig(f.ClientSet, "csi-fss-e2e-test")
47-
fssPV := fssPVCJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", []string{})
47+
fssPV := fssPVCJig.CreatePVorFailFSS(f.Namespace.Name, setupF.VolumeHandle, "false", "ReadWriteMany", "", []string{})
4848
fssPVC := fssPVCJig.CreateAndAwaitPVCOrFailStaticFSS(f.Namespace.Name, fssPV.Name, "50Gi", nil)
4949
f.VolumeIds = append(f.VolumeIds, fssPVC.Spec.VolumeName)
5050

5151
//LUSTRE
5252
lusterPVCJig := framework.NewPVCTestJig(f.ClientSet, "csi-lustre-e2e-test")
5353
pvVolumeAttributes := map[string]string{"lustreSubnetCidr": setupF.LustreSubnetCidr, "setupLnet": "true"}
54-
lustrePV := lusterPVCJig.CreatePVorFailLustre(f.Namespace.Name, setupF.LustreVolumeHandle, []string{}, pvVolumeAttributes)
54+
lustrePV := lusterPVCJig.CreatePVorFailLustre(f.Namespace.Name, setupF.LustreVolumeHandle, []string{}, pvVolumeAttributes)
5555
lustrePVC := lusterPVCJig.CreateAndAwaitPVCOrFailStaticLustre(f.Namespace.Name, lustrePV.Name, "50Gi", nil)
5656
f.VolumeIds = append(f.VolumeIds, lustrePVC.Spec.VolumeName)
5757

test/e2e/framework/pod_util.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,17 @@ func (j *PVCTestJig) GetNodeHostnameFromPod(podName, namespace string) string {
369369
hostName := pod.Labels[NodeHostnameLabel]
370370
return hostName
371371
}
372+
373+
func (j *PVCTestJig) CheckVolumeOwnership(namespace, podName, mountPath, expectedOwner string) {
374+
cmd := "ls -l " + mountPath + " | awk 'NR==2 { print $4 }'"
375+
cmdOutput, err := RunHostCmd(namespace, podName, cmd)
376+
if err != nil {
377+
Failf("Failed to check volume ownership in pod %q: %v", podName, err)
378+
}
379+
cmdOutput = strings.ReplaceAll(cmdOutput, "\n", "")
380+
if cmdOutput == expectedOwner {
381+
Logf("Verified volume group owner for PV in pod %q is %v", podName, cmdOutput)
382+
} else {
383+
Failf("Actual Volume group ownership: %v and expected ownership: %v is not matching", cmdOutput, expectedOwner)
384+
}
385+
}

test/e2e/framework/pvc_util.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,15 +536,16 @@ func (j *PVCTestJig) pvAddMountOptions(pv *v1.PersistentVolume,
536536
// newPVTemplateFSS returns the default template for this jig, but
537537
// does not actually create the PV. The default PV has the same name
538538
// as the jig
539-
func (j *PVCTestJig) newPVTemplateFSS(namespace, volumeHandle, enableIntransitEncrypt string, mountOptions []string) *v1.PersistentVolume {
539+
func (j *PVCTestJig) newPVTemplateFSS(namespace, volumeHandle, enableIntransitEncrypt, accessMode, fsType string, mountOptions []string) *v1.PersistentVolume {
540540
pv := j.CreatePVTemplate(namespace, "fss.csi.oraclecloud.com", "", "Retain")
541541
pv = j.pvAddVolumeMode(pv, v1.PersistentVolumeFilesystem)
542-
pv = j.pvAddAccessMode(pv, "ReadWriteMany")
542+
pv = j.pvAddAccessMode(pv, v1.PersistentVolumeAccessMode(accessMode))
543543
pv = j.pvAddMountOptions(pv, mountOptions)
544544
pv = j.pvAddPersistentVolumeSource(pv, v1.PersistentVolumeSource{
545545
CSI: &v1.CSIPersistentVolumeSource{
546546
Driver: driver.FSSDriverName,
547547
VolumeHandle: volumeHandle,
548+
FSType: fsType,
548549
VolumeAttributes: map[string]string{
549550
"encryptInTransit": enableIntransitEncrypt,
550551
},
@@ -613,8 +614,8 @@ func (j *PVCTestJig) newPVTemplateCSIHighPerf(namespace string, scName string, o
613614
// CreatePVForFSSorFail creates a new claim based on the jig's
614615
// defaults. Callers can provide a function to tweak the claim object
615616
// before it is created.
616-
func (j *PVCTestJig) CreatePVorFailFSS(namespace, volumeHandle, encryptInTransit string, mountOptions []string) *v1.PersistentVolume {
617-
pv := j.newPVTemplateFSS(namespace, volumeHandle, encryptInTransit, mountOptions)
617+
func (j *PVCTestJig) CreatePVorFailFSS(namespace, volumeHandle, encryptInTransit, accessMode, fsType string, mountOptions []string) *v1.PersistentVolume {
618+
pv := j.newPVTemplateFSS(namespace, volumeHandle, encryptInTransit, accessMode, fsType, mountOptions)
618619

619620
result, err := j.KubeClient.CoreV1().PersistentVolumes().Create(context.Background(), pv, metav1.CreateOptions{})
620621
if err != nil {

0 commit comments

Comments
 (0)