Skip to content

[Bug]: SET DEFAULT ROLE is a silent no-op — statement returns OK but never persists (mo_user.default_role unchanged, new connections stay public, role privileges unusable without manual SET ROLE every session) #30677

Closed

Description

@Ariznawlll

Bug or Feature Request

Bug

Description

SET DEFAULT ROLE <role> TO <user> is accepted silently but never executed — it is a complete no-op. The statement parses fine, passes privilege checks, returns OK to the client, but:

  1. mo_catalog.mo_user.default_role is not updated (remains 1 = public),
  2. new connections of the user still start with current_role() = public,
  3. therefore all privileges granted through that role are unusable without a manual SET ROLE in every session,
  4. no error or warning is ever raised — the DBA believes the role workflow is configured when it isn't.

This breaks the standard MySQL 8.0 role workflow that every MySQL-compat docs/tutorial teaches:

CREATE ROLE app_read;
GRANT SELECT ON db.* TO app_read;        -- (table-grant in MO)
GRANT app_read TO 'usr'@'localhost';
SET DEFAULT ROLE app_read TO 'usr'@'localhost';   -- MySQL: next login auto-activates the role
-- MO: OK returned... but nothing happens

Source-level evidence (v3.x @ b24d1b3)

  • Parser supports it: pkg/sql/parsers/dialect/mysql/mysql_sql_test.go:3484-3488 (all three variants: list, ALL, NONE), node defined in pkg/sql/parsers/tree/set.go:115.
  • Privilege layer classifies it: pkg/frontend/authenticate.go:6839 (case *tree.SetDefaultRole, *tree.SetRole, *tree.SetPassword: kind = privilegeKindNone).
  • Cache invalidation hook mentions it: pkg/frontend/status_stmt.go:218 and admin-statement classification pkg/frontend/stmt_kind.go:32.
  • But there is no execution body anywhere: grep -rn "SetDefaultRole" pkg/frontend/ pkg/sql/plan/ pkg/sql/compile/ (excluding parsers/tests) finds only the classification sites above. Contrast SET ROLE, which has a full executor at pkg/frontend/self_handle.go:42-49 → handleSwitchRole (pkg/frontend/mysql_cmd_executor.go:3686).
  • No code path ever UPDATEs mo_catalog.mo_user.default_role (only INSERT-time initialization writes it: authenticate.go:1240-1268; read side: session.go:3562 uses it during login).

So the statement falls through the default self-handle/plan path and exits with OK without doing anything.

Steps to Reproduce

MO v3.x commit b24d1b3 (2026-10-16), macOS arm64, fresh instance, sys account.

CREATE DATABASE grantdb;
CREATE TABLE grantdb.mytab (id INT);
INSERT INTO grantdb.mytab VALUES (42);
CREATE USER usr3 IDENTIFIED BY 'pw3';
CREATE ROLE r9;
GRANT SELECT ON TABLE grantdb.mytab TO r9;
GRANT r9 TO usr3;
SET DEFAULT ROLE r9 TO usr3;      -- returns OK
-- inspect persistence:
SELECT user_name, default_role FROM mo_catalog.mo_user WHERE user_name = 'usr3';
-- usr3 | 1        <-- NOT r9's role_id; unchanged

-- new connection as usr3:
SELECT current_role();            -- public   <-- role not activated
SELECT * FROM grantdb.mytab;      -- ERROR 20101: do not have privilege to execute the statement

Control — the role itself is fine; only the default-role wiring is missing:

-- same usr3 session:
SET ROLE r9;
SELECT current_role();            -- r9
SELECT * FROM grantdb.mytab;      -- 42   (works)

So GRANT, role grants, and SET ROLE all function; the persisted default-role activation specified by SET DEFAULT ROLE does not exist.

Expected behavior

MySQL 8.0 semantics: SET DEFAULT ROLE role_list TO user records the default role(s) so each subsequent login activates them automatically (equivalent of ALTER USER ... DEFAULT ROLE ...). In MO terms: update mo_user.default_role (or an equivalent multi-role structure) and have the login path (session.go step 4.2, which already reads default_role and validates it against mo_user_grant) activate the role without an explicit SET ROLE.

Note the login path already handles a non-public default role correctly when the column is populated (it checks "the role %s has not been granted to the user %s" on mismatch) — it's purely the writer that's missing.

If SET DEFAULT ROLE is intentionally unsupported in this version, the parser must reject it with not supported — silently returning OK is the worst outcome for a security-relevant statement.

Versions

  • MatrixOne: commit b24d1b3 (2026-10-16), v3.x dev
  • All three syntax variants tested: SET DEFAULT ROLE r TO u (no-op), SET DEFAULT ROLE ALL TO u (no-op), SET DEFAULT ROLE NONE TO u (no-op)

