Skip to content

Require the same source and WRITE for queue after_processing - #129383

Merged
NIKTONIKTO717 merged 29 commits into
masterfrom
fix-69745
Nov 22, 2026
Merged

NIKTONIKTO717 merged 29 commits into
masterfrom
fix-69745

Conversation

@NIKTONIKTO717

@NIKTONIKTO717 NIKTONIKTO717 commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Closes: https://github.com/ClickHouse/clickhouse-private/issues/69745
Related: #86907

Tables sharing a keeper_path share one after_processing, so a table joining another queue's path could make it delete, move or tag its files. Keeper now stores the source, which must match, these actions need WRITE, and ALTER changes only the settings it names.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fixed a table with the keeper_path of another S3Queue or AzureQueue making it delete, move or tag its source files. The source must now match, and these actions need the WRITE grant.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.12.1.167-master (included in 26.12 and later)
  • Backported to: 26.11.1.2922, 26.10.12.3, 26.9.37.9, 26.8.45.8, 26.3.71.5

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [10e54da]

Summary: ✅


AI Review

Summary

The PR binds shared queue metadata to a source hash, requires WRITE for destructive after_processing actions, and limits ALTER to the requested shared settings. One source-isolation bypass remains: session settings can change a literal S3 URL's meaning during reattachment, while the attach exemption hides the mismatch.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or configured build was available. The finding is based on tracing the current parser, attach, metadata-factory, and ordered-progress paths; the reproduction has not been executed locally.
Findings

❌ Blockers

  • ObjectStorageQueueMetadata.cpp:621: Literal sources can change during ATTACH and bypass source isolation. S3StorageParsedArguments::fromAST uses the current session's URL-parsing settings. Create two ordered queues with the same keeper_path, processing_threads_num = 1, buckets = 1, and after_processing = 'keep', using http://localhost:11111/test/prefix/*.csv?X-Amz-Signature=a under compatibility_s3_presigned_url_query_in_path = 1. Detach the second queue, switch that setting to 0, and reattach it. Its resolved pattern becomes prefix/*.csv, but the exemption overwrites its computed source hash with Keeper's hash, so the factory accepts the different source. Consuming prefix/z.csv through that queue advances the shared ordered pointer past an unconsumed prefix/a.csv_X-Amz-Signature=a, which the original queue then skips. This needs no WRITE grant. Enforce the resolved identity on user-controlled reattachment or persist the URL-parsing semantics; distinguish legacy startup compatibility from this path.
Tests
  • ⚠️ Add a focused regression that changes compatibility_s3_presigned_url_query_in_path between detach and attach and verifies that a mismatching source cannot resume against the original queue's progress. Cover the analogous s3_uri_style carrier if parsing semantics are persisted rather than validating every user reattachment.
Final Verdict

Status: ❌ Block

Close the literal-source reattachment bypass and add its regression coverage.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Nov 4, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). label Nov 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 10e54da34 with master 4cbc68b27 (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

32 object files changed (+55.44 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorageQueue/registerQueueStorage.cpp.o 313.98 KiB 332.47 KiB +18.48 KiB (+5.89%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp.o 1.19 MiB 1.21 MiB +18.21 KiB (+1.49%)

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

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

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

Job report

@antonio2368 antonio2368 assigned kssenii and unassigned antonio2368 Nov 5, 2026
Marouane-elfadli pushed a commit to Marouane-elfadli/ClickHouse that referenced this pull request Nov 6, 2026
The S3KernelHelper constructor detects the region-less AWS endpoint with
`url.endpoint.substr(11) == "amazonaws.com"` (11 = length of
"https://s3."). For an endpoint of at most 10 characters (`http://a`,
`http://s3`, `https://ab`, `http://a:1`), `substr(11)` has pos > size()
and throws std::out_of_range, so a DeltaLake table on such an
S3-compatible endpoint could not be opened: release builds returned
`Code: 1001 ... std::out_of_range`, debug and sanitizer builds aborted
on the LOGICAL_ERROR. Found by AST fuzzer (amd_debug, targeted) on
PR ClickHouse#129383.

Check the length first. The result is unchanged for every endpoint that
did not throw: for 11 characters the old `substr(11)` was "" (false),
and for longer ones the comparison is the same.

The test stops the query with an invalid `delta_lake_snapshot_version`
right after the metadata constructor, before the delta-kernel touches the
network; host `a` does not resolve, and a DNS failure is not retried by
the region probe, so the test is fast and deterministic.

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

kssenii commented Nov 13, 2026

Copy link
Copy Markdown
Member

This change gives up a property we rely on: after_processing is still written to Keeper, yet it is no longer applied from Keeper nor validated against it. Two replicas of the same queue can now silently disagree on the action (one deletes, the other keeps), and a DETACH/ATTACH no longer reports a METADATA_MISMATCH for it. The test even edits Keeper directly and expects the table to ignore it.

So I want to suggest a different fix:

Sharing a keeper_path only makes sense for replicas of one queue. Files are tracked in Keeper under a hash of the object key (ObjectStorageQueueIFileMetadata::getNodeName), so two tables with different sources on one path already collide on same-named keys and skip each other's files. The actual gap is that nothing checks who may join a keeper_path, and nothing checks the grant for after_processing = 'delete'. I would close those two gaps and keep the action in Keeper:

  1. Same keeper_path must require the same source. Store the source identity (endpoint, bucket/container, path pattern, no credentials) in the Keeper metadata JSON when the path is created and compare it in ObjectStorageQueueTableMetadata::checkImmutableFieldsEquals. Enforce on CREATE, warn on attach so existing tables keep loading; metadata without the field gets stamped by the first table that loads after the upgrade. Older servers ignore unknown fields in parse.

  2. after_processing = 'delete' must require WRITE on the source URL, at CREATE and in ALTER, like the move destination settings already require WRITE in ObjectStorageQueueMoveDestinationAccess.cpp. Here the check can be filtered by the table's own URL, since deletion has an exact target. Skipped when loading from existing metadata, matching the existing rule that a load never fails.

Both changes are necessary: with only (1), a joiner with a READ-only grant can still flip the shared action; with only (2), a table over a different bucket passes the URL-filtered check. Together, whoever changes the action holds WRITE on exactly the data being deleted, which is legitimate.

@NIKTONIKTO717 NIKTONIKTO717 changed the title Apply each S3Queue table own after_processing Require the same source and WRITE for queue after_processing Nov 13, 2026
# Conflicts:
#	tests/queries/0_stateless/05441_s3queue_move_destination_access.sh
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-synced-to-cloud The PR is synced to the cloud repo pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Nov 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #129383 to 26.11: Require the same source and `WRITE` for queue `after_processing`
NIKTONIKTO717 added a commit that referenced this pull request Nov 23, 2026
…rypick/26.10/129383

Conflicts:
- `registerQueueStorage.cpp`: keep only the `<Poco/URI.h>` include that the PR adds;
  26.10 does not include `<Databases/IDatabase.h>`.
- `StorageFactory.h`: add the new `getExportAccess` overload without `[[nodiscard]]`,
  like the other declarations in 26.10.
- `05441_s3queue_move_destination_access.sh`: keep the `RESTORE TEMPORARY TABLE` case
  of 26.10 and add the `RESTORE` case of the PR.
- `05366_s3queue_metadata_mismatch_immutable_fields`: 26.10 does not have this test,
  which was added in #125286. Add it with
  the cases of the PR.

Related: #129383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NIKTONIKTO717 added a commit that referenced this pull request Nov 23, 2026
…ypick/26.9/129383

Conflicts:
- `registerQueueStorage.cpp`: keep only the `<Poco/URI.h>` include that the PR adds;
  26.9 does not include `<Databases/IDatabase.h>`. 26.9 does not have
  `isReplayedTableDefinition` and `isSecondaryDDLReplay`, so `strict_metadata_check`
  uses the same conditions directly, as `registerStorageMergeTree.cpp` does in 26.9.
- `StorageFactory.h`: add the new `getExportAccess` overload without `[[nodiscard]]`,
  like the other declarations in 26.9.
- `StorageObjectStorageConfiguration.h`: add only `initialized_from_named_collection`;
  `is_replayed_definition` is not in 26.9.
- `InterpreterAlterQuery.cpp` and `InterpreterAlterQuery.h`: add the `engine` argument
  to the 26.9 signature of `getRequiredAccessForCommand`. 26.9 does not have
  `run_as_submitting_user` for `Replicated` databases, so that part of the PR is not
  backported, and the comment of the `Replicated` case in
  `05441_s3queue_move_destination_access.sh` says that the initiator checks the grants.
- `05441_s3queue_move_destination_access.sh`: keep the `RESTORE TEMPORARY TABLE` case
  of 26.9 and add the `RESTORE` case of the PR.
- `05366_s3queue_metadata_mismatch_immutable_fields`: 26.9 does not have this test,
  which was added in #125286. Add it with
  the cases of the PR.

Related: #129383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
Cherry pick #129383 to 26.9: Require the same source and `WRITE` for queue `after_processing`
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
Cherry pick #129383 to 26.10: Require the same source and `WRITE` for queue `after_processing`
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
NIKTONIKTO717 added a commit that referenced this pull request Nov 23, 2026
…ypick/26.8/129383

Conflicts:
- `registerQueueStorage.cpp`: keep only the `<Poco/URI.h>` include that the PR adds.
  26.8 does not have the `exclusive` mode, so the PR line that clears the path of an
  `exclusive` queue is not backported. 26.8 does not have `isReplayedTableDefinition`
  and `isSecondaryDDLReplay`, so `strict_metadata_check` uses the same conditions
  directly.
- `StorageFactory.h`: add the new `getExportAccess` overload without `[[nodiscard]]`,
  like the other declarations in 26.8.
- `StorageObjectStorageConfiguration.h`: add only `initialized_from_named_collection`;
  `is_replayed_definition` is not in 26.8.
- `InterpreterAlterQuery.cpp` and `InterpreterAlterQuery.h`: add the `engine` argument
  to the 26.8 signature of `getRequiredAccessForCommand`. 26.8 does not have
  `run_as_submitting_user` for `Replicated` databases, so that part of the PR is not
  backported, and the comment of the `Replicated` case in
  `05441_s3queue_move_destination_access.sh` says that the initiator checks the grants.
  26.8 does not look up the table by name again after the access check, and the
  `ALTER` runs on the table that was checked, so the second check of the PR is not
  needed.
- `05441_s3queue_move_destination_access.sh`: keep the `RESTORE TEMPORARY TABLE` case
  of 26.8 and add the `RESTORE` case of the PR.
- `05366_s3queue_metadata_mismatch_immutable_fields`: 26.8 does not have this test,
  which was added in #125286. Add it with
  the cases of the PR, without the case of the `exclusive` mode.

Related: #129383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NIKTONIKTO717 added a commit that referenced this pull request Nov 23, 2026
Cherry pick #129383 to 26.8: Require the same source and `WRITE` for queue `after_processing`
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
Cherry pick #129383 to 26.3: Require the same source and `WRITE` for queue `after_processing`
NIKTONIKTO717 added a commit that referenced this pull request Nov 23, 2026
…ypick/26.3/129383

Conflicts:
- `registerQueueStorage.cpp`: keep only the `<Poco/URI.h>` include that the PR adds.
  26.3 does not have the `s3_uri_style` setting, so `getQueueSource` parses the URL
  without user info with the default style, as 26.3 parses the URL of the table.
  `StorageAzureConfiguration` in 26.3 has `getNamespace` instead of `getContainer`.
  26.3 does not have the `exclusive` mode, so the PR line that clears the path of an
  `exclusive` queue is not backported. 26.3 does not have `isReplayedTableDefinition`
  and `isSecondaryDDLReplay`, so `strict_metadata_check` uses the same conditions
  directly.
- `Azure/Configuration.h`: 26.3 does not have `getSasKey`, so the new
  `getConnectionURLWithoutQuery` reads `connection_params.endpoint.sas_auth`.
- `StorageObjectStorageConfiguration.cpp` and `StorageObjectStorageConfiguration.h`:
  add only `initialized_from_named_collection`.
- `StorageFactory.h`: add the new `getExportAccess` overload without `[[nodiscard]]`,
  like the other declarations in 26.3.
- `StorageObjectStorageQueue.cpp`: `alter` in 26.3 takes the mode from
  `getTableMetadata`, so the settings of the queue on this server come from it too.
- `InterpreterAlterQuery.cpp` and `InterpreterAlterQuery.h`: `getRequiredAccess` in
  26.3 does not take the table, so it takes the name of the engine, and
  `executeToTable` passes the engine of the table that is not a stand-in of a table
  that is not loaded yet. 26.3 does not have `run_as_submitting_user` for
  `Replicated` databases, so that part of the PR is not backported, and the comment of
  the `Replicated` case in `05441_s3queue_move_destination_access.sh` says that the
  initiator checks the grants. 26.3 does not look up the table by name again after
  the access check, and the `ALTER` runs on the table that was checked, so the second
  check of the PR is not needed.
- `05441_s3queue_move_destination_access.sh`: keep the `RESTORE TEMPORARY TABLE` case
  of 26.3 and add the `RESTORE` case of the PR.
- `05366_s3queue_metadata_mismatch_immutable_fields`: 26.3 does not have this test,
  which was added in #125286. Add it with
  the cases of the PR, without the cases of the `exclusive` mode and of `s3_uri_style`.
- `test_storage_s3_queue/test_0.py`: the old version of the upgrade test is 25.10,
  because 26.7 is newer than 26.3.

Related: #129383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Nov 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 23, 2026
Backport #129383 to 26.9: Require the same source and `WRITE` for queue `after_processing`
clickhouse-gh Bot added a commit that referenced this pull request Nov 23, 2026
Backport #129383 to 26.10: Require the same source and `WRITE` for queue `after_processing`
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 23, 2026
Backport #129383 to 26.8: Require the same source and `WRITE` for queue `after_processing`
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
The `ALTER` of a setting named in the query also counts as a change when
its value differs from the queue's shared or Keeper value (ClickHouse#129383). That
comparison used the raw literal, so the current value written as a string
(`buckets = '4'`) was a change again: on an `Ordered` queue it was refused
because `s3queue_migrate_old_metadata_to_buckets` is not set, and it
rewrote the Keeper metadata for the other Keeper settings. Compare the
value converted by its setting instead, as for the table definition.
PedroTadim added a commit that referenced this pull request Nov 24, 2026
Backport #129383 to 26.3: Require the same source and `WRITE` for queue `after_processing`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants