@@ -18,10 +18,12 @@ package blob
18
18
19
19
import (
20
20
"fmt"
21
+ "io/fs"
21
22
"io/ioutil"
22
23
"os"
23
24
"os/exec"
24
25
"path/filepath"
26
+ "strconv"
25
27
"strings"
26
28
"time"
27
29
@@ -70,20 +72,30 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
70
72
return nil , status .Error (codes .InvalidArgument , "Target path not provided" )
71
73
}
72
74
75
+ mountPermissions := d .mountPermissions
73
76
context := req .GetVolumeContext ()
74
- if context != nil && strings .EqualFold (context [ephemeralField ], trueValue ) {
75
- context [secretNamespaceField ] = context [podNamespaceField ]
76
- // only get storage account from secret
77
- context [getAccountKeyFromSecretField ] = trueValue
78
- context [storageAccountField ] = ""
79
- klog .V (2 ).Infof ("NodePublishVolume: ephemeral volume(%s) mount on %s, VolumeContext: %v" , volumeID , target , context )
80
- _ , err := d .NodeStageVolume (ctx , & csi.NodeStageVolumeRequest {
81
- StagingTargetPath : target ,
82
- VolumeContext : context ,
83
- VolumeCapability : volCap ,
84
- VolumeId : volumeID ,
85
- })
86
- return & csi.NodePublishVolumeResponse {}, err
77
+ if context != nil {
78
+ if strings .EqualFold (context [ephemeralField ], trueValue ) {
79
+ context [secretNamespaceField ] = context [podNamespaceField ]
80
+ // only get storage account from secret
81
+ context [getAccountKeyFromSecretField ] = trueValue
82
+ context [storageAccountField ] = ""
83
+ klog .V (2 ).Infof ("NodePublishVolume: ephemeral volume(%s) mount on %s, VolumeContext: %v" , volumeID , target , context )
84
+ _ , err := d .NodeStageVolume (ctx , & csi.NodeStageVolumeRequest {
85
+ StagingTargetPath : target ,
86
+ VolumeContext : context ,
87
+ VolumeCapability : volCap ,
88
+ VolumeId : volumeID ,
89
+ })
90
+ return & csi.NodePublishVolumeResponse {}, err
91
+ }
92
+
93
+ if perm := context [mountPermissionsField ]; perm != "" {
94
+ var err error
95
+ if mountPermissions , err = strconv .ParseUint (perm , 8 , 32 ); err != nil {
96
+ return nil , status .Errorf (codes .InvalidArgument , fmt .Sprintf ("invalid mountPermissions %s" , perm ))
97
+ }
98
+ }
87
99
}
88
100
89
101
source := req .GetStagingTargetPath ()
@@ -96,7 +108,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
96
108
mountOptions = append (mountOptions , "ro" )
97
109
}
98
110
99
- mnt , err := d .ensureMountPoint (target )
111
+ mnt , err := d .ensureMountPoint (target , fs . FileMode ( mountPermissions ) )
100
112
if err != nil {
101
113
return nil , status .Errorf (codes .Internal , "Could not mount target %q: %v" , target , err )
102
114
}
@@ -108,7 +120,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
108
120
klog .V (2 ).Infof ("NodePublishVolume: volume %s mounting %s at %s with mountOptions: %v" , volumeID , source , target , mountOptions )
109
121
if d .enableBlobMockMount {
110
122
klog .Warningf ("NodePublishVolume: mock mount on volumeID(%s), this is only for TESTING!!!" , volumeID )
111
- if err := volumehelper .MakeDir (target , os .FileMode (d . mountPermissions )); err != nil {
123
+ if err := volumehelper .MakeDir (target , os .FileMode (mountPermissions )); err != nil {
112
124
klog .Errorf ("MakeDir failed on target: %s (%v)" , target , err )
113
125
return nil , err
114
126
}
@@ -199,21 +211,13 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
199
211
}
200
212
defer d .volumeLocks .Release (volumeID )
201
213
202
- mnt , err := d .ensureMountPoint (targetPath )
203
- if err != nil {
204
- return nil , status .Errorf (codes .Internal , "Could not mount target %q: %v" , targetPath , err )
205
- }
206
- if mnt {
207
- klog .V (2 ).Infof ("NodeStageVolume: volume %s is already mounted on %s" , volumeID , targetPath )
208
- return & csi.NodeStageVolumeResponse {}, nil
209
- }
210
-
211
214
mountFlags := req .GetVolumeCapability ().GetMount ().GetMountFlags ()
212
215
attrib := req .GetVolumeContext ()
213
216
secrets := req .GetSecrets ()
214
217
215
218
var serverAddress , storageEndpointSuffix , protocol , ephemeralVolMountOptions string
216
219
var ephemeralVol , isHnsEnabled bool
220
+ mountPermissions := d .mountPermissions
217
221
for k , v := range attrib {
218
222
switch strings .ToLower (k ) {
219
223
case serverNameField :
@@ -228,9 +232,25 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
228
232
ephemeralVolMountOptions = v
229
233
case isHnsEnabledField :
230
234
isHnsEnabled = strings .EqualFold (v , trueValue )
235
+ case mountPermissionsField :
236
+ if v != "" {
237
+ var err error
238
+ if mountPermissions , err = strconv .ParseUint (v , 8 , 32 ); err != nil {
239
+ return nil , status .Errorf (codes .InvalidArgument , fmt .Sprintf ("invalid mountPermissions %s" , v ))
240
+ }
241
+ }
231
242
}
232
243
}
233
244
245
+ mnt , err := d .ensureMountPoint (targetPath , fs .FileMode (mountPermissions ))
246
+ if err != nil {
247
+ return nil , status .Errorf (codes .Internal , "Could not mount target %q: %v" , targetPath , err )
248
+ }
249
+ if mnt {
250
+ klog .V (2 ).Infof ("NodeStageVolume: volume %s is already mounted on %s" , volumeID , targetPath )
251
+ return & csi.NodeStageVolumeResponse {}, nil
252
+ }
253
+
234
254
_ , accountName , _ , containerName , authEnv , err := d .GetAuthEnv (ctx , volumeID , protocol , attrib , secrets )
235
255
if err != nil {
236
256
return nil , err
@@ -262,10 +282,10 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
262
282
}
263
283
264
284
// set permissions for NFSv3 root folder
265
- if err := os .Chmod (targetPath , os .FileMode (d . mountPermissions )); err != nil {
285
+ if err := os .Chmod (targetPath , os .FileMode (mountPermissions )); err != nil {
266
286
return nil , status .Error (codes .Internal , fmt .Sprintf ("Chmod(%s) failed with %v" , targetPath , err ))
267
287
}
268
- klog .V (2 ).Infof ("volume(%s) mount %q on %q with 0%o succeeded" , volumeID , source , targetPath , d . mountPermissions )
288
+ klog .V (2 ).Infof ("volume(%s) mount %q on %q with 0%o succeeded" , volumeID , source , targetPath , mountPermissions )
269
289
270
290
return & csi.NodeStageVolumeResponse {}, nil
271
291
}
@@ -295,7 +315,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
295
315
authEnv = append (authEnv , "AZURE_STORAGE_ACCOUNT=" + accountName , "AZURE_STORAGE_BLOB_ENDPOINT=" + serverAddress )
296
316
if d .enableBlobMockMount {
297
317
klog .Warningf ("NodeStageVolume: mock mount on volumeID(%s), this is only for TESTING!!!" , volumeID )
298
- if err := volumehelper .MakeDir (targetPath , os .FileMode (d . mountPermissions )); err != nil {
318
+ if err := volumehelper .MakeDir (targetPath , os .FileMode (mountPermissions )); err != nil {
299
319
klog .Errorf ("MakeDir failed on target: %s (%v)" , targetPath , err )
300
320
return nil , err
301
321
}
@@ -454,7 +474,7 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
454
474
455
475
// ensureMountPoint: create mount point if not exists
456
476
// return <true, nil> if it's already a mounted point otherwise return <false, nil>
457
- func (d * Driver ) ensureMountPoint (target string ) (bool , error ) {
477
+ func (d * Driver ) ensureMountPoint (target string , perm os. FileMode ) (bool , error ) {
458
478
notMnt , err := d .mounter .IsLikelyNotMountPoint (target )
459
479
if err != nil && ! os .IsNotExist (err ) {
460
480
if IsCorruptedDir (target ) {
@@ -500,7 +520,7 @@ func (d *Driver) ensureMountPoint(target string) (bool, error) {
500
520
notMnt = true
501
521
return ! notMnt , err
502
522
}
503
- if err := volumehelper .MakeDir (target , os . FileMode ( d . mountPermissions ) ); err != nil {
523
+ if err := volumehelper .MakeDir (target , perm ); err != nil {
504
524
klog .Errorf ("MakeDir failed on target: %s (%v)" , target , err )
505
525
return ! notMnt , err
506
526
}
0 commit comments