@@ -263,8 +263,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
263
263
// don't respect fsType from req.GetVolumeCapability().GetMount().GetFsType()
264
264
// since it's ext4 by default on Linux
265
265
var fsType , server , protocol , ephemeralVolMountOptions , storageEndpointSuffix , folderName string
266
- var ephemeralVol bool
267
- var encryptInTransit bool
266
+ var ephemeralVol , encryptInTransit , mountWithManagedIdentity bool
268
267
fileShareNameReplaceMap := map [string ]string {}
269
268
270
269
mountPermissions := d .mountPermissions
@@ -298,7 +297,6 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
298
297
fileShareNameReplaceMap [pvNameMetadata ] = v
299
298
case mountPermissionsField :
300
299
if v != "" {
301
- var err error
302
300
var perm uint64
303
301
if perm , err = strconv .ParseUint (v , 8 , 32 ); err != nil {
304
302
return nil , status .Errorf (codes .InvalidArgument , "invalid mountPermissions %s" , v )
@@ -310,11 +308,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
310
308
}
311
309
}
312
310
case encryptInTransitField :
313
- var err error
314
311
encryptInTransit , err = strconv .ParseBool (v )
315
312
if err != nil {
316
313
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("Volume context property %q must be a boolean value: %v" , k , err ))
317
314
}
315
+ case mountWithManagedIdentityField :
316
+ mountWithManagedIdentity , err = strconv .ParseBool (v )
317
+ if err != nil {
318
+ return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("Volume context property %q must be a boolean value: %v" , k , err ))
319
+ }
318
320
}
319
321
}
320
322
@@ -379,22 +381,27 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
379
381
mountOptions = util .JoinMountOptions (mountFlags , []string {"vers=4,minorversion=1,sec=sys" })
380
382
mountOptions = appendDefaultNfsMountOptions (mountOptions , d .appendNoResvPortOption , d .appendActimeoOption )
381
383
} else {
382
- if accountName == "" || accountKey == "" {
383
- return nil , status .Errorf (codes .Internal , "accountName(%s) or accountKey is empty" , accountName )
384
- }
385
- if runtime .GOOS == "windows" {
386
- mountOptions = []string {fmt .Sprintf ("AZURE\\ %s" , accountName )}
387
- sensitiveMountOptions = []string {accountKey }
384
+ if mountWithManagedIdentity && runtime .GOOS != "windows" {
385
+ mountOptions = []string {"sec=krb5,cruid=0,upcall_target=mount" , fmt .Sprintf ("username=%s" , d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID )}
386
+ klog .V (2 ).Infof ("using managed identity %s for volume %s with mount options: %v" , d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID , volumeID , mountOptions )
388
387
} else {
389
- if err := os . MkdirAll ( targetPath , os . FileMode ( mountPermissions )); err != nil {
390
- return nil , status .Error (codes .Internal , fmt . Sprintf ( "MkdirAll %s failed with error: %v " , targetPath , err ) )
388
+ if accountName == "" || accountKey == "" {
389
+ return nil , status .Errorf (codes .Internal , "accountName(%s) or accountKey is empty " , accountName )
391
390
}
392
- // parameters suggested by https://azure.microsoft.com/en-us/documentation/articles/storage-how-to-use-files-linux/
393
- sensitiveMountOptions = []string {fmt .Sprintf ("username=%s,password=%s" , accountName , accountKey )}
394
- if ephemeralVol {
395
- cifsMountFlags = util .JoinMountOptions (cifsMountFlags , strings .Split (ephemeralVolMountOptions , "," ))
391
+ if runtime .GOOS == "windows" {
392
+ mountOptions = []string {fmt .Sprintf ("AZURE\\ %s" , accountName )}
393
+ sensitiveMountOptions = []string {accountKey }
394
+ } else {
395
+ if err := os .MkdirAll (targetPath , os .FileMode (mountPermissions )); err != nil {
396
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("MkdirAll %s failed with error: %v" , targetPath , err ))
397
+ }
398
+ // parameters suggested by https://azure.microsoft.com/en-us/documentation/articles/storage-how-to-use-files-linux/
399
+ sensitiveMountOptions = []string {fmt .Sprintf ("username=%s,password=%s" , accountName , accountKey )}
400
+ if ephemeralVol {
401
+ cifsMountFlags = util .JoinMountOptions (cifsMountFlags , strings .Split (ephemeralVolMountOptions , "," ))
402
+ }
403
+ mountOptions = appendDefaultCifsMountOptions (cifsMountFlags , d .appendNoShareSockOption , d .appendClosetimeoOption )
396
404
}
397
- mountOptions = appendDefaultCifsMountOptions (cifsMountFlags , d .appendNoShareSockOption , d .appendClosetimeoOption )
398
405
}
399
406
}
400
407
@@ -434,6 +441,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
434
441
klog .V (2 ).Infof ("mount with proxy succeeded for %s" , cifsMountPath )
435
442
} else {
436
443
execFunc := func () error {
444
+ if mountWithManagedIdentity && protocol != nfs && runtime .GOOS != "windows" {
445
+ if out , err := setCredentialCache (server , d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID ); err != nil {
446
+ return fmt .Errorf ("setCredentialCache failed for %s with error: %v, output: %s" , server , err , out )
447
+ }
448
+ }
437
449
return SMBMount (d .mounter , source , cifsMountPath , mountFsType , mountOptions , sensitiveMountOptions )
438
450
}
439
451
timeoutFunc := func () error { return fmt .Errorf ("time out" ) }
0 commit comments