Skip to content

26.8: Keep external roles when copying a Context - #121643

Merged
fm4v merged 1 commit into
26.8from
backport/26.8/copy-external-roles
Sep 23, 2026
Merged

fm4v merged 1 commit into
26.8from
backport/26.8/copy-external-roles

Conversation

@fm4v

@fm4v fm4v commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Backport of the relevant part of #110144 to 26.8.

Since #110867 (in 26.7 and 26.8), a remote node of a secret interserver query (Distributed, parallel replicas) 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 on the remote node that recalculates access (a change of readonly, allow_ddl or allow_introspection_functions, for example a view with such a setting in its SETTINGS clause) loses all roles. A user whose grants come from roles then gets ACCESS_DENIED on the remote node. This is what Cloud parallel-replicas queries (TPC-H benchmark) are hitting on 26.8.

The change:

Reproduced on 26.8.1.2745: the new test fails with ACCESS_DENIED on the view queries without the fix.

Related: #110867
Related: #110144
Related: https://github.com/ClickHouse/support-escalation/issues/8194
Related: https://github.com/ClickHouse/data-plane-application/issues/40347

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix ACCESS_DENIED on remote nodes of Distributed and parallel-replicas queries over an interserver-secret cluster for users whose grants come from roles, when the remote node recalculates access rights in a copied query context (for example, when reading a view with SETTINGS). The regression appeared in 26.7.

Version info

  • Merged into: 26.8.11.19

Since #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 #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.
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [b4bef00]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 8/8) ERROR

@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Sep 22, 2026
@fm4v
fm4v merged commit d819c45 into 26.8 Sep 23, 2026
39 of 42 checks passed
@fm4v
fm4v deleted the backport/26.8/copy-external-roles branch September 23, 2026 08:04
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

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant