Repository navigation
Cherry pick #127180 to 26.10: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue - #128945
Merged
robot-ch-test-poll4 merged 21 commits intoNov 3, 2026
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]>
- 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]>
…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
`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]>
…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]>
…nst the allowed hosts" This reverts commit 93da66f.
…he source endpoint Native copy sends `CopyObject` through the source client, so it writes the destination bucket on the source endpoint, which is not the endpoint of `after_processing_move_uri` that was checked against `remote_url_allow_hosts`. Backups use the same rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ht again Commit 13bcab7 moved the check into `InterpreterCreateQuery`, but `RESTORE ... ON CLUSTER` creates the tables on the other hosts in a context with no user, so the check passed there. The preflight runs under the restoring user, also for `ON CLUSTER`. It only sees the engine in the backup's definition, so a definition that inherits its engine with `AS <table>` is now rejected. `BACKUP` never writes one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…TTACH` and `RESTORE ... ON CLUSTER` Cover `RESTORE ... ON CLUSTER`, `ALTER ... ON CLUSTER` of a table that the initiator does not have, `CREATE ... ON CLUSTER` with a queue engine, `CREATE AS ... ON CLUSTER` with the default entry format, and `ATTACH` with a full definition. Each case is checked without `WRITE ON S3` and with it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ternary sent every kind that is not `S3` to `AZURE`. With a `switch` that has no `default`, the build fails when a new kind is added and this place is not updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hecks Check grants and allowed hosts for the move destination of S3Queue and AzureQueue
- `StorageFactory.cpp`: keep `getExportAccess` and `getExportAccessOfAnyEngine`; do not add `throwIfUnreplicatedTableDataNotAllowed` and its includes, which are not on 26.10. - `StorageObjectStorageQueue.cpp`: `validateSettings` gets the type, the remote host filter and `is_loading_from_existing_metadata` for the move destination host check. In `checkAlterIsPossible`, drop the call to `ObjectStorageQueuePostProcessor::checkAzureMoveDestination`, which comes from a change that is not on 26.10. - `ObjectStorageQueueMoveDestinationAccess.cpp`: use `ConnectionParams::getConnectionURL`, as `StorageAzureConfiguration::check` does on 26.10 (`getConnectionURLWithoutQuery` is not on 26.10). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #127180
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job