Skip to content

Add setting s3_request_payer for requester-pays S3 buckets - #131512

Merged
alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
groeneai:s3-request-payer-setting
Nov 22, 2026
Merged

alexey-milovidov merged 7 commits into
ClickHouse:masterfrom
groeneai:s3-request-payer-setting

Conversation

@groeneai

@groeneai groeneai commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131473

Changelog category (leave one):

  • New Feature

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

Add the setting s3_request_payer and the request_payer key of an endpoint section of the <s3> configuration and of an S3 disk. Set it to requester to read and write requester-pays S3 buckets with the s3 table function, the S3 table engine, S3 disks and BACKUP/RESTORE, without passing the raw x-amz-request-payer header.

Description

A requester-pays S3 bucket refuses every request that does not carry x-amz-request-payer: requester. Today it can be sent only as a raw header: the headers() argument of s3/S3, or a header key of a disk or an endpoint section, and an endpoint header is dropped for user queries under the default s3_allow_server_credentials_in_user_queries = 0. There is no setting, and BACKUP/RESTORE with keys in the query cannot send it at all (#131473).

This adds the setting s3_request_payer and the request_payer key of an <s3> endpoint section and of an S3 disk. One new S3AuthSettings field of the enum type S3RequestPayer (none or requester) serves all three, so an endpoint or disk key takes precedence over the setting. getClient (table functions, engines, disks) and makeS3Client (BACKUP/RESTORE) add the header to the client's signed extra headers after their header clears, so persistent S3 tables keep it across restarts. copyS3File now checks a copied object (s3_check_objects_after_upload) through the destination client: a requester-pays destination refuses a source client without the header.

This also answers item 2 of #131473: a generic endpoint header stays dropped under the restriction, since it can carry a credential such as Authorization that would also follow a redirect; request_payer is not one.

Validation: a test_storage_s3 mock in front of MinIO refuses (403) every request without a signed x-amz-request-payer: requester outside owner_pays/ and redirects the rest through itself. test_request_payer covers writes, HeadObject, ListObjectsV2, the endpoint key, the disk key, both keys under s3_request_payer = 'none', a restart, BACKUP/RESTORE, a RESTORE into the disk with s3_check_objects_after_upload, none, an invalid value and <http_forbid_headers>; each case fails on master. test_request_payer_does_not_send_endpoint_headers checks that an Authorization header next to request_payer in keyed and keyless endpoint sections reaches no request: s3, S3 tables across a restart, a bare-URL BACKUP, redirects. Its keyless cases fail without #131104.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.143-master (included in 26.12 and later)

A requester-pays bucket refuses every request without a signed
`x-amz-request-payer: requester` header. The only way to send it was the
`headers()` argument of the `s3` table function, so `ENGINE = S3`, S3 disks
and `BACKUP`/`RESTORE` could not read such a bucket.

Add a client field `request_payer` to `S3AuthSettings`. Through the existing
lookup it is the query setting `s3_request_payer`, the `request_payer` key of
the `<s3>` section and of an endpoint section, and the key of an S3 disk; an
endpoint or disk key takes precedence over the query setting. `requester` is
the only accepted value, anything else is `BAD_ARGUMENTS`.

`getClient` and `makeS3Client` append the derived header to the client's
extra headers, which are signed into every request kind, the same path the
`headers()` argument uses. In `getClient` it is added after the metadata-load
clear of the configured headers: that clear runs on every restricted metadata
load, also for a table whose client keeps its explicit keys, and such a client
is never rebuilt, so a header added before it was lost by a persistent `S3`
table after a restart. It is still checked by the existing final
`<http_forbid_headers>` check. `makeS3Client` never filters its header list,
so it checks the derived header explicitly and appends it after the
restriction clears the server-config headers. The field is a scalar, not
request-auth material, so `clearServerManagedRequestAuth` keeps it under the
default `s3_allow_server_credentials_in_user_queries = 0`.

The integration test puts a mock in front of MinIO that redirects a request to
MinIO only when the header is present and signed, and answers 403 otherwise.
It runs the endpoint and disk keys under a conflicting `s3_request_payer`, and
re-reads the `S3` table and the disk table after a server restart.

Related: ClickHouse#131473

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

mintlify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 80b4857.

Approve preview

@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds; final round: 0 findings)
Finding Verdict
❌ The payer header was added before the metadata-load header clear in getClient, so a persistent S3 table lost it after a restart AGREE, fixed; the test re-reads the table after a restart
⚠️ The endpoint/disk key precedence over s3_request_payer was not tested AGREE, fixed; both keys run under s3_request_payer = 'owner'
💡 Inline code for the setting name in two doc link labels AGREE, fixed
💡 s3_request_payer is validated when the client is built, not at SET noted, kept (one value)
💡 No request_payer key for named collections noted, s3(collection) SETTINGS s3_request_payer = 'requester' works

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @jkartseva, could you review this? It adds the setting s3_request_payer and a request_payer endpoint/disk key (one new S3AuthSettings field) that put x-amz-request-payer: requester into the S3 client's signed extra headers in getClient and in makeS3Client for BACKUP/RESTORE, so requester-pays buckets work without a raw header.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. test_storage_s3/test.py::test_request_payer against a mock that answers 403 to every request without a signed x-amz-request-payer: requester. On master the setting is unknown, and the endpoint and disk request_payer keys are ignored (403). The test also re-reads an S3 table and a disk table after a server restart.
b Root cause explained? The S3 client signs every x-amz-* entry of its extra headers into each request, which is how headers() works, but no setting or config key put x-amz-request-payer there, so ENGINE = S3, disks and BACKUP had no way to send it.
c Fix matches root cause? Yes. One S3AuthSettings field (query setting, endpoint key, disk key through the existing lookup) mapped onto the existing extra-header list in getClient and makeS3Client. No per-request plumbing, no change to signing or to the credential restriction.
d Test intent preserved / new tests added? New integration test; no existing test changed. The header is not observable with MinIO alone, hence the mock.
e Both directions demonstrated? Yes: fails on master, passes with the change (20/20 repeats); removing the getClient call site, the makeS3Client call site or the makeS3Client filter check each fails the cases that use it; adding the header before the metadata-load header clear fails the post-restart read of the S3 table.
f Fix is general across code paths? Both user-facing S3 client builders: getClient (s3, s3Cluster, S3, S3Queue, S3 disks) and makeS3Client (BACKUP/RESTORE). The Delta kernel object store already reads this header from the client's extra headers. The Keeper snapshot and Mecab dictionary clients are server-internal and not changed.
g Fix generalizes across inputs (params/datatypes/wrappers)? Values: empty (no header), requester, anything else is BAD_ARGUMENTS (tested). Surfaces: query setting, endpoint key under the default restriction, disk key, both keys under a conflicting s3_request_payer = 'owner', tables loaded at startup, backup, <http_forbid_headers>. Type wrappers: N/A.
h Backward compatible? (maintainer-approved exception only) Yes. New setting with an empty default, history recorded for 26.11; no default or format change.
i Invariants and contracts preserved? Every request path signs the extra headers; the per-request header filters drop only SSE and x-amz-meta-*; the metadata-load clear still drops every configured header and the SSE material, and only the derived header is added after it, so a table loaded at startup keeps it; the existing final checkHeaders covers the derived header in getClient, and makeS3Client checks it explicitly.

