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

Skip to content

s3: fix v2 auth failing when path style addressing is off - #9893

Open
ubmids wants to merge 1 commit into
rclone:masterfrom
ubmids:fix-v2-auth-virtual-host
Open

s3: fix v2 auth failing when path style addressing is off#9893
ubmids wants to merge 1 commit into
rclone:masterfrom
ubmids:fix-v2-auth-virtual-host

Conversation

@ubmids

@ubmids ubmids commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Fixes #8520.

I hit the same thing writing an S3-compatible store against a custom endpoint, and came looking to see how rclone handled it.

v2 signs the bucket as part of the canonical resource:

CanonicalizedResource = [ "/" + Bucket ] + <HTTP-Request-URI, from the protocol
name up to the query string> + [ subresource, if present ]

SignHTTP takes that resource straight from req.URL.EscapedPath(). With path style the path is already /bucket/key, so it comes out right by accident. With virtual host style the bucket is in the Host header and the path is only /key, so it never reaches the string to sign and the server computes a different signature.

That matches the report: dropping either --s3-v2-auth or --s3-force-path-style=false fixes it, because one puts the bucket back in the path and the other switches to v4, which signs Host anyway.

This pulls the bucket back out of the Host. With an endpoint configured that is exact; without one it looks for the s3 label, since AWS hosts are bucket.s3.amazonaws.com or bucket.s3.<region>.amazonaws.com.

There were no tests on the v2 signer, so I have added some. The one that matters asserts that the same bucket and key sign identically whether addressed path style or virtual host style, which is the invariant that was broken. Without the fix:

--- FAIL: TestV2SignVirtualHostMatchesPathStyle
    expected: "AWS accesskey:yzu+SH0vG0JLfNfVkIZJazPJxy0="
    actual  : "AWS accesskey:YaxEj2fIy2IYDVmbX6aU1bY1BIA="

What I have not done is test against real AWS, since I do not have a bucket set up for v2 auth to point at. So this is verified against the spec and the unit tests, not end to end. @lewoberst if you are still around, it would be worth a run.

One thing I noticed and left alone: SignHTTP ignores its signingTime argument and uses time.Now(), which is why that test has a retry around the Date header. Happy to do it separately if you want it.

make quicktest passes other than cmd/gitannex and cmd/nfsmount, which fail the same way on a clean checkout here (no rclone on PATH, and mount permissions).

…one#8520

v2 signs the bucket as part of the canonical resource. With path style
addressing it is already in the URL path, but with virtual host style it is
in the Host header, so the signed resource was missing it and the server
computed a different signature. Every request with --s3-v2-auth and
--s3-force-path-style=false failed.
@ubmids
ubmids requested a review from ncw as a code owner September 9, 2026 14:37
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.

Wrong v2 signature calculation with host-style s3 requests

1 participant