@@ -233,7 +233,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
233
233
volumeID := req .GetVolumeId ()
234
234
context := req .GetVolumeContext ()
235
235
236
- if getValueInMap (context , clientIDField ) != "" && context [serviceAccountTokenField ] == "" {
236
+ if getValueInMap (context , clientIDField ) != "" && ! strings . EqualFold ( getValueInMap ( context , mountWithManagedIdentityField ), trueValue ) && context [serviceAccountTokenField ] == "" {
237
237
klog .V (2 ).Infof ("Skip NodeStageVolume for volume(%s) since clientID %s is provided but service account token is empty" , volumeID , getValueInMap (context , clientIDField ))
238
238
return & csi.NodeStageVolumeResponse {}, nil
239
239
}
@@ -262,7 +262,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
262
262
}
263
263
// don't respect fsType from req.GetVolumeCapability().GetMount().GetFsType()
264
264
// since it's ext4 by default on Linux
265
- var fsType , server , protocol , ephemeralVolMountOptions , storageEndpointSuffix , folderName string
265
+ var fsType , server , protocol , ephemeralVolMountOptions , storageEndpointSuffix , folderName , clientID string
266
266
var ephemeralVol , encryptInTransit , mountWithManagedIdentity bool
267
267
fileShareNameReplaceMap := map [string ]string {}
268
268
@@ -317,6 +317,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
317
317
if err != nil {
318
318
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("Volume context property %q must be a boolean value: %v" , k , err ))
319
319
}
320
+ case clientIDField :
321
+ clientID = v
320
322
}
321
323
}
322
324
@@ -382,8 +384,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
382
384
mountOptions = appendDefaultNfsMountOptions (mountOptions , d .appendNoResvPortOption , d .appendActimeoOption )
383
385
} else {
384
386
if mountWithManagedIdentity && runtime .GOOS != "windows" {
385
- sensitiveMountOptions = []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 , sensitiveMountOptions )
387
+ if clientID == "" {
388
+ clientID = d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID
389
+ }
390
+ sensitiveMountOptions = []string {"sec=krb5,cruid=0,upcall_target=mount" , fmt .Sprintf ("username=%s" , clientID )}
391
+ klog .V (2 ).Infof ("using managed identity %s for volume %s with mount options: %v" , clientID , volumeID , sensitiveMountOptions )
387
392
} else {
388
393
if accountName == "" || accountKey == "" {
389
394
return nil , status .Errorf (codes .Internal , "accountName(%s) or accountKey is empty" , accountName )
@@ -445,7 +450,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
445
450
} else {
446
451
execFunc := func () error {
447
452
if mountWithManagedIdentity && protocol != nfs && runtime .GOOS != "windows" {
448
- if out , err := setCredentialCache (server , d . cloud . Config . AzureAuthConfig . UserAssignedIdentityID ); err != nil {
453
+ if out , err := setCredentialCache (server , clientID ); err != nil {
449
454
return fmt .Errorf ("setCredentialCache failed for %s with error: %v, output: %s" , server , err , out )
450
455
}
451
456
}
0 commit comments