Skip to content

Commit 827f159

Browse files
authored
Merge pull request #672 from andyzhangx/zero-mountpermissions
feat: skip chmod if mountPermissions is 0 after mount
2 parents 971e21f + 51347fe commit 827f159

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

docs/driver-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ secretName | specify secret name to store account key | | No |
2727
secretNamespace | specify the namespace of secret to store account key | `default`,`kube-system`, etc | No | pvc namespace
2828
isHnsEnabled | enable `Hierarchical namespace` for Azure DataLake storage account | `true`,`false` | No | `false`
2929
--- | **Following parameters are only for NFS protocol** | --- | --- |
30-
mountPermissions | mounted folder permissions | `0777` | No |
30+
mountPermissions | mounted folder permissions. The default is `0777`, if set as `0`, driver will not perform `chmod` after mount | `0777` | No |
3131

3232
- `fsGroup` securityContext setting
3333

pkg/blob/nodeserver.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
220220
var serverAddress, storageEndpointSuffix, protocol, ephemeralVolMountOptions string
221221
var ephemeralVol, isHnsEnabled bool
222222
mountPermissions := d.mountPermissions
223+
performChmodOp := (mountPermissions > 0)
223224
for k, v := range attrib {
224225
switch strings.ToLower(k) {
225226
case serverNameField:
@@ -237,9 +238,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
237238
case mountPermissionsField:
238239
if v != "" {
239240
var err error
240-
if mountPermissions, err = strconv.ParseUint(v, 8, 32); err != nil {
241+
var perm uint64
242+
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
241243
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
242244
}
245+
if perm == 0 {
246+
performChmodOp = false
247+
} else {
248+
mountPermissions = perm
249+
}
243250
}
244251
}
245252
}
@@ -283,12 +290,17 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
283290
return nil, status.Error(codes.Internal, fmt.Sprintf("volume(%s) mount %q on %q failed with %v", volumeID, source, targetPath, err))
284291
}
285292

286-
// set permissions for NFSv3 root folder
287-
if err := os.Chmod(targetPath, os.FileMode(mountPermissions)); err != nil {
288-
return nil, status.Error(codes.Internal, fmt.Sprintf("Chmod(%s) failed with %v", targetPath, err))
293+
if performChmodOp {
294+
klog.V(2).Infof("volumeID(%v): chmod targetPath(%s) with permissions(0%o)", volumeID, targetPath, mountPermissions)
295+
// set permissions for NFSv3 root folder
296+
if err := os.Chmod(targetPath, os.FileMode(mountPermissions)); err != nil {
297+
return nil, status.Error(codes.Internal, fmt.Sprintf("Chmod(%s) failed with %v", targetPath, err))
298+
}
299+
} else {
300+
klog.V(2).Infof("skip chmod on targetPath(%s) since mountPermissions is set as 0", targetPath)
289301
}
290-
klog.V(2).Infof("volume(%s) mount %q on %q with 0%o succeeded", volumeID, source, targetPath, mountPermissions)
291302

303+
klog.V(2).Infof("volume(%s) mount %s on %s succeeded", volumeID, source, targetPath)
292304
return &csi.NodeStageVolumeResponse{}, nil
293305
}
294306

test/e2e/dynamic_provisioning_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,37 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
531531
}
532532
test.Run(cs, ns)
533533
})
534+
535+
ginkgo.It("should create a NFSv3 volume on demand with zero mountPermissions [nfs]", func() {
536+
if isAzureStackCloud {
537+
ginkgo.Skip("test case is not available for Azure Stack")
538+
}
539+
pods := []testsuites.PodDetails{
540+
{
541+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
542+
Volumes: []testsuites.VolumeDetails{
543+
{
544+
ClaimSize: "10Gi",
545+
MountOptions: []string{
546+
"nconnect=8",
547+
},
548+
VolumeMount: testsuites.VolumeMountDetails{
549+
NameGenerate: "test-volume-",
550+
MountPathGenerate: "/mnt/test-",
551+
},
552+
},
553+
},
554+
},
555+
}
556+
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
557+
CSIDriver: testDriver,
558+
Pods: pods,
559+
StorageClassParameters: map[string]string{
560+
"skuName": "Premium_LRS",
561+
"protocol": "nfs",
562+
"mountPermissions": "0",
563+
},
564+
}
565+
test.Run(cs, ns)
566+
})
534567
})

0 commit comments

Comments
 (0)