Skip to content

Validate S3 request settings after the endpoint, disk and query settings are applied - #129670

Open
groeneai wants to merge 12 commits into
ClickHouse:masterfrom
groeneai:s3-validate-merged-request-settings-master
Open

groeneai wants to merge 12 commits into
ClickHouse:masterfrom
groeneai:s3-validate-merged-request-settings-master

Conversation

@groeneai

@groeneai groeneai commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #129578

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 rejection of valid S3 request settings: s3 queries, S3 tables, BACKUP and RESTORE validated the global <s3> section, an endpoint section and the query settings one at a time, so for example s3_max_upload_part_size below the default min_upload_part_size failed with INVALID_SETTING_VALUE even when an endpoint section lowered min_upload_part_size. The settings are now validated once, after all overrides. On config reload an S3 disk now validates its settings after merging the endpoint section: if they are invalid, the disk keeps its current request settings and logs an error, instead of later writes and merges failing, and its new credentials are still applied, while removed ones are dropped. The endpoint settings shared by all queries no longer take the s3_* settings of the first S3 query after server start.

Description

Follow-up to #129578, requested there by @ PedroTadim.

On 26.10.2.103, an s3 query, BACKUP or RESTORE whose effective request settings are valid is rejected with INVALID_SETTING_VALUE when one layer (the global <s3> section with the query settings, or an endpoint section) is invalid on its own. Example: an endpoint section with min_upload_part_size = 5242880 plus SETTINGS s3_max_upload_part_size = 8388608 fails against the default 16 MiB minimum.

Each intermediate S3RequestSettings layer was validated before the later layers were applied. These layers are now built without validation; the final checks are unchanged. An S3 table checks query overrides before storing them; a write without query settings checks the stored ones. At config reload S3 disks merged the endpoint section without validating the result, so a contradictory disk + endpoint pair was accepted and later writes failed. Now such a disk (or one with an invalid section of its own, which aborted the reload) keeps its request settings and logs an error, while its new credentials and the rest of the reload are applied; the endpoint map is rebuilt before the disks. A disk reload builds the credentials from the current config only, so removed keys or headers are no longer kept.

The endpoint map shared by all queries was built with the s3_* settings of the first S3 query after start; it is now built from the server settings.

Tests: stateless 05546_s3_request_settings_validated_after_endpoint_override, integration test_s3_request_settings_merged_layers and unit S3ObjectStorage.WriteWithoutQueryContextValidatesStoredSettings. Each fails on master and passes with the fix.

🤖 Generated with Claude Code


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

groeneai and others added 2 commits November 6, 2026 03:25
…ngs are applied

S3 request settings are built from layers: the global <s3> section, a
matching <s3> endpoint section, a disk's own section and the
user/profile/query s3_* settings. S3RequestSettings validated each layer
when it was built, before the later layers were applied, so a layer that
is invalid on its own was rejected even when the effective settings were
valid. For example an endpoint section with min_upload_part_size = 5 MiB
plus a query with s3_max_upload_part_size = 8 MiB failed with
INVALID_SETTING_VALUE against the default 16 MiB minimum, for s3()
queries, S3 tables, named collections, BACKUP and RESTORE. An endpoint
section that is invalid alone also threw in the middle of
S3SettingsByEndpoint::loadFromConfig, which leaves the lazily built
endpoint map half filled, so later queries lost their endpoint settings.

Intermediate layers are now built without validation. Every existing
final check stays as it was: the merged checks in fromAST, readObject
and writeObject per query, updateFromSettings in BackupReaderS3 and
BackupWriterS3, and the disk-section check at disk reload.

S3 disks merge the matching endpoint section at config reload and never
validated the merged result, and background merges use those settings
with no per-query check. A disk section and an endpoint section that are
each valid but contradict each other once merged were accepted by
SYSTEM RELOAD CONFIG; afterwards every write failed, and a merge could
abort a debug server in ExpBufferAllocationPolicy (std::clamp with
min > max). The config reload of a server disk now validates the merged
settings before installing them (ApplyNewSettingsOptions::
validate_merged_settings) and refuses the reload instead.
Context::updateStorageConfiguration now rebuilds the S3 endpoint map
before reloading the disks, so that check sees the endpoint section of
the same config rather than the one of the previous reload. Data-lake
tables on a disk keep applying query settings on top, so they are not
validated at that point.

