Skip to content
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

Adding identity provider source to user agent string #5029

Conversation

cenedhryn
Copy link
Contributor

Motivation and Context

This PR adds the identity source (which credentials provider that was used to resolve the identity / credentials) to the user agent string.

The provider of the identity is added to the cfg part of the user agent as an auth-source. Auth source is a new section and not ratified in any specification, but should be parseable by the ua metrics system.

We choose to add a short form of the credentials provider class as an identifier for now. This can easily be changed as the requirements for the user agent string format and contents are changed, and is backwards compatible.

In this PR, credential providers are represented by theStaticCredentialsProvider. A follow up PR will have implementations for all other credentials providers.

Modifications

  • Adds a provider name to StaticCredentialsProvider
  • Adds this name to the identity returned by the provider. Because this credentials provider returns externally created objects, it will make a copy of the object and add the provider string to the builder.
  • In the ApplyUserAgentStage, the SDK adds the identity source to the user agent string if present.
  • The value of the identity source is validated and in most cases transformed.
    • It's mapped to known values in order to get a shorter form of the name. StaticCredentialsProvider <-> STAT
    • If the value is not known, it will be added as-is if it
      • contains known characters
      • is shorter than 62 characters (our longest credentials provider has a class name of 47 characters)
      • ends with provider (debatable)

Q. Why not add the short name to the provider class

Most providers contain a toString that prints the name. There's a value in getting the complete name of the provider. In addition, in the future we may not use this short form as the usage of the UA string evolves

Q. How is this addition compatible with the proposed changes to the UA string?

When the SDK adds feature ID to the UA string, the value written to the identity by each provider can be changed to a different value, such as a string digit.

@cenedhryn cenedhryn requested a review from a team as a code owner March 20, 2024 18:10

for (IdentityProviderNameMapping provider : values()) {
if (provider.value().equals(value)) {
return Optional.of(provider.name());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaning towards using the lower case variant of the enum, stat instead of STAT.

}

private static String sanitizedProviderOrNull(String value) {
if (containsAllowedCharacters(value) && value.toLowerCase(Locale.US).endsWith("provider")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding provider as a criteria may be too narrow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided offline to remove this criterion

Copy link

sonarcloud bot commented Mar 20, 2024


private static <T extends Identity> Optional<String> providerNameFromIdentity(SelectedAuthScheme<T> selectedAuthScheme) {
CompletableFuture<? extends T> identityFuture = selectedAuthScheme.identity();
T identity = CompletableFutureUtils.joinLikeSync(identityFuture);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is another place where we are making it wait for a future. Do we just want to add a comment indicating that we are blocking here and we eventually would need to remove this ?

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 don't think it's necessary; it's easy to search for this in the code and that's something we'd have to do anyway when we've unblocked async identity handling.

import software.amazon.awssdk.utils.Logger;
import software.amazon.awssdk.utils.StringUtils;
import software.amazon.awssdk.utils.http.SdkHttpUtils;

/**
* Apply any custom user agent supplied, otherwise instrument the user agent with info about the SDK and environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would help to have some Javadoc

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 think I removed it because I had started a refactoring. Added a new text back.

*/
public enum IdentityProviderNameMapping {

SYS("SystemPropertyCredentialsProvider"),
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, would be great to expose these abbreviations to our internal users to avoid any confusions as to which abbreviation maps to which provider (probably in a separate action item)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be addressed when parsing the metrics.

@cenedhryn cenedhryn merged commit 46d3707 into feature/master/credentials-source Mar 22, 2024
6 of 16 checks passed
cenedhryn added a commit that referenced this pull request Apr 2, 2024
* Adding source to identity (provider name) (#5008)

* Adding identity provider source to user agent string (#5029)

* Adds provider name to all SDK identity providers (#5040)
@cenedhryn cenedhryn deleted the salande/credentials-source-add-agent branch May 13, 2024 00:52
akidambisrinivasan pushed a commit to akidambisrinivasan/aws-sdk-java-v2 that referenced this pull request Jun 28, 2024
* Adding source to identity (provider name) (aws#5008)

* Adding identity provider source to user agent string (aws#5029)

* Adds provider name to all SDK identity providers (aws#5040)
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.

2 participants