-
Notifications
You must be signed in to change notification settings - Fork 133
feat: robustify pre-signed URL checks #760
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f378d0
feat: robustify pre-signed URL checks
roeap 40e989a
chore: clippy
roeap 9fe90b3
fix: pr feedback
roeap c310284
fix: revert import order
roeap f89f4f0
Merge branch 'main' into feat/pre-signed
roeap 88d41dd
Merge branch 'main' into feat/pre-signed
roeap b2c6915
chore: PR feedback
roeap 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,35 @@ impl<E: TaskExecutor> Engine for DefaultEngine<E> { | |
| } | ||
| } | ||
|
|
||
| trait UrlExt { | ||
| // Check if a given url is a presigned url and can be used | ||
| // to access the object store via simple http requests | ||
| fn is_presigned(&self) -> bool; | ||
| } | ||
|
|
||
| impl UrlExt for Url { | ||
| fn is_presigned(&self) -> bool { | ||
| matches!(self.scheme(), "http" | "https") | ||
| && ( | ||
| // https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html | ||
| // https://developers.cloudflare.com/r2/api/s3/presigned-urls/ | ||
| self | ||
| .query_pairs() | ||
| .any(|(k, _)| k.eq_ignore_ascii_case("X-Amz-Signature")) || | ||
| // https://learn.microsoft.com/en-us/rest/api/storageservices/create-user-delegation-sas#version-2020-12-06-and-later | ||
| // note signed permission (sp) must always be present | ||
| self | ||
| .query_pairs().any(|(k, _)| k.eq_ignore_ascii_case("sp")) || | ||
| // <https://cloud.google.com/storage/docs/authentication/signatures | ||
| self | ||
| .query_pairs().any(|(k, _)| k.eq_ignore_ascii_case("X-Goog-Credential")) || | ||
| // https://www.alibabacloud.com/help/en/oss/user-guide/upload-files-using-presigned-urls | ||
| self | ||
| .query_pairs().any(|(k, _)| k.eq_ignore_ascii_case("X-OSS-Credential")) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::executor::tokio::TokioBackgroundExecutor; | ||
|
|
@@ -173,4 +202,22 @@ mod tests { | |
| let engine = DefaultEngine::new(store, Arc::new(TokioBackgroundExecutor::new())); | ||
| test_arrow_engine(&engine, &url); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_pre_signed_url() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: unit test for case insensitive comparison
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added :) |
||
| let url = Url::parse("https://example.com?X-Amz-Signature=foo").unwrap(); | ||
| assert!(url.is_presigned()); | ||
|
|
||
| let url = Url::parse("https://example.com?sp=foo").unwrap(); | ||
| assert!(url.is_presigned()); | ||
|
|
||
| let url = Url::parse("https://example.com?X-Goog-Credential=foo").unwrap(); | ||
| assert!(url.is_presigned()); | ||
|
|
||
| let url = Url::parse("https://example.com?X-OSS-Credential=foo").unwrap(); | ||
| assert!(url.is_presigned()); | ||
|
|
||
| let url = Url::parse("https://example.com").unwrap(); | ||
| assert!(!url.is_presigned()); | ||
| } | ||
| } | ||
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.
nit: stray angled bracket
<