Skip to content

Send the header of an <s3> endpoint section with user-query requests signed with the server-configured keys - #131529

Closed
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:s3-endpoint-header-signed-by-endpoint-keys
Closed

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:s3-endpoint-header-signed-by-endpoint-keys

Conversation

@groeneai

@groeneai groeneai commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131473
Related: #131104

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed the header of an <s3> endpoint section (for example x-amz-request-payer: requester for a requester-pays bucket) being ignored by the s3 and s3Cluster table functions, S3 tables and BACKUP/RESTORE to S3 with the default s3_allow_server_credentials_in_user_queries = 0, so their requests failed with 403 even though they were signed with the access_key_id and secret_access_key from the server configuration. The header is still not sent with NOSIGN requests, with requests that use keys from the query, or to a URL that matches no endpoint section.

Description

On 26.7 and later (measured on 26.10.2.103), with the default s3_allow_server_credentials_in_user_queries = 0, the header of an <s3> endpoint section is not sent by s3(), S3 tables or BACKUP TO S3, even when the request is signed with that endpoint's keys, so a requester-pays read fails with HTTP response code: 403 (item 2 of #131473).

#106855 drops all server <s3> request material on the bare-URL user-query paths so that a NOSIGN request, or one with the query's own keys, carries none of it. It also drops it from a request signed with the static keys of the endpoint section that matched the URL, which still sends those keys and its session_token.

Under the restriction, S3StorageParsedArguments::fromAST and the backup makeS3Client now keep headers when the URL matched an endpoint section and the request is signed with the server config's key pair (no keys, token or role_arn from the query, no NOSIGN). createObjectStorage drops them when a catalog credential replaces those keys. When the server loads an S3 table at startup, getClient now drops its headers only if it has no complete key pair. access_header and SSE keys stay dropped. Like getClient, makeS3Client now checks its headers against http_forbid_headers.

New cases in test_s3_credentials_hardening put a proxy in front of MinIO that refuses requests without x-amz-request-payer: HEAD, GET, ListObjectsV2, S3 schema inference, a read of the S3 table after a server restart, BACKUP and RESTORE carry the header (red on master and on 26.10.2.103 at the first request); NOSIGN, query keys, an unmatched URL, an explicit-key BACKUP and a BACKUP to an endpoint section without keys do not. An endpoint header forbidden by http_forbid_headers fails s3(), BACKUP and RESTORE before any request.


Workflow [PR]
Sync PR [sync-upstream/pr/131529]

groeneai and others added 2 commits November 14, 2026 04:27
…sts signed with the server-configured keys

