Skip to content

Commit f11af19

Browse files
committed
support clientID
1 parent c55ff84 commit f11af19

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pkg/azurefile/nodeserver.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
233233
volumeID := req.GetVolumeId()
234234
context := req.GetVolumeContext()
235235

236-
if getValueInMap(context, clientIDField) != "" && context[serviceAccountTokenField] == "" {
236+
if getValueInMap(context, clientIDField) != "" && !strings.EqualFold(getValueInMap(context, mountWithManagedIdentityField), trueValue) && context[serviceAccountTokenField] == "" {
237237
klog.V(2).Infof("Skip NodeStageVolume for volume(%s) since clientID %s is provided but service account token is empty", volumeID, getValueInMap(context, clientIDField))
238238
return &csi.NodeStageVolumeResponse{}, nil
239239
}
@@ -262,7 +262,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
262262
}
263263
// don't respect fsType from req.GetVolumeCapability().GetMount().GetFsType()
264264
// 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
266266
var ephemeralVol, encryptInTransit, mountWithManagedIdentity bool
267267
fileShareNameReplaceMap := map[string]string{}
268268

@@ -317,6 +317,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
317317
if err != nil {
318318
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Volume context property %q must be a boolean value: %v", k, err))
319319
}
320+
case clientIDField:
321+
clientID = v
320322
}
321323
}
322324

@@ -382,8 +384,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
382384
mountOptions = appendDefaultNfsMountOptions(mountOptions, d.appendNoResvPortOption, d.appendActimeoOption)
383385
} else {
384386
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)
387392
} else {
388393
if accountName == "" || accountKey == "" {
389394
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
445450
} else {
446451
execFunc := func() error {
447452
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 {
449454
return fmt.Errorf("setCredentialCache failed for %s with error: %v, output: %s", server, err, out)
450455
}
451456
}

0 commit comments

Comments
 (0)