Repository navigation
Check access to a parameterized view when a query resolves it - #129106
PedroTadim merged 8 commits into
Conversation
A parameterized view call is resolved as a table function, so the metadata check that ClickHouse#117979 added to table identifier resolution never runs for it. A user with no grant on a SQL SECURITY DEFINER parameterized view therefore got its column names and types from EXPLAIN QUERY TREE and EXPLAIN SYNTAX run_query_tree_passes = 1, and every user got errors that named the view's parameters, its columns (UNKNOWN_IDENTIFIER vs ACCESS_DENIED) or, for an INVOKER view, the tables behind it, because the parameters are substituted and the body is analyzed before anything checks the view. Check the view where each piece of information is obtained: - Context::buildParameterizedViewStorage: without implicit SHOW TABLES on the view (which any grant on the view or on one of its columns implies), report the standard SELECT denial before substituting the parameters or analyzing the body. - QueryAnalyzer::resolveTableFunction: once the columns are known, run the ClickHouse#117979 check (at least one column must be visible). The helper becomes a public static member of IdentifierResolver; the temporary-table exemption moves to its identifier-resolution caller. Executing a call needs SELECT on at least one of its columns, which passes both checks, so no executable query changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The parameterized-view branch of `Context::executeTableFunction` substitutes the parameters and analyzes the body like `buildParameterizedViewStorage`, and `INSERT ... SELECT` into a `Distributed` or replicated table reaches it through `JoinedTables::getLeftTableStorage` before the analyzer when `parallel_distributed_insert_select` is on (the default). Without the check, a user with only `INSERT` on the destination got errors naming the view's parameters or the tables an `INVOKER` view reads. Move the first check into a file-local helper and call it from both places. The test gets two `INSERT ... SELECT` arms that fail when only the new call is removed. 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) plus my own review, 2 rounds: round 1 on the first head (3 findings), round 2 a delta recheck of the fix round (0 findings).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261103-213200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261103-205300 |
|
cc @novikd @alexey-milovidov, could you review this and add the |
|
Workflow [PR], commit [1428451] Summary: ✅
AI ReviewSummaryThe PR checks access before parameterized-view expansion and before exposing resolved columns, while allowing virtual-column grants and aligning table-function precedence with the analyzer. Review of the current diff, callers, regression coverage, and all prior discussion found no new actionable issues. The focused regression passed 35 CI runs at Final VerdictStatus: ✅ Approve. No additional changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units22 translation units recompiled, 200 s compile time in total, 22 of them have a recent master baseline. |
… and update 05493
With `ORDER BY {sort:Identifier}` and `sort = 'missing'`, the analysis error under
`EXPLAIN SYNTAX run_query_tree_passes = 1` and `EXPLAIN AST optimize = 1` quoted the view
definition to a user with SELECT on the base table only. Since ClickHouse#129074 these modes no longer
inline the view for such a user and reach the check in `buildParameterizedViewStorage`, so the
two base-table-only analyzer arms of 05493 now get ACCESS_DENIED.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e same name in executeTableFunction The INSERT ... SELECT preflight into a Distributed table reached the parameterized view's access check for a call like `numbers(3)` that the analyzer resolves as the table function, when a view of that name exists in the current database. Check the factory first, as `QueryAnalyzer::resolveTableFunction` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A grant on only a virtual column such as `_table` lets the planner read it, but the metadata check counted only the declared columns, so such a query was refused before it was planned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…yzer's metadata check An Alias reports its target's virtual columns, so a grant on one of them on the alias alone made the target's columns visible to EXPLAIN QUERY TREE. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log, update (click to expand)Review of the update (merge of master for
|
Pre-PR validation gate (update: invalid `Identifier` parameter, `05493`, a table function shadowed by a view, virtual-column grants, an `Alias`) (click to expand)
|
|
🕵️ @groeneai The access checks look right to me. Both places that substitute the parameters are covered, and the
|
|
Thanks, I added both to the changelog entry. On 1: master replaces |
Related: #78938
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
EXPLAIN QUERY TREEandEXPLAIN SYNTAX run_query_tree_passes = 1showing the columns of a parameterized view to a user without grants on it. Such a user now getsACCESS_DENIEDfor any call of the view, instead of errors that name its columns, parameters or the tables it reads, or quote its definition. A user whose only grant on a parameterized view is on a subcolumn (SELECT(`t.a`)) can no longer read it, as for tables since #117979. With the old analyzer (enable_analyzer = 0, before 26.9), an unqualified call of a parameterized view named like a table function, such asnumbers(n = 3), now calls the table function, as the analyzer does; usedb.numbers(n = 3)for the view.Description
On 26.8.34.13 and 26.10.2.103,
EXPLAIN QUERY TREE SELECT * FROM pv(n = 3)prints aSQL SECURITY DEFINERparameterized view's columns to a user without grants;SELECT,DESCRIBE,SHOW CREATErefuse. #117979 checks tables and ordinary views, not parameterized view calls (table functions). Errors leak too:SELECT no_such_column FROM pv(...)givesUNKNOWN_IDENTIFIER,pv()names the missing parameter, anINVOKERview names its table.Two checks:
Context::buildParameterizedViewStorageand the view branch ofContext::executeTableFunction(reached before the analyzer byINSERT ... SELECTintoDistributed), before the parameters are substituted: withoutSHOW TABLESon the view, the user needsSELECTon it. That branch now prefers a same-named table function, as the analyzer does (DESCRIBEstill prefers the view, Parameterized views: Support DESCRIBE queries & scalar expressions in the analyzer #68978);QueryAnalyzer::resolveTableFunction: Check table access when the analyzer resolves a table identifier #117979's check that the user sees at least one column. It now counts virtual columns (it refused a_table-only grant on a table too); for anAlias, only with the grant on the target.Both are weaker than the column
SELECTexecution needs, so no working query is refused, except with a subcolumn-only grant (#103402 counts such grants). ASHOW TABLES-only or column-grant holder passes the first check, so a malformed call's error can still name parameters or, via anIdentifierparameter, quote the definition. Since #129074,EXPLAIN SYNTAX run_query_tree_passes = 1andEXPLAIN AST optimize = 1also reach the first check: two05493arms (base-table-only user) now expectACCESS_DENIED.The test covers three
EXPLAINmodes, anINsubquery, errors,INSERT ... SELECTintoDistributed, a shadowed table function, anAlias, and_table-only, base-table-only andSHOW TABLES-only users. Sixteen checks fail on master and pass with the fix (100 randomized runs).Workflow [PR]
Sync PR [sync-upstream/pr/129106]
Version info
26.11.1.1482-master(included in26.11and later)