2929import org .apache .hadoop .fs .azurebfs .constants .ConfigurationKeys ;
3030import org .apache .hadoop .fs .azurebfs .oauth2 .ClientCredsTokenProvider ;
3131import org .apache .hadoop .fs .azurebfs .oauth2 .MsiTokenProvider ;
32+ import org .apache .hadoop .fs .azurebfs .oauth2 .WorkloadIdentityTokenProvider ;
3233import org .apache .logging .log4j .LogManager ;
3334import org .apache .logging .log4j .Logger ;
3435
4041// For Azure Data Lake Gen1 (adl://)
4142// We support Managed Service Identity & Service Principal
4243// For Azure Data Lake Gen2 (abfs:// & abfss://)
43- // We support Managed Identity & Shared Key & Service Principal
44+ // We support Managed Identity & Shared Key & Service Principal & Workload Identity
4445abstract class AzureStorageCloudCredential implements CloudCredential {
4546
4647 public static final Logger LOG = LogManager .getLogger (AzureStorageCloudCredential .class );
@@ -231,10 +232,11 @@ class AzureADLS2CloudCredential extends AzureStorageCloudCredential {
231232 private final String sasToken ;
232233 private final String oauth2ClientSecret ;
233234 private final String oauth2ClientEndpoint ;
235+ private final String oauth2TokenFile ;
234236
235237 public AzureADLS2CloudCredential (String endpoint , boolean oauth2ManagedIdentity , String oauth2TenantId , String oauth2ClientId ,
236238 String storageAccount , String sharedKey , String sasToken , String oauth2ClientSecret ,
237- String oauth2ClientEndpoint ) {
239+ String oauth2ClientEndpoint , String oauth2TokenFile ) {
238240 Preconditions .checkNotNull (endpoint );
239241 Preconditions .checkNotNull (oauth2TenantId );
240242 Preconditions .checkNotNull (oauth2ClientId );
@@ -243,6 +245,7 @@ public AzureADLS2CloudCredential(String endpoint, boolean oauth2ManagedIdentity,
243245 Preconditions .checkNotNull (sasToken );
244246 Preconditions .checkNotNull (oauth2ClientSecret );
245247 Preconditions .checkNotNull (oauth2ClientEndpoint );
248+ Preconditions .checkNotNull (oauth2TokenFile );
246249
247250 this .endpoint = endpoint ;
248251 this .oauth2ManagedIdentity = oauth2ManagedIdentity ;
@@ -253,6 +256,7 @@ public AzureADLS2CloudCredential(String endpoint, boolean oauth2ManagedIdentity,
253256 this .sasToken = sasToken ;
254257 this .oauth2ClientSecret = oauth2ClientSecret ;
255258 this .oauth2ClientEndpoint = oauth2ClientEndpoint ;
259+ this .oauth2TokenFile = oauth2TokenFile ;
256260
257261 tryGenerateConfigurationMap ();
258262 }
@@ -315,6 +319,18 @@ void tryGenerateConfigurationMap() {
315319 oauth2ClientSecret );
316320 generatedConfigurationMap .put (createConfigKey (ConfigurationKeys .FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT ),
317321 oauth2ClientEndpoint );
322+ } else if (!oauth2TokenFile .isEmpty () && !oauth2TenantId .isEmpty () && !oauth2ClientId .isEmpty ()) {
323+ generatedConfigurationMap .put (createConfigKey (ConfigurationKeys .FS_AZURE_ACCOUNT_AUTH_TYPE_PROPERTY_NAME ),
324+ "OAuth" );
325+ generatedConfigurationMap .put (
326+ createConfigKey (ConfigurationKeys .FS_AZURE_ACCOUNT_TOKEN_PROVIDER_TYPE_PROPERTY_NAME ),
327+ WorkloadIdentityTokenProvider .class .getName ());
328+ generatedConfigurationMap .put (createConfigKey (ConfigurationKeys .FS_AZURE_ACCOUNT_OAUTH_TOKEN_FILE ),
329+ oauth2TokenFile );
330+ generatedConfigurationMap .put (createConfigKey (ConfigurationKeys .FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID ),
331+ oauth2ClientId );
332+ generatedConfigurationMap .put (createConfigKey (ConfigurationKeys .FS_AZURE_ACCOUNT_OAUTH_MSI_TENANT ),
333+ oauth2TenantId );
318334 }
319335 }
320336
@@ -328,6 +344,7 @@ public String toCredString() {
328344 ", sharedKey='" + sharedKey + '\'' +
329345 ", oauth2ClientSecret='" + oauth2ClientSecret + '\'' +
330346 ", oauth2ClientEndpoint='" + oauth2ClientEndpoint + '\'' +
347+ ", oauth2TokenFile='" + oauth2TokenFile + '\'' +
331348 '}' ;
332349 }
333350
0 commit comments