Skip to content

Check grants and allowed hosts for the move destination of S3Queue and AzureQueue - #127180

Merged
antonio2368 merged 19 commits into
masterfrom
s3queue-move-destination-checks
Nov 3, 2026
Merged

antonio2368 merged 19 commits into
masterfrom
s3queue-move-destination-checks

Conversation

@antonio2368

@antonio2368 antonio2368 commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Related: #106855
Related: #120343

The move destination of S3Queue and AzureQueue (after_processing_move_uri, after_processing_move_connection_string) receives every processed file, read with the source credentials of the table. Until now, ALTER TABLE ... MODIFY SETTING could set it with only the ALTER SETTINGS grant, and the destination was not checked against remote_url_allow_hosts.

Now:

  • Setting a destination needs the same grants as INSERT INTO FUNCTION s3('<destination>') SELECT * FROM <table>: WRITE ON S3 for the destination URL (or WRITE ON AZURE), and for ALTER also SELECT on the table. The initiator checks this, also for ON CLUSTER.
  • The destination must be allowed by remote_url_allow_hosts. It is checked at CREATE, at ALTER, and before each move.

Changelog category (leave one):

  • Backward Incompatible Change

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

Setting after_processing_move_uri or after_processing_move_connection_string of an S3Queue or AzureQueue table now requires WRITE ON S3 for the destination URL (or WRITE ON AZURE), and ALTER TABLE ... MODIFY SETTING also requires SELECT on the table. Before, the ALTER SETTINGS grant was enough. The destination must also be allowed by remote_url_allow_hosts.

🤖 Generated with Claude Code


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

Version info

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

…and `AzureQueue`

A move to another bucket or container (`after_processing = 'move'` with
`after_processing_move_uri` or `after_processing_move_connection_string`)
copies every processed file, read with the source credentials of the table,
to the destination. Before this change, `ALTER TABLE ... MODIFY SETTING`
could set the destination with only the `ALTER SETTINGS` grant, `CREATE`
checked no grant for it, and the destination never passed
`remote_url_allow_hosts`.

Grants: setting a destination is the same data flow as
`INSERT INTO FUNCTION s3('<destination>') SELECT * FROM <table>`, so it now
needs `WRITE ON S3` for the normalized destination URL (for Azure,
`WRITE ON AZURE` without a filter), and `ALTER` also needs `SELECT` on the
table. The check runs on the initiator, in the local path and in the
`ON CLUSTER` access hook, for both `ALTER` and `CREATE`.

Allowed hosts: the destination is checked against `remote_url_allow_hosts`
in `validateSettings` (not for definitions loaded from stored metadata),
in `checkAlterIsPossible` when a destination setting changes, and before
the move builds the destination client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@antonio2368
antonio2368 marked this pull request as ready for review October 21, 2026 13:30
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [57dc166]

Summary: ✅


AI Review

Summary

The PR adds destination WRITE grants, source SELECT and row-policy checks, and host filtering for S3Queue and AzureQueue moves. Reviewed head 57dc16623838c7fe744e7645a5fe209bd56b9be7, including all prior discussion. One previously reported host-filter bypass remains in native S3 copy.

Missing context / blind spots
  • ⚠️ The current-head workflow is still pending. Completed job reports do not establish that all checks have finished. No local ClickHouse binary or build was available for a runtime reproduction.
Findings

❌ Blockers

  • ObjectStorageQueuePostProcessor.cpp:419–420: Equal endpoint strings do not guarantee an authorized native-copy host. [dismissed by author -- https://github.com/Check grants and allowed hosts for the move destination of S3Queue and AzureQueue #127180#discussion_r4358732178]

    This still holds because the comparison omits the clients' addressing styles. With source https://source.s3.example.com/data/ and move destination https://s3.example.com/destination/, both clients have initial endpoint https://s3.example.com, but the source uses virtual-hosted addressing and the destination uses path-style addressing. An allowlist containing only source.s3.example.com and s3.example.com accepts both configured URLs, and this guard retains native copy. However, copyS3FileImpl gives CopyFileHelper the source client, whose CopyObject request uses bucket destination and therefore targets destination.s3.example.com, which was never allowed. The HTTP client checks redirects, not this initial request. A successful copy also removes the source object.

    Disable native copy when the addressing styles differ, or validate the effective destination request produced by the source client. The existing author-resolved thread is left unchanged; this remaining case is retained here only.

Tests
  • ⚠️ Add a runtime regression with a virtual-hosted source, a path-style destination sharing the same endpoint, and native copy enabled. Verify that no request reaches the non-allowlisted host and that rejection preserves the source object. The added host-filter test stops during CREATE validation and cannot exercise this path.
Final Verdict

Status: ❌ Block. Close the native-copy host-filter bypass and add the focused regression above.

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Oct 21, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-s3queue S3Queue/AzureQueue engines (queue-based ingestion from object storage). label Oct 21, 2026
- The move to another S3 bucket uses only the bucket of
  `after_processing_move_uri` and writes keys built from
  `after_processing_move_prefix` and the source keys. So a `WRITE ON S3` grant
  filtered by URL does not describe what is written: the S3 destination now
  needs `WRITE ON S3` without a filter, as the Azure destination already did.
- `after_processing_move_container` also chooses the destination of an Azure
  move, so it needs the same grants as `after_processing_move_connection_string`.
- `CREATE` checks the final definition, right after it is normalized and before
  anything is enqueued or created: the engine and settings inherited through
  `AS`, and the inner engines of materialized views, whose inner tables are
  created as internal queries. The legacy `ON CLUSTER` format checks the
  definition inherited through `AS` in its preflight.
- The move copies whole files and cannot filter rows, so `ALTER ... MODIFY
  SETTING` that sets a destination is rejected for a user restricted by a row
  policy on the table, as `StorageSet::checkNoRowPolicy` does, locally and on
  the `ON CLUSTER` initiator.

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

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 57dc16623 with master d6c89bcd8 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of f2187aa97; 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

57 object files changed (+129.97 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorageQueue/ObjectStorageQueueMoveDestinationAccess.cpp.o new 92.90 KiB +92.90 KiB

719 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

224 translation units recompiled, 2013 s compile time in total, 223 of them have a recent master baseline.

Job report

antonio2368 and others added 2 commits October 22, 2026 09:31
…database

With `access_control_improvements.enable_read_write_grants` disabled (the
default), the replicated access storage of that configuration round-trips
the user through serialized SQL, which rewrites `WRITE ON S3('<filter>')`
into the old-style whole-source `S3` grant without the filter. So the case
with a filtered grant is allowed there.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=127180&sha=9965284aed03243f06222eb40193fe97a7bc64c3&name_0=PR
#127180

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`RESTORE` creates each table with an internal `CREATE` query in the
`SECONDARY_CREATE` mode, so it skipped the destination check of `CREATE`.
But the definition comes from a backup that the restoring user supplies,
so a user without `WRITE ON S3` (`WRITE ON AZURE`) could restore a queue
table that moves the processed files to any destination.

`RestorerFromBackup::checkAccessForObjectsFoundInBackup` now checks the
queue engines of each table that it creates, including the inner engines,
under the restoring user and before anything is created. It skips the
check when `restore_replace_external_engines_to_null` replaces the engine
with `Null`. The walk over the engines of a definition moves into
`checkObjectStorageQueueMoveDestinationAccess`, which `CREATE` uses too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
antonio2368 and others added 2 commits October 22, 2026 10:26
… CLUSTER` preflight

On the legacy `ON CLUSTER` path, the preflight of `CREATE TABLE ... AS` runs only
`setEngine`, which copies the outer engine of a `TimeSeries` source but not its inner
engines. The worker copies them while normalizing and runs without the user, so the
move destination of an inherited inner `S3Queue` or `AzureQueue` was never checked.
Add the inner engines that the query does not override to the preflight copy before
the check.

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

# Conflicts:
#	src/Backups/RestorerFromBackup.cpp

/// The settings are checked at `CREATE` and `ALTER` too. This is defense in depth for a table that was created before
/// those checks existed, or before the list of allowed hosts was tightened. If it throws, nothing is copied and nothing is removed.
checkObjectStorageQueueS3MoveDestinationHost(move_uri, getContext()->getRemoteHostFilter());

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.

If we anyway throw here, why bypass check in constructor under is_loading_from_existing_metadata? In the background thread a user might not notice something is wrong for a while and it could lead to disruption of user's insert process, while attach failure will allow to quickly see something is missing. Though it is indeed hard to fix something when server does not start, so probably we do not have a choice.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Old tables never had the destination checked, so failing the load would break server start on upgrade for anyone whose destination isn't in remote_url_allow_hosts. A manual ATTACH, CREATE and ALTER still fail right away, it's only skipped on server start and UNDROP. Since it's a security fix, we could also mark the PR as backward incompatible and just always check it.

/// It checks the query as given: the explicit engines and the inner engines of views.
params.additional_access_check = [this, &create](const String & /* default_database */, bool /* throw_if_unresolved */)
{
checkQueueMoveDestinationAccess(create);

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.

I thought it is probably strange that we do not already have any storage specific access checks on InterpreterCreateQuery level, which means there should be a way to do this in a more encapsulated way. So I discussed with claude and he suggested this approach: https://pastila.clickhouse.com/?0007777d/2e790da1792935c794749fe5ca517e4b#GUtUv9A62XSKUJBTQ6orHQ==GCM. WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense, engines now declare these grants in StorageFactory and the interpreters just ask it. I kept ALTER checking by the settings only, the full version with the IStorage virtual touches a lot more code, so I'd rather do that in a separate PR to keep the backport small.

antonio2368 and others added 3 commits October 22, 2026 15:01
`S3Queue` and `AzureQueue` now register `get_export_access_fn` in their
`StorageFeatures`, and `CREATE`, `ALTER` and `RESTORE` ask `StorageFactory`
for these grants instead of calling queue-specific checks. For `CREATE`
they are a part of `getRequiredAccess`, so the `ON CLUSTER` preflight needs
no extra check. `ALTER` takes the grants of every engine from the setting
changes, so `ON CLUSTER` still works on an initiator without the table.

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

# Conflicts:
#	src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp
Master added an Azure credential check for a changed move destination in
`checkAlterIsPossible`, with its own `move_destination_changed`. Do this check
in the same block as the host check, so that one change detection covers both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`InterpreterAlterQuery` checks `SELECT` and the row policy for a setting that sends the table's data elsewhere
on the name in the query. Through an `Alias` that is the alias, not the queue that gets the setting, so
`StorageAlias::checkAlterIsPossible` now refuses such a change and asks to run the `ALTER` on the target table.
The refusal does not depend on the user, so it also holds on the hosts of `ON CLUSTER`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Backups/RestorerFromBackup.cpp Resolved
`RESTORE TEMPORARY TABLE` skipped the export check, so a temporary `S3Queue`
or `AzureQueue` with a move destination could be restored without `WRITE`
on the destination. The check now runs before the temporary-table branch.
Temporary tables do not get the `Null` engine of
`restore_replace_external_engines_to_null`, so that setting does not skip
the check for them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Backups/RestorerFromBackup.cpp Resolved
…solved

A definition in a backup can omit the engine and inherit it with `AS`, so the check of the definition as
stored in the backup saw no engine and asked for no grants. The check now runs in `InterpreterCreateQuery`
after `setEngine`, under the restoring user, for the tables that `RESTORE` creates, and replaces the
upfront check in `RestorerFromBackup`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The host check of `after_processing_move_uri` and the destination bucket use
automatic style detection, but the destination client used the `uri_style`
of the server `<s3>` config or the `s3_uri_style` query setting. With
`virtual_hosted`, the client could send requests to a host that the check
did not allow. Force automatic detection for the move client, so the check,
the client and the bucket use the same parse.

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

/// setEngine copies only the outer engine of a `TimeSeries` source, and the worker copies
/// its inner engines while normalizing, so add the ones this query does not give itself
if (inherited.is_time_series_table)

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.

[claude suggested] setEngine already loops over the inner engines inherited from a TimeSeries source (lines 1846-1849). Checking the export there covers the local and the ON CLUSTER paths in one place, and removes the second getCreateTableQuery of the source.

@@ src/Interpreters/InterpreterCreateQuery.cpp:1846
             if (as_create.targets)
+            {
                 for (const auto & target : as_create.targets->targets)
+                {
                     if (target.inner_engine && !create.getTargetInnerEngine(target.kind))
+                    {
                         check_access_to_inherited_definition(*target.inner_engine);
+                        if (!internal && target.inner_engine->engine && target.inner_engine->settings)
+                            getContext()->checkAccess(StorageFactory::instance().getExportAccess(
+                                target.inner_engine->engine->name, target.inner_engine->settings->changes));
+                    }
+                }
+            }
@@ :4114
-                /// setEngine copies only the outer engine of a `TimeSeries` source, and the worker copies
-                /// its inner engines while normalizing, so add the ones this query does not give itself
-                if (inherited.is_time_series_table)
-                {
-                    auto as_create_ptr = DatabaseCatalog::instance().getDatabase(inherited.as_database)->getCreateTableQuery(inherited.as_table, getContext());
-                    const auto & as_create = as_create_ptr->as<ASTCreateQuery &>();
-                    if (as_create.targets)
-                        for (const auto & target : as_create.targets->targets)
-                            if (target.inner_engine && !inherited.getTargetInnerEngine(target.kind))
-                                inherited.setTargetInnerEngine(target.kind, target.inner_engine->clone());
-                }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A local CREATE AS already checks the inner engines in checkExportAccess(create), because normalizeTimeSeriesDefinition copies them in before that. The legacy ON CLUSTER branch doesn't normalize, so this copy adds them there and the same checkExportAccess sees them. A check in setEngine would check the local case a second time, so I'd rather keep it like this.

…allowed hosts

Native copy sends `CopyObject` through the source client, so it writes the
destination bucket on the source endpoint, not on the endpoint of
`after_processing_move_uri`. That target was never checked against
`remote_url_allow_hosts`. If it is not allowed, copy through the destination
client instead, which uses the checked endpoint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 3, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 3, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Nov 3, 2026
Cherry pick #127180 to 26.10: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
robot-clickhouse added a commit that referenced this pull request Nov 3, 2026
antonio2368 added a commit that referenced this pull request Nov 3, 2026
Adapt #127180 to 26.3:
- `StorageFactory` and queue registration: no `Documentation` argument on 26.3.
- `ObjectStorageQueuePostProcessor`: 26.3 has no `uri_style` S3 auth setting, so the
  `S3UriStyle::AUTO` override is dropped; the unrelated server-credential clearing from master is not taken.
- `StorageObjectStorageQueue::checkAlterIsPossible`: 26.3 has no
  `ObjectStorageQueuePostProcessor::checkAzureMoveDestination`, so only the host check is added.
- Azure host check uses `ConnectionParams::getConnectionURL`, as `StorageAzureConfiguration::check` on 26.3.
- `InterpreterAlterQuery`: 26.3 has no `additional_access_check` in `DDLQueryOnClusterParams`,
  so the row policy check for `ON CLUSTER` runs on the initiator before the entry is enqueued.
- `RestorerFromBackup`: declare `restore_replace_external_engines_to_null`.
- Move the engine documentation added by the PR to the 26.3 markdown docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll4 added a commit that referenced this pull request Nov 3, 2026
Cherry pick #127180 to 26.3: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
robot-clickhouse added a commit that referenced this pull request Nov 3, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Nov 3, 2026
Cherry pick #127180 to 26.8: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
robot-clickhouse added a commit that referenced this pull request Nov 3, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Nov 3, 2026
Cherry pick #127180 to 26.9: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
robot-clickhouse added a commit that referenced this pull request Nov 3, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 3, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #127180 to 26.10: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #127180 to 26.8: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 3, 2026
…et-access

Resolves the conflict in checkAccessForObjectsFoundInBackup with ClickHouse#127180, which
also binds create above the temporary branch: keep master's is_temporary and
export-access check, then authorize the view targets as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Nov 3, 2026
Backport #127180 to 26.9: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
antonio2368 added a commit that referenced this pull request Nov 4, 2026
Backport #127180 to 26.3: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
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-backward-incompatible Pull request with backwards incompatible changes 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