@@ -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
@@ -460,7 +465,7 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
460
465
if secretName != "" && ! strings .EqualFold (azureStorageAuthType , "msi" ) {
461
466
// read from k8s secret first
462
467
var name string
463
- name , accountKey , err = d .GetStorageAccountFromSecret (secretName , secretNamespace )
468
+ name , accountKey , accountSasToken , msiSecret , storageSPNClientSecret , err = d .GetInfoFromSecret (secretName , secretNamespace )
464
469
if name != "" {
465
470
accountName = name
466
471
}
@@ -485,12 +490,12 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
485
490
accountKey = v
486
491
case defaultSecretAccountKey : // for compatibility with built-in blobfuse plugin
487
492
accountKey = v
488
- case "azurestorageaccountsastoken" :
493
+ case accountSasTokenField :
489
494
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 )
495
+ case msiSecretField :
496
+ msiSecret = v
497
+ case storageSPNClientSecretField :
498
+ storageSPNClientSecret = v
494
499
}
495
500
}
496
501
}
@@ -500,12 +505,23 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
500
505
err = fmt .Errorf ("could not find containerName from attributes(%v) or volumeID(%v)" , attrib , volumeID )
501
506
}
502
507
508
+ if accountKey != "" {
509
+ authEnv = append (authEnv , "AZURE_STORAGE_ACCESS_KEY=" + accountKey )
510
+ }
511
+
503
512
if accountSasToken != "" {
513
+ klog .V (2 ).Infof ("accountSasToken is not empty, use it to access storage account(%s), container(%s)" , accountName , containerName )
504
514
authEnv = append (authEnv , "AZURE_STORAGE_SAS_TOKEN=" + accountSasToken )
505
515
}
506
516
507
- if accountKey != "" {
508
- authEnv = append (authEnv , "AZURE_STORAGE_ACCESS_KEY=" + accountKey )
517
+ if msiSecret != "" {
518
+ klog .V (2 ).Infof ("msiSecret is not empty, use it to access storage account(%s), container(%s)" , accountName , containerName )
519
+ authEnv = append (authEnv , "MSI_SECRET=" + msiSecret )
520
+ }
521
+
522
+ if storageSPNClientSecret != "" {
523
+ klog .V (2 ).Infof ("storageSPNClientSecret is not empty, use it to access storage account(%s), container(%s)" , accountName , containerName )
524
+ authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_SECRET=" + storageSPNClientSecret )
509
525
}
510
526
511
527
return rgName , accountName , accountKey , containerName , authEnv , err
@@ -738,31 +754,34 @@ func (d *Driver) GetStorageAccesskey(ctx context.Context, accountOptions *azure.
738
754
if secretName == "" {
739
755
secretName = fmt .Sprintf (secretNameTemplate , accountOptions .Name )
740
756
}
741
- _ , accountKey , err := d .GetStorageAccountFromSecret (secretName , secretNamespace )
757
+ _ , accountKey , _ , _ , _ , err := d .GetInfoFromSecret (secretName , secretNamespace )
742
758
if err != nil {
743
759
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
760
accountKey , err = d .cloud .GetStorageAccesskey (ctx , accountOptions .SubscriptionID , accountOptions .Name , accountOptions .ResourceGroup )
745
761
}
746
762
return accountOptions .Name , accountKey , err
747
763
}
748
764
749
- // GetStorageAccountFromSecret get storage account key from k8s secret
750
- // return <accountName, accountKey, error>
751
- func (d * Driver ) GetStorageAccountFromSecret (secretName , secretNamespace string ) (string , string , error ) {
765
+ // GetInfoFromSecret get info from k8s secret
766
+ // return <accountName, accountKey, accountSasToken, msiSecret, spnClientSecret, error>
767
+ func (d * Driver ) GetInfoFromSecret (secretName , secretNamespace string ) (string , string , string , string , string , error ) {
752
768
if d .cloud .KubeClient == nil {
753
- return "" , "" , fmt .Errorf ("could not get account key from secret(%s): KubeClient is nil" , secretName )
769
+ return "" , "" , "" , "" , "" , fmt .Errorf ("could not get account key from secret(%s): KubeClient is nil" , secretName )
754
770
}
755
771
756
772
secret , err := d .cloud .KubeClient .CoreV1 ().Secrets (secretNamespace ).Get (context .TODO (), secretName , metav1.GetOptions {})
757
773
if err != nil {
758
- return "" , "" , fmt .Errorf ("could not get secret(%v): %w" , secretName , err )
774
+ return "" , "" , "" , "" , "" , fmt .Errorf ("could not get secret(%v): %w" , secretName , err )
759
775
}
760
776
761
777
accountName := strings .TrimSpace (string (secret .Data [defaultSecretAccountName ][:]))
762
778
accountKey := strings .TrimSpace (string (secret .Data [defaultSecretAccountKey ][:]))
779
+ accountSasToken := strings .TrimSpace (string (secret .Data [accountSasTokenField ][:]))
780
+ msiSecret := strings .TrimSpace (string (secret .Data [msiSecretField ][:]))
781
+ spnClientSecret := strings .TrimSpace (string (secret .Data [storageSPNClientSecretField ][:]))
763
782
764
783
klog .V (4 ).Infof ("got storage account(%s) from secret" , accountName )
765
- return accountName , accountKey , nil
784
+ return accountName , accountKey , accountSasToken , msiSecret , spnClientSecret , nil
766
785
}
767
786
768
787
// getSubnetResourceID get default subnet resource ID from cloud provider config
0 commit comments