-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[repository-s3] remove endpointOverride and let AWS SDK V2 S3 determine the s3 url based on bucket name or arn provided #20345
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
Open
cwperks
wants to merge
3
commits into
opensearch-project:main
Choose a base branch
from
cwperks:repository-s3-outposts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+269
−17
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
...ository-s3/src/test/java/org/opensearch/repositories/s3/S3ArnEndpointResolutionTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.repositories.s3; | ||
|
|
||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
| import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
| import software.amazon.awssdk.core.interceptor.Context; | ||
| import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
| import software.amazon.awssdk.core.interceptor.ExecutionInterceptor; | ||
| import software.amazon.awssdk.http.ExecutableHttpRequest; | ||
| import software.amazon.awssdk.http.HttpExecuteRequest; | ||
| import software.amazon.awssdk.http.HttpExecuteResponse; | ||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.s3.S3Client; | ||
| import software.amazon.awssdk.services.s3.S3Configuration; | ||
| import software.amazon.awssdk.services.s3.model.HeadBucketRequest; | ||
|
|
||
| import java.net.URI; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| /** | ||
| * Tests for AWS SDK endpoint resolution behavior for S3 bucket ARNs (Outposts / Access Points), | ||
| * and OpenSearch repository-s3 behavior around endpoint overrides. | ||
| * | ||
| * These tests are intentionally "no-network": they capture the resolved request URI using an | ||
| * ExecutionInterceptor and abort the request via a failing HTTP client. | ||
| */ | ||
| public class S3ArnEndpointResolutionTests extends AbstractS3RepositoryTestCase { | ||
|
|
||
| private static final StaticCredentialsProvider DUMMY_CREDENTIALS = StaticCredentialsProvider.create( | ||
| AwsBasicCredentials.create("dummy-access-key", "dummy-secret-key") | ||
| ); | ||
|
|
||
| // ---- Helpers ---- | ||
|
|
||
| private static final class CapturingInterceptor implements ExecutionInterceptor { | ||
| private final AtomicReference<URI> captured = new AtomicReference<>(); | ||
| private final AtomicReference<String> capturedSigningName = new AtomicReference<>(); | ||
|
|
||
| @Override | ||
| public void beforeTransmission(Context.BeforeTransmission context, ExecutionAttributes executionAttributes) { | ||
| captured.set(context.httpRequest().getUri()); | ||
| // Capture the signing name from the Authorization header | ||
| // Format: AWS4-HMAC-SHA256 Credential=AKID/20250101/us-east-1/s3-outposts/aws4_request, ... | ||
| context.httpRequest().firstMatchingHeader("Authorization").ifPresent(auth -> { | ||
| int credIdx = auth.indexOf("Credential="); | ||
| if (credIdx >= 0) { | ||
| String[] parts = auth.substring(credIdx).split("/"); | ||
| if (parts.length >= 5) { | ||
| capturedSigningName.set(parts[3]); // service name is 4th part (index 3) | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| URI capturedUri() { | ||
| return captured.get(); | ||
| } | ||
|
|
||
| String capturedSigningName() { | ||
| return capturedSigningName.get(); | ||
| } | ||
| } | ||
|
|
||
| private static SdkHttpClient failingHttpClient() { | ||
| return new SdkHttpClient() { | ||
| @Override | ||
| public ExecutableHttpRequest prepareRequest(HttpExecuteRequest request) { | ||
| return new ExecutableHttpRequest() { | ||
| @Override | ||
| public HttpExecuteResponse call() { | ||
| throw new RuntimeException("stop after endpoint resolution"); | ||
| } | ||
|
|
||
| @Override | ||
| public void abort() { | ||
| // no-op | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| // no-op | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private static void issueNoNetworkRequest(S3Client client, String bucket) { | ||
| try { | ||
| client.headBucket(HeadBucketRequest.builder().bucket(bucket).build()); | ||
| fail("Expected to fail due to no-network http client"); | ||
| } catch (RuntimeException e) { | ||
| // expected | ||
| } | ||
| } | ||
|
|
||
| // ---- SDK contract tests ---- | ||
|
|
||
| public void testSdkResolvesOutpostsEndpointFromBucketArn() { | ||
| // Shape matters more than reality for endpoint logic; account/outpost IDs can be dummy. | ||
| final String bucketArn = "arn:aws:s3-outposts:us-east-1:111122223333:outpost/op-0123456789abcdef/accesspoint/my-ap"; | ||
|
|
||
| final CapturingInterceptor interceptor = new CapturingInterceptor(); | ||
|
|
||
| try ( | ||
| S3Client client = S3Client.builder() | ||
| .region(Region.US_EAST_1) | ||
| .credentialsProvider(DUMMY_CREDENTIALS) | ||
| .serviceConfiguration( | ||
| S3Configuration.builder() | ||
| // Ensure ARN region behavior is enabled; harmless for this test if already defaulted. | ||
| .useArnRegionEnabled(true) | ||
| .build() | ||
| ) | ||
| .overrideConfiguration(ClientOverrideConfiguration.builder().addExecutionInterceptor(interceptor).build()) | ||
| .httpClient(failingHttpClient()) | ||
| // IMPORTANT: do NOT set endpointOverride(...) in these SDK tests. | ||
| .build() | ||
| ) { | ||
|
|
||
| issueNoNetworkRequest(client, bucketArn); | ||
| } | ||
|
|
||
| final URI uri = interceptor.capturedUri(); | ||
| assertNotNull("SDK did not reach beforeTransmission; endpoint not captured", uri); | ||
| assertNotNull(uri.getHost()); | ||
| assertTrue("Expected outposts endpoint but was: " + uri, uri.getHost().contains("s3-outposts")); | ||
|
|
||
| // Verify SDK uses correct signing service for Outposts | ||
| assertEquals("s3-outposts", interceptor.capturedSigningName()); | ||
| } | ||
|
|
||
| public void testSdkResolvesAccessPointEndpointFromBucketArn() { | ||
| final String bucketArn = "arn:aws:s3:us-west-2:111122223333:accesspoint/my-ap"; | ||
|
|
||
| final CapturingInterceptor interceptor = new CapturingInterceptor(); | ||
|
|
||
| try ( | ||
| S3Client client = S3Client.builder() | ||
| .region(Region.US_WEST_2) | ||
| .credentialsProvider(DUMMY_CREDENTIALS) | ||
| .serviceConfiguration(S3Configuration.builder().useArnRegionEnabled(true).build()) | ||
| .overrideConfiguration(ClientOverrideConfiguration.builder().addExecutionInterceptor(interceptor).build()) | ||
| .httpClient(failingHttpClient()) | ||
| .build() | ||
| ) { | ||
|
|
||
| issueNoNetworkRequest(client, bucketArn); | ||
| } | ||
|
|
||
| final URI uri = interceptor.capturedUri(); | ||
| assertNotNull("SDK did not reach beforeTransmission; endpoint not captured", uri); | ||
| assertNotNull(uri.getHost()); | ||
| assertTrue("Expected accesspoint endpoint but was: " + uri, uri.getHost().contains("s3-accesspoint")); | ||
|
|
||
| // Verify SDK uses correct signing service for access points | ||
| assertEquals("s3", interceptor.capturedSigningName()); | ||
| } | ||
|
|
||
| public void testSdkResolvesRegularBucketToRegularS3Endpoint() { | ||
| final String bucket = "my-standard-bucket"; | ||
|
|
||
| final CapturingInterceptor interceptor = new CapturingInterceptor(); | ||
|
|
||
| try ( | ||
| S3Client client = S3Client.builder() | ||
| .region(Region.US_EAST_1) | ||
| .credentialsProvider(DUMMY_CREDENTIALS) | ||
| .overrideConfiguration(ClientOverrideConfiguration.builder().addExecutionInterceptor(interceptor).build()) | ||
| .httpClient(failingHttpClient()) | ||
| .build() | ||
| ) { | ||
|
|
||
| issueNoNetworkRequest(client, bucket); | ||
| } | ||
|
|
||
| final URI uri = interceptor.capturedUri(); | ||
| assertNotNull("SDK did not reach beforeTransmission; endpoint not captured", uri); | ||
| assertNotNull(uri.getHost()); | ||
|
|
||
| final String host = uri.getHost(); | ||
| // Be tolerant across SDK versions/partitions: just assert it isn't ARN-specific routing. | ||
| assertFalse("Unexpected accesspoint host for non-ARN bucket: " + uri, host.contains("s3-accesspoint")); | ||
| assertFalse("Unexpected outposts host for non-ARN bucket: " + uri, host.contains("s3-outposts")); | ||
| assertTrue("Expected some form of S3 host but was: " + uri, host.contains("s3")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
AWS SDK Java issue #2274 endpoint scheme💡 Result:
I can't find an AWS SDK for Java issue numbered 2274. Did you mean the related aws-sdk-java-v2 bug about endpoint scheme handling (issue #5831)? That issue describes S3ClientBuilder throwing a URI/scheme error when an endpoint without "http(s)://" is supplied; the SDK docs require endpointOverride to be a URI with scheme. See the GitHub issue and the SDK docs: [1], [2].
Sources:
🌐 Web query:
AWS SDK Java S3 endpoint override scheme requirement v2💡 Result:
Yes — in AWS SDK for Java v2 the endpointOverride must be a java.net.URI that includes a scheme (e.g., "https://" or "http://"). If you pass a host-only string (no scheme) the S3 client builder will fail with "The URI scheme of endpointOverride must not be null." Use URI.create("https://your-endpoint") when calling endpointOverride.
Minimal example:
S3Client s3 = S3Client.builder()
.region(Region.US_WEST_2)
.endpointOverride(URI.create("https://my-custom-s3-endpoint.example.com"))
.build();
Sources: AWS SDK docs and community reports. [1][2][3]
Sources
[1] AWS SDK for Java v2 — Configuring client endpoints (endpointOverride example).
[2] GitHub issue discussing scheme requirement/behavior in aws-sdk-java-v2.
[3] StackOverflow: "The URI scheme of endpointOverride must not be null" (example and resolution).
Update the TODO comment with the correct AWS SDK issue reference.
The workaround is still necessary—AWS SDK v2 requires
endpointOverrideto be a URI with a scheme. However, the referenced issue #2274 appears to be incorrect or outdated. Update the comment to reference AWS SDK Java v2 issue #5831 (or the equivalent issue in your SDK version) that describes the scheme requirement forendpointOverride.🤖 Prompt for AI Agents