-
Notifications
You must be signed in to change notification settings - Fork 1k
Add support of Request-level credentials override in DefaultS3CrtAsyncClient #6793
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
47a17ac
add request level creds override for crt
Fred1155 88ef199
Merge branch 'master' into bole_support_crts3_credential_override
Fred1155 6e56c05
changelog added
Fred1155 655998a
change decription
Fred1155 06a9eeb
Merge branch 'master' into bole_support_crts3_credential_override
Fred1155 1f989a7
change integration test to wiremock test
Fred1155 bc87be6
added test for not happy path
Fred1155 81930b6
Merge branch 'master' into bole_support_crts3_credential_override
Fred1155 28a0c12
Merge branch 'master' into bole_support_crts3_credential_override
Fred1155 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "type": "feature", | ||
| "category": "Amazon S3", | ||
| "contributor": "", | ||
| "description": "Added support of Request-level credentials override in DefaultS3CrtAsyncClient. See [#5354](https://github.com/aws/aws-sdk-java-v2/issues/5354)." | ||
| } |
138 changes: 138 additions & 0 deletions
138
...a/software/amazon/awssdk/services/s3/crt/S3CrtRequestLevelCredentialsIntegrationTest.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,138 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.services.s3.crt; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName; | ||
|
|
||
| import java.io.File; | ||
| import java.util.concurrent.CompletionException; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
| import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
| import software.amazon.awssdk.core.async.AsyncRequestBody; | ||
| import software.amazon.awssdk.core.async.AsyncResponseTransformer; | ||
| import software.amazon.awssdk.services.s3.S3AsyncClient; | ||
| import software.amazon.awssdk.services.s3.S3IntegrationTestBase; | ||
| import software.amazon.awssdk.services.s3.internal.crt.S3CrtAsyncClient; | ||
| import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
| import software.amazon.awssdk.services.s3.model.S3Exception; | ||
| import software.amazon.awssdk.testutils.RandomTempFile; | ||
| import software.amazon.awssdk.testutils.service.AwsTestBase; | ||
|
|
||
| /** | ||
| * Integration tests verifying that request-level credential overrides work correctly | ||
| * with the S3 CRT client. | ||
| */ | ||
| public class S3CrtRequestLevelCredentialsIntegrationTest extends S3IntegrationTestBase { | ||
| private static final String BUCKET = temporaryBucketName(S3CrtRequestLevelCredentialsIntegrationTest.class); | ||
| private static final String KEY = "request-level-creds-test-key"; | ||
| private static File testFile; | ||
|
|
||
| private static final StaticCredentialsProvider INVALID_CREDENTIALS = | ||
| StaticCredentialsProvider.create(AwsBasicCredentials.create("invalidAccessKey", "invalidSecretKey")); | ||
|
|
||
| @BeforeAll | ||
| public static void setup() throws Exception { | ||
| S3IntegrationTestBase.setUp(); | ||
| S3IntegrationTestBase.createBucket(BUCKET); | ||
| testFile = new RandomTempFile(1024); | ||
| S3IntegrationTestBase.s3.putObject(PutObjectRequest.builder() | ||
| .bucket(BUCKET) | ||
| .key(KEY) | ||
| .build(), testFile.toPath()); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void cleanup() { | ||
| S3IntegrationTestBase.deleteBucketAndAllContents(BUCKET); | ||
| } | ||
|
|
||
| @Test | ||
| void getObject_withValidRequestLevelCredentials_overridingInvalidClientCredentials_shouldSucceed() { | ||
| // Client is built with INVALID credentials, but the request overrides with VALID ones. | ||
| // If request-level override works, the request should succeed. | ||
| try (S3AsyncClient crtClient = S3CrtAsyncClient.builder() | ||
| .region(DEFAULT_REGION) | ||
| .credentialsProvider(INVALID_CREDENTIALS) | ||
| .build()) { | ||
|
|
||
| byte[] result = crtClient.getObject( | ||
| b -> b.bucket(BUCKET).key(KEY) | ||
| .overrideConfiguration(o -> o.credentialsProvider(AwsTestBase.CREDENTIALS_PROVIDER_CHAIN)), | ||
| AsyncResponseTransformer.toBytes()).join().asByteArray(); | ||
|
|
||
| assertThat(result).hasSize(1024); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void putObject_withValidRequestLevelCredentials_overridingInvalidClientCredentials_shouldSucceed() { | ||
| String overrideKey = KEY + "-put-override"; | ||
| try (S3AsyncClient crtClient = S3CrtAsyncClient.builder() | ||
|
|
||
| .region(DEFAULT_REGION) | ||
| .credentialsProvider(INVALID_CREDENTIALS) | ||
| .build()) { | ||
|
|
||
| crtClient.putObject( | ||
| b -> b.bucket(BUCKET).key(overrideKey) | ||
| .overrideConfiguration(o -> o.credentialsProvider(AwsTestBase.CREDENTIALS_PROVIDER_CHAIN)), | ||
| AsyncRequestBody.fromString("hello")).join(); | ||
|
|
||
| byte[] content = S3IntegrationTestBase.s3.getObjectAsBytes( | ||
| b -> b.bucket(BUCKET).key(overrideKey)).asByteArray(); | ||
| assertThat(new String(content)).isEqualTo("hello"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void getObject_withInvalidRequestLevelCredentials_overridingValidClientCredentials_shouldFail() { | ||
| // Client is built with VALID credentials, but the request overrides with INVALID ones. | ||
| // The request should fail with a signing/auth error, proving the override is actually used. | ||
| try (S3AsyncClient crtClient = S3CrtAsyncClient.builder() | ||
| .region(DEFAULT_REGION) | ||
| .credentialsProvider(AwsTestBase.CREDENTIALS_PROVIDER_CHAIN) | ||
| .build()) { | ||
|
|
||
| assertThatThrownBy(() -> crtClient.getObject( | ||
| b -> b.bucket(BUCKET).key(KEY) | ||
| .overrideConfiguration(o -> o.credentialsProvider(INVALID_CREDENTIALS)), | ||
| AsyncResponseTransformer.toBytes()).join()) | ||
| .isInstanceOf(CompletionException.class) | ||
| .hasCauseInstanceOf(S3Exception.class); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void getObject_withValidClientCredentials_noOverride_shouldSucceed() { | ||
| // Baseline: client-level credentials work when no override is provided. | ||
| try (S3AsyncClient crtClient = S3CrtAsyncClient.builder() | ||
| .region(DEFAULT_REGION) | ||
| .credentialsProvider(AwsTestBase.CREDENTIALS_PROVIDER_CHAIN) | ||
| .build()) { | ||
|
|
||
| byte[] result = crtClient.getObject( | ||
| b -> b.bucket(BUCKET).key(KEY), | ||
| AsyncResponseTransformer.toBytes()).join().asByteArray(); | ||
|
|
||
| assertThat(result).hasSize(1024); | ||
| } | ||
| } | ||
| } | ||
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
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.
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.
Does this need to be an integration test? Can it be written to use wiremock?
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.
Good call. Changed to use wiremock instead.