Skip to content

Commit

Permalink
feat: skip chmod if mountPermissions is 0 after mount
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed May 5, 2022
1 parent 971e21f commit f7d2291
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/driver-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ secretName | specify secret name to store account key | | No |
secretNamespace | specify the namespace of secret to store account key | `default`,`kube-system`, etc | No | pvc namespace
isHnsEnabled | enable `Hierarchical namespace` for Azure DataLake storage account | `true`,`false` | No | `false`
--- | **Following parameters are only for NFS protocol** | --- | --- |
mountPermissions | mounted folder permissions | `0777` | No |
mountPermissions | mounted folder permissions. The default is `0777`, if set as `0`, driver will not perform `chmod` after mount | `0777` | No |

- `fsGroup` securityContext setting

Expand Down
22 changes: 17 additions & 5 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
var serverAddress, storageEndpointSuffix, protocol, ephemeralVolMountOptions string
var ephemeralVol, isHnsEnabled bool
mountPermissions := d.mountPermissions
performChmodOp := (mountPermissions > 0)
for k, v := range attrib {
switch strings.ToLower(k) {
case serverNameField:
Expand All @@ -237,9 +238,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
case mountPermissionsField:
if v != "" {
var err error
if mountPermissions, err = strconv.ParseUint(v, 8, 32); err != nil {
var perm uint64
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
}
if perm == 0 {
performChmodOp = false
} else {
mountPermissions = perm
}
}
}
}
Expand Down Expand Up @@ -283,12 +290,17 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
return nil, status.Error(codes.Internal, fmt.Sprintf("volume(%s) mount %q on %q failed with %v", volumeID, source, targetPath, err))
}

// set permissions for NFSv3 root folder
if err := os.Chmod(targetPath, os.FileMode(mountPermissions)); err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Chmod(%s) failed with %v", targetPath, err))
if performChmodOp {
klog.V(2).Infof("volumeID(%v): Chmod targetPath(%s) with permissions(0%o)", volumeID, targetPath, mountPermissions)
// set permissions for NFSv3 root folder
if err := os.Chmod(targetPath, os.FileMode(mountPermissions)); err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Chmod(%s) failed with %v", targetPath, err))
}
} else {
klog.V(2).Infof("skip chmod on targetPath(%s) since mountPermissions is set as 0", targetPath)
}
klog.V(2).Infof("volume(%s) mount %q on %q with 0%o succeeded", volumeID, source, targetPath, mountPermissions)

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

Expand Down
33 changes: 33 additions & 0 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,37 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
}
test.Run(cs, ns)
})

ginkgo.It("should create a NFSv3 volume on demand with zero mountPermissions [nfs]", func() {
if isAzureStackCloud {
ginkgo.Skip("test case is not available for Azure Stack")
}
pods := []testsuites.PodDetails{
{
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
Volumes: []testsuites.VolumeDetails{
{
ClaimSize: "10Gi",
MountOptions: []string{
"nconnect=8",
},
VolumeMount: testsuites.VolumeMountDetails{
NameGenerate: "test-volume-",
MountPathGenerate: "/mnt/test-",
},
},
},
},
}
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
CSIDriver: testDriver,
Pods: pods,
StorageClassParameters: map[string]string{
"skuName": "Premium_LRS",
"protocol": "nfs",
"mountPermissions": "0",
},
}
test.Run(cs, ns)
})
})

0 comments on commit f7d2291

Please sign in to comment.