@@ -88,6 +88,9 @@ const (
88
88
trueValue = "true"
89
89
defaultSecretAccountName = "azurestorageaccountname"
90
90
defaultSecretAccountKey = "azurestorageaccountkey"
91
+ accountSasTokenField = "azurestorageaccountsastoken"
92
+ msiSecretField = "msisecret"
93
+ storageSPNClientSecretField = "azurestoragespnclientsecret"
91
94
Fuse = "fuse"
92
95
Fuse2 = "fuse2"
93
96
NFS = "nfs"
@@ -364,6 +367,8 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
364
367
subsID string
365
368
accountKey string
366
369
accountSasToken string
370
+ msiSecret string
371
+ storageSPNClientSecret string
367
372
secretName string
368
373
pvcNamespace string
369
374
keyVaultURL string
@@ -456,15 +461,14 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
456
461
if secretName == "" && accountName != "" {
457
462
secretName = fmt .Sprintf (secretNameTemplate , accountName )
458
463
}
459
- // if msi is specified, don't list account key using cluster identity
460
- if secretName != "" && ! strings .EqualFold (azureStorageAuthType , "msi" ) {
464
+ if secretName != "" {
461
465
// read from k8s secret first
462
466
var name string
463
- name , accountKey , err = d .GetStorageAccountFromSecret ( secretName , secretNamespace )
467
+ name , accountKey , accountSasToken , msiSecret , storageSPNClientSecret , err = d .GetInfoFromSecret ( ctx , secretName , secretNamespace )
464
468
if name != "" {
465
469
accountName = name
466
470
}
467
- if err != nil && ! getAccountKeyFromSecret {
471
+ if err != nil && ! getAccountKeyFromSecret && ( azureStorageAuthType == "" || strings . EqualFold ( azureStorageAuthType , "key" )) {
468
472
klog .V (2 ).Infof ("get account(%s) key from secret(%s, %s) failed with error: %v, use cluster identity to get account key instead" ,
469
473
accountName , secretNamespace , secretName , err )
470
474
accountKey , err = d .cloud .GetStorageAccesskey (ctx , subsID , accountName , rgName )
@@ -485,12 +489,12 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
485
489
accountKey = v
486
490
case defaultSecretAccountKey : // for compatibility with built-in blobfuse plugin
487
491
accountKey = v
488
- case "azurestorageaccountsastoken" :
492
+ case accountSasTokenField :
489
493
accountSasToken = v
490
- case "msisecret" :
491
- authEnv = append ( authEnv , "MSI_SECRET=" + v )
492
- case "azurestoragespnclientsecret" :
493
- authEnv = append ( authEnv , "AZURE_STORAGE_SPN_CLIENT_SECRET=" + v )
494
+ case msiSecretField :
495
+ msiSecret = v
496
+ case storageSPNClientSecretField :
497
+ storageSPNClientSecret = v
494
498
}
495
499
}
496
500
}
@@ -500,12 +504,23 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
500
504
err = fmt .Errorf ("could not find containerName from attributes(%v) or volumeID(%v)" , attrib , volumeID )
501
505
}
502
506
507
+ if accountKey != "" {
508
+ authEnv = append (authEnv , "AZURE_STORAGE_ACCESS_KEY=" + accountKey )
509
+ }
510
+
503
511
if accountSasToken != "" {
512
+ klog .V (2 ).Infof ("accountSasToken is not empty, use it to access storage account(%s), container(%s)" , accountName , containerName )
504
513
authEnv = append (authEnv , "AZURE_STORAGE_SAS_TOKEN=" + accountSasToken )
505
514
}
506
515
507
- if accountKey != "" {
508
- authEnv = append (authEnv , "AZURE_STORAGE_ACCESS_KEY=" + accountKey )
516
+ if msiSecret != "" {
517
+ klog .V (2 ).Infof ("msiSecret is not empty, use it to access storage account(%s), container(%s)" , accountName , containerName )
518
+ authEnv = append (authEnv , "MSI_SECRET=" + msiSecret )
519
+ }
520
+
521
+ if storageSPNClientSecret != "" {
522
+ klog .V (2 ).Infof ("storageSPNClientSecret is not empty, use it to access storage account(%s), container(%s)" , accountName , containerName )
523
+ authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_SECRET=" + storageSPNClientSecret )
509
524
}
510
525
511
526
return rgName , accountName , accountKey , containerName , authEnv , err
@@ -738,7 +753,7 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
738
753
if secretName == "" {
739
754
secretName = fmt .Sprintf (secretNameTemplate , accountOptions .Name )
740
755
}
741
- _ , accountKey , err := d .GetStorageAccountFromSecret ( secretName , secretNamespace )
756
+ _ , accountKey , _ , _ , _ , err := d .GetInfoFromSecret ( ctx , secretName , secretNamespace ) //nolint
742
757
if err != nil {
743
758
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 )
744
759
accountKey , err = d .cloud .GetStorageAccesskey (ctx , accountOptions .SubscriptionID , accountOptions .Name , accountOptions .ResourceGroup )
@@ -748,21 +763,24 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
748
763
749
764
// GetStorageAccountFromSecret get storage account key from k8s secret
750
765
// return <accountName, accountKey, error>
751
- func (d * Driver ) GetStorageAccountFromSecret ( secretName , secretNamespace string ) (string , string , error ) {
766
+ func (d * Driver ) GetInfoFromSecret ( ctx context. Context , secretName , secretNamespace string ) (string , string , string , string , string , error ) {
752
767
if d .cloud .KubeClient == nil {
753
- return "" , "" , fmt .Errorf ("could not get account key from secret(%s): KubeClient is nil" , secretName )
768
+ return "" , "" , "" , "" , "" , fmt .Errorf ("could not get account key from secret(%s): KubeClient is nil" , secretName )
754
769
}
755
770
756
771
secret , err := d .cloud .KubeClient .CoreV1 ().Secrets (secretNamespace ).Get (context .TODO (), secretName , metav1.GetOptions {})
757
772
if err != nil {
758
- return "" , "" , fmt .Errorf ("could not get secret(%v): %w" , secretName , err )
773
+ return "" , "" , "" , "" , "" , fmt .Errorf ("could not get secret(%v): %w" , secretName , err )
759
774
}
760
775
761
776
accountName := strings .TrimSpace (string (secret .Data [defaultSecretAccountName ][:]))
762
777
accountKey := strings .TrimSpace (string (secret .Data [defaultSecretAccountKey ][:]))
778
+ accountSasToken := strings .TrimSpace (string (secret .Data [accountSasTokenField ][:]))
779
+ msiSecret := strings .TrimSpace (string (secret .Data [msiSecretField ][:]))
780
+ spnClientSecret := strings .TrimSpace (string (secret .Data [storageSPNClientSecretField ][:]))
763
781
764
782
klog .V (4 ).Infof ("got storage account(%s) from secret" , accountName )
765
- return accountName , accountKey , nil
783
+ return accountName , accountKey , accountSasToken , msiSecret , spnClientSecret , nil
766
784
}
767
785
768
786
// getSubnetResourceID get default subnet resource ID from cloud provider config
0 commit comments