With the default `s3_allow_server_credentials_in_user_queries = 0`, the
bare-URL user-query paths (`S3StorageParsedArguments::fromAST` and the
backup `makeS3Client`) dropped all server `<s3>` request material,
including the `header` of the endpoint section that matched the URL.
That drop came from ClickHouse#106855 and is meant to keep a `NOSIGN` request, or
one made with the query's own credentials, free of server material.
It also hit requests signed with the endpoint section's own static
keys: those keys and the section's `session_token` still reached the
endpoint, but its header did not, so a requester-pays read
(`x-amz-request-payer: requester`) failed with 403 on HeadObject,
ListObjectsV2, `S3` schema inference and BACKUP (ClickHouse#131473, item 2).

Under the restriction, keep `headers` when the URL matched an endpoint
section and the request is signed with the server config's key pair:
no keys, token or `role_arn` from the query (a query `role_arn` has
already emptied the keys at this point) and no `NOSIGN`. With the
server keys, a global `<s3>` header still never reaches a URL outside
the endpoint sections: the section's keys are what vouch for the host. `access_header` and the
SSE keys stay dropped (a changed SSE behaviour would break reads of
objects written without the key since 26.7).

A BigLake catalog credential and a DataLake catalog refresh callback
replace the server keys after the parse, so `createObjectStorage` drops
the kept headers again in that case, before `headers()` from the query
are appended. It only drops what was dropped before.

When the server loads an `S3` table at startup, `getClient` dropped
all its headers under the restriction, on the premise that the table is
downgraded to an anonymous client. A table with a complete key pair is
not downgraded (`getCredentialsProvider` signs with the pair), so it
lost the header kept for its keys on every restart. Drop the headers
there only for `NOSIGN` or without a complete key pair.

Tests: a proxy in front of MinIO in `test_s3_credentials_hardening`
refuses requests without `x-amz-request-payer`, like a requester-pays
bucket. Red on master and on 26.10.2.103 at the first request; each
condition of the rule except a query `role_arn` (it needs STS) has a
negative case that a mutant without that condition turns red. The
key-pair condition of the table path is not observable on master: a
configuration without keys is not static, so `update()` merges the
endpoint auth settings, headers included, again on each query (ClickHouse#131104
removes that), and only the BACKUP path can show it.

Related: ClickHouse#131473

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the fromAST restriction comment to two lines and drop the parse-time reference from the getClient comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (3 rounds, final verdict: clean)
Finding Verdict
⚠️ Tests did not cover a matched endpoint section without keys, nor the backup path's endpoint match AGREE for BACKUP, fixed. For s3()/S3 tables DISAGREE: a configuration without keys gets the endpoint settings merged again on each query, so on master such a request carries the header with or without this PR (measured); #131104 removes that merge
⚠️ An S3 table lost the header on server restart (the startup load cleared all headers, even with a key pair) AGREE, fixed
⚠️ The docs said the header is sent "only when" the server keys sign AGREE, reworded
💡 The new docs sentence "other request material is not sent" does not yet hold for an endpoint section without keys, for the same per-query merge AGREE, not blocking: it holds on every path this PR changes and once #131104 lands
💡 No test for the catalog-credential guard in createObjectStorage DISAGREE: the guard keeps master's behaviour (drop) for catalog-credentialed tables; the BigLake module passes
💡 Endpoint matching is a string prefix DISAGREE: pre-existing; the same section's keys and session_token already go to that URL

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. test_s3_credentials_hardening/test.py::test_endpoint_header_reaches_requests_signed_with_endpoint_keys fails 1/1 on master and on the official 26.10.2.103 binary at the first request: Failed to get object info for key rp/data.tsv ... HTTP response code: 403, error type: ACCESS_DENIED; the proxy logs HEAD /root/rp/data.tsv without x-amz-request-payer.
b Root cause explained? Under the default s3_allow_server_credentials_in_user_queries = 0, the bare-URL user-query paths (S3StorageParsedArguments::fromAST, backup makeS3Client) clear all server <s3> request material, including the matched endpoint's header, while that endpoint's static keys still sign the request. The signed request lacks x-amz-request-payer, so S3 refuses HeadObject, ListObjectsV2, schema inference and BACKUP. At server startup getClient also cleared all headers of every restricted S3 table, although a table with a complete key pair is not downgraded to anonymous.
c Fix matches root cause? Yes. The clear is narrowed where it happens: headers are kept only when the URL matched an endpoint section and the server config's own key pair signs (no query keys, token or role_arn, no NOSIGN); a catalog credential that replaces those keys drops them again in createObjectStorage. At startup getClient drops headers only for NOSIGN or an incomplete key pair, the requests that do go out anonymously. The client already sends extra headers with every request kind.
d Test intent preserved / new tests added? Three new cases in the module that pins the restriction: the positive covers HEAD, GET, ListObjectsV2, S3 schema inference, a read of the S3 table after a server restart, BACKUP and RESTORE; the negatives pin each condition (NOSIGN, query keys, unmatched URL for s3() and BACKUP, explicit-key BACKUP, BACKUP to an endpoint section without keys). The existing 26 cases of the module still pass.
e Both directions demonstrated? Yes. Master: positive red at steps 1-4 (each probed separately), negative green. Fix: all green, 5/5 in fresh clusters. Removing each condition of the rule from the fix turns exactly its own negative step red; reverting only the backup change turns the BACKUP step red; reverting only the startup change turns the post-restart read red (403, no header sent).
f Fix is general across code paths? Table path (s3, s3Cluster, S3, S3Queue, data-lake S3 table functions), loading a persistent S3 table at startup, catalog credential overlays (BigLake, DataLake catalog refresh), backup reader and writer. Named collections are unchanged on purpose: a collection replaces the keys, so the server keys never sign its requests.
g Fix generalizes across inputs (params/datatypes/wrappers)? Exact key, glob, ENGINE = S3 without a structure, BACKUP and RESTORE, NOSIGN, positional query keys, a URL outside the endpoint section with global keys and a global header, explicit-key BACKUP, an endpoint section without keys, a server restart. Data type wrappers do not apply (request authentication).
h Backward compatible? (maintainer-approved exception only) Yes. No setting, default or format change. Anonymous requests and requests with query credentials behave as before; SSE keys and access_header are still dropped. Only the keyed-endpoint case gets its 26.6 behaviour back.
i Invariants and contracts preserved? Server request material reaches a request only together with the server config's own static keys, for an endpoint section that matched the URL; never with an anonymous request, never with credentials from the query or a collection. A query role_arn empties the keys before the check; the only exit between the old and the new clear is a throw, which discards the settings. At startup every client that is downgraded to anonymous (NOSIGN or no complete key pair) still has its headers and SSE keys cleared.

Session id: cron:clickhouse-impl-slot-4:20261114-040200

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c948056]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, parallel) FAIL
03634_autopr_output_bytes_estimation FAIL cidb

