Thanks to visit codestin.com
Credit goes to github.com

Skip to content

implement S3 v3 pre-signed handler #8918

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 2 commits into from
Aug 22, 2023
Merged

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Aug 15, 2023

Motivation

Move the s3 pre-signed handler earlier in the handler chain, so that we can modify the request in the RequestContext before actually parsing it: this allows us to fully use the ASF parser.
When pre-signing a request, the S3 client will move some of the request parameters into the query string, when those parameters would be in the headers. Now, the pre-signed handler will add back some headers that we know should be in there, and the parser will properly pick it up.

Changes

Create a general pre-signed handler in the handler chain, which will be able to manage more kind of pre-signed URL than S3. Only S3 is implemented now. Some logic had to be changed in the handler, because we were using the previously parsed Bucket from the request. We now need to parse it ourselves following the same logic as the RequestParser (especially a weird case where we had the sanitized path, and we needed the raw one).

@bentsku bentsku self-assigned this Aug 15, 2023
@bentsku bentsku added aws:s3 Amazon Simple Storage Service semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Aug 15, 2023
@coveralls
Copy link

coveralls commented Aug 15, 2023

Coverage Status

coverage: 80.717% (+0.06%) from 80.658% when pulling 13f8dd4 on s3-native-pre-signed-handler into dacb3c8 on master.

@bentsku bentsku marked this pull request as ready for review August 16, 2023 15:10
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

LGTM! modifying the headers this way seems fine (we allowed for request header mutability for exactly these use cases). the impact on the handler chain is minimal since we're only executing this for specific services, which is good.
the encapsulation in the handler class is 👌

great set of changes overall! 🥇

Comment on lines +8 to +12
class ParsePreSignedUrlRequest(Handler):
def __init__(self):
self.pre_signed_handlers: dict[str, Handler] = {
"s3": S3PreSignedURLRequestHandler(),
}
Copy link
Member

Choose a reason for hiding this comment

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

nice 👍 maybe at some point in the future we can consolidate this with ServiceResponseHandlers

@bentsku bentsku force-pushed the s3-native-post-object branch from 3ed03e0 to 153493c Compare August 21, 2023 18:53
@bentsku bentsku force-pushed the s3-native-pre-signed-handler branch 2 times, most recently from 626bc96 to 555135b Compare August 21, 2023 19:45
Base automatically changed from s3-native-post-object to master August 22, 2023 14:28
@bentsku bentsku force-pushed the s3-native-pre-signed-handler branch from 555135b to 2c1a505 Compare August 22, 2023 14:55
@bentsku bentsku merged commit 2eddd22 into master Aug 22, 2023
@bentsku bentsku deleted the s3-native-pre-signed-handler branch August 22, 2023 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:s3 Amazon Simple Storage Service semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants