Repository navigation
Description
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):
- A session's effective privileges come from the current (primary) role only.
- Object ownership is therefore always deterministic: the owner is the primary role of the creating session.
- 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 ROLEbut 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
daviszhen commentedon Aug 7, 2026
等下次release.
修改 SET SECONDARY ROLE ALL/NONE, 禁用secondary role功能. 也不再报错, 避免修改moi代码.
Ariznawlll commentedon Aug 21, 2026
SECONDARY ROLE / DDL owner 测试补充
Happy Path 覆盖
current_role()始终为 primary role。mo_catalog.mo_tables和mo_role_privs,确认两个创建对象的 owner 及table ownership权限均只落在 primary role。Unhappy Path 覆盖
SET SECONDARY ROLE ALL,CREATE TABLE 被拒绝,后续 INSERT/SELECT 不能访问不存在的对象。回归覆盖
test/distributed/cases/zz_accesscontrol/secondary_role_ddl_owner.sql,覆盖普通 DDL、prepare DDL、catalog owner 与失败后的清理检查。Ariznawlll commentedon Aug 21, 2026
测试版本
main5735684d69c9b171c4d7a5ebee3ebcc539ffc8ccmo-tester多会话脚本和 SQL 客户端验证 catalog 元数据。原问题验证
以默认角色
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 覆盖
CREATE TABLE成功;SET SECONDARY ROLE ALL不改变current_role()。t_owner_primary由ddl_owner_ddl_primary创建,catalog owner 精确为ddl_owner_ddl_primary。ddl_owner_secondary后创建t_owner_secondary,catalog owner 精确为ddl_owner_secondary。PREPARE/EXECUTE两条入口;已有对象的 owner、ownership privilege 和 role metadata 均一并核对。Unhappy Path 覆盖
SET SECONDARY ROLE ALL后 CREATE TABLE 被拒绝;随后 INSERT、SELECT 均不能访问该不存在对象。mo_tables与mo_role_privs,确认没有对象或 table ownership 残留。PREPARE失败,后续EXECUTE返回 prepared statement 不存在;确认不会产生隐藏对象。白盒验证
不适用。本 Issue 的验收点是公开 SQL 权限语义和 catalog owner 可观察结果;BVT 已同时断言成功路径的 owner 归属和失败路径的 metadata 清理,没有新增只能通过内部注入才能触达的分支。
回归测试
测试证据
测试结论
测试通过。
test: complete BVT coverage for #24550 #25465 #23122 (#27456)
test: complete BVT coverage for matrixorigin#24550 matrixorigin#25465 m…
test: complete BVT coverage for matrixorigin#24550 matrixorigin#25465 m…
test: complete BVT coverage for matrixorigin#24550 matrixorigin#25465 m…