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

Move S3Presigner fully to SRA with HttpSigner #4569

Conversation

gosar
Copy link
Contributor

@gosar gosar commented Oct 10, 2023

Motivation and Context

S3PresignerTest.accessPointArn_multiRegion_useArnRegionTrue_correctEndpointAndSigner currently fails in feature/master/sra-identity-auth-testing (with useSraAuth=true) with X-Amz-Algorithm

Expected :"AWS4-ECDSA-P256-SHA256"
Actual   :"AWS4-HMAC-SHA256"

The reason is that DefaultS3Presigner is partially on SRA. i.e., it uses S3AuthSchemeResolver, but uses old Signer. And S3ResolveEndpointInterceptor won't have logic to use to old sigv4a Signer because of this conditional logic in codegen. Instead of solving this via more codegen changes, we might as well move the presigner fully to SRA and use the new HttpSigner from auth scheme resolution, which will select the correct sigv4/sigv4a HttpSigner.

Modifications

Testing

Picked up #4560 locally and successfully ran unit and integ tests in the s3 module.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

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

Comment on lines +88 to +97
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>identity-spi</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>http-auth-spi</artifactId>
<version>${awsjavasdk.version}</version>
</dependency>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DefaultS3Presigner directly depends on these, so declared explicitly, instead of coming in transitively.

// A fixed signingClock is used, so that the current time used by the signing logic, as well as to determine expiration
// are the same.
Instant signingInstant = Instant.now();
Clock signingClock = Clock.fixed(signingInstant, ZoneOffset.UTC);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative to this would be to let the HttpSigner use current time inside it's logic, and later to calculate expiration to set inside presignedRequest in initializePresignedRequest we could extract the current time value used by the HttpSigner by reading the value out of X-Amz-Date query param inserted by the HttpSigner. initializePresignedRequest already has some logic to extract from X-Amz-SignedHeaders query param. But it seemed better to not rely more on implementation details of the HttpSigner.

@@ -227,6 +228,7 @@ public void getObject_Sigv4PresignerHonorsSignatureDuration() {

assertThat(presigned.httpRequest().rawQueryParameters().get("X-Amz-Expires").get(0)).satisfies(expires -> {
assertThat(expires).containsOnlyDigits();
// TODO(sra-identity-auth): This should be isEqualTo(1234)?
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 think it's a bug if isCloseTo was needed for some reason earlier instead of isEqualTo check. Not sure why it was so from the beginning, but couldn't change it right now because of derived attributes behavior for PRESIGNER_EXPIRATION. I have an internal discussion thread about it. Will update that separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressing the derived attributes and isCloseTo in #4602

@gosar gosar marked this pull request as ready for review October 14, 2023 01:00
@gosar gosar requested a review from a team as a code owner October 14, 2023 01:00
@sonarcloud
Copy link

sonarcloud bot commented Oct 14, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 8 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 14 Code Smells

97.0% 97.0% Coverage
0.8% 0.8% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@gosar gosar merged commit 7d22755 into feature/master/sra-identity-auth-testing Oct 14, 2023
11 of 14 checks passed
@gosar gosar deleted the gosar/sra-ia-s3presigner-full-sra branch October 14, 2023 01:18
sugmanue added a commit that referenced this pull request Nov 6, 2023
* Set TIME_OFFSET attribtue in SRA signin methods (#4483)

* Verify that execution attributes set by old interceptors can be read by new signers. (#4494)

* Move S3Presigner fully to SRA with HttpSigner (#4569)

* Remove derived attribute logic for PRESIGNER_EXPIRATION (#4602)

* Remove derived attribute logic for PRESIGNER_EXPIRATION

Because of the 2 instant() calls in the write/read mappings, a basic
write this attribute and read it back, would give different values.

Since this attribute should only be set/read explicitly by our
presigner code, we don't need this mapping logic at all.

Also, update S3PresignerTest to assert isEqualTo instead of isCloseTo
and remove unnecessary override

* Remove PRESIGNER_EXPIRATION mirroring test

* Enable SRA Auth for S3

* Make follow up changes from PR 4396 (#4454)

* Make SigingStage updates similar to AsyncSigningStage.
* Simplify (Async)SigningStageTests based on updated logic.
* Minor typos

* If authType=none don't use the old signer, even if overridden  (#4523)

* Add authType=none tests to AwsExecutionContentBuilderTest

Some of these tests are failing. Will fix them in next commit

* If authType=none don't use the old signer, even if overridden

* Update signing stage logic for authType=none

* Add asserts on identity resolution for authType=none

* Add a missing http-auth-aws dependecy to aws-core

* Add a changelog entry

---------

Co-authored-by: Zoe Wang <33073555+zoewangg@users.noreply.github.com>
Co-authored-by: Matthew Miller <millem@amazon.com>
Co-authored-by: Jaykumar Gosar <5666661+gosar@users.noreply.github.com>
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