fix: preserve leading-slash S3 keys#78
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an S3/R2 regression where object keys starting with / could be signed/constructed incorrectly (leading to 403s), by introducing a consistent key-munging workaround when constructing rusty-s3 actions/URLs. This fits into oneio’s S3 backend (src/s3) by ensuring request URL construction remains compatible with path-style endpoints such as Cloudflare R2.
Changes:
- Add
s3_action_key()and apply it across S3 read/write/head/delete/multipart/copy-destination code paths to avoidUrl::join()dropping the path-style bucket component. - Add ignored Cloudflare R2 integration tests covering single-PUT and multipart flows using leading-slash keys.
- Add an Unreleased changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/s3/mod.rs |
Adds s3_action_key() and uses it broadly to preserve correct URL construction/signing for leading-slash keys. |
tests/s3_integration.rs |
Adds ignored R2 integration tests for leading-slash key single-PUT and multipart flows. |
CHANGELOG.md |
Documents the leading-slash key fix under [Unreleased]. |
Comment on lines
+142
to
+145
| assert_stream_matches(&bucket, &key, &data); | ||
|
|
||
| cleanup_test_objects(&bucket, &prefix); | ||
| } |
Comment on lines
+217
to
+220
| assert_stream_matches(&bucket, &key, &data); | ||
|
|
||
| cleanup_test_objects(&bucket, &prefix); | ||
| } |
Comment on lines
+70
to
+82
| /// Make an S3 object key safe to pass to rusty-s3's URL resolver. | ||
| /// | ||
| /// `rusty_s3::Bucket::object_url()` uses `Url::join()`, which treats a key | ||
| /// beginning with `/` as an absolute URL path and drops the path-style bucket | ||
| /// component. Prefixing a relative-path marker preserves the key's leading | ||
| /// slash in the resulting request path. | ||
| fn s3_action_key(key: &str) -> Cow<'_, str> { | ||
| if key.starts_with('/') { | ||
| Cow::Owned(format!(".{key}")) | ||
| } else { | ||
| Cow::Borrowed(key) | ||
| } | ||
| } |
digizeph
force-pushed
the
fix/leading-slash-r2-keys
branch
from
July 22, 2026 17:02
015d783 to
e7102c1
Compare
Comment on lines
+105
to
+110
| let datetime = query | ||
| .iter() | ||
| .find(|(name, _)| name == "X-Amz-Date") | ||
| .map(|(_, value)| value.as_str()) | ||
| .ok_or_else(|| OneIoError::NotSupported("Missing X-Amz-Date in S3 action".to_string()))?; | ||
| let datestamp = &datetime[..8]; |
Comment on lines
+91
to
+97
| let endpoint: reqwest::Url = config | ||
| .endpoint | ||
| .parse() | ||
| .map_err(|e| OneIoError::NotSupported(format!("Invalid S3 endpoint: {e}")))?; | ||
| let endpoint_path = endpoint.path().trim_end_matches('/'); | ||
| url.set_path(&format!("{endpoint_path}/{}/{}", config.bucket, key)); | ||
|
|
Comment on lines
+166
to
+181
| fn s3_object_url(config: &config::S3Config, key: &str) -> Result<reqwest::Url, OneIoError> { | ||
| if !key.starts_with('/') || !uses_path_style(config) { | ||
| return config | ||
| .rusty_bucket()? | ||
| .object_url(key) | ||
| .map_err(|e| OneIoError::NotSupported(format!("Invalid object key: {e}"))); | ||
| } | ||
|
|
||
| let mut endpoint: reqwest::Url = config | ||
| .endpoint | ||
| .parse() | ||
| .map_err(|e| OneIoError::NotSupported(format!("Invalid S3 endpoint: {e}")))?; | ||
| let endpoint_path = endpoint.path().trim_end_matches('/'); | ||
| endpoint.set_path(&format!("{endpoint_path}/{}/{}", config.bucket, key)); | ||
| Ok(endpoint) | ||
| } |
digizeph
force-pushed
the
fix/leading-slash-r2-keys
branch
from
July 22, 2026 20:42
e7102c1 to
0bfb178
Compare
Member
Author
|
Addressed the current Copilot feedback in 0bfb178:
Local checks and all 16 live R2 integration tests pass; CI has been re-triggered. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the Cloudflare R2 403 regression for S3 object keys that begin with
/.Closes #77.
Changes
Url::join()handling otherwise drops the path-style bucket component.Testing
cargo fmt --checkcargo build --no-default-featurescargo build --all-featurescargo test --all-featurescargo clippy --all-features -- -D warningscargo clippy --no-default-featurescargo test --test s3_integration --features s3,rustls -- --ignored --test-threads=1(15 R2 tests)Release
No release-workflow change is needed:
.github/workflows/release.ymltriggers onv[0-9]+.*pushes, then format-checks, creates the GitHub Release fromCHANGELOG.md, uploads CLI assets, and publishes to crates.io. Recent tag releases, includingv0.23.0, completed successfully.