Repository navigation
Text index: make mergeTreeTextIndex stricter when a row policy applies - #119032
Conversation
Previously, reading the text index was denied only when the row policy referenced an indexed column. But the index contains tokens of all rows, including those hidden by a policy on any other column, so the tokens of hidden rows were exposed. Now reading from `mergeTreeTextIndex` is not allowed whenever a row policy applies to the table, regardless of which columns it uses. Closes ClickHouse/clickhouse-private#69196.
|
Workflow [PR], commit [a1aab05] Summary: ❌
AI ReviewSummaryThis PR fixes the main row-policy leak in Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit a1aab05.
Changed lines: Changed C/C++ lines covered: 57/62 (91.94%) · Uncovered code |
Build profile diff (arm_release)Comparing commit See the job log for details. |
…xtindex-row-policy
…xtindex-row-policy
…xtindex-row-policy
…xtindex-row-policy
Cherry pick #119032 to 26.6: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
…ter when a row policy applies
Cherry pick #119032 to 26.7: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
…ter when a row policy applies
Cherry pick #119032 to 26.8: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
…ter when a row policy applies
Backport #119032 to 26.7: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
Backport #119032 to 26.8: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
Backport #119032 to 26.6: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
Cherry pick #119032 to 26.3: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
Resolutions:
- `TableFunctionMergeTreeTextIndex.cpp`: dropped `dependsOnCurrentUserGrants`.
The virtual does not exist on `ITableFunction` here, nor on any release
branch; it and its `InterpreterCreateQuery` consumer are master-only, so the
`override` would not compile. Kept `canBeUsedToCreateTable`, which the
cherry-pick carries as context and which the branch's `InterpreterCreateQuery`
does consume, as the merged 26.6 and 26.8 backports did. 26.3's
`MergeTreeIndexFactory::get` takes only the index description, so
`resolveIndex` calls the single-argument form and the `MergeTreeData` cast
that master needs only to reach `getSettings()` is dropped.
- `StorageMergeTreeTextIndex.{h,cpp}`: kept `checkAccess` and dropped
`createVirtuals`, which the cherry-pick carries as context and 26.3 does not
have. 26.3 still names the read entry point `read`, not `readImpl`, so that
name is kept.
`05153_text_index_mergeTreeTextIndex_create_table_as` is reduced to the form
26.6 and 26.8 carry: its two nested-`remote` cases assert the refusal that
`dependsOnCurrentUserGrants` drives, which this branch cannot do. All twelve
test files are now identical to the merged 26.8 backport.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ter when a row policy applies
Backport #119032 to 26.3: Text index: make `mergeTreeTextIndex` stricter when a row policy applies
…index read fails (#3268) ## Summary `Metadata.getMapKeys` returned `[]` whenever its `mergeTreeTextIndex` query threw, so the rollup table and bounded `mapKeys` scan paths never ran. Since ClickHouse/ClickHouse#119032 (backported to 26.6), ClickHouse refuses `mergeTreeTextIndex` with `ACCESS_DENIED` (497) on **any** table with a row policy. On those tables search bar autocomplete showed no Map keys. The same short-circuit also hides keys on Distributed tables (`BAD_ARGUMENTS`, #2880). The fix: both text-index `catch` blocks in `getMapKeys` now log and fall through to the next strategy, the same as when the index query succeeds with zero keys. This makes `getMapKeys` consistent with `getMapTextIndexKeyValues` and `getTextIndexKeyValues`, which already skip a failed strategy. The scan reads the table itself, so it respects row policies. Its result is cached under the normal key, so the failing index read isn't re-issued on later calls. ### Row policies Rollup tables (`metadataMaterializedViews`) are separate tables, and a row policy on the source table doesn't cover them. When the text index read fails with `ACCESS_DENIED`, we know a policy applies, so `getMapKeys` skips the rollup and reads keys only from the source-table scan, which ClickHouse filters by the policy. Failures that aren't access denials (e.g. `BAD_ARGUMENTS` on Distributed tables) still try the rollup first. Detection uses the client error's `type`/`code` (`ACCESS_DENIED`/497), with a message match as a fallback (`isAccessDeniedError` in `clickhouse/index.ts`). The shipped OTel rollups only index native columns, so on the default schema they never return Map keys. This only matters for custom rollups that aggregate Map columns. Some paths still read the rollup with no policy signal: no text index, no `system.data_skipping_indices` grant, or ClickHouse < 26.3. This PR doesn't change them, so admins using custom Map-indexing rollups should mirror the source's row policies onto the rollup tables. ### Aborts and slow reads If the caller aborts during the text index read, `getMapKeys` rethrows instead of falling through. Otherwise the rollup would run with a dead signal, reject at once, and have its `[]` cached under the rollup key with no TTL. The index read is capped at `max_execution_time: 15` with `timeout_overflow_mode: 'throw'`, matching the rollup and scan caps. A slow read falls through to rollup/scan promptly, and `'throw'` (not `'break'`) means a timeout never caches a partial key list. Tests cover a key index failure, a kv index failure, the rollup being skipped after an ACCESS_DENIED (from either the error `cause` or its message), the rollup still being tried for other failures, the 15s throw-on-timeout cap and abort signal, a timeout falling through to the rollup, an abort rethrowing without running or caching the fallback, and the fallback result being cached. They fail when the fix is reverted. Follow-ups tracked on the Linear ticket, not in this PR: - File a ClickHouse feature request for a policy-aware text-index read (refs ClickHouse/ClickHouse#119032, ClickHouse/ClickHouse#99507) - Confirm whether ClickStack Cloud-managed schemas or default roles can hit this row-policy path - A per-source toggle to skip the Map key text index was considered and left out: with fall-through, the only cost is one failed query before the result is cached ### How to test on Vercel preview N/A — non-UI change. To reproduce locally, follow the steps in #3265: create a row policy on `otel_logs` for a user that can read `system.data_skipping_indices`, then type `LogAttributes.` in the search bar. Keys now appear. ### References - Linear Issue: https://linear.app/clickhouse/issue/HDX-5598/key-discovery-fails-with-access-denied-497-under-row-policies-add-fall - Related PRs: Fixes #3265, related #2880
Previously, reading the text index was denied only when the row policy referenced an indexed column. But the index contains tokens of all rows, including those hidden by a policy on any other column, so the tokens of hidden rows were exposed.
Now reading from
mergeTreeTextIndexis not allowed whenever a row policy applies to the table, regardless of which columns it uses.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Make
mergeTreeTextIndexstricter with row policies: reading the text index is now denied whenever a row policy applies to the table, regardless of which columns the policy uses.Workflow [PR]
Sync PR [sync-upstream/pr/119032]
Version info
26.9.1.1560(included in26.9and later)26.8.7.7,26.7.11.6,26.6.9.7,26.3.33.101