Repository navigation
Fix access checks in PREWHERE and indexHint() that used aliases - #120516
Conversation
|
Workflow [PR], commit [9743109] Summary: ✅
AI ReviewSummaryThis PR correctly tightens most of the planner-time Findings❌ Blockers
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 9743109.
Changed lines: Changed C/C++ lines covered: 72/74 (97.30%) · Uncovered code |
| if (column_names.empty()) | ||
| return; | ||
|
|
||
| checkAccessRights( |
There was a problem hiding this comment.
checkAccessRights() only consults the StorageAlias target table in its empty-column fallback path. For ordinary reads that is masked by StorageAlias::read(), which re-checks the target with the actual column_names, but the whole point of getAccessCheckedColumnsNames() is that these columns never reach column_names.
That leaves the indexHint() half of this fix incomplete on ENGINE = Alias: SELECT pub FROM alias_mt WHERE indexHint(secret_alias >= 500) now passes as soon as the user has SELECT(pub, secret_alias) on alias_mt, even if they have no SELECT(secret_alias) on the target table. The same reference is denied once it is actually read. This helper needs to mirror the StorageAlias target-column check, or checkAccessRights() needs to enforce it for non-empty column lists too. An Alias-engine regression test here would also be useful.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units53 translation units recompiled, 514 s compile time in total, 53 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.09 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
| const TableNode & table_node, const TableExpressionData & table_expression_data, const ContextPtr & query_context) | ||
| { | ||
| const auto & column_names = table_expression_data.getAccessCheckedColumnsNames(); | ||
| if (column_names.empty()) |
There was a problem hiding this comment.
In spite of this, it routes into the column_names.empty() branch of checkAccessRights so it does not make the helper a no-op. Is that intended??
There was a problem hiding this comment.
Intended — empty list means trivial query.
`expressionSourceColumns` collects with ALIAS columns inlined and read the selected names, which relied on the children walk after inlining selecting the source columns. It wants the physical dependencies, so read the physical column list; that also covers a plain `x ALIAS y`, whose source was never selected. Also document why the resolved-away columns are checked separately from the selected ones. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Record the names PREWHERE references at the PREWHERE site, with the same traversal the filter access check uses, instead of marking inside the visitor: the inline mode also serves row policies, additional filters, the ALTER guards and mutations, where no check is wanted. Keep the replacement in `enterImpl` and stop the children walk from selecting the sources of the inlined expression, which the nested visitor has already collected. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…n through ALIAS Co-Authored-By: Claude Fable 5.1 <[email protected]>
vdimir
left a comment
There was a problem hiding this comment.
Pushed four commits on top, keeping your structure:
expressionSourceColumnsnow returnsgetColumnNames(physical read list). The selected list lost the sources of inlined aliases, which broke05076_json_lazy_type_hints_projection_safety; the physical list also covers plainx ALIAS y, which master missed.PREWHEREnames are recorded at thePREWHEREsite viacollectReferencedColumnNames(shared with the filter access check) instead of inside the visitor, which also serves row policies and the ALTER guards. Inlining stays inenterImpl; the walk into the inlined expression is blocked inneedChildVisit, replacing theleaveImpldeferral.- Tests:
05293(indexHintunderJOIN, subquery,PREWHERE) and05294(ALTER guard through an ALIAS).
Your 05218 and the existing indexHint, PREWHERE-alias and metadata-only ALTER tests pass unchanged.
Changelog should mention both directions: an ALIAS in PREWHERE now requires the grant on the alias name, as in WHERE; a grant on its source column is no longer enough.
|
Summary of all behaviour changes in this PR (as of fd835e7), each verified locally against a pre-PR master build. Access checks1. CREATE TABLE t (secret Int32, pub Int32, secret_alias ALIAS secret, secret_fn ALIAS secret * 2)
ENGINE = MergeTree ORDER BY secret;
Before, a plain alias ( 2. Columns used only as
Applies to 3. Unchanged on purpose: row policies and additional filters may still reference an ALTER4. CREATE TABLE src (k UInt64, c UInt64, v String) ENGINE = MergeTree ORDER BY k;
CREATE MATERIALIZED VIEW mv ENGINE = MergeTree ORDER BY k AS SELECT k, v FROM src WHERE indexHint(c = 1);
ALTER TABLE src DROP COLUMN c;
-- before: succeeds; the next INSERT INTO src fails with UNKNOWN_IDENTIFIER "while pushing to view"
-- after: ALTER_OF_COLUMN_IS_FORBIDDEN "referenced by materialized view ['mv']"This is a side effect of 5. The metadata-only named-tuple CREATE TABLE g (t Tuple(a Int64), t_alias ALIAS t, m String MATERIALIZED toString(t_alias))
ENGINE = MergeTree ORDER BY tuple();
INSERT INTO g (t) VALUES ((1));
ALTER TABLE g MODIFY COLUMN t Tuple(a Int64, b String) SETTINGS allow_metadata_only_named_tuple_alter = 1;
-- before: succeeds and nothing recomputes m; the row reads back as t = (1,''), m = '(1)'
-- after: ALTER_OF_COLUMN_IS_FORBIDDEN "subcolumn used by the MATERIALIZED column 'm'"Same for projection keys and TTL expressions, which go through the same |
|
📊 Cloud Performance Report ✅ AI verdict: This PR shows no performance changes on clickbench or tpch_adapted_1_official. The only flagged rows are clickbench Q33 (-5.2%) and Q34 (-6.2%). Both fall inside master's current range and both have flat CPU time, so the lower wall-clock times are variation rather than less work. That fits the diff: it only adds planning-time SELECT-privilege checks for columns used in explicit PREWHERE ALIAS references and indexHint arguments, and shares the column-name collection with the existing filter check. None of this sits on the execution path of ClickBench's GROUP BY queries, which also have no explicit PREWHERE or indexHint. All three source runs (the clickbench run and both TPC-H runs) were on the same node, which makes small speedups like these less trustworthy, but it does not change the result. clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
…check' into fix_prewhere_alias_access_check
| if (is_inside_index_hint_function && source_table->getStorage()->isMergeTree()) | ||
| return; | ||
|
|
||
| /// Note that arguments of the "indexHint" function need to be checked for SELECT privilege |
There was a problem hiding this comment.
collectSelectedColumnsFromTable() also feeds IStorage::getDependentViewsByColumn(), so this change is doing more than the new SELECT-privilege checks: it now makes ALTER TABLE src DROP COLUMN c reject a dependent view that mentions c only inside indexHint(). That looks like the right outcome, but I do not see a regression test for that path in this PR. The new tests cover direct query planning and the metadata-only named-tuple ALTER, not the dependent-view DROP COLUMN guard, so this can regress silently.
@groeneai why test failed with parallel replicas? Is it safe just exclude it from this run or there underlying issue or bug? |
|
It is a pre-existing difference in index analysis between the local and the parallel-replicas path, not an access-check issue, so the tag is safe. It reproduces on master without this PR and without any grants: CREATE TABLE t (id UInt64, secret UInt64, secret_alias ALIAS secret)
ENGINE = MergeTree ORDER BY secret SETTINGS index_granularity = 1;
INSERT INTO t SELECT number, number * 1000 FROM numbers(10);
SELECT count() FROM t WHERE id = 3 AND indexHint(secret_alias > 5000);
-- 1 locally, 0 with enable_parallel_replicas = 1, parallel_replicas_for_non_replicated_merge_tree = 1The parallel-replicas shipping paths inline The access checks hold with parallel replicas: in the failing runs every |
Backport #120516 to 26.9: Fix access checks in PREWHERE and indexHint() that used aliases
Backport #120516 to 26.8: Fix access checks in PREWHERE and indexHint() that used aliases
… indexHint() that used aliases
… indexHint() that used aliases
Cherry pick #120516 to 26.3: Fix access checks in PREWHERE and indexHint() that used aliases
Cherry pick #120516 to 26.7: Fix access checks in PREWHERE and indexHint() that used aliases
Backport #120516 to 26.7: Fix access checks in PREWHERE and indexHint() that used aliases
Backport #120516 to 26.3: Fix access checks in PREWHERE and indexHint() that used aliases
|
@shankar-iyer Unfortunately, this PR will need to be backported to 26.2 but there are merge conflicts. Would you resolve them so the fix can land in 26.2? Thanks! |
Enforce column-level
SELECTgrants for columns that the planner resolves away before the access check runs:ALIAScolumns inlined intoPREWHERE, and columns used only asindexHint()arguments. User will require the grant on the alias name itself.Changelog category
Changelog entry
Column-level
SELECTprivileges are now enforced for columns used only insideindexHintand forALIAScolumns referenced inPREWHERE. As inWHERE, referencing anALIAScolumn inPREWHERErequires the grant on the alias name; a grant on its source columns is no longer sufficient. A metadata-onlyALTERthat changes a subcolumn read by aMATERIALIZEDcolumn through anALIASis now refused like a direct reference.Workflow [PR]
Sync PR [sync-upstream/pr/120516]
Version info
26.10.1.1151-master(included in26.10and later)26.9.8.9,26.8.15.22,26.7.20.22,26.3.40.11