Follow-up to ClickHouse#129578, requested there by the assignee.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the two-line comments on validate_merged_settings and on the table-path validate flag in S3ObjectStorage::applyNewSettings to one line each.

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

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds)
  • ❌ Disk-reload merged check used the endpoint settings of the previous reload - AGREE, fixed: the endpoint map is rebuilt before the disks; the integration case covers a fixed endpoint section accepted without a restart.
  • ❌ Disk section still checked before the endpoint merge - DISAGREE: a disk is created at server start from its own section only (ObjectStorageFactory.cpp:194), so that config would fail the next start.
  • ❌ Named-collection request settings checked before query and endpoint overrides - DISAGREE: max_upload_part_size and strict_upload_part_size are not collection keys, so that layer fails alone only on a value invalid in any combination (zero, a min above the 5 GiB default max, a name outside the allow-list).
  • ❌ Explicit storage class applied after the check (s3(), BACKUP) - DISAGREE: the per-query re-merge applies the <s3>/endpoint class over the s3() argument, so a later check fails the same way at first use; checking the BACKUP class would reject s3_storage_class = 'GLACIER', which master accepts.
  • ⚠️ No test with an invalid global <s3> layer - DISAGREE: in 05546 the query's s3_max_upload_part_size enters that layer; reverting the backup or named-collection hunk turns it red.
  • 💡 A refused disk reload keeps the other parts of that reload, now including the endpoint map; every consumer still validates its final settings - noted, not blocking.

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local with an endpoint section min_upload_part_size = 5242880 and SETTINGS s3_max_upload_part_size = 8388608 fails with Code: 471 on every run, before any network I/O (also BACKUP, named collection, <s3> + endpoint layers). Disk case: disk s3_max_upload_part_size = 32 MiB + endpoint min_upload_part_size = 64 MiB, SYSTEM RELOAD CONFIG, OPTIMIZE ... FINAL.
b Root cause explained? S3RequestSettings validates at construction, and every intermediate layer (global <s3>, endpoint map entries, backup and table <s3> layers) was built with validation on, before the layers that override it. S3 disks merge the endpoint entry at reload and never validated the merged result; the endpoint map was rebuilt only after the disks at reload.
c Fix matches root cause? Yes. Intermediate layers are built without validation; every final check stays. The reload of a server disk validates its merged settings, which are its final settings (background operations use them as they are), against the endpoint map of the same config, now rebuilt before the disks.
d Test intent preserved / new tests added? New stateless test 05546_... and integration test test_s3_request_settings_merged_layers (4 cases). No existing test changed.
e Both directions demonstrated? Yes. Master: stateless test fails, 3 of 4 integration cases fail at their oracles, the disk case aborts a debug server. Fix: all pass, 50/50 randomized runs of the stateless test, 3 consecutive integration runs, and a contradiction fixed in the endpoint section is accepted by the next reload without a restart. Reverting each fix hunk separately reddens a case.
f Fix is general across code paths? Yes. Every construction/validation site of S3RequestSettings was classified as intermediate or final (s3 table functions and engines incl. data lakes and GCS, named collections, BACKUP/RESTORE, endpoint map, disk reload). Azure already validates at use only.
g Fix generalizes across inputs (params/datatypes/wrappers)? Type wrappers N/A (UInt64 settings). Covered layer combinations: <s3> + endpoint, endpoint + query, disk + endpoint, named collection, backup; invalid alone but valid merged, and valid alone but invalid merged.
h Backward compatible? (maintainer-approved exception only) No setting, default or format change. Configs that are valid after merging are now accepted. A disk + endpoint pair that contradict each other once merged now fails SYSTEM RELOAD CONFIG; master accepts it and writes then fail. Server start with such a config is unchanged.
i Invariants and contracts preserved? The merged check runs before the client rebuild and before the settings are installed, so a refused reload leaves the disk on its previous settings (measured: the disk keeps working). s3_validate_request_settings keeps its meaning; the backup final check still always validates.

Session id: cron:clickhouse-impl-slot-4:20261106-024900

@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

cc @alesapin @CheSema, could you review this and add the can be tested label so CI runs? Each S3 request settings layer (global <s3>, endpoint section, query settings) was validated on its own before the later layers were applied, which rejected valid merged settings; now only the final settings are validated, and the config reload of an S3 disk validates its merged disk + endpoint settings, with the endpoint map rebuilt before the disks.

