Repository navigation
Do not skip access checks of a user query executed as a nested query - #119848
Conversation
`InterpreterParallelWithQuery::executeSubquery`,
`InterpreterExecuteAsQuery::execute` and the local execution path of the
`QueryRunner` table engine re-execute a user-supplied query with
`QueryFlags{ .internal = true }`. That flag reaches `InterpreterCreateQuery`,
whose `getRequiredAccess` returns an empty set of required privileges for
internal queries, so no authorization check ran for `CREATE` subqueries. An empty
access set also means `checkAccessImpl` is never reached, which defeats the
`readonly` and `allow_ddl` settings on the same path.
A user holding only `GRANT SELECT` on a single database was denied a direct
`CREATE TABLE`, but the same statement wrapped in `PARALLEL WITH` succeeded.
`EXECUTE AS` was affected the same way, which inverts its contract: the
impersonated statement was checked against the privileges of neither party. For a
`QueryRunner` table the queued query text comes from whoever inserted it, so a
user with only `INSERT` on such a table could queue a `CREATE` and have it
executed regardless of the privileges of the principal the job runs as.
The flag cannot simply be cleared for these subqueries: `internal` also keeps a
nested query out of the `ProcessList` and deliberately leaves it without a
`SpanHolder` so that the spans already on the stack finish in the correct order,
`EXECUTE AS` relies on it to get raw blocks from the inner `executeQuery`, and it
is what marks `QueryRunner` jobs with `is_internal = 1` in `system.query_log`.
So the queries stay `internal`, and the authorization decision stops depending on
that flag: the new `QueryFlags::user_initiated` marks a query whose text was
written by the user, and `InterpreterCreateQuery` is told a query is
server-initiated only when `internal` is set and `user_initiated` is not.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [7099e77] Summary: ✅
AI ReviewSummaryThis PR keeps nested user-authored queries Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 7099e77.
Changed lines: Changed C/C++ lines covered: 33/33 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units721 translation units recompiled, 5581 s compile time in total, 721 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.92 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
|
|
|
diegomestre2
left a comment
There was a problem hiding this comment.
Good work, @Manerone I was wondering if you tested with 2 layers of subqueries.
…tem.query_log` The `INSERT` into a `QueryRunner` table succeeds no matter how the job ends, and the absence of the database would also be observed if the job never ran at all, so the test now reads the job's log entry - an `ACCESS_DENIED` exception before the grant, `QueryFinish` after it - instead of discarding the client output. Also cover two layers of nesting: a job that queues another job into a second `QueryRunner` table, and `PARALLEL WITH` inside `EXECUTE AS`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @diegomestre2, regarding two layers of subqueries: yes, each layer calls |
…g by it The style check asks every query of `system.query_log` to be constrained to the database of the test. A job of a `QueryRunner` table runs with the database its row names, so both tables now carry a `database` column and every job names the test database - which is what puts it in `current_database`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…a `Replicated` database The `05214` test read `system.query_log` rows filtered by names derived from the test database only, so a second run against the same database would print the jobs of the first run again, and its `QueryRunner` tables were never dropped. The user and the database now carry a random suffix, and the tables are dropped before and after the run: the test passes repeatedly in one database. The new `05215` test runs `PARALLEL WITH CREATE TABLE` in a `Replicated` database: the subquery is denied without `CREATE TABLE` and succeeds with it. The replay through the replicated DDL log is a separate server-side query which is non-internal for a direct `CREATE` as well, so a user-authored subquery is now treated exactly like the direct statement on that path. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The negative assertions of the two tests counted every table in the test database, and the success paths left their fixed-name tables behind, so a rerun with `clickhouse-test --database=X` printed the leftovers and failed with `TABLE_ALREADY_EXISTS`. Now only the objects each test creates are counted, and they are dropped both before and after the run, as `05214` already does. Verified locally with two consecutive runs of all three tests on one fixed database. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 |
Address review: the test assumed it owned `rdb_${CLICKHOUSE_DATABASE}` and a fixed
ZooKeeper path, so a previous run that died after `CREATE DATABASE` (or after creating
`t_parallel_1` / `t_parallel_2`) made the next run on the same server fail at setup.
Now the user, the database and its ZooKeeper path carry a per-run random suffix, the
database is dropped with `IF EXISTS ... SYNC` up front and at the end, and only the
tables this test creates are counted and listed, as was already done for `05212`-`05214`.
Verified: two consecutive runs on one fixed database pass.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…lickHouse` dictionary source For a local source, `ClickHouseDictionarySource::doInvalidateQuery` executed the `invalidate_query` text as an `internal` query on behalf of the configured user, without the `SELECT`-only check that `createStreamForQuery` applies to the main query. The text comes from `CREATE DICTIONARY`, so a user who may create a dictionary but has no `CREATE TABLE` privilege could run `CREATE TABLE ...` through it with the access checks of `internal` queries skipped - the same bypass this PR closes for `PARALLEL WITH`, `EXECUTE AS` and `QueryRunner`. The check is now shared by both paths (`checkQueryIsSelect`), and a non-`SELECT` invalidate query is rejected with `INCORRECT_QUERY` before anything is executed. Test `05218` creates such a dictionary as a restricted user, waits for the periodic invalidate check, and asserts that nothing was created and that a `SELECT` invalidate query keeps working. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 |
|
🕵 @groeneai, investigate the failure: It is unrelated to this PR (RBAC query flags): the same stack fails on master, e.g. |
|
Acknowledged. I am investigating the Confirming the arm split you describe: #119312 touches only |
|
@rschu1ze Yes, that is what I was trying to do yesterday, but CI was down due to MinIO issues. |
…d-access-checks Refresh the branch against master to get a new CI run; the previous run's only failure was `Build profile diff`, which errored on a CI logs cluster query rather than on anything in this branch. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Backport #119848 to 26.9: Do not skip access checks of a user query executed as a nested query
Backport #119848 to 26.7: Do not skip access checks of a user query executed as a nested query
Backport #119848 to 26.8: Do not skip access checks of a user query executed as a nested query
…er query executed as a nested query
…er query executed as a nested query
Cherry pick #119848 to 26.6: Do not skip access checks of a user query executed as a nested query
…xecuted as a nested query
Cherry pick #119848 to 26.3: Do not skip access checks of a user query executed as a nested query
…xecuted as a nested query
Backport #119848 to 26.6: Do not skip access checks of a user query executed as a nested query
Backport #119848 to 26.3: Do not skip access checks of a user query executed as a nested query
`natsSock_WaitReady` treated a `poll` interrupted by a signal (`EINTR`) as a socket error, so a connection attempt of a `NATS` table failed spuriously with `Cannot connect to Nats last error: (unix/sock.c:56): poll error: 4` whenever the query profiler signalled the connecting thread. With `nats_startup_connect_tries = 1` in the credentials-rotation tests this made `CREATE TABLE` fail at random. The fix (ClickHouse/nats.c@b88704df) waits again for the rest of the deadline. The bump also brings the two fork changes already merged there: the libuv attach ordering and the JetStream fetch lock-order backport. Failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119848&sha=ce21881b746a07dc79574410b18f5c5b57e38551&name_0=PR&name_1=Integration%20tests%20(amd_asan_ubsan,%20db%20disk,%204/8) PR: ClickHouse#119848 Co-Authored-By: Claude Fable 5.1 <[email protected]>
InterpreterParallelWithQuery::executeSubquery,InterpreterExecuteAsQuery::executeand the local execution path of theQueryRunnertable engine re-execute a user-supplied query withQueryFlags{ .internal = true }. That flag reachesInterpreterCreateQuery, whosegetRequiredAccessreturns an empty set of required privileges for internal queries, so no authorization check ran forCREATEsubqueries. An empty access set also meanscheckAccessImplis never reached, which defeats thereadonlyandallow_ddlsettings on the same path.A user holding only
GRANT SELECTon a single database was denied a directCREATE TABLE, but the same statement wrapped inPARALLEL WITHsucceeded.EXECUTE ASwas affected the same way, which inverts its contract: the impersonated statement was checked against the privileges of neither party. For aQueryRunnertable the queued query text comes from whoever inserted it, so a user with onlyINSERTon such a table could queue aCREATEand have it executed regardless of the privileges of the principal the job runs as.The flag cannot simply be cleared for these subqueries:
internalalso keeps a nested query out of theProcessListand deliberately leaves it without aSpanHolderso that the spans already on the stack finish in the correct order,EXECUTE ASrelies on it to get raw blocks from the innerexecuteQuery, and it is what marksQueryRunnerjobs withis_internal = 1insystem.query_log. So the queries stayinternaland the authorization decision stops depending on that flag: the newQueryFlags::user_initiatedmarks a query whose text was written by the user, andInterpreterCreateQueryis told that a query is server-initiated only wheninternalis set anduser_initiatedis not.This follows the approach of the internal patch prepared by @Manerone, and adds the tests for the three entry points.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
PARALLEL WITH,EXECUTE ASand theQueryRunnertable engine skipping the access checks of theCREATEstatements they execute, which allowed creating tables and databases without the corresponding privileges, and defeated thereadonlyandallow_ddlsettings.🤖 Generated with Claude Code
Closes: #119600
Workflow [PR]
Sync PR [sync-upstream/pr/119848]
Version info
26.10.1.39(included in26.10and later)26.9.1.1600,26.8.7.16,26.7.11.12,26.6.9.18,26.3.33.108