Skip to content

Commit 61b2df2

Browse files
committed
HADOOP-16470. Make last AWS credential provider in default auth chain EC2ContainerCredentialsProviderWrapper.
Contributed by Steve Loughran. Contains HADOOP-16471. Restore (documented) fs.s3a.SharedInstanceProfileCredentialsProvider. Change-Id: I06b99b57459cac80bf743c5c54f04e59bb54c2f8
1 parent 69ddb36 commit 61b2df2

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

hadoop-common-project/hadoop-common/src/main/resources/core-default.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,8 @@
10921092
configuration of AWS access key ID and secret access key in
10931093
environment variables named AWS_ACCESS_KEY_ID and
10941094
AWS_SECRET_ACCESS_KEY, as documented in the AWS SDK.
1095-
* com.amazonaws.auth.InstanceProfileCredentialsProvider: supports use
1096-
of instance profile credentials if running in an EC2 VM.
1095+
* org.apache.hadoop.fs.s3a.auth.IAMInstanceCredentialsProvider: picks up
1096+
IAM credentials of any EC2 VM or AWS container in which the process is running.
10971097
</description>
10981098
</property>
10991099

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.hadoop.fs.s3a;
20+
21+
import org.apache.hadoop.classification.InterfaceAudience;
22+
import org.apache.hadoop.classification.InterfaceStability;
23+
import org.apache.hadoop.fs.s3a.auth.IAMInstanceCredentialsProvider;
24+
import org.apache.hadoop.fs.s3a.auth.NoAwsCredentialsException;
25+
26+
/**
27+
* This credential provider has jittered between existing and non-existing,
28+
* but it turns up in documentation enough that it has been restored.
29+
* It extends {@link IAMInstanceCredentialsProvider} to pick up its
30+
* bindings, which are currently to use the
31+
* {@code EC2ContainerCredentialsProviderWrapper} class for IAM and container
32+
* authentication.
33+
* <p>
34+
* When it fails to authenticate, it raises a
35+
* {@link NoAwsCredentialsException} which can be recognized by retry handlers
36+
* as a non-recoverable failure.
37+
* <p>
38+
* It is implicitly public; marked evolving as we can change its semantics.
39+
*/
40+
@InterfaceAudience.Public
41+
@InterfaceStability.Evolving
42+
public final class SharedInstanceCredentialProvider extends
43+
IAMInstanceCredentialsProvider {
44+
}

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,44 @@
2424
import com.amazonaws.AmazonClientException;
2525
import com.amazonaws.auth.AWSCredentials;
2626
import com.amazonaws.auth.AWSCredentialsProvider;
27-
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
27+
import com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper;
2828

2929
import org.apache.hadoop.classification.InterfaceAudience;
3030
import org.apache.hadoop.classification.InterfaceStability;
3131

3232
/**
33-
* This is going to be an IAM credential provider which performs
34-
* async refresh for lower-latency on IO calls.
35-
* Initially it does not do this, simply shares the single IAM instance
36-
* across all instances. This makes it less expensive to declare.
37-
*
33+
* This is an IAM credential provider which wraps
34+
* an {@code EC2ContainerCredentialsProviderWrapper}
35+
* to provide credentials when the S3A connector is instantiated on AWS EC2
36+
* or the AWS container services.
37+
* <p>
38+
* When it fails to authenticate, it raises a
39+
* {@link NoAwsCredentialsException} which can be recognized by retry handlers
40+
* as a non-recoverable failure.
41+
* <p>
42+
* It is implicitly public; marked evolving as we can change its semantics.
3843
*/
39-
@InterfaceAudience.Private
40-
@InterfaceStability.Unstable
44+
@InterfaceAudience.Public
45+
@InterfaceStability.Evolving
4146
public class IAMInstanceCredentialsProvider
4247
implements AWSCredentialsProvider, Closeable {
4348

44-
private static final InstanceProfileCredentialsProvider INSTANCE =
45-
InstanceProfileCredentialsProvider.getInstance();
49+
private final AWSCredentialsProvider provider =
50+
new EC2ContainerCredentialsProviderWrapper();
4651

4752
public IAMInstanceCredentialsProvider() {
4853
}
4954

5055
/**
5156
* Ask for the credentials.
52-
* as it invariably means "you aren't running on EC2"
57+
* Failure invariably means "you aren't running in an EC2 VM or AWS container".
5358
* @return the credentials
59+
* @throws NoAwsCredentialsException on auth failure to indicate non-recoverable.
5460
*/
5561
@Override
5662
public AWSCredentials getCredentials() {
5763
try {
58-
return INSTANCE.getCredentials();
64+
return provider.getCredentials();
5965
} catch (AmazonClientException e) {
6066
throw new NoAwsCredentialsException("IAMInstanceCredentialsProvider",
6167
e.getMessage(),
@@ -65,11 +71,11 @@ public AWSCredentials getCredentials() {
6571

6672
@Override
6773
public void refresh() {
68-
INSTANCE.refresh();
74+
provider.refresh();
6975
}
7076

7177
@Override
7278
public void close() throws IOException {
73-
// until async, no-op.
79+
// no-op.
7480
}
7581
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ This means that the default S3A authentication chain can be defined as
539539
configuration of AWS access key ID and secret access key in
540540
environment variables named AWS_ACCESS_KEY_ID and
541541
AWS_SECRET_ACCESS_KEY, as documented in the AWS SDK.
542-
* com.amazonaws.auth.InstanceProfileCredentialsProvider: supports use
543-
of instance profile credentials if running in an EC2 VM.
542+
* org.apache.hadoop.fs.s3a.auth.IAMInstanceCredentialsProvider: picks up
543+
IAM credentials of any EC2 VM or AWS container in which the process is running.
544544
</description>
545545
</property>
546546
```

0 commit comments

Comments
 (0)