Session id: cron:clickhouse-impl-slot-7:20261114-015302

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [80b4857]

Summary: ✅


AI Review

Summary

Adds s3_request_payer and endpoint/disk request_payer configuration for requester-pays S3 access through table functions, engines, disks, and BACKUP/RESTORE. The previous restore-verification blocker is fixed and covered by the updated regression test. No outstanding findings. Both focused integration tests passed for 80b4857130da in the Praktika report.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-feature Pull request with new product feature can be tested Allows running workflows for external contributors labels Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 80b485713 with master 2b9cabd09 (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.

Object file sizes

72 object files changed (+46.70 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Core/SettingsEnums.cpp.o 2.47 MiB 2.49 MiB +23.53 KiB (+0.93%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Nov 14, 2026
groeneai and others added 2 commits November 16, 2026 20:50
…tting

# Conflicts:
#	src/IO/S3AuthSettings.h
Both endpoint sections of `requester_pays.xml` (one with keys, one keyless)
now also carry `Authorization: Bearer endpoint-header-token`. The new test
checks that under the default `s3_allow_server_credentials_in_user_queries = 0`
no request carries it next to `request_payer`: `s3()` writes and reads,
`S3` tables before and after a server restart, a bare-URL `BACKUP`, and the
redirected requests.

The requester-pays mock now records every request (`GET /__requests`,
`POST /__reset`) and routes an accepted request through a recorded
`/__redirected` hop, which checks it again, before redirecting it to
MinIO, so the redirected request is observed too.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review of the master merge and the new test (2 rounds; final round: 1 nit)
Finding Verdict
⚠️ The mock forwarded the redirected hop without checking the payer header, so a header lost on a 307 would have gone unnoticed AGREE, fixed; the mock checks every hop
💡 "the s3 function" in the moved doc sentence is not in inline code noted, kept (the existing doc wording)

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate, round 2: master merge + negative endpoint-header test (click to expand)
# Question Answer
a Deterministic repro? Yes. test_request_payer_does_not_send_endpoint_headers fails every run on the previous head built on pre-#131104 master (keyless s3() and S3 reads send Authorization: Bearer endpoint-header-token), and with the restricted clearServerManagedRequestAuth() in fromAST removed (keyed statements send it).
b Root cause explained? An endpoint header reaches a request if fromAST skips the restricted clear, or, before #131104, when applyNewSettings re-merged a keyless endpoint section per query; PocoHTTPClient re-applies extra headers after a redirect.
c Fix matches root cause? No new fix: the request_payer design is unchanged; the merge brings #131104 and the test pins the stripping next to request_payer.
d Test intent preserved / new tests added? New test only; test_request_payer is unchanged, its mock now routes accepted requests through a recorded redirect hop and checks the payer header on every hop.
e Both directions demonstrated? Passes on the merged tree: the new test and test_request_payer 3/3 each with the final mock (the new test 10/10 before the mock checked every hop); fails without #131104 (keyless cases) and without the fromAST clear (keyed cases). Local runs were a docker-free replay of the committed test functions (Docker was down on the build host).
f Fix is general across code paths? Covered: s3() (fromAST), S3 tables before and after a restart (getClient), bare-URL BACKUP (makeS3Client), the redirected requests.
g Fix generalizes across inputs (params/datatypes/wrappers)? Keyed and keyless endpoint sections; writes, reads, backup. Type wrappers: N/A.
h Backward compatible? (maintainer-approved exception only) Unchanged from round 1; no src/ change beyond the merge.
i Invariants and contracts preserved? No header-stripping code changed; the test asserts the stripping holds next to request_payer.

Session id: cron:clickhouse-impl-slot-4:20261116-204800

The 26.11 release branch was cut without this PR and master is now
26.12, so the settings history check requires the record of the new
setting under the current version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 20, 2026
@jkartseva jkartseva self-assigned this Nov 20, 2026
Comment thread src/Core/Settings.cpp Resolved
groeneai and others added 2 commits November 20, 2026 16:59
`s3_request_payer` and the `request_payer` key of an endpoint section or a
disk are now the enum `S3RequestPayer` with the values `none` (default) and
`requester`. An invalid value is rejected when the setting or the config key
is set, instead of when the S3 client is created.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tting

# Conflicts:
#	src/IO/S3AuthSettings.h
@clickhouse-gh
clickhouse-gh Bot dismissed their stale review November 21, 2026 15:14

AI review of a later commit does not approve the PR, see the AI Review comment.

`copyS3File` checked the copied object (`s3_check_objects_after_upload`)
through the source client. When the native copy is refused, the fallback
uploads the object through the destination client and checks it there, and
the outer check then repeated it through the source client. A `RESTORE`
from a backup that is not requester-pays into a disk with `request_payer`
on the same endpoint therefore failed after the upload succeeded: the
source client's `HeadObject` carries no `x-amz-request-payer`, and the
destination answers 403 ("Immediately after upload: Object ... suddenly
disappeared"). The same happens whenever the destination accepts only its
own client, e.g. other credentials.

Check through the destination client, which owns the destination in every
caller (it equals the source client unless a caller passes another one).

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

@alexey-milovidov alexey-milovidov 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.

All good.

@alexey-milovidov alexey-milovidov self-assigned this Nov 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 22, 2026
Merged via the queue into ClickHouse:master with commit 711cfda Nov 22, 2026
384 of 385 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 22, 2026
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-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants