@@ -75,6 +75,8 @@ const (
7575 softDeleteContainersField = "softdeletecontainers"
7676 enableBlobVersioningField = "enableblobversioning"
7777 getAccountKeyFromSecretField = "getaccountkeyfromsecret"
78+ storageSPNClientIDField = "azurestoragespnclientid"
79+ storageSPNTenantIDField = "azurestoragespntenantid"
7880 keyVaultURLField = "keyvaulturl"
7981 keyVaultSecretNameField = "keyvaultsecretname"
8082 keyVaultSecretVersionField = "keyvaultsecretversion"
@@ -369,6 +371,8 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
369371 accountSasToken string
370372 msiSecret string
371373 storageSPNClientSecret string
374+ storageSPNClientID string
375+ storageSPNTenantID string
372376 secretName string
373377 pvcNamespace string
374378 keyVaultURL string
@@ -416,10 +420,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
416420 authEnv = append (authEnv , "AZURE_STORAGE_IDENTITY_RESOURCE_ID=" + v )
417421 case "msiendpoint" :
418422 authEnv = append (authEnv , "MSI_ENDPOINT=" + v )
419- case "azurestoragespnclientid" :
420- authEnv = append ( authEnv , "AZURE_STORAGE_SPN_CLIENT_ID=" + v )
421- case "azurestoragespntenantid" :
422- authEnv = append ( authEnv , "AZURE_STORAGE_SPN_TENANT_ID=" + v )
423+ case storageSPNClientIDField :
424+ storageSPNClientID = v
425+ case storageSPNTenantIDField :
426+ storageSPNTenantID = v
423427 case "azurestorageaadendpoint" :
424428 authEnv = append (authEnv , "AZURE_STORAGE_AAD_ENDPOINT=" + v )
425429 }
@@ -463,11 +467,17 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
463467 }
464468 if secretName != "" {
465469 // read from k8s secret first
466- var name string
467- name , accountKey , accountSasToken , msiSecret , storageSPNClientSecret , err = d .GetInfoFromSecret (ctx , secretName , secretNamespace )
470+ var name , spnClientID , spnTenantID string
471+ name , accountKey , accountSasToken , msiSecret , storageSPNClientSecret , spnClientID , spnTenantID , err = d .GetInfoFromSecret (ctx , secretName , secretNamespace )
468472 if name != "" {
469473 accountName = name
470474 }
475+ if spnClientID != "" {
476+ storageSPNClientID = spnClientID
477+ }
478+ if spnTenantID != "" {
479+ storageSPNTenantID = spnTenantID
480+ }
471481 if err != nil && strings .EqualFold (azureStorageAuthType , "msi" ) {
472482 klog .V (2 ).Infof ("ignore error(%v) since secret is optional for auth type(%s)" , err , azureStorageAuthType )
473483 err = nil
@@ -499,6 +509,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
499509 msiSecret = v
500510 case storageSPNClientSecretField :
501511 storageSPNClientSecret = v
512+ case storageSPNClientIDField :
513+ storageSPNClientID = v
514+ case storageSPNTenantIDField :
515+ storageSPNTenantID = v
502516 }
503517 }
504518 }
@@ -527,6 +541,16 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
527541 authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_SECRET=" + storageSPNClientSecret )
528542 }
529543
544+ if storageSPNClientID != "" {
545+ klog .V (2 ).Infof ("storageSPNClientID(%s) is not empty, use it to access storage account(%s), container(%s)" , storageSPNClientID , accountName , containerName )
546+ authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_ID=" + storageSPNClientID )
547+ }
548+
549+ if storageSPNTenantID != "" {
550+ klog .V (2 ).Infof ("storageSPNTenantID(%s) is not empty, use it to access storage account(%s), container(%s)" , storageSPNTenantID , accountName , containerName )
551+ authEnv = append (authEnv , "AZURE_STORAGE_SPN_TENANT_ID=" + storageSPNTenantID )
552+ }
553+
530554 return rgName , accountName , accountKey , containerName , authEnv , err
531555}
532556
@@ -757,7 +781,7 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
757781 if secretName == "" {
758782 secretName = fmt .Sprintf (secretNameTemplate , accountOptions .Name )
759783 }
760- _ , accountKey , _ , _ , _ , err := d .GetInfoFromSecret (ctx , secretName , secretNamespace ) //nolint
784+ _ , accountKey , _ , _ , _ , _ , _ , err := d .GetInfoFromSecret (ctx , secretName , secretNamespace ) //nolint
761785 if err != nil {
762786 klog .V (2 ).Infof ("could not get account(%s) key from secret(%s) namespace(%s), error: %v, use cluster identity to get account key instead" , accountOptions .Name , secretName , secretNamespace , err )
763787 accountKey , err = d .cloud .GetStorageAccesskey (ctx , accountOptions .SubscriptionID , accountOptions .Name , accountOptions .ResourceGroup )
@@ -766,25 +790,27 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
766790}
767791
768792// GetInfoFromSecret get info from k8s secret
769- // return <accountName, accountKey, accountSasToken, msiSecret, spnClientSecret, error>
770- func (d * Driver ) GetInfoFromSecret (ctx context.Context , secretName , secretNamespace string ) (string , string , string , string , string , error ) {
793+ // return <accountName, accountKey, accountSasToken, msiSecret, spnClientSecret, spnClientID, spnTenantID, error>
794+ func (d * Driver ) GetInfoFromSecret (ctx context.Context , secretName , secretNamespace string ) (string , string , string , string , string , string , string , error ) {
771795 if d .cloud .KubeClient == nil {
772- return "" , "" , "" , "" , "" , fmt .Errorf ("could not get account key from secret(%s): KubeClient is nil" , secretName )
796+ return "" , "" , "" , "" , "" , "" , "" , fmt .Errorf ("could not get account key from secret(%s): KubeClient is nil" , secretName )
773797 }
774798
775799 secret , err := d .cloud .KubeClient .CoreV1 ().Secrets (secretNamespace ).Get (ctx , secretName , metav1.GetOptions {})
776800 if err != nil {
777- return "" , "" , "" , "" , "" , fmt .Errorf ("could not get secret(%v): %w" , secretName , err )
801+ return "" , "" , "" , "" , "" , "" , "" , fmt .Errorf ("could not get secret(%v): %w" , secretName , err )
778802 }
779803
780804 accountName := strings .TrimSpace (string (secret .Data [defaultSecretAccountName ][:]))
781805 accountKey := strings .TrimSpace (string (secret .Data [defaultSecretAccountKey ][:]))
782806 accountSasToken := strings .TrimSpace (string (secret .Data [accountSasTokenField ][:]))
783807 msiSecret := strings .TrimSpace (string (secret .Data [msiSecretField ][:]))
784808 spnClientSecret := strings .TrimSpace (string (secret .Data [storageSPNClientSecretField ][:]))
809+ spnClientID := strings .TrimSpace (string (secret .Data [storageSPNClientIDField ][:]))
810+ spnTenantID := strings .TrimSpace (string (secret .Data [storageSPNTenantIDField ][:]))
785811
786812 klog .V (4 ).Infof ("got storage account(%s) from secret" , accountName )
787- return accountName , accountKey , accountSasToken , msiSecret , spnClientSecret , nil
813+ return accountName , accountKey , accountSasToken , msiSecret , spnClientSecret , spnClientID , spnTenantID , nil
788814}
789815
790816// getSubnetResourceID get default subnet resource ID from cloud provider config
0 commit comments