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 5 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

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

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.

Endpoint Region Endpoints 2.0 Metadata Environment Config File Code Result
us-west-2 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 n/a n/a us-west-2
us-west-2 * n/a us-west-2 n/a us-west-2
us-west-2 * n/a n/a us-west-2 us-west-2
us-west-2 n/a * us-west-2 n/a 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
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 n/a us-west-2, us-east-1
us-west-2 n/a us-west-2, us-east-1 n/a n/a us-west-2, us-east-1
us-west-2 n/a n/a us-west-2, us-east-1 n/a us-west-2, us-east-1
us-west-2 n/a n/a n/a us-west-2, us-east-1 us-west-2, us-east-1

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)

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

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).

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.

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