@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a1bc1f9]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

The PR defers S3 request-settings validation until configuration layers are merged and preserves credential updates when a disk's request settings are rejected. Credential removal is still incomplete for existing data-lake tables using private copies of the disk's object storage.

Findings

❌ Blockers

  • src/Disks/DiskObjectStorage/ObjectStorages/S3/S3ObjectStorage.cpp:816: Disk-backed data-lake tables retain removed credentials. DataLakeConfiguration::fromDisk clones the object storage, while StorageObjectStorageConfiguration::update refreshes that clone with server_disk_reload = false. The new authentication reset is skipped, and updateIfChanged preserves omitted credentials. Create an Iceberg table using a disk with key pair A and use_environment_credentials = false, remove both key fields, then reload otherwise valid configuration: the original disk loses A, but the existing table continues signing new writes with A. Reconstruct configuration-derived authentication for these copies too and detect removals when deciding whether to replace their clients; keep this separate from request-validation mode so query overrides remain supported.
Tests
  • ⚠️ Extend the credential-removal regression with an existing disk-backed Iceberg table and assert that a new write is denied after reload. Current coverage exercises the original disk only. The finding is based on source tracing; no local ClickHouse binary/build was available for a live reproduction.
Final Verdict

Status: ❌ Block. Apply credential removal to existing disk-derived clients and add the focused regression above.

@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 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 8114eaaaf with master 4553bee2f (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.

Compile time of recompiled translation units

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

Job report

The query settings of the test (s3_max_upload_part_size = 8 MiB) are valid only at the test endpoint,
whose min_upload_part_size is 5 MiB. Every S3 object storage applies and validates the query's S3
settings on each read and write (S3ObjectStorage::readObject/writeObject), so a query that also
reads another S3 storage fails there: with the remote database disk (`db disk` CI lanes) the BACKUP
reads the table metadata from it, the read fails with "max_upload_part_size (8.00 MiB) can't be
less than setting min_upload_part_size (16.00 MiB)", and the swallowed error surfaces as
"Table ... was not found" (UNKNOWN_TABLE). With MergeTree on S3 (`s3 storage` lanes) the s3()
INSERT and the RESTORE fail the same way. This is master behaviour, unrelated to the fix.
A Memory table in a Memory database keeps the metadata and the data off any disk.

Also check that invalid effective settings are still rejected by RESTORE (BackupReaderS3) and by
a named-collection INSERT and SELECT (per-operation checks in S3ObjectStorage). Each new case
turns red when its check is disabled; the INSERT one then aborts a debug server in
ExpBufferAllocationPolicy.

Measured with a local MinIO: the test passes on the PR binary with the plain, remote database
disk and S3 MergeTree configurations (50/50 with both), and fails on master 770b0c15 with the
per-layer rejection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/IO/S3Settings.cpp Resolved
`Context::getStorageS3Settings` built the server-wide endpoint map lazily
with the settings of its first caller, so the `s3_*` settings of the first
S3 query after start were copied into every endpoint entry and applied to
later queries of all users. A config reload already rebuilds the map from
the global context's settings. Every per-request path re-applies the
query's own `s3_*` settings on top (the end of `fromAST`, `BackupReaderS3`/
`BackupWriterS3`, `S3ObjectStorage::readObject`/`writeObject`), so nothing
needs them in the shared map.

The previous commits made this easier to reach: a first query that is only
valid with its endpoint's override (endpoint A `min_upload_part_size` 5 MiB
plus `s3_max_upload_part_size = 8388608`) used to be rejected before the map
was built; it now succeeds and left an 8 MiB maximum for endpoint B, so
default queries to B failed with INVALID_SETTING_VALUE until the next reload.
The same leak was reachable on master with a first query valid everywhere
(`<s3>` min 5 MiB / max 20 MiB, endpoint A max 1 GiB, first query
`s3_min_upload_part_size = 25165824`: later default queries to B failed).

`S3ObjectStorage::writeObject` validates the stored request settings when no
query settings are applied on top. A table merges its endpoint section into
them without validation, and an unpartitioned S3 sink opens its write buffer
before the insert gets a query thread group, so a Buffer flush into such a
table after a reload added an endpoint section with
`upload_part_size_multiply_parts_count_threshold = 0` reached
`ExpBufferAllocationPolicy` unvalidated (debug abort on
`multiply_threshold > 0`, modulo by zero otherwise). Master refuses that
reload because it validated the endpoint entry while building the map. The
server's `s3_validate_request_settings` applies there, as for the reload.

