@@ -75,6 +75,8 @@ const (
75
75
softDeleteContainersField = "softdeletecontainers"
76
76
enableBlobVersioningField = "enableblobversioning"
77
77
getAccountKeyFromSecretField = "getaccountkeyfromsecret"
78
+ storageSPNClientIDField = "azurestoragespnclientid"
79
+ storageSPNTenantIDField = "azurestoragespntenantid"
78
80
keyVaultURLField = "keyvaulturl"
79
81
keyVaultSecretNameField = "keyvaultsecretname"
80
82
keyVaultSecretVersionField = "keyvaultsecretversion"
@@ -369,6 +371,8 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
369
371
accountSasToken string
370
372
msiSecret string
371
373
storageSPNClientSecret string
374
+ storageSPNClientID string
375
+ storageSPNTenantID string
372
376
secretName string
373
377
pvcNamespace string
374
378
keyVaultURL string
@@ -416,10 +420,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
416
420
authEnv = append (authEnv , "AZURE_STORAGE_IDENTITY_RESOURCE_ID=" + v )
417
421
case "msiendpoint" :
418
422
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
423
427
case "azurestorageaadendpoint" :
424
428
authEnv = append (authEnv , "AZURE_STORAGE_AAD_ENDPOINT=" + v )
425
429
}
@@ -463,11 +467,17 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
463
467
}
464
468
if secretName != "" {
465
469
// 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 )
468
472
if name != "" {
469
473
accountName = name
470
474
}
475
+ if spnClientID != "" {
476
+ storageSPNClientID = spnClientID
477
+ }
478
+ if spnTenantID != "" {
479
+ storageSPNTenantID = spnTenantID
480
+ }
471
481
if err != nil && strings .EqualFold (azureStorageAuthType , "msi" ) {
472
482
klog .V (2 ).Infof ("ignore error(%v) since secret is optional for auth type(%s)" , err , azureStorageAuthType )
473
483
err = nil
@@ -499,6 +509,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
499
509
msiSecret = v
500
510
case storageSPNClientSecretField :
501
511
storageSPNClientSecret = v
512
+ case storageSPNClientIDField :
513
+ storageSPNClientID = v
514
+ case storageSPNTenantIDField :
515
+ storageSPNTenantID = v
502
516
}
503
517
}
504
518
}
@@ -527,6 +541,16 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
527
541
authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_SECRET=" + storageSPNClientSecret )
528
542
}
529
543
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
+
530
554
return rgName , accountName , accountKey , containerName , authEnv , err
531
555
}
532
556
@@ -757,7 +781,7 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
757
781
if secretName == "" {
758
782
secretName = fmt .Sprintf (secretNameTemplate , accountOptions .Name )
759
783
}
760
- _ , accountKey , _ , _ , _ , err := d .GetInfoFromSecret (ctx , secretName , secretNamespace ) //nolint
784
+ _ , accountKey , _ , _ , _ , _ , _ , err := d .GetInfoFromSecret (ctx , secretName , secretNamespace ) //nolint
761
785
if err != nil {
762
786
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 )
763
787
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.
766
790
}
767
791
768
792
// 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 ) {
771
795
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 )
773
797
}
774
798
775
799
secret , err := d .cloud .KubeClient .CoreV1 ().Secrets (secretNamespace ).Get (ctx , secretName , metav1.GetOptions {})
776
800
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 )
778
802
}
779
803
780
804
accountName := strings .TrimSpace (string (secret .Data [defaultSecretAccountName ][:]))
781
805
accountKey := strings .TrimSpace (string (secret .Data [defaultSecretAccountKey ][:]))
782
806
accountSasToken := strings .TrimSpace (string (secret .Data [accountSasTokenField ][:]))
783
807
msiSecret := strings .TrimSpace (string (secret .Data [msiSecretField ][:]))
784
808
spnClientSecret := strings .TrimSpace (string (secret .Data [storageSPNClientSecretField ][:]))
809
+ spnClientID := strings .TrimSpace (string (secret .Data [storageSPNClientIDField ][:]))
810
+ spnTenantID := strings .TrimSpace (string (secret .Data [storageSPNTenantIDField ][:]))
785
811
786
812
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
788
814
}
789
815
790
816
// getSubnetResourceID get default subnet resource ID from cloud provider config
0 commit comments