Skip to content

Do not explicitly add Host header when making requests with S3Builder - #790

Merged
alamb merged 7 commits into
apache:mainfrom
ntjohnson1:nick/hf_buckets
Jul 10, 2026
Merged

alamb merged 7 commits into
apache:mainfrom
ntjohnson1:nick/hf_buckets

Conversation

@ntjohnson1

@ntjohnson1 ntjohnson1 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

I included a commit with the exemplar I was using to verify arrow-rs-object-store works with HF buckets (to demonstrate things work if you want to try it yourself)

Rationale for this change

With hugging face buckets S3 compatible API you can create a builder via:

let mut builder = AmazonS3Builder::new()
        .with_endpoint(endpoint)
        .with_region(region)
        .with_bucket_name(bucket)
        .with_access_key_id(env_req("AWS_ACCESS_KEY_ID"))
        .with_secret_access_key(env_req("AWS_SECRET_ACCESS_KEY"))
        .with_disable_bulk_delete(disable_bulk_delete);

However, when I did this and tried connecting to a bucket I was getting issues with the redirect.

object_store's SigV4 signer inserted an explicit Host header on every request. reqwest carries user-set headers across redirects, so when an S3-compatible gateway answers GetObject with a cross-host 302 ( e.g. the Hugging Face gateway: s3.hf.co redirecting to its Xet CDN: cas-bridge.xethub.hf.co) the stale Host: s3.hf.co header poisoned the redirected request and the download failed with a connection error. list/head worked (no redirect); every get failed.

What changes are included in this PR?

Host is still part of the SigV4 signature, but it's now added to a throwaway copy of the headers used only to compute the signature, instead of being pinned on the outgoing request. The actual Host header is left to hyper, which derives it from the URL and regenerates it on redirect. The produced signature is identical, so AWS S3 and all other providers are unaffected.

Are there any user-facing changes?

No

ntjohnson1 and others added 3 commits July 6, 2026 07:30
The SigV4 signer inserted an explicit `Host` header on the outgoing
request. reqwest carries that header across redirects, so when an
S3-compatible gateway answers GET with a cross-host 302 — e.g. the
Hugging Face gateway at `s3.hf.co` redirecting to a Xet CDN on
`cas-bridge.xethub.hf.co` — the stale `Host: s3.hf.co` header poisoned
the redirected request and the download failed with a connection error.
`list`/`head` (no redirect) worked, but every `get` failed.

Host must still be part of the SigV4 signature, so it is now added to a
throwaway copy of the headers used only to compute the signature; the
actual Host header is left to the transport (hyper), which derives it
from the request URL and regenerates it on redirect. The produced
signature is unchanged (existing signing tests still pass), so AWS S3 and
other providers are unaffected.

