Repository navigation
Cherry pick #117798 to 26.3: Send the definer identity to remote shards from SQL SECURITY DEFINER views without an invoker - #128497
Merged
robot-ch-test-poll4 merged 20 commits intoNov 2, 2026
Conversation
…views without an invoker `getSQLSecurityOverriddenContext` called `Context::setUser` for the definer, which sets only `user_id` and leaves the `ClientInfo` user names untouched. When there is no invoker, such as a scheduled refresh of a refreshable materialized view, those names are empty, `RemoteQueryExecutor` sends them as-is, and a shard behind an interserver `<secret>` treats the empty `initial_user` as interserver mode: it skips authentication and runs the query with full access. Fill the empty `current_user`, `initial_user` and `authenticated_user` with the definer's name, and stop `createRefreshContext` from overwriting them with the identity-less copy. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…s into Distributed `Kafka` and `RabbitMQ` push consumed batches only into their materialized views, from a copy of the global context that has no user. A view with `SQL SECURITY DEFINER` switches the push to the definer, but until the previous commit the definer's name did not reach a shard behind an interserver `<secret>`, which then executed the push with full access. The test builds `Kafka -> MV -> Distributed` and `RabbitMQ -> MV -> Distributed` pipelines with the same statements for a user with `INSERT` on the shard and for a tenant without it, and checks in the shard's `system.query_log` that the push ran under the definer's name: the rows arrive for the former and are rejected with `ACCESS_DENIED` for the latter. Co-Authored-By: Claude Fable 5.1 <[email protected]>
# Conflicts: # src/Storages/StorageInMemoryMetadata.cpp
… streaming engines `Kafka` / `RabbitMQ` push into views from contexts with `query_kind = NO_QUERY`, for which `ClientInfo::write` stores only the kind. With the default `distributed_foreground_insert = 0` the queued insert was therefore replayed with an empty `initial_user`, which a shard accepting the interserver `<secret>` executes with full access. `DistributedSink` now persists such a `ClientInfo` as `SECONDARY_QUERY` (as `RemoteInserter` sends it anyway), so the definer's name survives the queue. The integration test now also runs the `Kafka` pipeline with `distributed_foreground_insert = 0`; the tenant's rows reached the shard without this change. The setting moved from the server profile to the users, because the settings of the context the push starts from override the definer's ones. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t users `DistributedAsyncInsertBatch::sendBatch` sends the whole batch with the `ClientInfo` of its first file, and over a cluster with an interserver `<secret>` the shard authenticates it as that file's `initial_user`. The batch key did not include `initial_user`, so with `background_insert_batch = 1` rows of a user without the remote grant could be delivered under another user's identity. Include `initial_user` in the batch key equality and hash. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test uses `test_cluster_interserver_secret`, and the interserver `<secret>` requires SSL, which the fast test build does not have, so the expected `ACCESS_DENIED` is never produced there. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117798&sha=latest&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t too, validate restored batches The shard authenticates a queued insert as `initial_user` from the host of `initial_address` (checked against the allowed hosts of the user), and the whole batch is sent with the `ClientInfo` of its first file. So the batch key now includes the originating host in addition to `initial_user`. A `current_batch.txt` left by an older server could also list files of different users or hosts; such a restored batch is no longer resent as a whole: it is dropped, and its files are batched again by identity. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`test_direct_insert` passes on the unfixed binary by design, so the bugfix validation jobs reported it as a failure of the validation, turning both `Bugfix validation (integration tests, ...)` jobs red although every other new test reproduced the bug. Run the control check at the start of `test_rabbitmq` instead, so each test in the module fails without the fix. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117798&sha=latest&name_0=PR&name_1=Bugfix%20validation%20(integration%20tests%2C%20amd64) PR: #117798 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…coming from the local host Without an invoker, `ClientInfo::initial_address` was the unspecified `0.0.0.0`. The shard checks it against the allowed hosts of `initial_user` when it authenticates an interserver query, so a definer restricted with `HOST LOCAL` (or anything other than `HOST ANY`) could not run scheduled refreshes over `Distributed`. Set the loopback address together with the definer name, the same way a client connected locally to the initiator is seen by the shards. The address is written to queued `Distributed` insert files with the rest of `ClientInfo`, so it is preserved there too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…entity Send the definer identity to remote shards from SQL SECURITY DEFINER views without an invoker
Resolve conflicts against 26.3: - `BatchHeader` in 26.3 has no `client_agent` / `is_internal`; keep the 26.3 comparison and add the identity check. - `ClientInfo::write` in 26.3 has no `with_trailing_fields` parameter. - `Context::setAuthenticatedUserName` does not exist in 26.3; set `authenticated_user` through `setClientInfo`. - `getInMemoryMetadataPtr` in 26.3 takes no arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]>
On 26.3 it is not available transitively, so `initial_address->host()` did not compile. 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 #117798
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