Skip to content

Backport #117798 to 26.3: Send the definer identity to remote shards from SQL SECURITY DEFINER views without an invoker - #128668

Merged
antonio2368 merged 6 commits into
26.3from
backport/26.3/117798
Nov 3, 2026
Merged

antonio2368 merged 6 commits into
26.3from
backport/26.3/117798

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #117798
Cherry-pick pull-request #128497

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

…from SQL SECURITY DEFINER views without an invoker
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-critical-bugfix labels Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [5eb07b5]

Summary: ✅

@antonio2368 antonio2368 self-assigned this Nov 2, 2026
antonio2368 and others added 5 commits November 2, 2026 15:39
On 26.3, with `table_engines_require_grant = false`, `TABLE ENGINE` on
`Distributed`, `Kafka` and `RabbitMQ` is implicitly revoked unless the
user also has `READ` and `WRITE` on the `REMOTE`, `KAFKA` and
`RABBITMQ` sources. So `CREATE TABLE ... ENGINE = Distributed` failed
with `ACCESS_DENIED` in the test setup.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128668&sha=latest&name_0=BackportPR
PR: #128668

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The loop in `DistributedAsyncInsertBatch::recoverBatch` read the header
of `files.back()` on each iteration, so only the last file was validated
and the mixed-identity check added by #117798 compared the last file with
itself and never fired. On master this was fixed by #105281, which was not
backported to 26.3.

Related: #105281
PR: #128668

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…flush context

On 26.3 `async_insert` is enabled by default, and the flush context of
`AsynchronousInsertQueue` is built from the global context with only
`Context::setUser`, so its `ClientInfo` user names are empty. A direct
`INSERT` into a `Distributed` table over a cluster with an interserver
`<secret>` was therefore flushed to the shard with an empty `initial_user`,
which the shard executes in interserver mode with full access. This is the
same hole that #117798 closes for the definer of `SQL SECURITY DEFINER`
views, and `test_streaming_engines_definer_interserver_secret::test_rabbitmq[tenant]`
caught it in its control case: the tenant's direct insert was accepted on the
shard.

Bring the fix from #107541 (merged to master in edb9295): capture
`current_user`, `initial_user` and `authenticated_user` in the async insert
queue key at push time and restore them on the flush context. The only
conflict is in `InsertQuery::toTupleCmp`, where 26.3 already uses
`query_str_with_secrets` instead of `query_str`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128668&sha=0dc411340520ff9f52dfdb04638aa63196712372&name_0=BackportPR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29
PR: #128668
Related: #107541

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On 26.3, with `table_engines_require_grant = false`, `TABLE ENGINE ON
Distributed` is implicitly revoked unless the user also has `READ` and
`WRITE` on `REMOTE`, so `CREATE TABLE ... ENGINE = Distributed` by the
tenant failed with `ACCESS_DENIED` in the test setup. Same as the fix
for test_streaming_engines_definer_interserver_secret.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128668&sha=0dc411340520ff9f52dfdb04638aa63196712372&name_0=BackportPR&name_1=Integration%20tests%20%28amd_asan%2C%20db%20disk%2C%20old%20analyzer%2C%203%2F8%29
PR: #128668

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Fixed the two integration test failures from the last run:

  • test_refreshable_mv_definer_interserver_secret: on 26.3, TABLE ENGINE ON Distributed is implicitly revoked unless the user also has READ, WRITE ON REMOTE. I added that grant, the same way it was done for the streaming-engines test.
  • test_streaming_engines_definer_interserver_secret::test_rabbitmq[tenant] caught a real problem on 26.3. This is the direct-INSERT control case. async_insert is on by default in 26.3, and 26.3 doesn't have Fix currentUser() being empty during async_insert flush #107541, so the async insert flush context had empty ClientInfo user names. The tenant's insert reached the shard with an empty initial_user, and the shard executed it in interserver mode with full access: node2 logged User (no user, interserver mode), and the row was written. That's the same hole this PR closes for definer views. I brought the Fix currentUser() being empty during async_insert flush #107541 fix into this backport as a separate commit (one trivial conflict: query_str_with_secrets).

The affected files pass a syntax check against 26.3 headers. I couldn't run the tests locally because no 26.3 binary is available here, so the next CI run will be the real check. I also merged the latest 26.3.

A reviewer should confirm that bundling #107541 into this backport is acceptable. The alternative is a separate 26.3 backport of #107541, which this PR's tests would then depend on.

@antonio2368
antonio2368 merged commit 7b4e730 into 26.3 Nov 3, 2026
36 checks passed
@antonio2368
antonio2368 deleted the backport/26.3/117798 branch November 3, 2026 08:14
leshikus pushed a commit that referenced this pull request Nov 13, 2026
On 26.3, with `table_engines_require_grant = false`, `TABLE ENGINE` on
`Distributed`, `Kafka` and `RabbitMQ` is implicitly revoked unless the
user also has `READ` and `WRITE` on the `REMOTE`, `KAFKA` and
`RABBITMQ` sources. So `CREATE TABLE ... ENGINE = Distributed` failed
with `ACCESS_DENIED` in the test setup.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128668&sha=latest&name_0=BackportPR
PR: #128668

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
The loop in `DistributedAsyncInsertBatch::recoverBatch` read the header
of `files.back()` on each iteration, so only the last file was validated
and the mixed-identity check added by #117798 compared the last file with
itself and never fired. On master this was fixed by #105281, which was not
backported to 26.3.

Related: #105281
PR: #128668

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
…flush context

On 26.3 `async_insert` is enabled by default, and the flush context of
`AsynchronousInsertQueue` is built from the global context with only
`Context::setUser`, so its `ClientInfo` user names are empty. A direct
`INSERT` into a `Distributed` table over a cluster with an interserver
`<secret>` was therefore flushed to the shard with an empty `initial_user`,
which the shard executes in interserver mode with full access. This is the
same hole that #117798 closes for the definer of `SQL SECURITY DEFINER`
views, and `test_streaming_engines_definer_interserver_secret::test_rabbitmq[tenant]`
caught it in its control case: the tenant's direct insert was accepted on the
shard.

Bring the fix from #107541 (merged to master in edb9295): capture
`current_user`, `initial_user` and `authenticated_user` in the async insert
queue key at push time and restore them on the flush context. The only
conflict is in `InsertQuery::toTupleCmp`, where 26.3 already uses
`query_str_with_secrets` instead of `query_str`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128668&sha=0dc411340520ff9f52dfdb04638aa63196712372&name_0=BackportPR&name_1=Integration%20tests%20%28amd_tsan%2C%203%2F6%29
PR: #128668
Related: #107541

Co-Authored-By: Claude Opus 5.5 <[email protected]>
leshikus pushed a commit that referenced this pull request Nov 13, 2026
On 26.3, with `table_engines_require_grant = false`, `TABLE ENGINE ON
Distributed` is implicitly revoked unless the user also has `READ` and
`WRITE` on `REMOTE`, so `CREATE TABLE ... ENGINE = Distributed` by the
tenant failed with `ACCESS_DENIED` in the test setup. Same as the fix
for test_streaming_engines_definer_interserver_secret.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=128668&sha=0dc411340520ff9f52dfdb04638aa63196712372&name_0=BackportPR&name_1=Integration%20tests%20%28amd_asan%2C%20db%20disk%2C%20old%20analyzer%2C%203%2F8%29
PR: #128668

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

pr-backport Changes, backported to release branch. 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