Skip to content

[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

Closed as not planned

Description

@Ariznawlll

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:

  1. 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.

  2. Catalog-based audit queries are degraded. mo_catalog.mo_role_privs.privilege_level is the documented surface for compliance queries; storing the template (d.t, and correspondingly d, d.*, t for other shapes — distinct values observed in catalog: only *, *.*, d.t) instead of concrete names ruptures any SQL audit that filters/groups by privilege_level. Note obj_id still holds the real rel_id, so cross-joining to mo_tables can 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 objects

Positive/negative control proving enforcement itself is fine (bug is audit-only):

  • SET ROLE r2; SELECT * FROM grantdb.mytab; → row (42) returned: works
  • SET ROLE r2; SELECT * FROM grantdb.other_tab; (same db, not granted) → do not have privilege
  • SET 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

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 26, 2026

    @XuPeng-SH
    Contributor

    Duplicate of #30626 — merged into the consolidated privilege-enforcement tracking table in #30626. Original reproduction remains in this issue.

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