Adds a fresh-server case to test_s3_request_settings_merged_layers, plus two
cases for the deferred checks: a Buffer flush into an unpartitioned S3 table
whose endpoint section sets a value invalid in any combination is rejected
(without the new check the debug server aborts), and the data-lake case now
uses an endpoint section invalid alone (max 8 MiB) and asserts that without
the query override the merged disk + endpoint settings are rejected with
their effective values (fails on master and when either layer is skipped).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim PedroTadim self-assigned this Nov 6, 2026
@groeneai

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 155c67d

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
Performance Comparison (arm_release, master_head, iceberg_local, 2/3) / prewhere_subcolumn_read_steps not from this PR's diff: the shard's one run error is Column j of type JSON(max_dynamic_paths = 0) has no Iceberg equivalent, because the test was missing from tests/performance/iceberg_skip_list.txt. The tested merge commit ce2615a29da6 does not contain the fix #129658 (ours, merged)
Performance Comparison (arm_release, master_head, iceberg_s3, 2/3) / prewhere_subcolumn_read_steps same run error and same tested tree as the row above #129658 (ours, merged)
Performance Comparison (arm_release, master_head, iceberg_local, 3/3) / lazy_final_aggregation_in_order not from this PR's diff: the shard's one run error is the test's fill check expected 2 active parts, which finds no parts for the Iceberg table; same tested tree, without the skip-list entry #129658 (ours, merged)
Performance Comparison (arm_release, master_head, iceberg_s3, 3/3) / lazy_final_aggregation_in_order same run error and same tested tree as the row above #129658 (ours, merged)
PR praktika rollup of the rows above #129658 (ours, merged)

The slower marks in the 3/3 shards (aggregation_by_partitions, minmax_count_projection_plan_time) do not fail an Iceberg shard on their own: 425 of 462 Iceberg shard runs with a slower mark in the last 7 days passed. The Config Workflow / Pre Hooks rows in CIDB belong to the run before the can be tested label.

Session id: cron:our-pr-ci-monitor:20261106-130003

@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai Validating once after all layers looks right for s3(), BACKUP/RESTORE, named collections and tables, and building the shared endpoint map from the server settings fixes the cross-query leak.

One concern with the new disk-reload check: a failed check now aborts much more than that disk's reload.

  • A server that starts with such a config refuses every later reload. At start a disk is built from its own section only (registerS3ObjectStorage calls loadFromConfigForObjectStorage(..., true) without the endpoint map), and only applyNewSettings merges the endpoint section. test_disk_reload_with_contradicting_endpoint_section_is_refused shows it: the server starts with disk max 32 MiB + endpoint min 64 MiB, and then SYSTEM RELOAD CONFIG fails. That stays so until the config is fixed, including reloads for unrelated changes.
  • The exception propagates out of DiskSelector::updateFromConfig and Context::updateStorageConfiguration into the reload callback in Server.cpp, and ConfigReloader only logs it. So everything after updateStorageConfiguration is skipped: updateInterserverCredentials, all the cache resizes, NamedCollectionFactory::reloadFromConfig, latest_config = reload_config. Inside the storage reload, the disks before the failing one have already applied their new settings, the ones after it have not, new disks and storage policies are not installed, and the endpoint map (now rebuilt first) already holds the new config.

Before this PR, such a reload succeeded and only that disk's writes failed later. A failure of the disk's own section could already abort the reload the same way, but that section is also checked at start, so a server could not run into it with an unchanged config.

Could a failed merged check keep the disk's current settings and log an error instead of throwing out of the reload? The rest of the reload would then still apply, and the integration test could check that the disk keeps its settings while another setting in the same reload is applied.

…n reload

At config reload an S3 disk merges the endpoint section into its settings and
validates the result. A failed check threw out of `DiskSelector::updateFromConfig`
and `Context::updateStorageConfiguration`, so the rest of the reload was skipped:
later disks, new disks and storage policies, interserver credentials, cache sizes,
named collections. A server started with such a pair (at start a disk is built from
its own section only) refused every later reload, including unrelated changes.

Now the disk keeps its current settings, the error is logged, and the rest of the
reload is applied. The check of the disk's own section is unchanged.

