Skip to content

Cherry pick #117798 to 26.9: Send the definer identity to remote shards from SQL SECURITY DEFINER views without an invoker - #128499

Merged
robot-clickhouse-ci-1 merged 19 commits into
backport/26.9/117798from
cherrypick/26.9/117798
Nov 2, 2026
Merged

robot-clickhouse-ci-1 merged 19 commits into
backport/26.9/117798from
cherrypick/26.9/117798

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

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-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

al13n321 and others added 18 commits September 2, 2026 16:40
…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]>
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
@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 pr-critical-bugfix labels Nov 1, 2026
Resolve the conflict in `StorageInMemoryMetadata::getSQLSecurityOverriddenContext`: the 26.9 branch
keeps the early-return structure for `SQL SECURITY NONE` and has no `allow_experimental_analyzer`
normalization, so the definer identity stamping is placed right after `setUser` in that structure.
Include `Poco/Net/SocketAddress.h` for the `SocketAddress` constructor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@antonio2368 antonio2368 self-assigned this Nov 2, 2026
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit 883c721 into backport/26.9/117798 Nov 2, 2026
1 check passed
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.9/117798 branch November 2, 2026 15:29
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! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants