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

Override RegionSet in EnpointResolverInterceptor after fetching the Signing Properties from Endpoint rules #5825

Open
wants to merge 6 commits into
base: feature/master/multi-auth-sigv4a
Choose a base branch
from

Conversation

joviegas
Copy link
Contributor

@joviegas joviegas commented Jan 26, 2025

Motivation and Context

  • Currently, sigv4a is is resolved as floows
  1. In finalizeAwsConfiguration() of AwsClientOption.AWS_SIGV4A_SIGNING_REGION_SET we resolveSigv4aRegionSet in folllowing order
    private Set<String> resolveSigv4aRegionSet(LazyValueSource config) {
        Supplier<ProfileFile> profileFile = config.get(SdkClientOption.PROFILE_FILE_SUPPLIER);
        String profileName = config.get(SdkClientOption.PROFILE_NAME);
        return Sigv4aSigningRegionSetProvider.builder()
                                             .profileFile(profileFile)
                                             .profileName(profileName)
                                             .build()
                                             .resolveRegionSet();
    }

  1. In AwsExecutionContextBuilder we update AwsExecutionAttribute.AWS_SIGV4A_SIGNING_REGION_SET from AwsClientOption.AWS_SIGV4A_SIGNING_REGION_SET
  2. Then in ServiceAuthSchemeInterceptor we update the authSchemeParams from above and then can call resolveAuthScheme where the Auth option is updated with this option
  3. Then In ServiceResolveEndpointInterceptor will then resolve based on this PR

Modifications

  • Modified the code where we override the Auth Scheme properties to make sure we follow above table for Sigv4a
  • Also added changes to support new mult-auth launched services which will not have deprecated "authType" trait.

Testing

  • Codegen changes to verify Generated interceptors are generated as required.
  • Added signer test to make sure properties get overridden after Endpoint resolution

Screenshots (if appropriate)

Appendix

The Sigv4a signing region set should be resolved based on below specifications

Sigv4a signing region set resolution

Configuration follows the same resolution order as other client configuration
options, where more specific configuration is preferred over less specific. The
following table shows cases that demonstrate this. Each column except for
Result shows a source for the signing region set, and Result is the value
that should be used. Note that * indcates the request is valid in all regions.

Code Environment Config File Endpoints 2.0 Metadata Endpoint Region Result
n/a n/a n/a n/a us-west-2 us-west-2
n/a n/a n/a * us-west-2 *
n/a * n/a n/a us-west-2 *
n/a n/a * n/a us-west-2 *
* n/a n/a n/a us-west-2 *
us-west-2 us-west-2 n/a * us-west-2 us-west-2
us-west-2 n/a us-west-2 * us-west-2 us-west-2
us-west-2 n/a n/a * us-west-2 us-west-2
us-west-2 * us-west-2 n/a us-west-2 us-west-2
us-west-2 * n/a n/a us-west-2 us-west-2
us-west-2 n/a * n/a us-west-2 us-west-2
n/a n/a n/a n/a us-west-2 us-west-2
us-west-2, us-east-1 n/a n/a us-west-2, us-east-1 us-west-2 us-west-2, us-east-1
us-west-2, us-east-1 us-west-2, us-east-1 n/a n/a us-west-2 us-west-2, us-east-1
us-west-2, us-east-1 n/a us-west-2, us-east-1 n/a us-west-2 us-west-2, us-east-1
us-west-2, us-east-1 n/a n/a n/a us-west-2 us-west-2, us-east-1

License

  • I confirm that this pull request can be released under the Apache 2 license

@joviegas joviegas requested a review from a team as a code owner January 26, 2025 05:49
@joviegas joviegas force-pushed the joviegas/resolve-regioset-after-endpoints branch from e5fb5b7 to 5953fdf Compare January 26, 2025 20:26
@@ -187,8 +201,7 @@ public void async_endpointProviderReturnsHeaders_appendedToExistingRequest() {
assertThat(interceptor.context.httpRequest().matchingHeaders("TestHeader")).containsExactly("TestValue", "TestValue0");
}