Requested in ClickHouse#129670 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The per-query update of an S3 table merges the query's `s3_*` settings into the
settings stored in the table, and a later query with default settings cannot
revert them. Since the merged settings are validated only in `readObject` and
`writeObject`, a rejected override stayed stored: after
`INSERT ... SETTINGS s3_max_upload_part_size = 4194304` failed against an
endpoint with `min_upload_part_size = 5242880`, every later default INSERT into
the table failed with the same error. On master the per-layer check rejected the
query before the settings were stored.

The table path now runs the same check, with the query settings on top, before
storing the settings.

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

groeneai commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Done in 65f23d1 (commit). When the merged check fails, the disk logs The new S3 settings of disk <name> were not applied, it keeps its current settings: <reason> and returns before its S3 settings or client are replaced, so it keeps the valid settings it runs with. The rest of the reload is applied. The check of the disk's own section is unchanged.

The integration case now starts the server with disk max 32 MiB + endpoint min 64 MiB, then reloads with an extra disk added: the reload succeeds, the new disk is in system.disks, the error is logged, and INSERT + OPTIMIZE FINAL on the disk work. The same holds for a later endpoint-only contradiction. It fails on the previous head (the reload fails with code 347) and with a variant that logs but installs the merged settings (the next INSERT fails with code 471).

Also fixed in 4cabbf4 (commit), a regression from this PR found in re-review: the table path stores the query's s3_* settings and no longer checked them first, so a rejected SETTINGS s3_max_upload_part_size = 4194304 stayed in an S3 table and every later default INSERT into it failed. The table path now runs the per-query check before storing. A new integration case fails on the previous head and passes on master and with the fix.

@PedroTadim PedroTadim removed their assignment Nov 6, 2026
The server's ConfigReloader polls the config files every 2 seconds, so it could
reload a replaced file on its own before the test's SYSTEM RELOAD CONFIG. Both
reloads log "were not applied", and the absolute counts (1, then 2) failed in
the flaky check with 3. A background reload also hid a revert of the
endpoint-map-before-disks ordering, since the explicit reload then saw the
already rebuilt endpoint settings.

Pin config_reload_interval_ms to an hour in the test's config, as other
reload tests do, and match the log line of each explicit reload by its
query_id with wait_for_log_line, which also waits for the asynchronous logger.

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

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

🤖 Please add a focused regression test for this failure path first: start an S3 disk with credential A, reload credential B (or remove credentials) together with contradictory request settings, and verify that credential A can no longer be used.

In S3ObjectStorage::applyNewSettings, both authentication and request settings are merged into modified_settings, but a request-settings validation failure returns before the client is rebuilt or the new settings are installed. As a result, an invalid upload setting can leave the old authenticated client active indefinitely, even when the same configuration reload was intended to rotate or revoke its credentials.

This path must always fail closed. On validation failure, the disk must not continue serving requests through the old authenticated client. It can preserve the previous validated non-authentication request settings only if the new authentication state is safely applied and the client is rebuilt; otherwise, disable the disk/client until a valid configuration is loaded.

groeneai and others added 2 commits November 16, 2026 17:10
… invalid

A config reload that left the request settings of an S3 disk invalid returned
from `S3ObjectStorage::applyNewSettings` before the client was rebuilt, so a
reload that also rotated or revoked the disk's credentials kept the old
authenticated client. An invalid disk section alone threw out of the reload
with the same result.

Now both checks of a disk reload (the disk section alone and the settings
merged with the endpoint section) only keep the current request settings and
log an error: the new authentication settings are still applied and the
client is rebuilt.

Also test the check of `writeObject` for writes without a query context
directly: the table check in `applyNewSettings` now rejects the Buffer flush
of `test_background_write_checks_endpoint_settings` before the write.

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

Copy link
Copy Markdown
Collaborator Author

Thanks, fixed in 8114eaa.

  • When the new request settings of a disk are invalid, only its request settings are kept now. The new authentication settings are applied and the client is rebuilt (the disk reload always rebuilds it), so the old client is not used after the reload. The check of the disk section alone works the same way now; it used to throw out of the reload, which also left the old client in place.
  • Test test_disk_reload_with_invalid_request_settings_applies_new_credentials: the disk starts with credential A, then a reload switches it to credentials that MinIO rejects, first together with a contradictory endpoint section, then with an invalid disk section. The next INSERT must fail with The Access Key Id you provided does not exist, and after reloading valid credentials it succeeds again. On the previous head (5bba379) the INSERT after the first reload still succeeds with credential A, and the second reload fails (Code: 347 wrapping 471).

I also merged master to resolve the conflict in S3ObjectStorage::applyNewSettings; the new explicit_request_settings are applied before the check.

…request-settings-master

# Conflicts:
#	tests/config/config.d/s3_settings_override.xml
`S3ObjectStorage::applyNewSettings` merged the authentication settings of
the endpoint section and of the disk section into the previous ones with
`S3AuthSettings::updateIfChanged`, which only copies the fields a layer
sets. So a reload that removed `access_key_id`/`secret_access_key` (or a
header) from a disk kept signing with the removed credentials. Since the
previous commit, a reload with invalid request settings also succeeds and
rebuilds the client, so removing the credentials together with an invalid
request setting kept them as well (clickhouse-gh review on ClickHouse#129670).

The config reload of a server disk now builds the authentication settings
from the current config only (endpoint section, then disk section). The
option is renamed to `server_disk_reload`, since it now controls both
the authentication rebuild and the merged request-settings check.

Measured on a private bucket with `use_environment_credentials = false`:
before, the INSERT after a reload removing the keys still succeeded (also on
master for a reload with valid request settings); now it fails with
`Access Denied`, and reloading the keys again restores writes. The
integration test covers the plain removal and the removal together with
both kinds of invalid request settings.

auto modified_settings = std::make_unique<S3Settings>(*s3_settings.get());
/// Merging below only adds the fields a layer sets, so credentials removed from the config would be kept.
if (options.server_disk_reload)

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.

[Blocker] Apply credential removal to existing data-lake copies of the disk

DataLakeConfiguration::fromDisk retains a private clone of the disk's object storage. Its refresh in StorageObjectStorageConfiguration::update calls applyNewSettings with server_disk_reload = false, so this reset never runs for that clone. Both authentication merges still use updateIfChanged, which preserves omitted keys and empty header lists. Reloading the original disk does not replace the clone's client.

For example, create an Iceberg table with SETTINGS disk = 'merged_s3', using key pair A and use_environment_credentials = false. Remove both key fields and run SYSTEM RELOAD CONFIG with otherwise valid request settings. The original disk loses A, but an INSERT into the existing Iceberg table still uses A: its refresh merges the now-absent fields into its old settings and retains the authenticated client. Credential revocation therefore remains bypassable through a supported consumer of this disk.

Reconstruct configuration-derived authentication for these copies too, and ensure removals trigger client replacement (hasUpdates also uses updateIfChanged). Keep this independent of the request-validation mode, since data-lake copies still need query overrides. Extend the removal regression with an existing disk-backed Iceberg table and verify that a new write is denied after reload.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This PR does not change that path: the copy a disk-backed data-lake table keeps is refreshed by StorageObjectStorageConfiguration::update without server_disk_reload and merges into its old credentials exactly as on master, so it keeps removed keys there as well. Making that refresh rebuild its credentials from the config is a separate change to the data-lake path, not part of validating the merged request settings, so I am leaving it out of this PR.

huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 17, 2026
… the first query

`Context::getStorageS3Settings` builds the `S3SettingsByEndpoint` map shared
by all queries on first use, and passed the settings of the calling query.
`S3RequestSettings(config, settings, prefix)` copies every changed `s3_*`
setting into the object as changed, `loadFromConfig` puts it into every
endpoint entry, and consumers merge the entry with `updateIfChanged`. So the
first S3 query after a start set the endpoint values for every later query
and user: a default backup to a configured endpoint ran with that query's
`s3_max_inflight_parts_for_one_file` / `s3_min_upload_part_size`, and a
valid `s3_min_upload_part_size` above that query's `s3_max_upload_part_size`
was rejected with INVALID_SETTING_VALUE, until `SYSTEM RELOAD CONFIG`, which
rebuilds the map from the server settings.

The first build now uses the global context's settings, the same input as
the reload. Every consumer still applies the current query's own changed
settings on its copy. `getGlobalContext()` and `getSettingsRef()` take no
lock, so nothing new is locked under `shared->mutex`; the global settings
are written only at startup, before any query. The line is the same as in
ClickHouse#129670.

The new integration test restarts the server before each case so that the
map is built by its first S3 query, which no stateless test can do.

Closes ClickHouse#131964

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

This branch has not been deployed

No deployments
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.

3 participants