Skip to content

Propagate current roles to remote read nodes - #110867

Merged
evillique merged 2 commits into
ClickHouse:masterfrom
evillique:propagate-current-roles-to-remote-nodes
Jul 20, 2026
Merged

evillique merged 2 commits into
ClickHouse:masterfrom
evillique:propagate-current-roles-to-remote-nodes

Conversation

@evillique

Copy link
Copy Markdown
Member

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

  • Bug Fix (user-visible misbehavior in an official stable release)

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

  • I have made the corresponding changes to the documentation.

@clickhouse-gh

clickhouse-gh Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6911f9a]

Summary: ❌

job_name test_name status info comment
Stress test (amd_asan_ubsan) FAIL
UndefinedBehaviorSanitizer: undefined behavior (STID: 4141-5b13) FAIL cidb, issue

AI Review

Summary

This PR extends ClientInfo and the interserver auth hash so remote read nodes can reconstruct the initiator's active roles instead of silently falling back to default roles. The protocol update and receiver-side application mostly line up, but the sender still lets an ordinary query setting suppress current_roles, so the old inconsistent row-policy behavior is still reachable on demand.

Findings

⚠️ Majors

  • [src/QueryPipeline/RemoteQueryExecutor.cpp:468] current_roles propagation is still gated by push_external_roles_in_interserver_queries, which is a normal per-query setting. A user can still run SET ROLE role_narrow; SELECT ... SETTINGS push_external_roles_in_interserver_queries = 0 and make remote shards evaluate row policies under the default roles again, returning rows outside the active role scope. Send/apply the new current_roles unconditionally for secret interserver reads, or make this knob server-side and non-overridable for the current_roles path.
Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 17, 2026
/// 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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@clickhouse-gh

clickhouse-gh Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.10% 86.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 78.20% 78.20% +0.00%

Changed lines: Changed C/C++ lines covered: 95/97 (97.94%) · Uncovered code

Full report · Diff report

@evillique

Copy link
Copy Markdown
Member Author

@evillique
evillique added this pull request to the merge queue Jul 20, 2026
Merged via the queue into ClickHouse:master with commit b4a622f Jul 20, 2026
176 of 178 checks passed
@evillique
evillique deleted the propagate-current-roles-to-remote-nodes branch July 20, 2026 17:27
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 20, 2026
devcrafter added a commit that referenced this pull request Jul 28, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-roles-to-remote-nodes

Propagate current roles to remote read nodes
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 25, 2026
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.
abraithwaite added a commit to abraithwaite/ClickHouse that referenced this pull request Oct 5, 2026
…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.
abraithwaite added a commit to abraithwaite/ClickHouse that referenced this pull request Oct 5, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

3 participants