Repository navigation
Fix SQL SECURITY DEFINER / NONE views and refreshable materialized views read with parallel replicas as the wrong user - #123729
Conversation
…llel replicas The query of a `SQL SECURITY DEFINER` / `NONE` view runs in the context built by `getSQLSecurityOverriddenContext`: the definer's user (or no user for `NONE`), but the invoker's `ClientInfo`. Nothing kept that context from initiating task-based parallel replicas, so the planner of the view's query shipped its read as SQL to the replicas. A replica cannot run it as the definer: it authenticates as the cluster user and applies the row policies of `initial_user` (the invoker), or with an interserver secret runs as the invoker. So the definer's row policy is dropped: with the default `throw_on_unmatched_row_policies = false` the replica returns the rows the policy hides, with an interserver secret an invoker granted only the view gets ACCESS_DENIED. The same holds for the refresh of a refreshable materialized view, which runs in the same kind of context. In CI the test config sets `throw_on_unmatched_row_policies = true`, so `05257_sql_security_view_sealed` failed with ACCESS_DENIED in the new arm_binary ParallelReplicas job whenever a remote replica's read was not cancelled first. The context built for such a query is now marked with a server-only flag, copied into every context derived from it, and `Context::canUseParallelReplicasOnInitiator` returns false for it unless plan-based parallel replicas are used (the plan of a sealed view is already local there). It is a context field rather than a setting, so neither a `SETTINGS` clause in the view's query nor a settings profile of the definer can turn it back. Followers are unaffected, and a transparent view can still be read with parallel replicas through the outer query (`parallel_replicas_allow_view_over_mergetree = 1`), where each replica expands the view itself. The analyzer no longer inlines a `DEFINER` / `NONE` view while the outer query may ship it to parallel replicas, since the shipped outer query would carry the view's query text. Tests: 05257 gets deterministic parallel-replicas arms (`parallel_replicas_local_plan = 0`, a `NONE` view with an invoker row policy, inlining on and off, a view that asks for parallel replicas in its own `SETTINGS`, and a liveness control). 05330 covers the refreshable materialized view. 04545 asserted that the parameterized DEFINER view was read with parallel replicas (it then ran as the cluster user); it now asserts the opposite, with a liveness control. 05288 reads its `NONE` view through the outer query. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…RITY DEFINER / NONE query With `parallel_replicas_for_cluster_engines` (on by default), `url()`, the object-storage table functions and data-lake catalog tables were still converted to a `-Cluster` storage in the query of a `SQL SECURITY DEFINER` / `NONE` view, because that check ignored the flag of such a query, so the read ran on the replicas with the invoker as `initial_user` (with an interserver secret: ACCESS_DENIED for an invoker granted only the view). The conversion branch at the three sites now also requires the context not to be such a query, leaving the shared `can_use_parallel_replicas` value, which the data-lake follower path reuses, unchanged. 05257 gains a `url()` view arm on `test_cluster_interserver_secret`, with a direct `url()` read by the definer as the positive control that the same settings do distribute. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…FINER / NONE query `getSQLSecurityOverriddenContext` drops only the invoker's `parallel_replicas_custom_key`, so a custom key enabled by the view's own `SETTINGS` or by the definer's profile still made the planner of the view's query ship its read as SQL to `cluster_for_parallel_replicas`, where a replica runs it as the cluster user with the invoker's row policies (on production defaults it returns the rows the definer's row policy hides). The custom-key initiation in `buildQueryPlanForTableExpression` now also requires the context not to be such a query; the follower-side custom-key filter and the invoker-key drop keep reading the unchanged `canUseParallelReplicasCustomKey`. 05257 gains a custom-key view arm, with a direct read by the definer as the positive control that the same settings do distribute. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 rounds: 1, 1 and 0 findings) plus my own cold review (3 rounds).
Scope: explicit Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261003-171000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261003-120800, cron:clickhouse-impl-slot-7:20261003-150028, cron:clickhouse-impl-slot-5:20261003-163900 |
|
Workflow [PR], commit [354ab1a] Summary: ✅
AI ReviewSummaryThe PR prevents query-based parallel replicas from executing Final VerdictStatus: ✅ Approve. |
The url() arm reads through test_cluster_interserver_secret, and an interserver secret needs SSL, which the Fast test build does not have: `Code: 344 ... Inter-server secret support is disabled, because ClickHouse was built without SSL library. (SUPPORT_IS_DISABLED)`. Tag the test `no-fasttest`, like the other tests that use this cluster. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes139 object files changed (+105.34 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1328 translation units recompiled, 8640 s compile time in total, 1327 of them have a recent master baseline. Translation units without a recent master baseline:
|
…ew-parallel-replicas-principal
# Conflicts: # tests/queries/0_stateless/05257_sql_security_view_sealed.sh
CI finish ledger - 7a08b64Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-060011 |
# Conflicts: # src/Interpreters/ClusterProxy/executeQuery.cpp
…` / `NONE` body in every mode - `getSQLSecurityOverriddenContext` clears `allow_experimental_parallel_reading_from_replicas` (and `parallel_replicas_custom_key`) in the body of an initiator after the definer's profile is applied, unless plan-based task parallel replicas are used. The checks for what parallel replicas do not support (`FINAL`, `JOIN` with a custom key, ...) no longer reject a body that is read locally anyway, and a custom key coming from the definer's profile no longer survives. - `updateSettingsAndClientInfoForCluster` clears parallel replicas for any cluster hop of such a body, not only in the `read_tasks` mode, so `ReadFromRemote` does not fan the shard query out with `canUseOffsetParallelReplicas`. - `inlineViewSubqueryIfNeeded` does not inline such a view when the query uses offset or custom-key parallel replicas, which ship the query text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123729&sha=7a08b64999946a926eeed1d2532c3f4f4b844bfd&name_0=PR&name_1=Stateless%20tests%20(arm_asan_ubsan%2C%20azure%2C%20sequential) and provide a fix in a separate PR. If the fix is already in progress, link it here. The job hit its 9000 s timeout at test 1177 / 1180 with every test passing, so it does not look related to this PR. |
|
The fix is already merged: #123849 split this job into 2 batches (merged 2026-10-14, after the run on 7a08b64). Your master merge c2a715d brings it onto this branch, and the CI now running on fa1014a uses the split jobs. Since the merge, the two halves ran about 2,100 times on PRs and master with no timeout (longest run 7,118 s against the 9,000 s limit). In the week before it, the single job timed out 206 times. |
CI finish ledger - fa1014aEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All check runs completed and Session id: cron:our-pr-ci-monitor:20261018-020007 |
Resolved conflicts: `Context::positional_arguments_already_resolved` was dropped on master, kept only `is_sql_security_overridden_body`; in 05288 kept both `parallel_replicas_allow_view_over_mergetree = 1` and master's `parallel_replicas_plan_based = 0`.
…er its own `SETTINGS`, keep `sampling_key` followers' slice The restriction of parallel replicas in the body of a `SQL SECURITY DEFINER` / `NONE` view moves to `Context::restrictParallelReplicasInSQLSecurityOverriddenBody`. It is applied in `getSQLSecurityOverriddenContext` as before, and also after each `SETTINGS` clause inside the body (`applyQueryLevelSettings`), so a body that turns parallel replicas on in its own `SETTINGS` no longer fails with `FINAL modifier is not supported with parallel replicas` / `JOINs are not supported with parallel replicas`. A `sampling_key` follower (a secondary query with `parallel_replicas_count > 1`) keeps parallel replicas enabled, so that it reads only the slice assigned by `parallel_replica_offset` instead of the whole table, which multiplied the result of a `Distributed` table over such a view by the number of replicas. The body still cannot fan out by itself: `updateSettingsAndClientInfoForCluster` turns parallel replicas off for its shards. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…NER` / `NONE` view body across cluster hops The body of such a view cleared `allow_experimental_parallel_reading_from_replicas` for the shards it reads, so when the view reads a `Distributed` table, a `sampling_key` follower lost its slice on the next hop and `MergeTreeDataSelectExecutor::getSampling` read the whole table, multiplying the result by the number of replicas. Keep the setting for a `sampling_key` follower, and prevent the new fan-out with `disableOffsetParallelReplicas` instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…as again The `ParallelReplicas` job ran it as a blacklisted test that is expected to fail (ClickHouse#74411). On master it fails there in about one run of five with `Table ... has row policies, but none of them are for the current user. (ACCESS_DENIED)`: a replica runs the body of the `DEFINER` view as the cluster user `default`. With this change the body of a `DEFINER` / `NONE` view is not read with query-tree parallel replicas (`Context::canUseParallelReplicasOnInitiator`), and all five runs of this pull request reported `NOT_FAILED`.
The refresh of a `SQL SECURITY DEFINER` refreshable materialized view with parallel replicas no longer leaks rows on master: ClickHouse#117798 (merged 2026-11-01) stamps the definer into the empty `initial_user` of the refresh context, so a replica applies the definer's row policies. Bugfix validation passed this test on master from then on, while it reproduced on every earlier commit of this pull request.
fm4v
left a comment
There was a problem hiding this comment.
Reviewed the full diff and all review threads. The new flag only restricts (server-local, never sent over the wire), so I found no privilege escalation, with or without an interserver secret. SQL SECURITY NONE, nested views and INSERT SELECT with parallel_distributed_insert_select = 2 are covered, and plan-based parallel replicas stays allowed because it ships the definer's row-policy filter as an explicit step. There is no protocol change, so no spec update or revision gate is needed.
Follow-ups pushed to the branch: 02884_create_view_with_sql_security_option is removed from tests/parallel_replicas_blacklist.txt, and the refreshable materialized view claim is dropped from the changelog, because #117798 already fixed that path on master.
The two red fuzzer jobs (AST fuzzer (amd_release, oracle), a -0. float TLP mismatch, and La Casa Del Dolor (amd_debug)) also fail on master and other PRs, and are unrelated.
e6c0a8e
26.10 does not include Formats/FormatSettings.h in StorageView.cpp, and does not have the GRANTs of #123729 in 05257_sql_security_view_sealed.sh, so only this PR's lines are added there. The test 05331_short_circuit_constant_false_join_totals (#124134) is not on 26.10, so this PR's change to it is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #74411
Related: #122330
Related: https://github.com/ClickHouse/clickhouse-private/issues/79501
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed reading a
SQL SECURITY DEFINERorNONEview withenable_parallel_replicas = 1: the replicas ran the view's query as the cluster user with the invoker's row policies instead of as the definer, so the read could return the rows the definer's row policy hides, or fail withACCESS_DENIEDon a cluster with an interserver secret. Queries readingDEFINER/NONEviews no longer use query-tree parallel replicas; plan-based parallel replicas (parallel_replicas_plan_based = 1) still apply.Description
On 26.9.8.3, a user granted only a
SQL SECURITY DEFINERview gets the rows the definer's row policy hides if the view'sSETTINGSenable custom-key parallel replicas, or if the user reads it withenable_parallel_replicas = 1andparallel_replicas_local_plan = 0; with an interserver<secret>that read fails withNot enough privileges(#74411). In CI,05257_sql_security_view_sealedfailed withACCESS_DENIEDin the ParallelReplicas job (report).Root cause: the context
getSQLSecurityOverriddenContextbuilds for such a query has the definer's user but the invoker'sClientInfo, and nothing kept it from initiating parallel replicas. A replica cannot run the shipped read as the definer: it runs as the cluster user plus the row policies ofinitial_user, or, with a secret, as the invoker.Change: that context gets a server-only flag (copied into derived contexts, not a setting, so a view's
SETTINGSor a definer profile cannot undo it). With it,Context::canUseParallelReplicasOnInitiatoris false unless parallel replicas are plan-based, aDistributedshard is not spread over replicas, no custom-key read is started, and aurl(), object-storage or data-lake read does not become its-Clustervariant. ADEFINER/NONEview is not inlined while the outer query can ship it. Followers are unaffected.Price: these queries lose query-tree parallel replicas; a transparent view keeps them via the outer query (
parallel_replicas_allow_view_over_mergetree = 1).The refresh of a
DEFINERrefreshable materialized view is not affected on master: it has no invoker, and since #117798 (merged 2026-11-01, backported to 26.8, 26.9 and 26.10) its context carries the definer asinitial_user, so a replica applies the definer's row policies. It uses the same context, so this change also reads it without query-tree parallel replicas.02884_create_view_with_sql_security_optionis removed fromtests/parallel_replicas_blacklist.txt: on master it fails in theParallelReplicasjob in about one run of five withhas row policies, but none of them are for the current userfrom a replica, and it passes in every run of this PR.Tests: 05257 (deterministic
local_plan = 0, custom-key,Distributedand interserver-secreturl()arms), new 05406 and 05452, 04545 and 05288 adjusted. New 05330 is a regression test for the refresh: it passes on master since #117798.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123729]
Version info
26.11.1.1176-master(included in26.11and later)