Skip to content

Cherry pick #127180 to 26.3: Check grants and allowed hosts for the move destination of S3Queue and AzureQueue - #128941

Merged
robot-ch-test-poll4 merged 22 commits into
backport/26.3/127180from
cherrypick/26.3/127180
Nov 3, 2026
Merged

robot-ch-test-poll4 merged 22 commits into
backport/26.3/127180from
cherrypick/26.3/127180

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

antonio2368 and others added 20 commits October 21, 2026 15:27
…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]>
…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
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Nov 3, 2026
antonio2368 and others added 2 commits November 3, 2026 13:06
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants