Repository navigation
[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
Description
Bug or Feature Request
Bug
Description
When a table-level privilege is granted (GRANT SELECT ON db_name.tbl_name TO role), the catalog row in mo_catalog.mo_role_privs stores a placeholder template d.t in the privilege_level column instead of the actual db_name.tbl_name:
role_id | obj_id | obj_type | privilege_level | privilege_name
10001 | 293534 | table | d.t | select
10002 | 293537 | table | d.t | select <-- completely different table
10003 | 293539 | table | d.t | select <-- again a different table
Consequences:
-
SHOW GRANTS loses all object identity. Then output becomes non-distinguishing — N table-level grants render as N identical lines:
mysql> show grants for usr2; | GRANT select ON table d.t `usr2`@`localhost` | | GRANT select ON table d.t `usr2`@`localhost` | | GRANT connect ON account `usr2`@`localhost` |There is no way for a DBA to know from SHOW GRANTS which tables a role/user can access — the lines differ neither in database nor table. The privilege enforcement being correct makes this worse, not better: auditors trusting SHOW GRANTS see "d.t" (or apparently the same grant twice) while the real grants scope over different objects; "same-string" grants are also impossible to revoke selectively by reading back the display.
-
Catalog-based audit queries are degraded.
mo_catalog.mo_role_privs.privilege_levelis the documented surface for compliance queries; storing the template (d.t, and correspondinglyd,d.*,tfor other shapes — distinct values observed in catalog: only*,*.*,d.t) instead of concrete names ruptures any SQL audit that filters/groups by privilege_level. Noteobj_idstill holds the real rel_id, so cross-joining tomo_tablescan recover names — but SHOW GRANTS itself doesn't join, and nothing in the docs suggests privilege_level is a template.
MySQL semantics for comparison: information_schema / SHOW GRANTS resolve the template to actual qualified names — GRANT SELECT ON "mydb"."mytab" TO 'u'@'%' is displayed with the real object names.
Root cause (source-verified): pkg/frontend/authenticate.go line ~640-656 — privilegeLevelDatabaseTable.String() returns the format string "d.t" (documented as a template by its comment), and the GRANT write path persists that constant directly:
case privilegeLevelDatabaseTable:
return "d.t"The writer never substitutes the concrete db/table names into the stored privilege_level.
Steps to Reproduce
MO v3.x commit b24d1b3 (2026-10-16), macOS arm64, fresh instance.
-- clean account, three different tables in different databases
CREATE DATABASE grantdb; CREATE TABLE grantdb.mytab (id INT);
CREATE DATABASE grantdb2; CREATE TABLE grantdb2.mytab (id INT);
CREATE DATABASE db_acc; CREATE TABLE db_acc.secret (id INT);
CREATE USER usr2 IDENTIFIED BY 'pw2';
CREATE ROLE r2;
GRANT SELECT ON TABLE grantdb.mytab TO r2;
GRANT r2 TO usr2;
CREATE ROLE r3;
GRANT SELECT ON TABLE grantdb2.mytab TO r3;
GRANT r3 TO usr2;
SHOW GRANTS FOR usr2;
-- two identical lines: GRANT select ON table d.t <-- cannot tell grantdb.mytab from grantdb2.mytab
SELECT role_id, obj_id, obj_type, privilege_level FROM mo_catalog.mo_role_privs WHERE obj_type='table' AND role_id >= 10000;
-- privilege_level = 'd.t' for all three objectsPositive/negative control proving enforcement itself is fine (bug is audit-only):
SET ROLE r2; SELECT * FROM grantdb.mytab;→ row (42) returned: worksSET ROLE r2; SELECT * FROM grantdb.other_tab;(same db, not granted) →do not have privilegeSET ROLE r2; SELECT * FROM db_acc.secret;(cross-db, not granted) →do not have privilege
Expected behavior
privilege_level should persist (and SHOW GRANTS display) the concrete object reference — e.g. db_name.tbl_name (MySQL-style quoting) or a resolvable form, so that different table-level grants are distinguishable and compliance queries over mo_role_privs are meaningful.
Versions
- MatrixOne: commit
b24d1b3(2026-10-16), v3.x dev, macOS 14.5 arm64 - Roles observed: role_id 10001-10003, all with privilege_level = 'd.t'
Additional context
- Related family: [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). This one is the audit/display dimension: enforcement is OK, but the privilege catalog + SHOW GRANTS — the tools auditors actually use — cannot identify what a grant covers.
- Minor cosmetic: account-level grants also render with an odd double space before the grantee ("
GRANT connect ON account \u1`@...") due to concat ofcase ... then ''+ literal" `inbuild_show.go:1083`.
Activity
XuPeng-SH commentedon Oct 26, 2026
Duplicate of #30626 — merged into the consolidated privilege-enforcement tracking table in #30626. Original reproduction remains in this issue.