AI Review

Summary

The PR restores endpoint-configured header entries for S3 user queries signed with the matching server-configured keys, including persistent S3 tables after restart and BACKUP/RESTORE. Reviewed commit c9480567666305245f9fc4afd2d3b9979d36a6f2, the current code, regression coverage, and all prior discussion. The previous http_forbid_headers blocker is fixed; no additional actionable findings remain.

Missing context / blind spots
  • ⚠️ Integration tests were not rerun locally because this checkout has no ClickHouse build. The author reports successful focused before/after validation; the fetched CI reports contain no results for the new cases yet. A completed run of test_s3_credentials_hardening would provide independent execution evidence.
Final Verdict

Status: ✅ Approve. No new inline findings or thread changes are needed.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. labels Nov 14, 2026
Comment thread src/Backups/BackupIO_S3.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c94805676 with master 253dc40d7 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.58, programs/clickhouse-keeper ×0.67 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.9 s 10.3 s +6.8 s (+198%)
Compile time of recompiled translation units

11 translation units recompiled, 48 s compile time in total, 11 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -5.3 s (-10%) in total before that adjustment.

Job report

…headers`

`getClient` checks the headers of every `s3` table function and `S3` table client
against `http_forbid_headers`, but `makeS3Client` did not. Now that a restricted
bare-URL BACKUP/RESTORE keeps the matched endpoint section's `header` when the server
keys sign the request, such a header could reach the endpoint although the operator
forbade it. Check the headers before the client is created, as `getClient` does.

The new case configures an endpoint section with static keys and a header that
`http_forbid_headers` forbids: the `s3` read, BACKUP and RESTORE all fail with the
"forbidden" error, and the proxy records no request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c948056

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_asan_ubsan, azure, parallel) / 03634_autopr_output_bytes_estimation flaky, unrelated to this diff: query_10 estimate 142018 vs 362202 (below the test's 2.5x bound), passed 3 of 3 reruns; the tested tree already contains #131358, so that fix did not cover this run a fix task is moved to pending (investigating at full effort, fixing-PR link to follow here)

Session id: cron:our-pr-ci-monitor:20261114-113014

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 03634_autopr_output_bytes_estimation (ledger row for c9480567666305245f9fc4afd2d3b9979d36a6f2): #131697

@Algunenano Algunenano self-assigned this Nov 16, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Requesting changes because the implementation relaxes the credential boundary much more broadly than the requester-pays use case requires.

The motivating behavior only needs x-amz-request-payer: requester. This patch instead retains every generic <s3> header whenever the merged settings contain a complete static key pair. Generic headers can contain reusable credentials such as Authorization: Bearer ..., cookies, or API keys. The presence of a SigV4 key pair does not establish that those unrelated headers are safe to send.

There are two concrete problems:

  1. S3SettingsByEndpoint::loadFromConfig constructs endpoint settings by copying the global <s3> defaults and overlaying the endpoint section. Therefore, endpoint_settings.has_value() plus a complete merged key pair does not prove that either the header or the keys came from the matched endpoint section. A global header can be sent to a matched endpoint, and global keys can make a keyless endpoint header pass signed_with_server_keys.

  2. PocoHTTPClient reapplies extra_headers after a 307 redirect. Retaining arbitrary endpoint headers therefore allows a bearer token or API key to be forwarded to a different redirect target. http_forbid_headers is a blocklist and cannot establish that every otherwise permitted generic header is non-sensitive.

PR #131104 is a prerequisite because it prevents server authentication settings from being merged back into a restricted persistent S3 table. Please wait for #131104 to merge, merge the updated master into this branch, and rerun the focused tests before proceeding.

Please narrow this change to the exact requester-pays requirement instead of restoring arbitrary headers. A first-class request_payer = requester/s3_request_payer implementation, as proposed in #131512, is the safer shape. Alternatively, only synthesize the exact x-amz-request-payer: requester header from a typed, validated option. General <s3> header entries should remain stripped under s3_allow_server_credentials_in_user_queries = 0.

The minimum requested changes are:

  • Do not retain the complete generic auth.headers collection.
  • Support only the typed requester-pays behavior needed by the issue.
  • Wait for #131104 and merge the resulting master changes.
  • Add a negative test proving that an arbitrary endpoint header such as Authorization remains absent, including after table reload and on redirects.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks. Agreed on both problems, and that generic header entries stay stripped under s3_allow_server_credentials_in_user_queries = 0.

The typed shape you describe is already #131512: the request_payer = requester endpoint/disk key and the s3_request_payer setting synthesize only x-amz-request-payer: requester, appended after the restricted clear and checked against http_forbid_headers. Its test covers HeadObject, ListObjectsV2 and GetObject, an S3 table using the endpoint key before and after a restart, and BACKUP/RESTORE. With it, the reporter's config uses request_payer: requester instead of header.

Narrowed to the typed option, this PR would duplicate #131512. So my proposal: close this PR, and after #131104 merges, merge master into #131512 and add there the negative test you asked for (an arbitrary endpoint header such as Authorization stays absent next to request_payer, for s3(), after a table reload, and on a 307 redirect).

Should I close this PR in favour of #131512?

@Algunenano

Copy link
Copy Markdown
Member

@groeneai Yes please, let's wait until #131104 and keep #131512 only, whose security is way easier to track and validate that this PR

@groeneai

Copy link
Copy Markdown
Collaborator Author

Closing in favour of #131512. After #131104 merges I will merge master into #131512 and add the negative test there.

@groeneai groeneai closed this Nov 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done in #131512: master (with #131104) is merged in, and test_request_payer_does_not_send_endpoint_headers checks that an Authorization endpoint header next to request_payer, in a keyed and a keyless endpoint section, reaches no request: s3(), S3 tables before and after a restart, a bare-URL BACKUP, and the redirected requests. Its keyless cases fail without #131104. test_request_payer and the new test pass locally on the merged tree; the whole test_storage_s3 module and test_s3_credentials_hardening run in this PR's CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants