Repository navigation
Check grants and allowed hosts for the move destination of S3Queue and AzureQueue - #127180
Conversation
…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]>
|
Workflow [PR], commit [57dc166] Summary: ✅
AI ReviewSummaryThe PR adds destination Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Close the native-copy host-filter bypass and add the focused regression above. |
- 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]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes57 object files changed (+129.97 KiB total), 1 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units224 translation units recompiled, 2013 s compile time in total, 223 of them have a recent master baseline. |
…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]>
… 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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
`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]>
`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]>
…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) |
There was a problem hiding this comment.
[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());
- }
There was a problem hiding this comment.
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]>
Cherry pick #127180 to 26.10: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
…e destination of S3Queue and AzureQueue
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]>
Cherry pick #127180 to 26.3: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
… destination of S3Queue and AzureQueue
Cherry pick #127180 to 26.8: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
… destination of S3Queue and AzureQueue
Cherry pick #127180 to 26.9: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
… destination of S3Queue and AzureQueue
Backport #127180 to 26.10: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
Backport #127180 to 26.8: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
…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]>
Backport #127180 to 26.9: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
Backport #127180 to 26.3: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
… destination of S3Queue and AzureQueue
… destination of S3Queue and AzureQueue
… destination of S3Queue and AzureQueue
…e destination of S3Queue and AzureQueue
Related: #106855
Related: #120343
The move destination of
S3QueueandAzureQueue(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 SETTINGcould set it with only theALTER SETTINGSgrant, and the destination was not checked againstremote_url_allow_hosts.Now:
INSERT INTO FUNCTION s3('<destination>') SELECT * FROM <table>:WRITE ON S3for the destination URL (orWRITE ON AZURE), and forALTERalsoSELECTon the table. The initiator checks this, also forON CLUSTER.remote_url_allow_hosts. It is checked atCREATE, atALTER, and before each move.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Setting
after_processing_move_uriorafter_processing_move_connection_stringof anS3QueueorAzureQueuetable now requiresWRITE ON S3for the destination URL (orWRITE ON AZURE), andALTER TABLE ... MODIFY SETTINGalso requiresSELECTon the table. Before, theALTER SETTINGSgrant was enough. The destination must also be allowed byremote_url_allow_hosts.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127180]
Version info
26.11.1.1196-master(included in26.11and later)