-
Notifications
You must be signed in to change notification settings - Fork 9.1k
HADOOP-18945. S3A: IAMInstanceCredentialsProvider failing. #6202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
steveloughran
merged 5 commits into
apache:trunk
from
steveloughran:s3/HADOOP-18945-IAMInstanceCredentialsProvider
Oct 23, 2023
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
433ce77
HADOOP-18945. S3A: IAMInstanceCredentialsProvider failing.
steveloughran 8d3bff9
HADOOP-18945. S3A: IAMInstanceCredentialsProvider failing.
steveloughran 922f82a
HADOOP-18945. Review comments
steveloughran 55297c1
HADOOP-18945. IDE warns of unused variable
steveloughran 9f2ffea
HADOOP-18945. incomplete javadoc comment
steveloughran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...p-aws/src/test/java/org/apache/hadoop/fs/s3a/auth/TestIAMInstanceCredentialsProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.fs.s3a.auth; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.Test; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import software.amazon.awssdk.auth.credentials.AwsCredentials; | ||
|
|
||
| import org.apache.hadoop.test.AbstractHadoopTestBase; | ||
|
|
||
| /** | ||
| * Unit tests for IAMInstanceCredentials provider. | ||
| * This is a bit tricky as we don't want to require running in EC2, | ||
| * but nor do we want a test which doesn't work in EC2. | ||
| */ | ||
| public class TestIAMInstanceCredentialsProvider extends AbstractHadoopTestBase { | ||
steveloughran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(TestIAMInstanceCredentialsProvider.class); | ||
|
|
||
| /** | ||
| * Error string from | ||
| * software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider, | ||
| * if IAM resolution has been disabled: {@value}. | ||
| */ | ||
| public static final String DISABLED = | ||
| "IMDS credentials have been disabled by environment variable or system property"; | ||
|
|
||
| /** | ||
| * Test an immediate create/close. | ||
| */ | ||
| @Test | ||
| public void testIAMInstanceCredentialsProviderClose() throws Throwable { | ||
| new IAMInstanceCredentialsProvider().close(); | ||
| } | ||
|
|
||
| /** | ||
| * Test instantiation. | ||
| * Multiple outcomes depending on host setup. | ||
| * <ol> | ||
| * <li> In EC2: credentials resolved. | ||
| * Assert the credentials comes with a key.</li> | ||
| * <li> Not in EC2: NoAwsCredentialsException wraps network error trying | ||
| * to talk to the service. | ||
| * Assert wrapped exception is an IOE.</li> | ||
| * <li> IMDS resolution disabled by env var/sysprop. | ||
| * NoAwsCredentialsException raised doesn't contain an IOE. | ||
| * Require the message to contain the {@link #DISABLED} text.</li>j | ||
| * </ol> | ||
| */ | ||
| @Test | ||
| public void testIAMInstanceCredentialsInstantiate() throws Throwable { | ||
| try (IAMInstanceCredentialsProvider provider = new IAMInstanceCredentialsProvider()) { | ||
| try { | ||
| final AwsCredentials credentials = provider.resolveCredentials(); | ||
| // if we get here this test suite is running in a container/EC2 | ||
| LOG.info("Credentials: retrieved from {}: key={}", | ||
| provider.isContainerCredentialsProvider() ? "container" : "EC2", | ||
| credentials.accessKeyId()); | ||
| Assertions.assertThat(credentials.accessKeyId()) | ||
| .describedAs("Access key from IMDS") | ||
| .isNotBlank(); | ||
|
|
||
| // and if we get here, so does a second call | ||
| provider.resolveCredentials(); | ||
| } catch (NoAwsCredentialsException expected) { | ||
| // this is expected if the test is not running in a container/EC2 | ||
| LOG.info("Not running in a container/EC2"); | ||
| LOG.info("Exception raised", expected); | ||
| // and we expect to have fallen back to InstanceProfileCredentialsProvider | ||
| Assertions.assertThat(provider.isContainerCredentialsProvider()) | ||
| .describedAs("%s: shoud be using InstanceProfileCredentialsProvider") | ||
| .isFalse(); | ||
| final Throwable cause = expected.getCause(); | ||
| if (cause == null) { | ||
| throw expected; | ||
| } | ||
| if (!(cause instanceof IOException) | ||
| && !cause.toString().contains(DISABLED)) { | ||
| throw new AssertionError("Cause not a IOException", cause); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this have been synchronized from the start?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, because it was creating and collecting credentials on every call. so if multiple requests came in, it instantiated new ones and did new HTTP calls. inefficient and clearl a bit brittle. now we want to only have one instance which we close() after