Addresses apache#706 (Hugging Face Storage Buckets).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Adds `verification/hf-smoke`, the standalone harness used to verify the Host-header
fix end-to-end against a real Hugging Face Storage Bucket (issue apache#706):
- exercises get / ranged get / head / list / list_with_delimiter / copy / multipart /
  conditional create / bulk delete, plus presigned-URL download (Signer trait);
- has a read-only mode (get/head/list only) for Read-scoped tokens;
- `gather.py` (a uv PEP-723 script) collects + boto3-validates credentials;
- `repro.rs` isolates the reqwest cross-host-redirect behaviour;
- `live-results.sample.md` is an actual passing run against `s3.hf.co`.

This is committed only for reviewer inspection and is reverted by the next commit;
it is not part of the object_store crate.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@ntjohnson1
ntjohnson1 marked this pull request as ready for review July 8, 2026 17:19

@alamb alamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @ntjohnson1 -- this seems ok to me, though I found the code and comments a bit confusing (I left some suggestions to improve them)

I also don't understand what is special about Hugging face -- does this mean S3 requests that return redirect's aren't working at all (for any provider)?

What I am most worried about is that removing the Host header from the request headers will mess up some other existing users.

However, I spent a bunch of time researching this and I think this is ok -- under the covers if the HeadersMap from reqwest don't have Headers, it is set by the lower level hyper library, so I think all is good

BTW it took me a while to verify the assertion in your comments:

the actual Host header is managed by the HTTP transport (hyper derives it from the request URL).

But it took me a while to get codex to prove to me that this is the case

Comment thread src/aws/credential.rs Resolved
Comment thread src/aws/credential.rs Resolved
@alamb alamb changed the title Small fix for HF buckets with existing S3Builder Do not explicitly add Host header when making requests with S3Builder Jul 9, 2026
@ntjohnson1

Copy link
Copy Markdown
Contributor Author

Thanks for an in-depth review as always.

I also don't understand what is special about Hugging face -- does this mean S3 requests that return redirect's aren't working at all (for any provider)?

I suspect the more general title makes more sense. I'm not sure how popular the redirects are for s3 like apis. We mostly just use the major supported ones here today but are explore R2/B2 etc starting with HF buckets.

That's weird Codex had such a hard time digging through to the root cause. Claude seemed to stumble on it pretty easily, next time I can provide the better trace through for easier ability to verify.

What I am most worried about is that removing the Host header from the request headers will mess up some other existing users.

I'm kind of relying on the existing tests CI to cover this here. Alternatively I could try to include this branch as a patch on a system we use with aws to see if things still go through correctly over there (but would probably take some time to get that setup). I don't have super in depth familiarity here to gauge the risk.

@alamb

alamb commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

That's weird Codex had such a hard time digging through to the root cause. Claude seemed to stumble on it pretty easily, next time I can provide the better trace through for easier ability to verify.

Well, it is more like its description of "hyper just does this" was not convincing to me and I made it come up with the exact call chai

@alamb

alamb commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

clippy failure seems unrelated

Update

@alamb

alamb commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Merged up to get a clean CI run

@alamb
alamb merged commit 7a7deea into apache:main Jul 10, 2026
9 checks passed
@alamb

alamb commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Thanks again @ntjohnson1

ilya-zlobintsev added a commit to rerun-io/arrow-rs-object-store that referenced this pull request Jul 27, 2026
…er (apache#790) (#4)

* fix: don't pin Host header when signing S3 requests

The SigV4 signer inserted an explicit `Host` header on the outgoing
request. reqwest carries that header across redirects, so when an
S3-compatible gateway answers GET with a cross-host 302 — e.g. the
Hugging Face gateway at `s3.hf.co` redirecting to a Xet CDN on
`cas-bridge.xethub.hf.co` — the stale `Host: s3.hf.co` header poisoned
the redirected request and the download failed with a connection error.
`list`/`head` (no redirect) worked, but every `get` failed.

Host must still be part of the SigV4 signature, so it is now added to a
throwaway copy of the headers used only to compute the signature; the
actual Host header is left to the transport (hyper), which derives it
from the request URL and regenerates it on redirect. The produced
signature is unchanged (existing signing tests still pass), so AWS S3 and
other providers are unaffected.

Addresses apache#706 (Hugging Face Storage Buckets).



* test: add throwaway HF S3 gateway verification harness

Adds `verification/hf-smoke`, the standalone harness used to verify the Host-header
fix end-to-end against a real Hugging Face Storage Bucket (issue apache#706):
- exercises get / ranged get / head / list / list_with_delimiter / copy / multipart /
  conditional create / bulk delete, plus presigned-URL download (Signer trait);
- has a read-only mode (get/head/list only) for Read-scoped tokens;
- `gather.py` (a uv PEP-723 script) collects + boto3-validates credentials;
- `repro.rs` isolates the reqwest cross-host-redirect behaviour;
- `live-results.sample.md` is an actual passing run against `s3.hf.co`.

This is committed only for reviewer inspection and is reverted by the next commit;
it is not part of the object_store crate.



* Revert "test: add throwaway HF S3 gateway verification harness"

This reverts commit d5fa455.

* Update comment on why headers are handled in this specific way



* Clarify HOST mutation

* Cargo fmt

---------

Co-authored-by: Nick <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
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.

Support for HF Storage Buckets

2 participants