@@ -84,6 +84,7 @@ const (
84
84
storageSPNClientIDField = "azurestoragespnclientid"
85
85
storageSPNTenantIDField = "azurestoragespntenantid"
86
86
storageAuthTypeField = "azurestorageauthtype"
87
+ storageAuthTypeMSI = "msi"
87
88
storageIdentityClientIDField = "azurestorageidentityclientid"
88
89
storageIdentityObjectIDField = "azurestorageidentityobjectid"
89
90
storageIdentityResourceIDField = "azurestorageidentityresourceid"
@@ -600,7 +601,7 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
600
601
if spnTenantID != "" {
601
602
storageSPNTenantID = spnTenantID
602
603
}
603
- if err != nil && strings .EqualFold (azureStorageAuthType , "msi" ) {
604
+ if err != nil && strings .EqualFold (azureStorageAuthType , storageAuthTypeMSI ) {
604
605
klog .V (2 ).Infof ("ignore error(%v) since secret is optional for auth type(%s)" , err , azureStorageAuthType )
605
606
err = nil
606
607
}
@@ -673,6 +674,23 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
673
674
authEnv = append (authEnv , "AZURE_STORAGE_SPN_TENANT_ID=" + storageSPNTenantID )
674
675
}
675
676
677
+ if azureStorageAuthType == storageAuthTypeMSI {
678
+ // check whether authEnv contains AZURE_STORAGE_IDENTITY_ prefix
679
+ containsIdentityEnv := false
680
+ for _ , env := range authEnv {
681
+ if strings .HasPrefix (env , "AZURE_STORAGE_IDENTITY_" ) {
682
+ klog .V (2 ).Infof ("AZURE_STORAGE_IDENTITY_ is already set in authEnv, skip setting it again" )
683
+ containsIdentityEnv = true
684
+ break
685
+ }
686
+ }
687
+ if ! containsIdentityEnv && d .cloud != nil && d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID != "" {
688
+ klog .V (2 ).Infof ("azureStorageAuthType is set to %s, add AZURE_STORAGE_IDENTITY_CLIENT_ID(%s) into authEnv" ,
689
+ azureStorageAuthType , d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID )
690
+ authEnv = append (authEnv , "AZURE_STORAGE_IDENTITY_CLIENT_ID=" + d .cloud .Config .AzureAuthConfig .UserAssignedIdentityID )
691
+ }
692
+ }
693
+
676
694
return rgName , accountName , accountKey , containerName , authEnv , err
677
695
}
678
696
0 commit comments