Skip to content

Commit bc7def5

Browse files
authored
Merge pull request #388 from andyzhangx/mountpermissions-fix
fix: default mountPermissions issue
2 parents 8df9678 + fcb4ceb commit bc7def5

File tree

7 files changed

+14
-19
lines changed

7 files changed

+14
-19
lines changed

charts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The following table lists the configurable parameters of the latest NFS CSI Driv
3838
|---------------------------------------------------|------------------------------------------------------------|-------------------------------------------------------------------|
3939
| `customLabels` | optional extra labels to k8s resources deployed by chart | `{}` |
4040
| `driver.name` | alternative driver name | `nfs.csi.k8s.io` |
41-
| `driver.mountPermissions` | mounted folder permissions name | `0777`
41+
| `driver.mountPermissions` | default mounted folder permissions | `0`
4242
| `feature.enableFSGroupPolicy` | enable `fsGroupPolicy` on a k8s 1.20+ cluster | `true` |
4343
| `feature.enableInlineVolume` | enable inline volume | `false` |
4444
| `kubeletDir` | alternative kubelet directory | `/var/lib/kubelet` |
-1 Bytes
Binary file not shown.

charts/latest/csi-driver-nfs/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rbac:
2727

2828
driver:
2929
name: nfs.csi.k8s.io
30-
mountPermissions: 0777
30+
mountPermissions: 0
3131

3232
feature:
3333
enableFSGroupPolicy: true

cmd/nfsplugin/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
var (
2929
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
3030
nodeID = flag.String("nodeid", "", "node id")
31-
mountPermissions = flag.Uint64("mount-permissions", 0777, "mounted folder permissions")
31+
mountPermissions = flag.Uint64("mount-permissions", 0, "mounted folder permissions")
3232
driverName = flag.String("drivername", nfs.DefaultDriverName, "name of the driver")
3333
workingMountDir = flag.String("working-mount-dir", "/tmp", "working directory for provisioner to mount nfs shares temporarily")
3434
)

docs/driver-parameters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Name | Meaning | Example Value | Mandatory | Default value
99
server | NFS Server address | domain name `nfs-server.default.svc.cluster.local` <br>or IP address `127.0.0.1` | Yes |
1010
share | NFS share path | `/` | Yes |
1111
subDir | sub directory under nfs share | | No | if sub directory does not exist, this driver would create a new one
12-
mountPermissions | mounted folder permissions. The default is `0777`, if set as `0`, driver will not perform `chmod` after mount | | No |
12+
mountPermissions | mounted folder permissions. The default is `0`, if set as non-zero, driver will perform `chmod` after mount | | No |
1313

1414
### PV/PVC usage (static provisioning)
1515
> [`PersistentVolume` example](../deploy/example/pv-nfs-csi.yaml)
@@ -18,7 +18,7 @@ Name | Meaning | Example Value | Mandatory | Default value
1818
--- | --- | --- | --- | ---
1919
volumeAttributes.server | NFS Server address | domain name `nfs-server.default.svc.cluster.local` <br>or IP address `127.0.0.1` | Yes |
2020
volumeAttributes.share | NFS share path | `/` | Yes |
21-
volumeAttributes.mountPermissions | mounted folder permissions. The default is `0777` | | No |
21+
volumeAttributes.mountPermissions | mounted folder permissions. The default is `0`, if set as non-zero, driver will perform `chmod` after mount | | No |
2222

2323
### Tips
2424
#### `subDir` parameter supports following pv/pvc metadata conversion

pkg/nfs/controllerserver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,17 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
130130
}
131131
}()
132132

133-
fileMode := os.FileMode(mountPermissions)
134133
// Create subdirectory under base-dir
135134
internalVolumePath := getInternalVolumePath(cs.Driver.workingMountDir, nfsVol)
136-
if err = os.Mkdir(internalVolumePath, fileMode); err != nil && !os.IsExist(err) {
135+
if err = os.Mkdir(internalVolumePath, 0777); err != nil && !os.IsExist(err) {
137136
return nil, status.Errorf(codes.Internal, "failed to make subdirectory: %v", err.Error())
138137
}
139-
// Reset directory permissions because of umask problems
140-
if err = os.Chmod(internalVolumePath, fileMode); err != nil {
141-
klog.Warningf("failed to chmod subdirectory: %v", err.Error())
138+
139+
if mountPermissions > 0 {
140+
// Reset directory permissions because of umask problems
141+
if err = os.Chmod(internalVolumePath, os.FileMode(mountPermissions)); err != nil {
142+
klog.Warningf("failed to chmod subdirectory: %v", err.Error())
143+
}
142144
}
143145

144146
setKeyValueInMap(parameters, paramSubDir, nfsVol.subDir)

pkg/nfs/nodeserver.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
6060
subDirReplaceMap := map[string]string{}
6161

6262
mountPermissions := ns.Driver.mountPermissions
63-
performChmodOp := (mountPermissions > 0)
6463
for k, v := range req.GetVolumeContext() {
6564
switch strings.ToLower(k) {
6665
case paramServer:
@@ -82,15 +81,9 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8281
case mountPermissionsField:
8382
if v != "" {
8483
var err error
85-
var perm uint64
86-
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
84+
if mountPermissions, err = strconv.ParseUint(v, 8, 32); err != nil {
8785
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
8886
}
89-
if perm == 0 {
90-
performChmodOp = false
91-
} else {
92-
mountPermissions = perm
93-
}
9487
}
9588
}
9689
}
@@ -138,7 +131,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
138131
return nil, status.Error(codes.Internal, err.Error())
139132
}
140133

141-
if performChmodOp {
134+
if mountPermissions > 0 {
142135
if err := chmodIfPermissionMismatch(targetPath, os.FileMode(mountPermissions)); err != nil {
143136
return nil, status.Error(codes.Internal, err.Error())
144137
}

0 commit comments

Comments
 (0)