Skip to content

Commit ca25b1b

Browse files
authored
HADOOP-19535: S3A: Support WebIdentityTokenFileCredentialsProvider
Support authentication through WebIdentityTokenFileCredentialsProvider, Syed Shameerur Rahman
1 parent ed05d79 commit ca25b1b

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/AWSCredentialProviderList.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ public AwsCredentials resolveCredentials() {
198198
lastException = e;
199199
LOG.debug("No credentials provided by {}: {}",
200200
provider, e.toString(), e);
201+
} catch (Exception e) {
202+
// convert any other exception into SDKException.
203+
// This is required because some credential provider like
204+
// WebIdentityTokenFileCredentialsProvider might throw
205+
// exceptions other than SdkException.
206+
if (e.getMessage() != null) {
207+
lastException = SdkException.create(e.getMessage(), e);
208+
}
209+
LOG.debug("No credentials provided by {}: {}",
210+
provider, e.toString(), e);
201211
}
202212
}
203213

hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/authentication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ There are also many in the Amazon SDKs, with the common ones being as follows
184184
| `software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider` | AWS Environment Variables |
185185
| `software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider` | EC2 Metadata Credentials |
186186
| `software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider` | EC2/k8s Metadata Credentials |
187+
| `software.amazon.awssdk.auth.credentials.WebIdentityTokenFileCredentialsProvider`| K8s Metadata Credentials |
187188

188189

189190

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AAWSCredentialsProvider.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ public void testDefaultChain() throws Exception {
187187
assertCredentialProviders(expectedClasses, list2);
188188
}
189189

190+
@Test
191+
public void testNonSdkExceptionConversion() throws Throwable {
192+
// Create a mock credential provider that throws a non-SDK exception
193+
AwsCredentialsProvider mockProvider = () -> {
194+
throw new RuntimeException("Test credential error");
195+
};
196+
197+
// Create the provider list with our mock provider
198+
AWSCredentialProviderList providerList =
199+
new AWSCredentialProviderList(Collections.singletonList(mockProvider));
200+
201+
// Attempt to get credentials, which should trigger the exception
202+
intercept(NoAuthWithAWSException.class,
203+
"No AWS Credentials provided",
204+
() -> providerList.resolveCredentials());
205+
}
206+
190207
@Test
191208
public void testDefaultChainNoURI() throws Exception {
192209
Configuration conf = new Configuration(false);

0 commit comments

Comments
 (0)