Repository navigation
Conversation
|
Workflow [PR], commit [6911f9a] Summary: ❌
AI ReviewSummaryThis PR extends Findings
Final VerdictStatus: |
| /// Forward this node's current roles so the remote scopes row policies the same way (gated by the setting). | ||
| /// Reset first against stale/injected values, and skip when initial_user was rewritten (remote(user=>...)). | ||
| modified_client_info.current_roles.reset(); | ||
| if (context->getSettingsRef()[Setting::push_external_roles_in_interserver_queries] |
There was a problem hiding this comment.
This still leaves the old row-policy inconsistency reachable via a normal query setting.
push_external_roles_in_interserver_queries comes from context->getSettingsRef(), so a user can do:
SET ROLE role_narrow;
SELECT ... FROM dist
SETTINGS push_external_roles_in_interserver_queries = 0;and current_roles stays absent here. The receiver then falls back to the user's default roles again, so remote shards can still return rows outside the initiator's active role scope.
If the contract of this PR is "remote nodes honor the initiator's current roles", the new current_roles path cannot stay behind a user-overridable query setting. It needs to be unconditional for secret interserver reads, or at least controlled by a server-side knob that the query itself cannot lower.
There was a problem hiding this comment.
Yes, and the user initiating the query can choose to set SETTINGS push_external_roles_in_interserver_queries = 0 the same way as simply not executing SET ROLE role_narrow.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 95/97 (97.94%) · Uncovered code |
|
Failures: |
b4a622f
Address review comment on PR #110318: the existing 04538 test only used a `TO ALL` policy, which every user (including a fallback identity) matches, so it cannot catch a bug where the parallel-replica read nodes lose the caller identity and evaluate the policy as the wrong principal. Add a role-scoped test that binds row policies to roles and runs the query as a dedicated user with `SET ROLE`, over parallel replicas. This requires an interserver-secret cluster (the initiating user's identity and roles are only forwarded to remote nodes in interserver mode) that also has several replicas per shard so parallel replicas engage - none existed, so add `test_cluster_one_shard_three_replicas_localhost_secret` to the stateless config. The test reads with `parallel_replicas_local_plan = 0` so the reading happens on the remote replicas (with a local plan the initiator reads the data itself, already under the active role, and the remote-side role propagation is never exercised). It also asserts the parallel-replicas path was actually used (`ParallelReplicasUsedCount > 0`). This is a regression guard for the role-propagation fix in #110867: verified locally that the test fails (narrow role leaks rows outside its policy) on a pre-fix binary and passes on a binary containing that fix. Review comment: #110318 (comment) Related: #110867 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…-roles-to-remote-nodes Propagate current roles to remote read nodes
Since ClickHouse#110867 a remote node of a secret interserver query enables the initiator's current roles only as external roles and clears the user's default roles. The `ContextData` copy constructor did not copy `external_roles`, so any copied context that recalculated access (for example, a view with an access-related setting in its `SETTINGS` clause) lost all roles and a user whose grants come from roles got `ACCESS_DENIED` on the remote node. This is the relevant part of ClickHouse#110144 (master): copy `external_roles` and make `setExternalRolesWithLock` replace the list instead of appending, so that `setUser` on a copied context (e.g. `EXECUTE AS`) does not inherit the pushed roles.
…es to remote read nodes Backport of ClickHouse#110867 (Propagate current roles to remote read nodes) and the follow-up regression fix ClickHouse#121643 (Keep external roles when copying a Context) to the 26.3 LTS branch. When a query sets its active roles via SET ROLE / role=, those roles were not propagated to remote nodes on parallel-replica and Distributed reads over an interserver-secret cluster. Row policies on remote nodes fell back to the user's default roles instead of the active roles. This patch: 1. Adds a new ClientInfo wire field (current_roles) at protocol version 54485, carrying the initiator's active role names to remote nodes. 2. Includes current_roles in the interserver auth hash so they cannot be tampered with in transit. 3. On the receiver (Session.cpp), resolves the forwarded role names to UUIDs, pushes them as external roles, and clears the user's default roles so row policies are evaluated consistently with the initiator. 4. Fixes the ContextData copy constructor to copy external_roles (the regression from ClickHouse#121643 that caused ACCESS_DENIED on remote nodes when a copied context recalculated access). 5. Changes setExternalRolesWithLock to replace instead of append, so that setUser on a copied context does not inherit stale pushed roles. Changelog category: Bug Fix (user-visible misbehavior in an official stable release) Changelog entry: Propagate a query's active roles (SET ROLE / role=) to remote nodes on parallel-replica and Distributed reads over a cluster secured with an interserver secret; previously the remote nodes fell back to the user's default roles, evaluating row policies inconsistently with the initiator.
…es to remote read nodes Backport of the fix from ClickHouse#110867 and the follow-up regression fix from ClickHouse#121643 to the 26.3 LTS branch. When a query sets its active roles via SET ROLE / role=, those roles were not propagated to remote nodes on parallel-replica and Distributed reads over an interserver-secret cluster. Row policies on remote nodes fell back to the user's default roles instead of the active roles. This backport takes a simpler approach than the master PR: instead of adding a new ClientInfo wire field and protocol version (which would collide with master's version numbering and break mixed-version clusters), it reuses the existing external_roles transport mechanism: 1. Sender (RemoteQueryExecutor): when SET ROLE is active, sends the current (active) role names instead of all granted roles via the existing external_roles parameter. 2. Receiver (Session): when external_roles are received over an interserver connection, clears the user's default current_roles so that only the pushed external_roles are active. This ensures row policies are evaluated consistently with the initiator. 3. Context copy constructor: copies external_roles (the regression from PR ClickHouse#121643 that caused ACCESS_DENIED on remote nodes when a copied context recalculated access). 4. setExternalRolesWithLock: replaces instead of appending, so that setUser on a copied context does not inherit stale pushed roles. No protocol version change. No ClientInfo wire format change. No auth hash change. Rolling-upgrade safe: an old receiver without the 'clear defaults' logic will add the roles on top of defaults (same as the pre-fix behavior, not a regression). Changelog category: Bug Fix (user-visible misbehavior in an official stable release) Changelog entry: Propagate a query's active roles (SET ROLE / role=) to remote nodes on parallel-replica and Distributed reads over a cluster secured with an interserver secret; previously the remote nodes fell back to the user's default roles, evaluating row policies inconsistently with the initiator.
When a query set its active roles via SET ROLE / role=, those roles weren't propagated to remote nodes on parallel-replica and Distributed reads over an interserver-secret cluster, so row policies there fell back to the user's default roles. This sends the initiator's active roles to remote nodes so role scoping is consistent.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Propagate a query's active roles (SET ROLE / role=) to remote nodes on parallel-replica and Distributed reads over an interserver-secret cluster; previously they fell back to the user's default roles, evaluating row policies inconsistently with the initiator.
Documentation entry for user-facing changes