Skip to content

Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key - #118063

Merged
novikd merged 22 commits into
masterfrom
fix-additional-table-filters-access
Sep 9, 2026
Merged

novikd merged 22 commits into
masterfrom
fix-additional-table-filters-access

Conversation

@novikd

@novikd novikd commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Predicates supplied through the additional_table_filters setting (and the expression in parallel_replicas_custom_key) were resolved and evaluated over table columns without the column-level SELECT check a WHERE predicate gets. A user with SELECT(id, public_label) on a table could put secret_token = '...' into the setting and read the denied column value through the row count. The planner ran its only column check before these filters were resolved, and the legacy interpreter checked only the query's own columns.

The fix resolves each settings-provided filter against its table expression and checks the referenced columns with the same checkAccessRights used for the query's columns, before the filter DAG is built. It covers the planner (buildAdditionalFiltersIfNeeded, buildCustomKeyFilterIfNeeded, the trivial view pushdown to Distributed, and the initiator side of parallel_replicas_custom_key when the key is shipped to replicas), the legacy InterpreterSelectQuery, and SQL SECURITY DEFINER/NONE views, whose body no longer inherits the invoker's additional_table_filters or parallel_replicas_custom_key (an access check there would run as the definer; the custom key is still applied to the view's own columns by the outer query). Row policies are unchanged. Column names are collected before ALIAS expansion so a grant on the alias name keeps working, matching the main path.

User-visible changes: an additional_table_filters or parallel_replicas_custom_key expression over a column the user cannot select (including one coming from a settings profile) now fails with ACCESS_DENIED; an invoker's additional_table_filters entry keyed on a table read inside a SQL SECURITY DEFINER or NONE view is no longer applied (filters keyed on the view itself still are); the body of such a view is read without the invoker's parallel_replicas_custom_key (the key still applies to the view's columns) and, for an initial query, without the internal parallel_replicas_count/parallel_replica_offset pair (an invoker could otherwise pick the slice of a SAMPLE in the body); a query that declares itself secondary, that is a follower or a client that sets query_kind, keeps the pair so that follower partitioning in parallel_replicas_mode = 'sampling_key' still works.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Expressions supplied through the additional_table_filters and parallel_replicas_custom_key settings are now subject to the column-level SELECT check, and are no longer injected into the body of SQL SECURITY DEFINER or NONE views. Previously a user could evaluate predicates over columns they were not granted.


Workflow [PR]
Sync PR [sync-upstream/pr/118063]

Version info

  • Backported to: 26.8.3.74, 26.7.7.84, 26.6.5.113, 26.3.33.64

novikd and others added 7 commits September 4, 2026 11:19
Column-level SELECT grants are not consulted for the columns referenced by
`additional_table_filters`, `parallel_replicas_custom_key`, and for the
underlying table of an `INVOKER` view, so a user with SELECT on only a
subset of a table's columns can still learn about denied columns by passing
a filter expression that references them. This test pins the expected
(fixed) behaviour across both the old and new analyzer, and is RED against
the current unfixed binary.

Related: ClickHouse/clickhouse-private#69185
… filters in the planner

Filters coming from the `additional_table_filters` and `parallel_replicas_custom_key`
settings are supplied by the user, but they were resolved after the planner had already
checked `SELECT` on the columns of the query, so they could read columns the user has no
grant for. Split the filter resolution out of `buildFilterInfo` into `buildFilterQueryTree`
and, for the settings-provided filters only, collect the table columns the resolved filter
reads and run the same column-aware `SELECT` check the query columns get. Row policies are
admin-defined and stay unchecked.

Related: ClickHouse/clickhouse-private#69185

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…em from DEFINER view context

`InterpreterSelectQuery` used to apply the filters coming from `additional_table_filters` and
`parallel_replicas_custom_key` without any column-level `SELECT` check, so a user could probe
columns they are not granted. The filter AST is now analyzed as `SELECT <filter> FROM db.table`
and passed through `checkAccessRightsForSelect` next to the main query check, reusing the
`SELECT ... FROM` AST builder extracted from `generateFilterActions` as `makeSelectFromTable`.
For `SQL SECURITY DEFINER`/`NONE` bodies the check would pass as the definer, so
`additional_table_filters` is stripped from the overridden context instead.

Related: ClickHouse/clickhouse-private#69185

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Three fixes from the review of the test:

- Case 1 compared `secret_token` against the literal `'T'` instead of the
  secret value in `$T`.
- `run` merged stderr into the captured output, so a server warning printed
  by the client on a successful query leaked into the reference. Observed:
  the legacy-analyzer custom-key cases log `Parallel replicas with custom key
  will not be used ...` when the harness randomizes
  `parallel_replicas_for_non_replicated_merge_tree`, which made case 17 fail.
  Stderr now goes to a separate file and only stdout is printed on success.
- On failure the error code name is taken from the trailing `(CODE_NAME)`
  token instead of a fixed alternation, so an unexpected error still prints a
  token and the following lines do not shift.

Reference values are unchanged.

Related: ClickHouse/clickhouse-private#69185

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…t to replicas

The custom key was checked only when the server applied the filter itself
(`parallel_replicas_count > 1`). When the initiator ships the key to the replicas -
a `Distributed` table over a one-shard multi-replica cluster, or a `MergeTree` table
over `cluster_for_parallel_replicas` - the key is spliced into the shipped query's
`WHERE` and evaluated on the replicas under the cluster user, so the initiator never
checked the current user's column-level `SELECT` grants on it.

Check the key's columns on both initiator paths, in the planner and in the legacy
interpreter.

Related: ClickHouse/clickhouse-private#69185

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…y the planner helpers

Note in the `additional_table_filters` description that a filter keyed on a table read
through a `SQL SECURITY DEFINER` or `NONE` view is not applied inside the view, since the
view body runs under the definer's context which does not carry the setting.

Use the `ConstInDepthQueryTreeVisitor` alias for `CollectFilterColumnNamesVisitor` and wrap
the over-long signatures of `checkAccessRightsForFilter` and `buildFilterQueryTree`.

Related: ClickHouse/clickhouse-private#69185

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e5c73dd]

Summary: ✅


AI Review

Summary

This PR closes the main column-level SELECT gaps for additional_table_filters and parallel_replicas_custom_key across the planner, legacy interpreter, Distributed, views, and parameterized views, and the new stateless coverage is broad. One blocker remains: the SQL SECURITY DEFINER / NONE protection for parallel_replicas_count and parallel_replica_offset still trusts client-declared query_kind, so a native client can keep those initiator-only settings in the overridden view body and still steer an inner SAMPLE.

Findings

❌ Blockers

  • [src/Storages/StorageInMemoryMetadata.cpp:211-217] [dismissed by author -- https://github.com/Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key #118063#discussion_r3951364192] The new guard strips parallel_replicas_count / parallel_replica_offset only when context->getClientInfo().query_kind != SECONDARY_QUERY, but query_kind is explicitly client-controlled on the native protocol: the server accepts any INITIAL_QUERY or SECONDARY_QUERY value from the wire at [src/Server/TCPHandler.cpp:2565-2575], the client exposes --query_kind secondary_query at [src/Client/ClientBase.cpp:4411], and the codebase already documents that query_kind == SECONDARY_QUERY is spoofable and unsafe for security-sensitive checks at [src/Interpreters/Context.h:607-608]. Because [src/Storages/StorageView.cpp:334-352] builds the SQL SECURITY DEFINER / NONE body through getSQLSecurityOverriddenContext, a user can still send an initial query as SECONDARY_QUERY, preserve the pair in the inner context, and let [src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp:392,426-432] repartition an explicit SAMPLE inside the view body. That keeps the row-count probe alive for sampled bodies even after this PR.
    Suggested fix: preserve the pair only on a server-trusted signal of a genuine follower query, not on ClientInfo::query_kind alone. If there is no such signal today, add one in the remote-query path and gate this branch on it; then add a focused native-protocol regression that runs clickhouse-client --query_kind secondary_query against SQL SECURITY DEFINER / NONE sampled views.
Tests
  • ⚠️ 05076_additional_table_filters_column_access no longer exercises the spoofed-native-client path above. Cases 37-41 cover ordinary initial queries and genuine distributed followers, but none sends a client-declared SECONDARY_QUERY, so the remaining bypass is untested.
Final Verdict

❌ Changes requested

LLVM Coverage Report

Measured on commit e5c73dd.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 225/227 (99.12%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e5c73dda2 with master 7f6b3f065 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

9 object files changed (+28.51 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Planner/Utils.cpp.o 278.30 KiB 306.51 KiB +28.21 KiB (+10.14%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

43 translation units recompiled, 396 s compile time in total, 43 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Sep 4, 2026
… with traverseQueryTree

Move `checkAccessRights` and `checkAccessRightsForFilter` from the anonymous
namespace of `PlannerJoinTree.cpp` to `Planner/Utils.{h,cpp}`, replace
`CollectFilterColumnNamesVisitor` with `traverseQueryTree`, and turn
`buildFilterInfoWithAccessCheck` into a `check_access_rights` parameter of
`buildFilterInfo`.

The check-only sites (the view-keyed fold, the Distributed-keyed check in the
pushdown and the two initiator custom-key checks) keep calling
`buildFilterQueryTree` plus `checkAccessRightsForFilter`, because
`buildFilterInfo` registers the filter's columns on the table expression data
and would change the columns read from the Distributed table.

Behaviour-neutral refactor.

Related: ClickHouse/clickhouse-private#69185

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Sep 5, 2026
…ITY DEFINER`/`NONE` view body

`getSQLSecurityOverriddenContext` stripped `additional_table_filters` but still carried
`parallel_replicas_custom_key` (and the settings that activate it) into the body context of a
`DEFINER`/`NONE` view. The custom key filter in the body was then resolved and access-checked as
the definer (or with no user), so an invoker whose key names a view column shadowing a denied
table column could observe the table column through the row count.

The overridden context now turns parallel replicas off and clears the key when the invoker uses
custom-key parallel replicas. The key is still applied to the view's own columns by the outer
query, with the invoker's grants.

Adds `SQL SECURITY DEFINER`/`NONE` custom key cases (and a `NONE` `additional_table_filters` case)
to `05076_additional_table_filters_column_access`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Planner/Utils.cpp Resolved
…n 05076

The analyzer resolves a parameterized view as a `TableFunctionNode` wrapping the `StorageView`, and
`checkAccessRightsForFilter` has a dedicated branch for it that nothing exercised. Add cases with a
`SQL SECURITY DEFINER` parameterized view whose body reads the denied column as the definer, so the
view's own column-level grants are the only gate: `additional_table_filters` keyed by the view over an
ungranted column is denied (bare and database-qualified key), over a granted column it works, and the
plain read still returns every row.

The cases run with the analyzer only, because the legacy interpreter does not apply
`additional_table_filters` keyed by a parameterized view at all.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…INER`/`NONE` body even when the invoker's context does not activate it

`drop_custom_key` was derived from `canUseParallelReplicasCustomKey` of the invoker's context only. When the invoker supplied just `parallel_replicas_custom_key` (with the follower-side `parallel_replicas_count` / `parallel_replica_offset`) and the activation settings came from the definer's profile after `setUser`, the key travelled through `changed_settings` into the `SQL SECURITY DEFINER` / `NONE` body context and was evaluated there as the definer, reopening the row-count probe of a denied column.

The key is now dropped both when the invoker's context has custom-key parallel replicas active and when the query supplied the key at all.

Test `05076` gains case 25: a definer whose settings profile enables custom-key parallel replicas, and an invoker that only supplies the key; the parameterized-view cases are renumbered to 26-29.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Planner/PlannerJoinTree.cpp Resolved
…ble when a trivial view is pushed down to it

With `optimize_trivial_view_pushdown_to_distributed`, the analyzer inlines a trivial view over a `Distributed` table and hands the read to the `Distributed` table itself. `StorageDistributed::read` then ships `parallel_replicas_custom_key` to the replicas as a filter over the columns of that table, but the column-level `SELECT` check for the key only ran when the original storage was already a `Distributed` table, so an invoker could probe a denied column of the underlying table through the row count. Run the same check against the `Distributed` table node in the pushdown branch.

Test `05076`, cases 30-32: an `INVOKER` trivial view over the one-shard, three-replica `Distributed` table, with and without the pushdown.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…gacy interpreter

`checkAccessRightsForFilter` and `generateFilterActions` analyzed the synthetic `SELECT <filter> FROM db.table`
with an empty `TablesWithColumns`, so `TreeRewriter` never translated table-qualified names. On `enable_analyzer = 0`
a filter such as `{'db.t': 'db.t.secret_token = ...'}` or a `parallel_replicas_custom_key` of `db.t.id` failed with
`UNKNOWN_IDENTIFIER` during name resolution, while the same predicate in `WHERE` is resolved (and access-checked).

Pass the first table of the query (`JoinedTables::tablesWithColumns`) to both helpers, the same metadata the main
query is analyzed with, so a granted qualified predicate works and a denied one reaches the column-level `SELECT`
check. Test `05076`: case 03 now expects `ACCESS_DENIED` on both interpreters; new cases 26 and 27 cover a granted
qualified `additional_table_filters` predicate and a qualified `parallel_replicas_custom_key`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Comment thread src/Planner/PlannerJoinTree.cpp Resolved
alexey-milovidov and others added 3 commits September 6, 2026 13:14
…rivial view shadowing a denied column

The test launched a client process per case (61 of them), which took 85-100 s even in the debug
and TSan runs and exceeded the 180 s limit in the ASan flaky check, where three copies run at once:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118063&sha=21cfac6cda3e8bdba06a75e41ee9f7572075289a&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29
Running the cases through `curl` over HTTP brings the test from 30 s to under 2 s on a release build.

Also add cases 35-36: an `SQL SECURITY INVOKER` trivial view over the three-replica `Distributed`
table with a view column shadowing the denied column of the table (`'' AS secret_token`), with the
trivial view pushdown on and off. The `parallel_replicas_custom_key` is shipped to the replicas as a
filter over the columns of the `Distributed` table on both paths (the INVOKER body reads the table
as the invoker), so it resolves against the table, not the view, and is denied on both.

#118063

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The randomized settings `enable_parallel_replicas` and
`parallel_replicas_for_non_replicated_merge_tree` made case 06 of
`05076_additional_table_filters_column_access` return `ACCESS_DENIED`
instead of the count in the distributed-plan job.

A grant on an `ALIAS` column alone does not survive parallel replicas
with a serialized query plan: the replica checks the grant on the whole
table. This is pre-existing behavior unrelated to the change here - a
plain `SELECT count() FROM t WHERE alias_col = '...'` fails the same way
with `enable_parallel_replicas = 1`, `serialize_query_plan = 1` and no
`additional_table_filters` at all.

So pin `enable_parallel_replicas = 0` in that case to keep it about the
filter and not about the randomized settings. Verified against a local
server with `process_query_plan_packet` enabled: the test reproduces the
CI diff without the pin and passes with it, both with and without the
randomized settings.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118063&sha=107cfa7522a4dc7d754fce3a316178e81949864f&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%2C%20selected%20tests%29
PR: #118063
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Both CI failures on 411c1865 are pre-existing, unrelated to this pull request, and already tracked with a fix in flight. This pull request only adds column-level SELECT grant checks for additional_table_filters / parallel_replicas_custom_key; the AST fuzzer runs as default, with every grant and no additional filters, so neither code path is reachable from it.

1. AST fuzzer (amd_release, oracle) — TLP Aggregate oracle mismatch

Reproducer from the report:

SELECT count() FROM tab__fuzz_4 WHERE hasToken(str, 'aa')

tab__fuzz_4 is str FixedString(1) NULL with INDEX inv_idx str TYPE text(...), and every value ends up NULL. Reduced locally to:

CREATE TABLE t1 (i UInt32, str Nullable(String),
    INDEX inv_idx str TYPE text(tokenizer = 'splitByNonAlpha') GRANULARITY 1)
ENGINE = MergeTree ORDER BY i SETTINGS min_bytes_for_wide_part = 0;
INSERT INTO t1 VALUES (1, 'aa'), (2, 'bb'), (3, NULL);

SELECT count() FROM t1 WHERE NOT hasToken(str, 'aa');                          -- 2, wrong
SELECT count() FROM t1 WHERE NOT hasToken(str, 'aa') SETTINGS use_skip_indexes = 0; -- 1, correct

The direct read from the text index replaces hasToken with a non-Nullable UInt8 virtual column, so a NULL row materializes as 0 and NOT 0 wrongly passes. The three TLP partitions then sum to more than the reference count().

This is exactly #106922, and the fix is open in #113332 (not yet on master, so merging master does not clear this red).

2. AST fuzzer (arm_asan_ubsan) — Invalid number of columns in chunk pushed to OutputPort. Expected 0, found 1

Triggered by a fuzzed SELECT * APPLY lambda(...) REPLACE (...) EXCEPT (...) over a window-function subquery — a pre-existing zero-column-chunk issue, already linked by the CI comment: #114611.

Nothing to change here: 0 unresolved review threads, the AI review verdict on the head is Approve, and the branch already contains the latest master.

@novikd
novikd deleted the fix-additional-table-filters-access branch September 9, 2026 19:28
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 9, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 9, 2026
Backport #118063 to 26.8: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 10, 2026
Two conflicts, both at the two sites this branch gates. Master (ClickHouse#118063,
"Check column-level SELECT grants for additional_table_filters and
parallel_replicas_custom_key") started parsing the custom key in the same
StorageDistributed branch, to run an access check on it:

  * InterpreterSelectQuery.cpp: master assigns the parsed key to
    parallel_replicas_custom_key_ast_to_check, consumed later by the
    column-grant check.
  * PlannerJoinTree.cpp: master parses it into custom_key_ast and passes it to
    buildFilterQueryTree(..., check_access_rights=true).

Both sides needed the same parsed AST, so the resolution keeps master's parse
and access check untouched and in its original order, and gates only the
setSetting("distributed_group_by_no_merge", 2) call on
customKeyResultCanSkipMerge() using master's already-parsed AST. That drops the
branch's own parseCustomKeyForTable() call at both sites: the key is now parsed
exactly once per query, and this branch's diff at each call site shrinks from
ten lines to five. buildFilterQueryTree() takes the ASTPtr by value and does
not mutate the pointee, so reading it afterwards is safe.

No behaviour change relative to either side: master's access check still runs
unconditionally, and the no-merge fast path is still taken only when the custom
key is a deterministic function of the GROUP BY keys.
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
…for additional_table_filters and parallel_replicas_custom_key
alexey-milovidov added a commit that referenced this pull request Sep 11, 2026
Resolve the cherry-pick of #118063 against the 26.3 release branch.

The 26.3 branch predates several master-only changes the original patch
was written on top of, so the mechanical merge could not be used as is:

* `buildFilterInfo` takes `const QueryTreeNodePtr &` in 26.3, not
  `TableExpressionNodePtr`, so `buildFilterQueryTree` and the new
  `check_access_rights` parameter use the 26.3 signature.
* 26.3 has no standalone-subquery wrapping in `buildFilterInfo` and runs
  `LogicalExpressionOptimizerPass` in the `ASTPtr` overload; the split into
  `buildFilterQueryTree` keeps that behaviour unchanged.
* `checkAccessRights` moved from `PlannerJoinTree.cpp` to `Planner/Utils.cpp`
  with the storage/storage id/snapshot signature, but without the
  `StorageAlias` target-table check, which does not exist in 26.3
  (`StorageAlias::isTargetTableGranted` was added later on master).
* `getSQLSecurityOverriddenContext` in 26.3 applies the parallel replicas
  callbacks at the end of the function and has no cluster read-task
  callback, so only the settings handling from the patch was applied.
* `checkAccessRightsForSelect` takes four arguments in 26.3 and
  `generateFilterActions` is not `static`; the new `makeSelectFromTable` /
  `getTablesWithColumnsForFilter` helpers and `checkAccessRightsForFilter`
  are adapted accordingly.
* The master-only trivial view pushdown to `Distributed`
  (`optimize_trivial_view_pushdown_to_distributed`) does not exist in 26.3,
  so that part of the patch and test cases 32-36 are dropped.

Test adaptations for 26.3:

* Case 06 (a grant on an `ALIAS` column only) is dropped: in 26.3 a plain
  `SELECT count() FROM t` by a user granted only an `ALIAS` column already
  fails with `No available columns`, independently of this change.
* Cases 15, 16, 17 and 27 pin `parallel_replicas_for_non_replicated_merge_tree`
  to 1: without it, 26.3's `InterpreterSelectQuery` turns custom-key parallel
  replicas off on a plain `MergeTree` table before the key is built, so the
  cases would not exercise the filter at all.

The test passes with both analyzers.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
robot-clickhouse added a commit that referenced this pull request Sep 11, 2026
Cherry pick #118063 to 26.3: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
robot-clickhouse added a commit that referenced this pull request Sep 11, 2026
…onal_table_filters and parallel_replicas_custom_key
alexey-milovidov added a commit that referenced this pull request Sep 11, 2026
- `checkAccessRightsForSelect` in `InterpreterSelectQuery` has no `storage` parameter on 26.7 (it was added on master together with `StorageAlias`), so `checkAccessRightsForFilter` calls the four-argument form.
- The test cases that exercise `optimize_trivial_view_pushdown_to_distributed` are dropped: the view pushdown does not exist on 26.7. The two non-pushdown cases over the trivial `INVOKER` views are kept.
- On 26.7 the legacy interpreter disables parallel replicas for a plain `MergeTree` table unless `parallel_replicas_for_non_replicated_merge_tree` is enabled (master gates this on task-based parallel replicas only), so the custom-key cases over `t` enable it to keep exercising the custom key filter and its access check with `enable_analyzer = 0`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
robot-ch-test-poll2 added a commit that referenced this pull request Sep 11, 2026
Cherry pick #118063 to 26.7: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
robot-clickhouse added a commit that referenced this pull request Sep 11, 2026
…onal_table_filters and parallel_replicas_custom_key
alexey-milovidov added a commit that referenced this pull request Sep 11, 2026
Resolve the conflicts of the cherry-pick of #118063 against 26.6:

- `PlannerJoinTree.cpp`, `Planner/Utils.cpp`, `Planner/Utils.h`: 26.6 still has
  `checkAccessRights` taking a `TableNode` (master takes storage, id and
  snapshot after the `Alias` grant work), so it is moved to `Planner/Utils.cpp`
  with the 26.6 signature and `checkAccessRightsForFilter` builds a temporary
  `TableNode` for the check. `TableExpressionNodePtr` does not exist in 26.6,
  `QueryTreeNodePtr` is used instead. The hunks for the inlined view over a
  `Distributed` table are dropped: that code path does not exist in 26.6.
- `InterpreterSelectQuery.cpp`: `checkAccessRightsForSelect` has no `storage`
  argument in 26.6.
- `StorageInMemoryMetadata.cpp`: applied on top of the 26.6 version of
  `getSQLSecurityOverriddenContext`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Sep 11, 2026
- Case 06 (filter over an ALIAS column with a grant on the alias only): on 26.6 a trivial
  `SELECT count()` over a table whose only granted column is an ALIAS column throws a
  logical error even without any filter, so the user also gets `SELECT(id)`; `secret_token`
  stays denied, and the case still checks that the grant on the alias is sufficient.
- Cases 15, 16, 17, 27 (custom key parallel replicas over a plain `MergeTree`): #112942 is
  not in 26.6, so the old analyzer disables the parallel replicas together with the custom
  key filter unless `parallel_replicas_for_non_replicated_merge_tree` is set. Set it.
- Cases 32-36 (trivial view over a `Distributed` table inlined into the outer query): the
  `optimize_trivial_view_pushdown_to_distributed` setting and the code path it exercises do
  not exist in 26.6, so the cases and the views they read are dropped.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
robot-ch-test-poll3 added a commit that referenced this pull request Sep 11, 2026
Cherry pick #118063 to 26.6: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
robot-clickhouse added a commit that referenced this pull request Sep 11, 2026
…onal_table_filters and parallel_replicas_custom_key
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 11, 2026
Backport #118063 to 26.6: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
clickhouse-gh Bot added a commit that referenced this pull request Sep 11, 2026
Backport #118063 to 26.7: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
PedroTadim added a commit that referenced this pull request Sep 12, 2026
Backport #118063 to 26.3: Check column-level SELECT grants for additional_table_filters and parallel_replicas_custom_key
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 27, 2026
The arm read a table from its own row policy through a `SQL SECURITY NONE` view, the one way to
do that without recursion, and expected an `additional_table_filters` entry for that table to
apply inside the view. Since ClickHouse#118063 such entries are stripped from `DEFINER` / `NONE` view
bodies on purpose, so the arm read `[]` on every path, including a local read on master, and
could no longer tell a per-read suppression of the entry from a per-context one.

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

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants