Skip to content

Adds accountId to STS credentials providers #4040

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

Conversation

cenedhryn
Copy link
Contributor

Motivation and Context

STS provides accountId in the ARN of the assumedRoleUser included in its response objects. This PR extracts that accountId, if present, and adds it to the credentials identity.

Resolving credentials end-to-end should work once credentials are resolved before the endpoint.

Modifications

  • Added accountId to AwsBasicCredentials and AwsSessionCredentials since the credentials providers use those classes.
  • Modified STS providers to find accountId in the response and add it to the returned credentials

Testing

Added codegen classes test to verify that the accountId is available to the endpoint resolution logic. Because we currently resolve the endpoint before we resolve credentials, this test is not working.

@cenedhryn cenedhryn requested a review from a team as a code owner May 25, 2023 23:33
@cenedhryn cenedhryn force-pushed the salande/accountid-add-sts branch from 540597a to d9a4675 Compare May 25, 2023 23:36
@@ -123,7 +124,16 @@ public Duration prefetchTime() {
/**
* Implemented by a child class to call STS and get a new set of credentials to be used by this provider.
*/
protected abstract Credentials getUpdatedCredentials(StsClient stsClient);
protected abstract SessionCredentialsHolder getUpdatedCredentials(StsClient stsClient);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically backwards-incompatible since this is a public class. That said, it was only recently made public so it's probably not a problem.

SessionCredentialsHolder isn't a public type, though, so we probably shouldn't expose it on a protected method of a public class. Is there a better way to get the credential information up to this type? Maybe just have the subtypes return AwsSessionCredentials directly? Add the optional expiration to AwsSessionCredentials as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit confused by the public part, because that change went out at the same time that this PR was created.
Changing signature to AwsSessionCredentials - note that the code does not use SessionCredentialsHolder anymore, the RefreshResult uses . If this change is approved, we can remove SessionCredentialsHolder from the public PR (the non-identity non-accountId changes should probably be punted to master asap before customers have more time to use the newly public class)

* This should be accessed via {@link AnonymousCredentialsProvider#resolveCredentials()}.
*/
@SdkInternalApi
static final AwsBasicCredentials ANONYMOUS_CREDENTIALS = new AwsBasicCredentials(null, null, false);
static final AwsBasicCredentials ANONYMOUS_CREDENTIALS = builder().validateCredentials(Boolean.FALSE).build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/Boolean.FALSE/false


if (validateCredentials) {
if (Boolean.TRUE.equals(builder.validateCredentials)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can be if (builder.validateCredentials) { if it is changed to boolean

@@ -27,22 +27,48 @@
@SdkInternalApi
@ThreadSafe
final class SessionCredentialsHolder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this anymore, since the expiration is in the session credentials now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be removed in subsequent PRs.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 2, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 4 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 123 Code Smells

65.3% 65.3% Coverage
2.6% 2.6% Duplication

/**
* Whether this class should verify that accessKeyId and secretAccessKey are not null.
*/
Builder validateCredentials(Boolean validateCredentials) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think this can be boolean too.

return Optional.ofNullable(accountId);
}

public Optional<Instant> expiration() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this makes sense to add to this interface, why not add it to AwsSessionCredentialsIdentity and @Override here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the top Identity interface already defines expirationTime(), which is what we should use.

@cenedhryn cenedhryn merged commit f7df929 into feature/master/accountid-endpoint-routing Jun 2, 2023
@cenedhryn cenedhryn deleted the salande/accountid-add-sts branch June 2, 2023 15:36
cenedhryn added a commit that referenced this pull request Apr 17, 2024
Adds accountId to STS credentials providers
cenedhryn added a commit that referenced this pull request Apr 22, 2024
…5119)

* Adds account ID as a built-in endpoint parameter (#4016)

* Refactors credential identity with separate implementing classes (#4024) (#4028)

* Adds accountId as a parameter to AWS credentials identity (#4029)

* Adds accountId to STS credentials providers (#4040)

* Adding accountId support to environment variable credential provider (#4327)

* Adds accountId support to process credentials provider (#4332)

* Adds account ID support for profile credentials provider sources (#4340)

* Adds accountId endpoint mode (#4984)

* Adding back existing endpoint files (#5120)

* changelog (#5121)
akidambisrinivasan pushed a commit to akidambisrinivasan/aws-sdk-java-v2 that referenced this pull request Jun 28, 2024
…ws#5119)

* Adds account ID as a built-in endpoint parameter (aws#4016)

* Refactors credential identity with separate implementing classes (aws#4024) (aws#4028)

* Adds accountId as a parameter to AWS credentials identity (aws#4029)

* Adds accountId to STS credentials providers (aws#4040)

* Adding accountId support to environment variable credential provider (aws#4327)

* Adds accountId support to process credentials provider (aws#4332)

* Adds account ID support for profile credentials provider sources (aws#4340)

* Adds accountId endpoint mode (aws#4984)

* Adding back existing endpoint files (aws#5120)

* changelog (aws#5121)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants