-
Notifications
You must be signed in to change notification settings - Fork 999
Fix S3Express utils and tests for auth scheme resolution pipeline migration #6947
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,10 +17,13 @@ | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import static software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute.SELECTED_AUTH_SCHEME; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.core.SdkRequest; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.core.SelectedAuthScheme; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.core.spi.identity.AuthSchemeOptionsResolver; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.core.useragent.BusinessMetricFeatureId; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.endpoints.Endpoint; | ||||||||||||||||||||||||||||||||||||||||||
| import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption; | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -31,26 +34,37 @@ | |||||||||||||||||||||||||||||||||||||||||
| public final class S3ExpressUtils { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| public static final String S3_EXPRESS = "S3Express"; | ||||||||||||||||||||||||||||||||||||||||||
| private static final String S3_EXPRESS_BUCKET_SUFFIX = "--x-s3"; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private S3ExpressUtils() { | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Returns true if the resolved endpoint contains S3Express, else false. | ||||||||||||||||||||||||||||||||||||||||||
| * Determines if this request targets an S3Express bucket by checking the bucket name suffix. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| public static boolean useS3Express(ExecutionAttributes executionAttributes) { | ||||||||||||||||||||||||||||||||||||||||||
| Endpoint endpoint = executionAttributes.getAttribute(SdkInternalExecutionAttribute.RESOLVED_ENDPOINT); | ||||||||||||||||||||||||||||||||||||||||||
| if (endpoint != null) { | ||||||||||||||||||||||||||||||||||||||||||
| String useS3Express = endpoint.attribute(KnownS3ExpressEndpointProperty.BACKEND); | ||||||||||||||||||||||||||||||||||||||||||
| return S3_EXPRESS.equals(useS3Express); | ||||||||||||||||||||||||||||||||||||||||||
| public static boolean isS3ExpressBucket(SdkRequest request) { | ||||||||||||||||||||||||||||||||||||||||||
| return request.getValueForField("Bucket", String.class) | ||||||||||||||||||||||||||||||||||||||||||
| .map(b -> b.endsWith(S3_EXPRESS_BUCKET_SUFFIX)) | ||||||||||||||||||||||||||||||||||||||||||
| .orElse(false); | ||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit/Not blocking query: The endpoint ruleset aws-sdk-java-v2/services/s3/src/main/resources/codegen-resources/endpoint-rule-set.json Lines 261 to 280 in 2619c3d
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah makes sense, added tests for this. |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Determines if this request uses S3Express auth by checking the auth scheme options. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| public static boolean isS3ExpressAuthRequest(SdkRequest request, ExecutionAttributes executionAttributes) { | ||||||||||||||||||||||||||||||||||||||||||
| AuthSchemeOptionsResolver resolver = | ||||||||||||||||||||||||||||||||||||||||||
| executionAttributes.getAttribute(SdkInternalExecutionAttribute.AUTH_SCHEME_OPTIONS_RESOLVER); | ||||||||||||||||||||||||||||||||||||||||||
| if (resolver != null) { | ||||||||||||||||||||||||||||||||||||||||||
| List<AuthSchemeOption> options = resolver.resolve(request); | ||||||||||||||||||||||||||||||||||||||||||
| return options.stream().anyMatch(o -> S3ExpressAuthScheme.SCHEME_ID.equals(o.schemeId())); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Whether aws.auth#sigv4-s3express is used or not | ||||||||||||||||||||||||||||||||||||||||||
| * Whether aws.auth#sigv4-s3express is the selected auth scheme. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| public static boolean useS3ExpressAuthScheme(ExecutionAttributes executionAttributes) { | ||||||||||||||||||||||||||||||||||||||||||
| private static boolean useS3ExpressAuthScheme(ExecutionAttributes executionAttributes) { | ||||||||||||||||||||||||||||||||||||||||||
| SelectedAuthScheme<?> selectedAuthScheme = executionAttributes.getAttribute(SELECTED_AUTH_SCHEME); | ||||||||||||||||||||||||||||||||||||||||||
| if (selectedAuthScheme != null) { | ||||||||||||||||||||||||||||||||||||||||||
| AuthSchemeOption authSchemeOption = selectedAuthScheme.authSchemeOption(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -62,8 +76,10 @@ public static boolean useS3ExpressAuthScheme(ExecutionAttributes executionAttrib | |||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Adds S3 Express business metric if applicable for the current operation. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| public static void addS3ExpressBusinessMetricIfApplicable(ExecutionAttributes executionAttributes) { | ||||||||||||||||||||||||||||||||||||||||||
| if (executionAttributes != null && useS3Express(executionAttributes) && useS3ExpressAuthScheme(executionAttributes)) { | ||||||||||||||||||||||||||||||||||||||||||
| public static void addS3ExpressBusinessMetricIfApplicable(Endpoint endpoint, ExecutionAttributes executionAttributes) { | ||||||||||||||||||||||||||||||||||||||||||
| if (endpoint != null && executionAttributes != null | ||||||||||||||||||||||||||||||||||||||||||
| && S3_EXPRESS.equals(endpoint.attribute(KnownS3ExpressEndpointProperty.BACKEND)) | ||||||||||||||||||||||||||||||||||||||||||
| && useS3ExpressAuthScheme(executionAttributes)) { | ||||||||||||||||||||||||||||||||||||||||||
| executionAttributes.getOptionalAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS) | ||||||||||||||||||||||||||||||||||||||||||
| .ifPresent(businessMetrics -> | ||||||||||||||||||||||||||||||||||||||||||
| businessMetrics.addMetric(BusinessMetricFeatureId.S3_EXPRESS_BUCKET.value())); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
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.
The previous code checked SELECTED_AUTH_SCHEME, which is set by
S3AuthSchemeInterceptor.beforeExecution. The new isS3ExpressAuthRequestdepends on AUTH_SCHEME_OPTIONS_RESOLVER being available. If null, it silently returns false.
Do we have tests verifying USE_S3_EXPRESS_AUTH is correctly set in the CRT path for:
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.
We dont have any currently, added tests for these cases.