// TODO(sra-identity-auth): Enable for useSraAuth=true
/*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uncommented these test cases

@@ -74,7 +74,8 @@ public static Metadata constructMetadata(ServiceModel serviceModel,
.withJsonVersion(serviceMetadata.getJsonVersion())
.withEndpointPrefix(serviceMetadata.getEndpointPrefix())
.withSigningName(serviceMetadata.getSigningName())
.withAuthType(AuthType.fromValue(serviceMetadata.getSignatureVersion()))
.withAuthType(serviceMetadata.getSignatureVersion() != null ?
Copy link
Contributor

Choose a reason for hiding this comment

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

When can this be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The specifications states

The authType and signatureVersion traits will be deprecated in favor of the auth and unsignedPayload traits.

Thus for new services which will be completed based on multi-auth signatureVersion will be null.
I added a test case for in codegen-tst when a new service is added with just multi-auth supporting only sigv4a

@@ -219,7 +227,11 @@ private MethodSpec modifyRequestMethod(String endpointAuthSchemeStrategyFieldNam
SelectedAuthScheme.class, SdkInternalExecutionAttribute.class);
b.beginControlFlow("if (endpointAuthSchemes != null && selectedAuthScheme != null)");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is selectedAuthScheme ever null nowadays? It feels like this should be a dead code branch 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.

Removed this check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad , we need this check , the S3 integ test failed , will revert this

java.lang.NullPointerException: Cannot invoke "software.amazon.awssdk.core.SelectedAuthScheme.authSchemeOption()" because "selectedAuthScheme" is null
    at software.amazon.awssdk.services.s3.endpoints.internal.S3ResolveEndpointInterceptor.authSchemeWithEndpointSignerProperties(S3ResolveEndpointInterceptor.java:1383)
    at software.amazon.awssdk.services.s3.endpoints.internal.S3ResolveEndpointInterceptor.modifyRequest(S3ResolveEndpointInterceptor.java:177)
    at software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain.modifyRequest(ExecutionInterceptorC

Comment on lines 799 to 803
if (multiAuthSigv4a) {
code.beginControlFlow("if (!hasRegionSet(selectedAuthScheme) && v4aAuthScheme.signingRegionSet() != null)");
} else {
code.beginControlFlow("if (v4aAuthScheme.signingRegionSet() != null)");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

hasRegionSet seems like a relatively small method. Same with updateAuthSchemeWithRegionSet. Do we want to just always generate those methods, so that we don't have to do this branching in the code generator? It feels simpler to have a single code path regardless of sigv4a or sigv4 (both in the code generator, and in the generated code).

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 have made updateAuthSchemeWithRegionSet and hasRegionSet inline. The reason I added a specific check for multiAuthSigv4a is because for non-Sigv4a existing features, that check is dead code and might confuse readers of generated packages while debugging or during code walks.

Comment on lines 137 to 140
if (!hasRegionSet(selectedAuthScheme) && v4aAuthScheme.signingRegionSet() != null) {
RegionSet regionSet = RegionSet.create(v4aAuthScheme.signingRegionSet());
option.putSignerProperty(AwsV4aHttpSigner.REGION_SET, regionSet);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm remembering the priorities right from the discussion with Alex, the endpoint provider's setting takes precedence over the auth scheme resolver's setting. This looks like we're favoring the auth scheme resolver. Am I misreading or misremembering?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The discussion covered two distinct concepts: Signing Region and RegionSet. The current implementation specifically addresses SigV4a RegionSet, where Endpoint Parameters have the lowest precedence according to the Multi-auth specification. The precedence order is documented in the attached table.

Copy link
Contributor

Choose a reason for hiding this comment

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

The table doesn't include the auth scheme resolver. In the discussion with Alex, when we added that, endpoint resolver came out higher than auth scheme resolver.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated a comment

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
7.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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