Anonymous access can now be configured by allowing specific S3 methods.
Currently, this only includes `s3:HeadObject` and `s3:GetObject`. Umbrella
grants can also be used that translate to lists of methods (`garage:ReadObject` ->
[`s3:HeadObject`, `s3:GetObject`].
The CLI takes either a list of `--allow`ed methods, or a `--revoke-all`.
`ReqCtx` is now represented by an enum of either an authenticated requests
or an anonymous one. Handlers will take either one of those depending on whether
they allow anonymous access or not. `ReqCtxEnum` implements `TryInto` to transform
into the requested type (where building an anonymous context always works, but
building an authenticated one only works if the request contained valid
credentials).
When building an anonymous context, the bucket anonymous configuration will
be checked against the requested endpoint to check if all required methods are
allowed anonymously.
Path-style URLs of the form /bucket//key address an object whose key begins with "/". Two greedy uses of `trim_start_matches('/')` were collapsing these leading slashes away:
- `uri.path().trim_start_matches('/')` stripped all leading slashes from the raw path before any further parsing.
- `p.trim_start_matches('/')` stripped leading slashes from the remainder after `split_once('/')` had already consumed the bucket/key separator
The combined effect wath that `HEAD /bucket//` and `GET /bucket//` produced an empty key, which the router treated as bucket-level operations (HeadBucket -> 200 OK, and ListObjectsV2) instead of an object-level op (HeadObject/GetObject -> 404 NoSuchKey).
The fix is simple: Replace the first `trim_start_matches` with `strip_prefix` (to strip exactly one separator slash) and remove the second one entirely. Path-style and vhost-style requests are now consistent: a double slash in the URL correctly addresses a key whose name begins with "/".
Regression tests added for `HEAD //` and `GET //` requests in both request styles.
Fixes: #1464
---
Disclaimer: I'm not fluent in Rust and I did use an LLM to explain the code to me. All code was written by me.
I'm not sure whether the large `test_cases!` block in the `test_aws_doc_examples` function is the right place for my tests (it certainly was a convenient one).
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1465
Return an internal error instead of a response without the -N suffix
when a composite checksum has no part count, or when a part count is
given for a non-composite checksum. Also add a FIXME about parsing the
part count out of the etag.
Credits: MUTED CYBERSECURITY S.L. for reporting that lifecycle
configuration endpoints were accessible with simple `write` permission.
This commit reorganizes permission checking to have explicit lists of
endpoints allowed with `write` access, and require `owner` permissions
for all other endpoints
Add the missing x-amz-checksum-type response header / ChecksumType XML
element to operations where AWS S3 specifies it:
- PutObject: x-amz-checksum-type: FULL_OBJECT header when the object
was uploaded with a checksum
- GetObject / HeadObject: x-amz-checksum-type header when the request
enables x-amz-checksum-mode and the object has a stored checksum type
- CreateMultipartUpload: x-amz-checksum-algorithm and
x-amz-checksum-type headers when a checksum algorithm was requested
- CopyObject: ChecksumType element (plus the ChecksumCRC32/CRC32C/
CRC64NVME/SHA1/SHA256 elements) in the CopyObjectResult XML body
UploadPart and UploadPartCopy responses are unchanged, as AWS S3 does
not return a checksum type for part-level operations.
To support this, add_checksum_response_headers() now takes the stored
ChecksumType as an additional parameter.
body_from_blocks_range indexed all_blocks[0] to size a capacity hint. A
version with zero blocks made that index panic and kill the process on a
plain GET, the read-side twin of the CompleteMultipartUpload panic at
multipart.rs:479. Fall back to the existing 1024 floor when the slice is
empty; with a non-empty slice the hint is unchanged.
CompleteMultipartUpload builds the final version and then reads
`final_version.blocks.items()[0]` unconditionally. When the assembled
version ends up with an empty block list the index panics and the
process dies before it can answer the request:
panicked at src/api/s3/multipart.rs:479:3:
index out of bounds: the len is 0 but the index is 0
Use `.first()` and return an internal error instead, matching how the
rest of this file handles missing data. The empty-block case is an
internal consistency condition rather than a malformed request, so it
maps to an internal error rather than a 4xx.
The same panic was reported earlier in #1403, at multipart.rs:483 on
v2.2.0. That report was closed without a fix after the reporter moved
off consistency_mode = "dangerous".
Closes#1521
PostObject (presigned POST) returns `400 InvalidHeaderValue` when the upload involves a non-ASCII filename. The same key uploads fine vie PUT, as the issue #1489 noted.
The problem was that `handle_post_object` stores the form field values in an `http::HeaderMap`. values go in through `HeaderValue::from_str` but are read back with the strict `HeaderValue::to_str()` (ASCII-only) which fails on any UTF-8 value.
This is the same problem fixed in eab2b81b for `x-amz-meta-*` headers, and the fix is the same:
`std::str::from_utf8(value.as_bytes())` instead of `to_str()`. The `key` field in `post_object.rs` and the standard headers (`content-disposition` etc.) in `extract_metadata_headers`.
Added integration tests for PostObject (there were none): UTF-8 key, `${filename}` substitution, and UTF-8 `Content-Disposition` metadata. The substitution test passes even without the fix, proving that the filename path was never broken, only the form-params round-trip.
Co-authored-by: Mathew Storm <mathew@stormdevelopments.ca>
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1492
Reviewed-by: trinity-1686a <trinity-1686a@noreply.localhost>