Repository navigation
Refuse a Set table on the right side of IN when a row policy applies to it - #120312
Conversation
…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
The legacy `IN` path tested the `StorageSet` cast twice around the Cloud `SharedSet` block. One block now runs the row-policy check and both dispatches. The comments and the error message drop the invented wording and read as short sentences. No behaviour change.
|
Workflow [PR], commit [c0596ea] Summary: ✅
AI ReviewSummaryThis PR closes most of the Missing context / blind spots
Findings❌ Blockers
Final Verdict
LLVM Coverage ReportMeasured on commit c0596ea.
Changed lines: Changed C/C++ lines covered: 163/181 (90.06%) · Uncovered code |
|
@antaljanosbenjamin are you currently reviewing this PR? If not, could you please assign to me? |
|
Sorry, I was on holiday. I can take a look at it now |
antaljanosbenjamin
left a comment
There was a problem hiding this comment.
The code looks good, however is there any occasion when
Does it mean that a Set table with a row policy becomes completely unusable? Should we disallow creating it instead? Also, please check if we have other table engines that cannot apply row policies |
That's ok.
I suspect |
Cover serialized query plans when only the remote worker has a row policy. The control query proves the initiator can plan it before the worker rejects it with `ACCESS_DENIED`.
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Yes, but it would be slightly better to throw on CREATE ROW POLICY for unsupported engines
We also have |
`DatabaseReplicated` replays mutations with an internal context, which can otherwise bypass row policies on `Set` operands. Check those operands with the submitting context before enqueueing the mutation. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120312&sha=b7a2906a123003ca929ace0092959bb287543826&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%203%2F3%29 PR: ClickHouse#120312
Run the `Set` row-policy precheck with the submitting context before local background mutation dispatch and before replicated enqueue. Cover ALTER, standalone DELETE, and standalone UPDATE syntaxes. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120312&sha=b7a2906a123003ca929ace0092959bb287543826&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%203%2F3%29 PR: ClickHouse#120312 Related: ClickHouse#120312 (comment) Related: ClickHouse#120312 (comment)
…ne-row-policy # Conflicts: # src/Interpreters/MutationsInterpreter.cpp
Run the initiator-side policy check before `ALTER` and `UPDATE` queries are enqueued for `ON CLUSTER` execution. PR: ClickHouse#120312 Review: ClickHouse#120312 (comment)
Resolve mutation `Set` operands through the analyzer access path and defer clustered policy checks until the standard cluster and target privileges pass. ClickHouse#120312 ClickHouse#120312 (comment)
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review effort: Lite
Findings: 1
Open (3)
What changed in this PR
This PR closes a security/RBAC gap where row policies defined on Set-engine tables were silently ignored when the table was used on the right-hand side of IN. The fix refuses such queries (and related mutation paths) with ACCESS_DENIED whenever a non-trivial row policy applies, since StorageSet has no read path to enforce filtering.
Changes:
- Add
StorageSet::checkNoRowPolicy()and invoke it from planner set collection, legacyActionsVisitorset building, and serialized-plan set materialization. - Introduce an
additional_access_checkhook forexecuteDDLQueryOnCluster()and run theSetrow-policy check pre-enqueue forON CLUSTERmutations (UPDATE/DELETE/ALTER ... DELETE/UPDATE). - Add stateless and integration tests for plain
IN,GLOBAL IN, mutations, database-wide policies, and serialized query plan execution across nodes.
| File | Description |
|---|---|
src/Storages/StorageSet.{h,cpp} |
Adds and implements the row-policy refusal check for Set tables. |
src/Planner/CollectSets.cpp |
Enforces the refusal early in the analyzer/planner path. |
src/Interpreters/ActionsVisitor.cpp |
Enforces the refusal in the legacy set-building path used by mutations. |
src/Processors/QueryPlan/SetsSerialization.cpp |
Enforces the refusal when materializing sets from serialized plans on replicas. |
src/Interpreters/executeDDLQueryOnCluster.{h,cpp} |
Adds a hook to run additional authorization checks before enqueueing distributed DDL. |
src/Interpreters/MutationsInterpreter.{h,cpp} |
Adds helper to detect IN set_table in mutation ASTs and enforce the refusal in submitting context. |
src/Interpreters/Interpreter{Update,Delete,Alter}Query.cpp |
Invokes the mutation-side check locally and for ON CLUSTER. |
src/Interpreters/ExpressionAnalyzer.{h,cpp} |
Removes unused isPlainStorageSetInSubquery() helper. |
tests/queries/0_stateless/05218_set_engine_row_policy.* |
Adds stateless regression coverage for IN/GLOBAL IN and policy scopes. |
tests/integration/test_set_engine_row_policy_serialized_plan/* |
Adds integration coverage for serialized plans, replicas, and ON CLUSTER mutation authorization ordering. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def test_worker_checks_set_row_policy(started_cluster): | ||
| for node in (initiator, worker): | ||
| node.query("CREATE TABLE set_rp (k UInt64) ENGINE = Set") | ||
| node.query("INSERT INTO set_rp VALUES (1), (2)") | ||
| node.query("CREATE TABLE data_rp (k UInt64) ENGINE = MergeTree ORDER BY k") | ||
| node.query("INSERT INTO data_rp VALUES (1), (2)") |
| if (!storage_set) | ||
| throw Exception(ErrorCodes::INCORRECT_DATA, "Table {} is not a StorageSet", set.storage_name); | ||
|
|
||
| /// The initiator ran this check against its own policies; the replica's may differ. |
| if (row_policy_filter && !row_policy_filter->isAlwaysTrue()) | ||
| throw Exception(ErrorCodes::ACCESS_DENIED, | ||
| "Cannot use table {} on the right side of IN because a row policy applies to it. " | ||
| "The Set engine has no read path that could filter the rows", |
| { | ||
| auto resolved = IdentifierResolver::tryResolveTableIdentifierFromDatabaseCatalog( | ||
| Identifier(table_identifier->name_parts), context); | ||
| if (!resolved.resolved_identifier && throw_if_unresolved) |
There was a problem hiding this comment.
This makes the clustered mutation paths treat the initiator's local catalog as authoritative for the RHS table name, but IN rhs_table is resolved independently on each worker. That creates both a false positive and a false negative.
For example, ALTER TABLE dst ON CLUSTER worker_only DELETE WHERE k IN remote_mt now throws UNKNOWN_TABLE if remote_mt exists only on the worker, even when it is an ordinary MergeTree table and no Set fast path is involved. The opposite mismatch is worse: if the initiator has a local non-Set homonym while the worker resolves the same name to a Set, this helper skips the guard entirely and the worker still executes under its default context when distributed_ddl_use_initial_user_and_roles = 0.
So the new precheck is only sound if the initiator can prove it is looking at the same source object the worker will use. Suggested fix: do not make the initiator-local lookup authoritative for ON CLUSTER mutations. Either run the source-table check on each worker under the submitting access snapshot, or fail closed only after proving the worker-side object identity instead of throwing/skipping based on the initiator's catalog alone.
875485a
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 119274 118919 Revert "Carry the mutation version onto a rewritten lightweight `DELETE`" Changelog-revert: 119306 119274 Revert "Revert "Carry the mutation version onto a rewritten lightweight `DELETE`"" Changelog-revert: 119334 117356 Revert "Unify the spill trigger for hash joins" Changelog-revert: 119335 119334 Revert "Revert "Unify the spill trigger for hash joins"" Changelog-revert: 121135 118279 Revert "Test the ESCAPE route into the ngram LIKE-pattern tokenizer" Changelog-revert: 121136 121135 Revert "Revert "Test the ESCAPE route into the ngram LIKE-pattern tokenizer"" Changelog-revert: 121258 118216 Revert "Do not invert an ordered comparison that can see a `NaN` in the CNF form" Changelog-revert: 121298 117578 Revert "Bound the docker buildx retry ladder by wall clock, not by the timeout divisor" Changelog-revert: 121443 114465 Revert "Fix an error reading an Iceberg table whose `current-snapshot-id` is JSON null" Changelog-revert: 121477 121096 Revert "Trim `test_max_bytes_ratio_before_external_distinct` to fit the client timeout" Changelog-revert: 121901 121869 Revert "docs(managed-postgres): updated Private Service Connect" Changelog-revert: 122110 118223 Revert "Correct nightly coverage selection and share PR test manifests" Changelog-revert: 122140 120312 Revert "Refuse a `Set` table on the right side of `IN` when a row policy applies to it" Changelog-deleted-entry: 114465 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed an error when reading an Iceberg table whose `current-snapshot-id` is JSON null, which some writers emit for a table with no current snapshot. [#114465](#114465) ([Shaohua Wang](https://github.com/tiandiwonder)). Changelog-deleted-entry: 118216 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed `convert_query_to_cnf = 1` silently dropping rows with a `NaN` in a floating point column: the conversion rewrote `NOT (x < c)` into `x >= c`, which is not an equivalent condition for `NaN`. [#118216](#118216) ([Alexey Milovidov](https://github.com/alexey-milovidov)). Changelog-deleted-entry: 118223 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Correct nightly coverage selection and share PR test manifests. [#118223](#118223) ([Nikita Fomichev](https://github.com/fm4v)). Changelog-deleted-entry: 120312 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * A row policy on a `Set`-engine table was accepted but never applied: the right side of `IN` read the prebuilt set directly and returned the rows the policy hides. Such a query now fails with `ACCESS_DENIED`, because the `Set` engine has no read path that could filter the rows. Queries that used a `Set` table covered by a database-wide row policy ran unfiltered before and now throw. [#120312](#120312) ([Harikrishnan Prabakaran](https://github.com/harikrishnan94)). Changelog-deleted-entry: 121096 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Sized `test_max_bytes_ratio_before_external_distinct` to fit the integration harness's 600 second per-query timeout. [#121096](#121096) ([Groene AI](https://github.com/groeneai)).
…ress Picks up ClickHouse#122140, the revert of ClickHouse#120312. That change left a null set in the plan for the *IgnoreSet functions, and the stress test crashed on it in serializeConstant. No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>


Related: #115304
CREATE ROW POLICYon aSet-engine table succeeds and shows up insystem.row_policies, but nothing applies it. The only reader of aSettable is the right side ofIN, and that path takes the prebuilt set straight fromStorageSet::getSet, so with ak = 1policy over{1, 2}the querynumber IN set_tablestill returns both rows. Every other engine on the right ofINgoes through a subquery and gets filtered.There is nothing to fall back to.
StorageSethas no read path (SELECT * FROM set_tablethrowsNOT_IMPLEMENTED), so the query now fails withACCESS_DENIEDwhen a non-trivialSELECTfilter applies, the same way #115304 handledmergeTreeIndex. The check isStorageSet::checkNoRowPolicy, called from 3 places:collectSetsin the planner, the legacyActionsVisitorpath that mutations still use, andmakeSetsFromStoragewhen a replica materializes a set from a serialized plan.ExpressionAnalyzer::isPlainStorageSetInSubqueryhad 0 callers and is removed.Rejecting the policy at DDL time is not an option: a database-wide policy (
ON db.*) is legitimate and also coversSettables created after it. The test covers plainIN,GLOBAL IN, a key condition,ALTER TABLE ... DELETE(the only way to reach the legacy path now thatenable_analyzer = 0is rejected), an always-true policy, and a database-wide policy.Cloud:
StorageSharedSetderives fromStorageSet, and the check runs before theSharedSetdispatch at both call sites, so the private engine is covered with no private-side change.Breaking for anyone with a database-wide policy over a database that contains a
Settable: thoseINqueries ran unfiltered before and throw now.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A row policy on a
Set-engine table was accepted but never applied: the right side ofINread the prebuilt set directly and returned the rows the policy hides. Such a query now fails withACCESS_DENIED, because theSetengine has no read path that could filter the rows. Queries that used aSettable covered by a database-wide row policy ran unfiltered before and now throw.Workflow [PR]
Sync PR [sync-upstream/pr/120312]
Version info
26.10.1.603-master(included in26.10and later)