Skip to content

[Feature Request]: Disable SET SECONDARY ROLE — non-deterministic object ownership under DAC #25465

Closed

Description

@LiSong0214

Is your feature request related to a problem? Please describe.

MatrixOne currently enables secondary roles by default: a session effectively runs with SET SECONDARY ROLE ALL, so the user holds the union of privileges of the current (primary) role plus all of their other granted roles.

Under MatrixOne's DAC (Discretionary Access Control) model, an object created in a session should be owned by the current (primary) role of that session. However, the actual behavior today is:

  • When a statement passes the privilege check via the merged privilege set, the created object's owner may be assigned to an arbitrary one of the roles that happened to hold the required privilege — not necessarily the primary role.
  • Which role ends up as the owner is effectively non-deterministic from the user's point of view. Two identical sessions can produce objects with different owners depending on which role satisfied the privilege check.

This non-determinism is incorrect for a DAC system, where ownership is the anchor of all subsequent privilege management. Ownership should be predictable: the object owner should always be the primary role, regardless of whether the primary role itself held the privilege that authorized the creation.

Real-world impact (MatrixOne Intelligence)

MOI (MatrixOne Intelligence) manages catalogs/databases/tables on top of MatrixOne with role-based access control, and runs into this problem in practice:

  • Objects created through MOI (e.g. via SQL Editor) can end up owned by an unintended role, which silently breaks the subsequent grant/revoke workflow (privileges can no longer be revoked or re-assigned as expected).
  • Even in cases where the owner does land on the current role, the merged-privilege behavior of secondary roles still confuses downstream privilege assignment — the effective privilege set a user operates with does not match the role model MOI manages.

Describe the feature you'd like

Disable the SET SECONDARY ROLE capability (i.e. stop merging secondary-role privileges into the session by default, equivalent to SET SECONDARY ROLE NONE semantics):

  1. A session's effective privileges come from the current (primary) role only.
  2. Object ownership is therefore always deterministic: the owner is the primary role of the creating session.
  3. Privilege checks and ownership assignment become consistent with the DAC model and with how role-based platforms (such as MOI) manage permissions.

Note on behavior change / compatibility

The feature is currently enabled by default, and the existing behavior is already inconsistent (ownership varies with which role passes the privilege check). Turning it off is a behavior change for accounts that rely on merged secondary-role privileges, so this should be called out explicitly (release note / migration note). The current default-on state is precisely what produces the inconsistent ownership behavior described above.

Describe alternatives you've considered

  • Keeping SET SECONDARY ROLE but always assigning ownership to the primary role: this fixes the non-determinism of ownership, but the merged privilege set still causes confusion in subsequent privilege management, so we prefer disabling the capability.

Additional context

  • Downstream issue observed in MOI: object ownership landing on an unexpected role breaks RBAC revocation flows (e.g. matrixorigin/matrixflow#11272).

Activity

  1. added
    severity/s0
    on Jul 6, 2026
  2. added theissue type on Jul 6, 2026
  3. added this to the MO-202607 milestone on Jul 6, 2026
  4. daviszhen commented on Aug 7, 2026

    @daviszhen
    Contributor

    等下次release.

    修改 SET SECONDARY ROLE ALL/NONE, 禁用secondary role功能. 也不再报错, 避免修改moi代码.

  5. Ariznawlll commented on Aug 21, 2026

    @Ariznawlll
    Collaborator

    SECONDARY ROLE / DDL owner 测试补充

    Happy Path 覆盖

    • 使用 primary role 为默认角色、另授予 secondary role 的用户,确认 current_role() 始终为 primary role。
    • primary role 获得 CREATE TABLE 后,普通 CREATE TABLE 与 PREPARE/EXECUTE 两条 DDL 路径均成功。
    • 查询 mo_catalog.mo_tables 和 mo_role_privs,确认两个创建对象的 owner 及 table ownership 权限均只落在 primary role。

    Unhappy Path 覆盖

    • 仅 secondary role 持有 CREATE TABLE / DML 权限时,即使执行 SET SECONDARY ROLE ALL,CREATE TABLE 被拒绝,后续 INSERT/SELECT 不能访问不存在的对象。
    • PREPARE 阶段因权限失败后,EXECUTE 返回 prepared statement 不存在;未产生对象及 ownership 残留。
    • 撤销 secondary role 后再次设置 ALL,不会恢复 secondary-role 的权限。

    回归覆盖

    • 已补充 BVT:test/distributed/cases/zz_accesscontrol/secondary_role_ddl_owner.sql,覆盖普通 DDL、prepare DDL、catalog owner 与失败后的清理检查。
  6. Ariznawlll commented on Aug 21, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:5735684d69c9b171c4d7a5ebee3ebcc539ffc8cc
    • 部署方式:基于该 commit 构建的本地隔离单 CN / 单 TN 服务;通过 mo-tester 多会话脚本和 SQL 客户端验证 catalog 元数据。
    • 测试日期:2026-08-21

    原问题验证

    以默认角色 ddl_owner_primary、仅持有 DDL 权限的 ddl_owner_secondary 以及测试用户构造 DAC 场景。执行 SET SECONDARY ROLE ALL 后,当前角色仍为显式 current role,secondary role 的 CREATE TABLE / DML 权限不会与当前角色合并;仅依赖 secondary 权限的 DDL 被拒绝,未出现随机 owner。

    随后分别将拥有 DDL 权限的 ddl_owner_ddl_primary 和 ddl_owner_secondary 设为 current role,并在两种情况下再次执行 SET SECONDARY ROLE ALL。创建对象后查询 mo_catalog.mo_tables.owner 和 mo_catalog.mo_role_privs,owner 与 table ownership 均稳定落在当前角色,而非由任一 secondary privilege 随机决定。

    Happy Path 覆盖

    1. current role 拥有 DDL 权限时,CREATE TABLE 成功;SET SECONDARY ROLE ALL 不改变 current_role()。
    2. t_owner_primary 由 ddl_owner_ddl_primary 创建,catalog owner 精确为 ddl_owner_ddl_primary。
    3. 显式切换至 ddl_owner_secondary 后创建 t_owner_secondary,catalog owner 精确为 ddl_owner_secondary。
    4. 已覆盖普通 DDL 与 PREPARE / EXECUTE 两条入口;已有对象的 owner、ownership privilege 和 role metadata 均一并核对。

    Unhappy Path 覆盖

    1. 只有 secondary role 持有 CREATE TABLE / INSERT / SELECT 时,SET SECONDARY ROLE ALL 后 CREATE TABLE 被拒绝;随后 INSERT、SELECT 均不能访问该不存在对象。
    2. 失败 DDL 后查询 mo_tables 与 mo_role_privs,确认没有对象或 table ownership 残留。
    3. 权限不足的 PREPARE 失败,后续 EXECUTE 返回 prepared statement 不存在;确认不会产生隐藏对象。
    4. 撤销 secondary role 后再次设置 ALL,权限不会重新出现;会话继续执行并保持可用。

    白盒验证

    不适用。本 Issue 的验收点是公开 SQL 权限语义和 catalog owner 可观察结果;BVT 已同时断言成功路径的 owner 归属和失败路径的 metadata 清理,没有新增只能通过内部注入才能触达的分支。

    回归测试

    测试证据

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/featureseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions