Repository navigation
Description
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:
mo_catalog.mo_user.default_roleis not updated (remains1= public),- new connections of the user still start with
current_role() = public, - therefore all privileges granted through that role are unusable without a manual
SET ROLEin every session, - 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 happensSource-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 inpkg/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:218and admin-statement classificationpkg/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. ContrastSET ROLE, which has a full executor atpkg/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:3562uses 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 statementControl — 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
- Security/audit dimension: a DBA following the MySQL role tutorial believes least-privilege is enforced via default role; in reality the account has no privileges after login (fail-closed here, fortunately) — but the flip side is applications break at runtime with 20101 errors whose root cause (an ignored DDL-like statement) is far away from the symptom.
- Related: [Bug]: GRANT model divergences block least-privilege app accounts (db-level GRANT rejected, UPDATE/DELETE table-scope only, role-owned-table DELETE denied) #30626 (GRANT model divergences), [Bug]: mo_catalog.mo_role_privs.privilege_level stores placeholder template 'd.t' for ALL table-level grants — SHOW GRANTS renders every table grant as the same indistinguishable 'GRANT select ON table d.t' line (audit identity lost; enforcement itself is correct) #30676 (privilege_level 'd.t' template). This is the third member of the role-management fidelity family.
Activity
XuPeng-SH commentedon Oct 23, 2026
QA checkpoint — PR #30709 synchronized
The current PR snapshot is open and unmerged at head
d249f1d909e06e2c85fc7bcf854bf3b89f478acb(basebc84bd142600b745503e225cb89cb1526df8d35e). Its latest commit mergesmain. The PR description's validation receipt is for the earlier delivery headc155d0ef64bf98aa9f7baaa626793a3e1c3ea50a; I am not treating that as execution evidence ford249f1d.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 ROLEdefect 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 toLundomn; no status or assignee change.fix(frontend): persist default role selection (#30709)
XuPeng-SH commentedon Oct 25, 2026
Fresh-round latest-main validation (2026-10-25)
Runtime: isolated local MatrixOne built from pinned main
aeaa273daf588a9988ba423915d3ae6b8c82124a; binary SHA-256450363d5ec5e693bdd7ded44565b3b0ab1addcb807d3f9569c5d5eedeb1486e4. SQL/MySQL protocol tests used a fresh QA database, role, and user.Results:
public; the protected SELECT was denied.SET DEFAULT ROLE qa_round2_30709_reader TO qa_round2_30709_user, the existing session remainedpublic; a fresh login used the reader role and read value42.NONE. The existing session retained its active reader role, while the next login usedpublicand the protected SELECT was denied.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:
/workspace/qa-challenge/fixtures/round2-30709-default-role-setup.sql/workspace/qa-challenge/fixtures/round2-30709-default-role-live.goand/workspace/qa-challenge/logs/round2-aeaa273-30709-default-role-live.log/workspace/qa-challenge/fixtures/round2-30709-default-role-restart.goand/workspace/qa-challenge/logs/round2-aeaa273-30709-default-role-restart.log/workspace/qa-challenge/logs/round2-main-aeaa273-restart-default-role.logAriznawlll commentedon Oct 26, 2026
测试版本
main5fe08a3307e246e1ab9951ab690b50557af0f509;隔离构建二进制对应该完整 SHA,服务git_version()=5fe08a330768fe0510515a4b9a005279c3e2e8d16dc860b5bb是上述 main 的祖先原问题验证
新建用户初始
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 覆盖
current_role()仍为 reader,读到 42。持久化重启 3/3;结束后删除测试 user、role、database。Unhappy Path 覆盖
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。测试结论
测试通过。