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

Skip to content

S3 ASF Presigned URL #6908

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 1 commit into from
Oct 1, 2022
Merged

S3 ASF Presigned URL #6908

merged 1 commit into from
Oct 1, 2022

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Sep 21, 2022

Pre-signed URLs are a feature of S3, allowing to use the client or the CLI to pre-sign a request with the credentials used by the client. The docs are quite extensive about it, and you see more about it here:
https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html
https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3_Authentication2.html

You can sign the request with 2 types: SigV2, which is supposed to be deprecated by still used, and SigV4.
You effectively sign the request like you would in the headers normally, but pass it in the query parameters instead.

The LocalStack pre-signed URLs feature is checking if the signature of the request is valid (and does not authenticate the request).

We verify the signature by checking the request we received, reconstructing the Canonical Request as required by AWS, and signing the request with the utilities from botocore to check if the signatures are identical. We keep the usage of the feature flag S3_SKIP_SIGNATURE_VALIDATION to allow requests with wrong signatures to go through.

We are making use of the handler chain, to catch the requests before they go through the skeleton to reject them if necessary.
We also modify the responses of operations using PUT method, because AWS "erases" the body content when the request is coming from a pre-signed URL.

This PR still miss the pre-signed POST requests, added in a follow-up PR.

The validation should work better than the old provider, and be more precise and in-line with AWS.

@bentsku bentsku temporarily deployed to localstack-ext-tests September 21, 2022 22:41 Inactive
@github-actions
Copy link

github-actions bot commented Sep 22, 2022

LocalStack integration with Pro

       1 files   -     2         1 suites   - 2   1h 3m 41s ⏱️ - 9m 40s
1 323 tests  -     6  1 191 ✔️  -   17  132 💤 +  11  0 ±0 
1 323 runs   - 520  1 191 ✔️  - 385  132 💤  - 135  0 ±0 

Results for commit bdeadc8. ± Comparison against base commit dd483f2.

♻️ This comment has been updated with latest results.

@bentsku bentsku temporarily deployed to localstack-ext-tests September 22, 2022 12:33 Inactive
@bentsku bentsku force-pushed the s3-asf-presigned-url branch from e828540 to c74ee58 Compare September 28, 2022 11:34
@bentsku bentsku temporarily deployed to localstack-ext-tests September 28, 2022 11:34 Inactive
@bentsku bentsku marked this pull request as ready for review September 28, 2022 11:42
@bentsku bentsku requested a review from thrau as a code owner September 28, 2022 11:42
@bentsku bentsku changed the title WIP: S3 ASF Presigned URL S3 ASF Presigned URL Sep 28, 2022
@bentsku bentsku temporarily deployed to localstack-ext-tests September 28, 2022 13:03 Inactive
@coveralls
Copy link

coveralls commented Sep 28, 2022

Coverage Status

Coverage decreased (-0.2%) to 79.074% when pulling bdeadc8 on s3-asf-presigned-url into dd483f2 on master.

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.

awesome 💯 well done on the implementation, some of the code looks really tricky!

i have a fundamental question about pre-signed URL validation: is all the validation state encapsulated in the signature? is there no need to check IAM or the s3 store data? in other words: can the signature validation handler remain stateless? otherwise it could maybe be useful to move s3_presigned_url_request_handler into a a class, and insantiate the class from the provider so we have the possibility to inject dependencies or state into the validator.

maybe a couple of unit tests couldn't hurt to improve the base test coverage :-)

@bentsku
Copy link
Contributor Author

bentsku commented Sep 30, 2022

Thanks for the review, I will work on that!

I have a fundamental question about pre-signed URL validation: is all the validation state encapsulated in the signature? is there no need to check IAM or the s3 store data? in other words: can the signature validation handler remain stateless? otherwise it could maybe be useful to move s3_presigned_url_request_handler into a a class, and insantiate the class from the provider so we have the possibility to inject dependencies or state into the validator.

To me, signature validation is only doing signature validation. It is a stateless operation validating if the signature provided matches the request received.

Then, I agree credentials should be validated in case of ENFORCE_IAM=True, so maybe we should set the Authorization headers with the data from the query parameters for the IAM engine to work, or any other solution, but it would come as another step.

I love the idea to be able to inject state from the class, but I am not sure it should be done at this step exactly. I would say the pre-signed URLs are a way to access a resource with credentials provided in another location than the headers. Should we see what should be done with @dfangl?

@bentsku bentsku force-pushed the s3-asf-presigned-url branch from f9d8f35 to 6f7abbf Compare September 30, 2022 14:56
@bentsku bentsku temporarily deployed to localstack-ext-tests September 30, 2022 14:57 Inactive
@bentsku bentsku force-pushed the s3-asf-presigned-url branch from 6f7abbf to 455809b Compare September 30, 2022 16:57
@bentsku bentsku temporarily deployed to localstack-ext-tests September 30, 2022 16:57 Inactive
@bentsku bentsku requested a review from thrau September 30, 2022 16:59
@bentsku
Copy link
Contributor Author

bentsku commented Sep 30, 2022

I added some unit tests, I could also add the actual signing, but this should be tested with integration tests, it would be a bit tedious to unit test, craft some request, get the real signature values, and you need to have the right credentials set to test/test.
It was nice as it allowed me to detect some small issues! 😄
After refactoring the notifications, this would seem like a good target for the Strategy Pattern as well. But as there are only 2 possibles solutions, I'd say we can keep it that way for now. It would be simple to refactor it with a class containing "is this request this type of signature" method, and another one to actually verify the request.
I guess we can leave it as is for now, I don't think AWS will add a new signature method pretty soon, V4 is working for now.

Thanks again for the review, and great points!

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 after rebasing and fixing the conflicts! the tests could maybe have been written with parameterization, but doesn't really matter much to me :-)

@bentsku bentsku force-pushed the s3-asf-presigned-url branch from 455809b to f0b32b8 Compare September 30, 2022 21:12
@bentsku bentsku temporarily deployed to localstack-ext-tests September 30, 2022 21:12 Inactive
@bentsku bentsku force-pushed the s3-asf-presigned-url branch from f0b32b8 to 584c474 Compare September 30, 2022 21:20
@bentsku bentsku temporarily deployed to localstack-ext-tests September 30, 2022 21:21 Inactive
@bentsku bentsku force-pushed the s3-asf-presigned-url branch from 584c474 to bdeadc8 Compare September 30, 2022 21:28
@bentsku bentsku temporarily deployed to localstack-ext-tests September 30, 2022 21:28 Inactive
@bentsku bentsku merged commit 7bfb54d into master Oct 1, 2022
@bentsku bentsku deleted the s3-asf-presigned-url branch October 1, 2022 20:34
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.

3 participants