Skip to content

Do not let a session switch a shared object storage client to server credentials - #131104

Merged
Algunenano merged 8 commits into
ClickHouse:masterfrom
Algunenano:pin-object-storage-credential-mode
Nov 16, 2026
Merged

Algunenano merged 8 commits into
ClickHouse:masterfrom
Algunenano:pin-object-storage-credential-mode

Conversation

@Algunenano

@Algunenano Algunenano commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Related: #120343
Related: #106855

The S3 or Azure client of a table is shared by all sessions that access it. Before, each query rebuilt it for its own session, so a session with s3_allow_server_credentials_in_user_queries enabled could switch it to the server's credentials while a restricted query that had already passed its check was still reading with it. Now a table keeps the restriction mode it was created with (or the one of the startup context), and only a forced rebuild by the server changes it.

Also:

  • A direct SELECT from an S3Queue, and ALTER, OPTIMIZE and mutations of S3 tables, now check the restriction for S3 too, as was already done for Azure.
  • A session with the setting disabled cannot use an S3 table created with it enabled, even with explicit keys or NOSIGN: its settings may hold a server role_arn, headers or encryption keys that only the parsing of a restricted query drops.
  • A restricted S3 table no longer merges the auth settings of the server <s3> and endpoint config on each query, which brought back the role_arn, headers and encryption keys dropped when it was created.

Changelog category (leave one):

  • Backward Incompatible Change

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

Previously, each session accessing a persistent S3, S3Queue, AzureBlobStorage, or AzureQueue table could rebuild its shared client using that session's s3_allow_server_credentials_in_user_queries value. The table now keeps the credential-restriction mode used to build its client. A session where the setting is disabled cannot use an S3 or S3Queue table created with it enabled, even with explicit credentials or NOSIGN; an Azure table is rejected only when its cached client uses the server's identity. Enabling the setting no longer restores server credentials to a table loaded anonymously after restart, and an S3 table created with the setting disabled no longer picks up authentication changes from <s3> or endpoint configuration on each query. DETACH and ATTACH the table in a session with the intended setting after restart or credential rotation to rebuild its client.


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

Version info

  • Merged into: 26.11.1.2459-master (included in 26.11 and later)

Algunenano and others added 7 commits November 12, 2026 17:05
…credentials

The client of an `S3` or `AzureBlobStorage` table is shared by all sessions, so an opt-in session upgrading it could hand server credentials to a concurrent restricted query that already passed its check. Sessions may now only make the client stricter; only a forced rebuild follows the given context.

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

A direct `SELECT` from an `S3Queue`, and `ALTER`/`OPTIMIZE`/mutations of S3 tables, use the client without refreshing it for the session. A restricted session is now refused there if the client was built with the opt-in and the definition needs the server's credentials, as was already done for Azure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rebuilding such a client under the restricted context is not a sound check: its stored settings may keep server-derived material, such as a `role_arn` or headers, which only the parsing of a restricted query drops. It could also race with an opt-in rebuild. Now a session never changes the restriction mode of a shared client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A restricted query drops the server's `role_arn`, headers and encryption keys from its S3 settings, but every later query merged the `<s3>` and endpoint auth settings back and rebuilt the client with them. A restricted client now keeps the auth settings it was created with.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Instead of freezing the auth settings of a restricted client, merge the config as before and then restore the fields that the parsing of a restricted query drops (`role_arn`, GCP OAuth, headers, encryption keys) from its stored settings. Static keys rotated in the config still reach existing tables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The parsing of a restricted query filters the config's auth settings with conditional rules, e.g. it drops the config's static keys when the query supplies a `role_arn` without its own keys. Restoring a fixed list of fields after the merge misses such rules, so a restricted client keeps the auth settings it was created with.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sessions with different values of `s3_allow_server_credentials_in_user_queries` do not share a table's access: the table keeps the mode it was created with, and only attaching it again changes it.

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

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c819dc8]

Summary: ✅


AI Review

Summary

Reviewed PR #131104 at c819dc874ae14b516976418ab5cde1fdac08ba64, including all prior discussion. The change prevents sessions from upgrading shared S3/Azure clients to server credentials and extends S3 checks to entrypoints that reuse a client. No remaining findings. The added Azure regression checks anonymous requests after restart and authenticated requests after detach/attach, addressing the previous finding; that thread has been resolved.

Missing context / blind spots
  • ⚠️ Focused S3/Azure runtime results were unavailable in the CI reports inspected. Regression tests were reviewed but not run locally; their CI execution remains pending validation.
Final Verdict

✅ Approve. No new inline findings; focused runtime validation remains with CI.

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Nov 12, 2026
@Algunenano Algunenano self-assigned this Nov 12, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c819dc874 with master d89be9791 (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.69, programs/clickhouse-keeper ×0.68 (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.8 s 12.2 s +8.2 s (+206%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 7.7 s +5.4 s (+232%)
Compile time of recompiled translation units

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

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

Job report

…anonymous

A table created with the opt-in now serves no restricted session, so create it restricted. Add a test that an
opted-in read does not give the server's identity back to an Azure table loaded anonymously after a restart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano
Algunenano added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit 1ece88b Nov 16, 2026
204 checks passed
@Algunenano
Algunenano deleted the pin-object-storage-credential-mode branch November 16, 2026 18:00
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@Algunenano — title/description suggestions:

Description (currently incomplete):

  • Why: The body says a restricted S3 table no longer merges the auth settings of the server <s3> and endpoint config, which reads as credentials only. The gate (merge_auth_from_config, S3ObjectStorage.cpp:810) covers all of S3AuthSettings, which also holds client settings read by getClient (diskSettings.cpp:109-183). The changelog entry text is empty.

  • Suggested addition:

    Note: S3AuthSettings also holds connect_timeout_ms, request_timeout_ms, use_adaptive_timeouts, region, uri_style and the keep-alive settings. A restricted non-static S3 table therefore no longer merges them per query, from the server <s3>/endpoint config or from session s3_connect_timeout_ms/s3_request_timeout_ms/s3_use_adaptive_timeouts/s3_uri_style, the same as a table with explicit keys already behaved. DESCRIBE TABLE of an opt-in S3 table is refused for restricted sessions as well, because it triggers the deferred hive sample-path listing.

Ignore if intentional.

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

Labels

comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-backward-incompatible Pull request with backwards incompatible changes 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.

3 participants