Skip to content

Do not bypass row policies in the mergeTreeIndex table function - #115304

Merged
CurtizJ merged 5 commits into
masterfrom
yarik/fix-mergetree-index-row-policy
Aug 21, 2026
Merged

CurtizJ merged 5 commits into
masterfrom
yarik/fix-mergetree-index-row-policy

Conversation

@yariks5s

@yariks5s yariks5s commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

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):

Fixed a row policy bypass where the mergeTreeIndex table function exposed primary key and minmax index values of the rows hidden by a SELECT row policy on the source table; reading mergeTreeIndex for a table with a row policy is now denied.

Closes #115230


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

Version info

  • Backported to: 26.7.6.5, 26.6.4.10, 26.5.8.18, 26.3.22.6

@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ac57378]

Summary: ✅


AI Review

Summary

This PR closes the direct mergeTreeIndex RBAC leak by denying reads when a non-trivial SELECT row policy exists on the source table. I still see one major gap: the sibling mergeTreeAnalyzeIndexes / mergeTreeAnalyzeIndexesUUID path remains able to answer predicates over policy-hidden rows via returned mark ranges, and the new test explicitly preserves that behavior, so I would not merge this as a complete row-policy fix for MergeTree index introspection.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04891_mergetree_index_respects_row_policy.sql:23-24, src/Storages/StorageMergeTreeAnalyzeIndexes.cpp:135-198,350] The new contract is only enforced for mergeTreeIndex. mergeTreeAnalyzeIndexes still takes the caller's predicate, builds key/skip-index conditions from it, and returns mark ranges after only a plain SELECT grant check, without ever consulting getRowPolicyFilter on the source table. A restricted user can therefore ask about a policy-hidden key such as department = 'finance' and distinguish hidden matches from no matches by inspecting the returned ranges. The added test now locks in that bypass by asserting the call remains allowed under the row policy.
    Suggested fix: either deny the user-callable mergeTreeAnalyzeIndexes variants under non-trivial row policies as well, or split the internal distributed-analysis RPC from the public table function so the former can stay available while the latter cannot leak hidden-row ranges.
Final Verdict

⚠️ Needs changes. The direct mergeTreeIndex leak is fixed, but the sibling public index-analysis table function still bypasses the same row-policy boundary.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.90% 86.90% +0.00%
Functions 91.90% 92.00% +0.10%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 10/10 (100.00%) · 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 Aug 18, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@yariks5s from my research, the mergeTreeProjection function also bypasses row policies. Can you confirm that?

Comment thread src/Storages/StorageMergeTreeIndex.cpp Resolved
@yariks5s

Copy link
Copy Markdown
Member Author

@PedroTadim it should be covered by #112329

@rschu1ze

Copy link
Copy Markdown
Member

@CurtizJ FYI^^

@CurtizJ CurtizJ self-assigned this Aug 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ac5737807 with master 8a4969205 (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
Binary Master PR Δ
programs/clickhouse-stripped 702.08 MiB 699.05 MiB -3.03 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

yariks5s and others added 2 commits August 19, 2026 14:17
clickhouse-gh Bot added a commit that referenced this pull request Aug 21, 2026
Backport #115304 to 26.6: Do not bypass row policies in the mergeTreeIndex table function
clickhouse-gh Bot added a commit that referenced this pull request Aug 21, 2026
Backport #115304 to 26.7: Do not bypass row policies in the mergeTreeIndex table function
yariks5s added a commit that referenced this pull request Aug 24, 2026
Cherry pick #115304 to 26.3: Do not bypass row policies in the mergeTreeIndex table function
robot-clickhouse added a commit that referenced this pull request Aug 24, 2026
CurtizJ added a commit that referenced this pull request Aug 25, 2026
Backport #115304 to 26.3: Do not bypass row policies in the mergeTreeIndex table function
CurtizJ added a commit that referenced this pull request Aug 25, 2026
Backport #115304 to 26.5: Do not bypass row policies in the mergeTreeIndex table function
robot-clickhouse-ci-1 added a commit that referenced this pull request Aug 25, 2026
Cherry pick #115304 to 25.8: Do not bypass row policies in the mergeTreeIndex table function
robot-clickhouse added a commit that referenced this pull request Aug 25, 2026
@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 Aug 25, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 28, 2026
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Sep 16, 2026
PedroTadim pushed a commit to groeneai/ClickHouse that referenced this pull request Sep 24, 2026
…ies to it

A row policy on a `Set`-engine table was accepted and listed in `system.row_policies`, but
the only consumer of such a table, the right-hand side of `IN`, reads the prebuilt set directly
and never sees the filter, so every hidden element stayed testable. The engine has no read path
that could apply the policy, so such a query now fails with `ACCESS_DENIED`, the same way
`mergeTreeIndex` fails closed for a policed source table. The check runs in the planner, in the
legacy expression analyzer that mutations still use, and when a replica materializes a set
from a serialized plan. `ExpressionAnalyzer::isPlainStorageSetInSubquery` had no callers and
is removed.

Closes: ClickHouse/clickhouse-private#70502
Related: ClickHouse#115304
fm4v added a commit to BoloniniD/ClickHouse that referenced this pull request Sep 25, 2026
Master decided in ec411d7 (ClickHouse#115304) that `mergeTreeAnalyzeIndexes` returns mark ranges, not values, and is used for distributed index analysis, so the row policy is intentionally not enforced there. `04891_mergetree_index_respects_row_policy` pins that. Restore master's behaviour and drop the conflicting test.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=103402&sha=9c0eb6b85de088b3b50641c2e633ee4f3b124e27&name_0=PR&name_1=Fast%20test
vdimir added a commit that referenced this pull request Sep 29, 2026
…CESS_DENIED`

The check in `CREATE ROW POLICY` protected nothing: `ON db.*`, a policy
created before the table, and a table created after the policy all
bypassed it, while it broke `ALTER ROW POLICY` on an existing policy and
ran per node under `ON CLUSTER`. The query-time rejection in `JOIN` and
`joinGet` is the actual boundary, and persisted policies never went
through the interpreter anyway. The error code follows the `mergeTreeIndex`
fix in #115304.

Related: ClickHouse/clickhouse-private#70504

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

mergeTreeIndex table function ignores the source table's row policy

7 participants