@@ -101,6 +101,7 @@ const (
101
101
podNamespaceField = "csi.storage.k8s.io/pod.namespace"
102
102
serviceAccountTokenField = "csi.storage.k8s.io/serviceAccount.tokens"
103
103
clientIDField = "clientid"
104
+ mountWithWITokenField = "mountwithworkloadidentitytoken"
104
105
tenantIDField = "tenantid"
105
106
mountOptionsField = "mountoptions"
106
107
falseValue = "false"
@@ -490,6 +491,7 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
490
491
getAccountKeyFromSecret bool
491
492
getLatestAccountKey bool
492
493
clientID string
494
+ mountWithWIToken bool
493
495
tenantID string
494
496
serviceAccountToken string
495
497
)
@@ -543,6 +545,10 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
543
545
}
544
546
case clientIDField :
545
547
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
+ }
546
552
case tenantIDField :
547
553
tenantID = v
548
554
case strings .ToLower (serviceAccountTokenField ):
@@ -572,21 +578,29 @@ func (d *Driver) GetAuthEnv(ctx context.Context, volumeID, protocol string, attr
572
578
tenantID = d .cloud .TenantID
573
579
}
574
580
575
- // if client id is specified, we only use workload identity for blobfuse auth
576
581
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 )
578
595
579
- workloadIdentityToken , err := parseServiceAccountToken (serviceAccountToken )
580
- if err != nil {
581
596
return rgName , accountName , accountKey , containerName , authEnv , err
582
597
}
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
587
601
}
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 )
590
604
return rgName , accountName , accountKey , containerName , authEnv , err
591
605
}
592
606
0 commit comments