Additional context

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. added this to the MO-202610 milestone on Oct 20, 2026
  3. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    QA checkpoint — PR #30709 synchronized

    The current PR snapshot is open and unmerged at head d249f1d909e06e2c85fc7bcf854bf3b89f478acb (base bc84bd142600b745503e225cb89cb1526df8d35e). Its latest commit merges main. The PR description's validation receipt is for the earlier delivery head c155d0ef64bf98aa9f7baaa626793a3e1c3ea50a; I am not treating that as execution evidence for d249f1d.

    For the exact current SHA, GitHub has no combined status checks. The associated Connector/J Pool Reset E2E and Iceberg Connector E2E runs are both in progress; neither is a completed, role-specific result. The merge queue is checking required conditions. Existing approvals/assessment cite an earlier review commit, so current-head review evidence is still needed. This workspace has no MatrixOne checkout or Go runtime; I did not run the PR tests locally.

    The previously identified SET DEFAULT ROLE defect remains addressed by this PR's seven-file delta, but current-head build, regression and CI evidence are not yet independently established here. Issue #30677 remains open and assigned to Lundomn; no status or assignee change.

  4. XuPeng-SH commented on Oct 25, 2026

    @XuPeng-SH
    Contributor

    Fresh-round latest-main validation (2026-10-25)

    Runtime: isolated local MatrixOne built from pinned main aeaa273daf588a9988ba423915d3ae6b8c82124a; binary SHA-256 450363d5ec5e693bdd7ded44565b3b0ab1addcb807d3f9569c5d5eedeb1486e4. SQL/MySQL protocol tests used a fresh QA database, role, and user.

    Results:

    • New user initially logged in as public; the protected SELECT was denied.
    • After SET DEFAULT ROLE qa_round2_30709_reader TO qa_round2_30709_user, the existing session remained public; a fresh login used the reader role and read value 42.
    • The user set its own default to NONE. The existing session retained its active reader role, while the next login used public and the protected SELECT was denied.
    • Restoring the reader default, gracefully stopping and restarting the same binary with the same isolated data directory, then logging in again preserved the reader role and access to value 42.

    This validates the reported persistence/login behavior on one isolated CN. It does not cover a broad privilege matrix, multi-CN topology, or full frontend/package suites.

    Evidence retained locally:

    • Setup SQL: /workspace/qa-challenge/fixtures/round2-30709-default-role-setup.sql
    • Fresh-login protocol probe: /workspace/qa-challenge/fixtures/round2-30709-default-role-live.go and /workspace/qa-challenge/logs/round2-aeaa273-30709-default-role-live.log
    • Restart probe: /workspace/qa-challenge/fixtures/round2-30709-default-role-restart.go and /workspace/qa-challenge/logs/round2-aeaa273-30709-default-role-restart.log
    • Restart service log: /workspace/qa-challenge/logs/round2-main-aeaa273-restart-default-role.log
  5. Ariznawlll commented on Oct 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:5fe08a3307e246e1ab9951ab690b50557af0f509;隔离构建二进制对应该完整 SHA,服务 git_version()=5fe08a3307
    • 修复:PR #30709 已 MERGED,merge commit 68fe0510515a4b9a005279c3e2e8d16dc860b5bb 是上述 main 的祖先
    • 部署方式:macOS arm64;SQL 矩阵在独立 1 LogService/1 TN/2 CN+Proxy 上执行;重启持久化在另一个独立的单进程 LogService/TN/CN、持久化数据目录、真实 MySQL 协议上执行
    • 测试日期:2026-10-26

    原问题验证

    新建用户初始 current_role()=public,读取受保护表被拒绝;执行 SET DEFAULT ROLE reader TO user 后,mo_catalog.mo_user.default_role 与 reader 的真实 role_id 相同,新的用户连接以 reader 角色读到值 42。执行 SET DEFAULT ROLE NONE 后,下一条新连接回到 public 且不能读受保护表;再次设为 reader 后又可读 42。SQL 场景三组独立库 3/3,MOTR 定向再重复三次,合计 9/9。

    Happy Path 覆盖

    1. 重新设置 reader 后,优雅停止并重新启动同一个当前 main 二进制及同一个隔离数据目录,连续三轮;每次重启后新连接的 current_role() 仍为 reader,读到 42。持久化重启 3/3;结束后删除测试 user、role、database。
    2. 每次新登录都是新的真实协议连接,不依赖旧会话的已激活角色。

    Unhappy Path 覆盖

    1. reader 未设置时以及设为 NONE 后的 protected SELECT 均被拒绝,权限未串漏。
    2. SET DEFAULT ROLE ALL(当前实现不支持)与包含未授权用户的多目标设置均返回错误;失败后用户仍以 public 登录,目录默认角色未发生部分写入。

    白盒验证

    本次用真实权限/登录/重启路径验证;未另外运行 Go UT/-race,不能声称全量前端包测试通过。

    回归测试

    公共 SQL/多连接回归已加入 MOTR #278 的 script/14_issue_regression/issue_20261026_recent_assigned_sql.py 与配对 .out;本地定向 --repeat 3 成功 3/3。重启由隔离服务单独手工执行 3/3,未伪称 MOTR 自动编排了进程重启。完整 suite 与远端 CI 未运行。

    测试证据

    MOTR 回归脚本;定向记录 /private/tmp/mo-qa-new-20261026-ROza73/motr-278/var/log/run-1792982597562506000;重启探针 /private/tmp/mo-qa-new-20261026-ROza73/role-restart-30677.py 的三轮输出均为 PASS: persisted role, fresh login, protected value=42。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions