@@ -101,6 +101,7 @@ const (
101101 podNamespaceField = "csi.storage.k8s.io/pod.namespace"
102102 serviceAccountTokenField = "csi.storage.k8s.io/serviceAccount.tokens"
103103 clientIDField = "clientid"
104+ mountWithWITokenField = "mountwithworkloadidentitytoken"
104105 tenantIDField = "tenantid"
105106 mountOptionsField = "mountoptions"
106107 falseValue = "false"
@@ -490,6 +491,7 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
490491 getAccountKeyFromSecret bool
491492 getLatestAccountKey bool
492493 clientID string
494+ mountWithWIToken bool
493495 tenantID string
494496 serviceAccountToken string
495497 )
@@ -543,6 +545,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
543545 }
544546 case clientIDField :
545547 clientID = v
548+ case mountWithWITokenField :
549+ if mountWithWIToken , err = strconv .ParseBool (v ); err != nil {
550+ return rgName , accountName , accountKey , containerName , authEnv , fmt .Errorf ("invalid %s: %s in volume context" , mountWithWITokenField , v )
551+ }
546552 case tenantIDField :
547553 tenantID = v
548554 case strings .ToLower (serviceAccountTokenField ):
@@ -572,21 +578,29 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
572578 tenantID = d .cloud .TenantID
573579 }
574580
575- // if client id is specified, we only use workload identity for blobfuse auth
576581 if clientID != "" {
577- klog .V (2 ).Infof ("clientID(%s) is specified, use workload identity for blobfuse auth" , clientID )
582+ if mountWithWIToken {
583+ klog .V (2 ).Infof ("clientID(%s) is specified, use workload identity for blobfuse auth" , clientID )
584+
585+ workloadIdentityToken , err := parseServiceAccountToken (serviceAccountToken )
586+ if err != nil {
587+ return rgName , accountName , accountKey , containerName , authEnv , err
588+ }
589+
590+ authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_ID=" + clientID )
591+ if tenantID != "" {
592+ authEnv = append (authEnv , "AZURE_STORAGE_SPN_TENANT_ID=" + tenantID )
593+ }
594+ authEnv = append (authEnv , "WORKLOAD_IDENTITY_TOKEN=" + workloadIdentityToken )
578595
579- workloadIdentityToken , err := parseServiceAccountToken (serviceAccountToken )
580- if err != nil {
581596 return rgName , accountName , accountKey , containerName , authEnv , err
582597 }
583-
584- authEnv = append (authEnv , "AZURE_STORAGE_SPN_CLIENT_ID=" + clientID )
585- if tenantID != "" {
586- authEnv = append (authEnv , "AZURE_STORAGE_SPN_TENANT_ID=" + tenantID )
598+ klog .V (2 ).Infof ("clientID(%s) is specified, use service account token to get account key" , clientID )
599+ if subsID == "" {
600+ subsID = d .cloud .SubscriptionID
587601 }
588- authEnv = append ( authEnv , "WORKLOAD_IDENTITY_TOKEN=" + workloadIdentityToken )
589-
602+ accountKey , err := d . cloud . GetStorageAccesskeyFromServiceAccountToken ( ctx , subsID , accountName , rgName , clientID , tenantID , serviceAccountToken )
603+ authEnv = append ( authEnv , "AZURE_STORAGE_ACCESS_KEY=" + accountKey )
590604 return rgName , accountName , accountKey , containerName , authEnv , err
591605 }
592606
0 commit comments