Repository navigation
Conversation
This is ClickHouse#126334 at head b4be48e, applied verbatim as the base of the child-row variant proposed by @ vdimir in ClickHouse#126334 (comment). Co-authored-by: Sergey Kuznetsov <[email protected]> Co-authored-by: vdimir <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ery_log row The body of a `SQL SECURITY DEFINER` / `NONE` view or materialized view runs in a query context of its own (`getSQLSecurityOverriddenContext`), and everything it records goes to that context's `QueryAccessInfo`, which nothing logs. The previous commit (ClickHouse#126334) merges it into the caller's row, and so needs the `query_access_info_is_hidden` marker, its marking sites, the reader's marker logic and the `query_log.enable_query_access_info_attribution` option. This replaces all of that with the design proposed by @ vdimir in ClickHouse#126334 (comment): the body is logged as a child row of the query, like the shard query of a distributed query. - `Context::addSQLSecurityOverriddenBody` registers a body's `QueryAccessInfo` on the enclosing query context. It is called where the body context is created: `getViewContext` (a view read), `StorageMaterializedView::readImpl` (a read through an MV, logged as `SELECT <columns> FROM <target>`), the root of `InsertDependenciesBuilder` (an insert into an MV, logged as `INSERT INTO <target>`) and `createSelectInsertContext` (an MV run on INSERT). A body registered again with the same view, query tree hash and user is redirected to the first registration, so a view planned for every block of an MV insert is one row. The registry is not copied with a context. - `executeQuery` writes one row per registered body after the caller's row at QueryFinish, ExceptionWhileProcessing and ExceptionBeforeStart, recursively for nested bodies, and consumes the registry: `is_initial_query = 0`, a generated `query_id`, the caller's `initial_query_id`, `user` = the definer (empty for NONE), the body's query formatted for logging, and what it accessed; no metrics. - `InsertDependenciesBuilder` records an MV's target and the views its write triggers on the context that writes them, so for a DEFINER/NONE MV they are in its child row. INVOKER and legacy MVs share the caller's query context, so their rows do not change. - `analyzer_inline_views` no longer inlines a DEFINER/NONE view (the parallel-replicas bail-out becomes unconditional): an inlined body's query context has no owner, and keeping every inlined occurrence alive would grow per block inside an MV body. The view is read through `readImpl`, whose transparent plan is still merged into the caller's. ClickHouse#126334's switch of the inlined body to the caller's query context and its `enable_shared_storage_snapshot_in_query` override are reverted with it. Deviation from the proposal: transparent views, reads through an MV and inserts into an MV are child rows too. Attributed to the caller, a transparent body would put the partition ids it selected, of a partition key the view need not expose, into the grant-free `system.user_query_log`. `system.user_query_log` keeps ClickHouse#126334's identity check and its `is_initial_query = 1` filter, which now also hides the child rows. 05257 counted every non-initial row as a query shipped to another server; it now counts only rows with `distributed_depth > 0`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s child row A read through a `SQL SECURITY DEFINER` / `NONE` materialized view reads its target with `storage->read`, which bypasses the planner, so the body's child row named no table or column. `StorageMaterializedView::readImpl` now records the target and the columns read on the body's query context, after the body is registered. - 05617: a read through a DEFINER MV with a `Memory` target, and exact `tables` / `columns` of both MV-read child rows. - 05617: `INSERT INTO mv_definer ... VALUES` runs with `async_insert = 0`. Under an `async_insert = 1` profile the insert is flushed by the async-insert queue, whose context has current database `default`, so its child rows were outside the test's database filter. - 05616: a child row logged at `ExceptionWhileProcessing`. - 05616: `used_row_policies` of a child row (a row policy on the table a DEFINER view reads). - QueryAnalyzer.cpp: drop the now unused `parallel_replicas_plan_based` declaration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ns of child rows - test_user_query_log_insecure_cluster_uses_initial_user: a read through the `insecure` cluster reaches n2 as `default` with `initial_user` = the caller, and must not return the caller's top-level `user_query_log` rows. - 05617: the child rows of reads through a materialized view assert their `partitions` and `databases` exactly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Delete comments that narrate the new code and condense the rest to standalone invariants; no code change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 rounds, 11 findings) plus my own review (7 findings, 1 withdrawn).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261110-230700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261110-192400 |
|
Workflow [PR], commit [b396466] Summary: ✅
AI ReviewSummaryReviewed PR #130654 at Consumers of the additional log rows reviewed:
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1531 translation units recompiled, 12463 s compile time in total, 1531 of them have a recent master baseline. |
…s child rows `DESCRIBE TABLE pv(...)` of a `DEFINER`/`NONE` parameterized view analyzes the substituted body in the view's own context without `only_analyze`, so a scalar subquery of the body runs under the definer (a `throwIf` in it fires), and `Context::buildParameterizedViewStorage` runs the scalar subqueries in the arguments of a table function in the body even in analysis mode (`EXPLAIN QUERY TREE SELECT * FROM pv(...)`). Neither context was registered, so neither the caller's row nor a child row listed what they read. Both now register the body like `StorageView::readImpl` does; a `SELECT` still gets one child row per body, because the registration of the analysis and of the read coalesce on view, query hash and user. The pre-analyzer overload `Context::executeTableFunction(const ASTPtr &)` builds a parameterized view the same way and now registers it too. No SQL statement was found to reach that branch (`x IN pv(p = 1)` fails on the unknown identifier `p` in SELECT, ALTER DELETE/UPDATE, DELETE, CHECK, DEFAULT, MATERIALIZED and row policies; `IN (SELECT ... FROM pv(...))` and JOIN go through the analyzer and get child rows), so it has no test. The "has a query context of its own" check moves into `Context::addSQLSecurityOverriddenBody`, so call sites need not repeat it. Found by the AI review of ClickHouse#130654 (r4532409526). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sql-security-child-rows-126334 Co-Authored-By: Claude Opus 5.5 <[email protected]>
05616_sql_security_definer_view_read_by_definer counts only top-level rows: the read of a DEFINER view is now also logged as a child row without metrics, which its query_log probe matched too. The body of a DEFINER or NONE materialized view is registered where its chain is attached to the pipeline, not when the view is found as a dependent. A view skipped for a dropped target (ignore_materialized_views_with_dropped_target_table = 1) or behind a storage that does not push on INSERT (Kafka, NATS, RabbitMQ, FileLog) no longer gets a child row for a body that never ran. 05616 and 05617 cover a NONE materialized view, the target of a nested one, two distinct views with the same body, a dropped target and an INSERT into a FileLog table; each child row is joined to its caller by initial_query_id, and child query ids must be distinct. Co-Authored-By: Claude Opus 5.5 <[email protected]>
In a Replicated database the DDL worker replays every CREATE/DROP of the test as a secondary query, logged as QueryStart and QueryFinish rows with is_initial_query = 0 and one query_id. The check counted those rows too, so 05616 and 05617 failed `1 1` -> `1 0` in the DBReplicated jobs. Count only the non-initial rows of the labelled queries, whose child rows the check is about. Also say in the system.user_query_log description that a row policy keyed on any of `user`, `initial_user` or `authenticated_user` exposes child rows: a child row keeps the caller's `initial_user` and `authenticated_user` and has the definer as `user`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@groeneai please resolve conflicts |
…sql-security-child-rows-126334 # Conflicts: # src/Interpreters/executeQuery.cpp
|
Resolved by merging master in b396466. The only conflict was in |
…and under randomized settings - Since #130654 the body of a `SQL SECURITY NONE` view is logged as a child `query_log` row with the same `log_comment`; select only `is_initial_query` rows. - Pin `merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability = 0`: the CI diagnosis named it as the culprit for one extra row read from `t_outer_sv`. - Disable parallel replicas: with them `05618_clone_recovered` did not take the recovery path. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=130374&sha=latest&name_0=PR&name_1=Stateless%20tests%20(arm_binary%2C%20AsyncInsert%2C%20s3%20storage%2C%20sequential) PR: #130374 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #126334
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
What a query runs under the identity of a
SQL SECURITY DEFINERorNONEview or materialized view is now logged insystem.query_logas a child row (is_initial_query = 0, the query'sinitial_query_id, the definer asuser) with the tables, columns, partitions and projections it accessed; the caller's row no longer lists the tables such a materialized view writes. Reads of a serialized query plan record the tables they read.system.user_query_logreturns only top-level (is_initial_query = 1) rows of the authenticated matching user. A row policy that exposessystem.query_logrows by user (user,initial_userorauthenticated_user) should addis_initial_query = 1to keep the child rows hidden.Description
On master, the body of a
SQL SECURITY DEFINER/NONEview or materialized view runs in a query context of its own. What it accesses is recorded there and never logged, sosystem.query_logdoes not show what a query read through such a view. #126334 merges it into the caller's row, which then needs a marker column, reader filters and a default-off server option. This PR implements @ vdimir's alternative (#126334 (comment)): the body is logged as a child row, like a distributed query's shard query.The first commit is #126334 at
b4be48e6; the second replaces its marker, marking sites, reader logic and option. Each caller ofgetSQLSecurityOverriddenContextthat runs something (includingDESCRIBEand the analysis of a parameterized view) registers the body'sQueryAccessInfoon the enclosing query context (a materialized view only when the insert pushes to it), andexecuteQuerywrites one row per distinct body.Deviations from the proposal:
system.user_query_log.analyzer_inline_views(experimental) no longer inlinesDEFINER/NONEviews, because an inlined body's query context has no owner.05257_sql_security_view_sealedcounts only forwarded rows (distributed_depth > 0), and05616_sql_security_definer_view_read_by_defineronly top-level rows.Validation: 05616-05618 fail on master and pass here (150/150 randomized runs), 20 one-line mutations each fail them, one more fails
test_user_query_log_insecure_cluster_uses_initial_user, and 57 related tests are unchanged apart from those two.Workflow [PR]
Sync PR [sync-upstream/pr/130654]
Version info
26.11.1.2673-master(included in26.11and later)