Skip to content

[Bug]: GRANT model divergences block least-privilege app accounts (db-level GRANT rejected, UPDATE/DELETE table-scope only, role-owned-table DELETE denied) #30626

Open

Description

@aqqi666

Branch Name

nightly main build, matrixorigin/matrixone:nightly-7b911aea-arm64 (main @ 7b911ae, 2026-10-18 nightly)

Commit ID

SELECT git_version() = 7b911aea6874

Is there an existing issue for the same bug?

  • I have checked the existing issues (searched: grant database privilege / do not have privilege / GRANT UPDATE DELETE table).

Actual Behavior

Several GRANT-related behaviors diverge from MySQL 8 and block minimal-privilege service accounts (verified while provisioning a database account for Keycloak 26.x):

A. Database-level and global GRANT ALL are rejected by the parser

CREATE USER keycloak IDENTIFIED BY '...';
GRANT ALL ON `keycloak`.* TO keycloak;
-- ERROR 1064 (42000): SQL parser error: ... syntax error at line 1 column 23 near " `keycloak`.* TO keycloak"
GRANT ALL ON *.* TO keycloak;
-- ERROR 1064 (42000): SQL parser error: ... syntax error near " *.* TO keycloak"

B. UPDATE/DELETE can only be granted at table/view scope

GRANT UPDATE,DELETE ON DATABASE keycloak TO kcrole;
-- ERROR 20101 (HY000): internal error: the privilege "update" can only be granted to the object type "table" or "view"

C. A non-admin role is denied DELETE even on tables created by that role itself — reproducible on a clean database:

-- as root (moadmin)
CREATE DATABASE keycloak_qa;
CREATE ROLE kcrole_qa;
GRANT ALL PRIVILEGES ON DATABASE keycloak_qa TO kcrole_qa;
GRANT kcrole_qa TO keycloak;
-- as sys#keycloak#kcrole_qa (account#user#role login): import schema, e.g.
CREATE TABLE credential (USER_ID VARCHAR(36) PRIMARY KEY);

-- still as sys#keycloak#kcrole_qa:
DELETE FROM credential WHERE USER_ID = 'x';
-- ERROR 20101 (HY000): internal error: do not have privilege to execute the statement

-- even after, as root:
GRANT UPDATE,DELETE ON TABLE keycloak_qa.credential TO kcrole_qa;
-- (persisted: mo_role_privs shows update/delete/table ownership rows for kcrole_qa)
-- the same DELETE is still denied for the role login, while root can delete freely.

-- Control: on a ROOT-created table granted with
GRANT UPDATE,DELETE ON TABLE keycloak_qa.root_made TO kcrole_qa;
-- DELETE as the role login SUCCEEDS.

Observed grant asymmetry: INSERT/SELECT/CREATE TABLE/DROP TABLE work for the role login on its own schema; DELETE (and by extension the whole runtime write/update pattern of JPA apps) is denied unless operating as an account administrator such as root.

For comparison, provisioning the same application account as root (moadmin) works fully — which matches how other services are deployed on a dedicated account's accountadmin user, but blocks running third-party apps as a least-privilege user inside sys.

Expected Behavior

  1. Accept GRANT <privs> ON db.* [TO user] with MySQL 8 semantics (or document the divergence and provide an equivalent single statement).
  2. Make table-scoped UPDATE/DELETE grants effective regardless of the table creator's role membership.
  3. Clarify whether USE <database> intentionally requires privileges beyond GRANT ... ON ACCOUNT/database (it is currently denied for non-privileged roles while URL-scoped connections work).

Steps to Reproduce

Follow the exact statements listed in section C above (all statements and outputs captured verbatim from a single mysql 8.0 CLI session against the nightly image).

Other Environment Information

  • Server: matrixorigin/matrixone:nightly-7b911aea-arm64 docker, standalone, macOS arm64 (OrbStack)
  • Client: mysql CLI 8.0; the same behavior was first observed behind MySQL Connector/J 9.6.0 (Keycloak 26.6.4), where Liquibase/Hibernate DML fails with do not have privilege to execute the statement

Consolidated tracking (2026-10-27)

Item Original issue Status
Column-level GRANT silently widened to whole-table scope (column list discarded) #30915 open, tracked here
GRANT ... ON TABLE <view> silently accepted but grants nothing #30887 open, tracked here
mo_catalog.mo_role_privs.privilege_level stores placeholder template 'd.t' #30676 open, tracked here

Original reproductions remain in the linked issues (closed as duplicates of this tracking issue).

Activity

  1. added
    kind/bug
    on Oct 20, 2026
  2. daviszhen commented on Oct 21, 2026

    @daviszhen
    Contributor

    Rechecked on main 04fe057bd73520cdf30754f79f66f6505060ad1f with a real MySQL role login. The results need to be separated:

    • C, role-created-table DML: no longer reproduces. INSERT, UPDATE and DELETE succeed on the role-owned VARCHAR primary-key table; explicit table grants also work on both role-created and administrator-created tables. The regression asserts actual affected rows/data, not only successful execution.
    • A/B: implicit MySQL ON db.* TO user syntax and UPDATE/DELETE ON DATABASE remain unsupported; this update does not claim otherwise. MatrixOne uses role grantees and distinct DATABASE-DDL / TABLE-DML object scopes. ON TABLE db.* is supported database-wide table scope, not one grant per table.
    • USE: independently needs CONNECT; selecting the initial database during the handshake does not replace that grant.

    For example, an administrator can use:

    CREATE DATABASE app_db;
    CREATE ROLE app_role;
    CREATE USER app_user IDENTIFIED BY 'replace-with-a-secret';
    GRANT app_role TO app_user;
    GRANT CONNECT ON ACCOUNT * TO app_role;
    GRANT ALL PRIVILEGES ON DATABASE app_db TO app_role;
    GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE app_db.* TO app_role;

    Then log in as sys#app_user#app_role with app_db selected. Omit the DATABASE-DDL grant for runtime-only users. This does not grant moadmin/accountadmin or cross-database DML.

    Submitted the guide and real-protocol regression in #30720 (63e7a285f2). It passes with privilege caching on/off, retaining the same role connection across committed grants/revokes, checking cross-database/delegation rejection, and confirming denied operations leave data unchanged. No authorization checks were relaxed. This is a documented supported equivalent and regression guard, not an implementation of MySQL's full privilege model; full Keycloak startup was not tested.

  3. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    Collaborator

    Additional data point for section A (same parser-gap family, third form): the table-level form without the TABLE keyword is also rejected, and the standard MySQL user@host grantee spelling is unrepresentable in the TO clause entirely:

    -- All on dev build 3a1e42b430 (v1.3.0, 2026-10-22), account sys root:
    CREATE USER u_nobody@localhost IDENTIFIED BY 'pw123';      -- ok
    
    GRANT SELECT ON d4perm.secret TO 'u_nobody'@'localhost';   -- ERROR 1064 near " d4perm.secret to ..."
    GRANT SELECT ON d4perm.* TO 'u_nobody'@'localhost';        -- ERROR 1064 near " d4perm.* to ..."
    GRANT SELECT ON *.* TO 'u_nobody'@'localhost';             -- ERROR 1064 near " *.* to ..."
    GRANT SELECT ON TABLE d4perm.secret TO 'u_nobody'@'localhost'; -- ERROR 1064 near "@'localhost'"
    GRANT SELECT ON TABLE d4perm.secret TO u_nobody@localhost; -- ERROR 1064 near "@localhost"
    GRANT SELECT ON TABLE d4perm.secret TO u_nobody;           -- ERROR 20101: internal error: there is no role u_nobody

    MySQL 8.0.45 accepts all of the first five verbatim (GRANT SELECT ON d4perm.secret TO 'u_nobody'@'localhost' shows as GRANT SELECT ON \d4perm`.`secret` TO ...`).

    Two distinct consequences beyond what section A already documents:

    1. Table-scope grants cannot be written in MySQL syntax at all: db.tbl (no keyword) is rejected, and
    2. No syntactic form can name a user@host as grantee: host-qualified — quoted or unquoted — fails with 1064, while bare u_nobody fails with there is no role u_nobody because the grantee position is resolved against roles only. The working path is the two-step role indirection (CREATE ROLE r; GRANT SELECT ON TABLE d.t TO r; GRANT r TO u_nobody;), which matches the "least-privilege app accounts blocked" theme but is broader: even granting to a pre-existing user directly is impossible.

    Repull condition: any of GRANT <priv> ON [TABLE] db.tbl TO user[@host] working.

  4. aqqi666 commented on Oct 26, 2026

    @aqqi666
    Author

    Verification on latest nightly (2026-10-25, matrixorigin/matrixone:nightly-b14d67a2-arm64)

    Re-ran the exact original sequence from the issue body as sys#kcprobe_user#kcprobe_role (user = role member only, no account-admin):

    -- as root:
    CREATE DATABASE kcprobe_db;
    CREATE USER kcprobe_user IDENTIFIED BY '...';
    CREATE ROLE kcprobe_role;
    GRANT ALL PRIVILEGES ON DATABASE kcprobe_db TO kcprobe_role;
    GRANT kcprobe_role TO kcprobe_user;
    
    -- as sys#kcprobe_user#kcprobe_role (URL/CLI database = kcprobe_db):
    CREATE TABLE credential (USER_ID VARCHAR(36) PRIMARY KEY);
    INSERT INTO credential VALUES ('x');
    SELECT COUNT(*) FROM credential;    -- 1
    DELETE FROM credential WHERE USER_ID='x';
    SELECT COUNT(*) FROM credential;    -- 0  ✅

    Gap C no longer reproduces ✅ (matches daviszhen's recheck on 04fe057b). The same sequence failed with ERROR 20101 on the 2026-10-18 nightly (nightly-7b911aea-arm64), so the fix landed between the two nightlies [not pinpointed to a specific PR].

    Supplementary probes on the same nightly

    Probe Result
    GRANT SELECT ON kcprobe_db.* TO kcprobe_role still ERROR 1064 near " kcprobe_db.* TO kcprobe_role" (gap A unchanged)
    GRANT SELECT,UPDATE,DELETE ON TABLE kcprobe_db.* TO kcprobe_role accepted; mo_role_privs shows select/update/delete rows with obj_type=table, obj_id=<database id> — this is the one-statement database-wide table-scope grant form (gap B has a working equivalent)
    USE kcprobe_db as role login still ERROR 20101 (do not have privilege to execute the statement); GRANT CONNECT ... to a role is rejected by the parser in both forms tried (GRANT CONNECT ON ACCOUNT TO role → 1064 near TO; GRANT CONNECT TO role → 1064 near TO). Connecting with the database on the command line / in the JDBC URL works fine, so this is CLI-ergonomics only

    Net for the Keycloak-style service-account provisioning pattern on current main:

    GRANT ALL PRIVILEGES ON DATABASE keycloak TO kcrole;
    GRANT SELECT, UPDATE, DELETE ON TABLE keycloak.* TO kcrole;
    GRANT kcrole TO keycloak;
    -- connect via JDBC URL database (no USE needed); no account-admin rights required for own-schema DML now

    Remaining open gaps in this issue: A (MySQL ON db.*/*.* parser form), USE statement CONNECT semantics for role logins.

  5. Ariznawlll commented on Oct 29, 2026

    @Ariznawlll
    Collaborator

    Additional working syntax intelligence on main c6683bd2f5 (2026-10-29) for anyone fixing the parser gap in item A — three things an app port needs to know, none of which is discoverable from the 1064 message:

    1. The accepted object syntax requires an object-type keyword: GRANT SELECT ON TABLE <db>.<obj> TO <role> and GRANT CONNECT ON ACCOUNT * TO <role> parse and record rows in mo_catalog.mo_role_privs. The MySQL-shape GRANT ALL ON db.* TO u / GRANT SELECT ON db.tbl TO u variants all die with 1064.

    2. TO <user> is not valid either — the grantee must be a role: even with the TABLE keyword, GRANT SELECT ON TABLE vdst.* TO someuser fails with ERROR 20101: there is no role someuser. The working path is CREATE ROLE r; GRANT ... TO r; GRANT r TO someuser; — meaning every least-privilege migration (Keycloak, legacy app provisioning scripts) needs a 3-step rewrite, not a keyword fix.

    3. A role is not auto-activated for its grantee: after GRANT r TO someuser, a fresh session of that user still has CURRENT_ROLE()=public and none of r's privileges apply until the user runs SET ROLE r (accepted only with autocommit — under an open transaction it dies with ERROR 20101: administrative command is unsupported in transactions). So even the 3-step port ends in a runtime permission failure unless the app also sets the role per session — unlike MySQL where granting a privilege to a user (or their default role) is enough.

    Point 3 compounds the report: even after correcting GRANT syntax in application bootstrap code, the privileged account still fails at runtime because the role is dormant. Bundling an auto-activation story (MySQL-style DEFAULT ROLE semantics; see also the SET DEFAULT ROLE silent-no-op history) into this fix would make the least-privilege path actually usable end to end.

  6. XuPeng-SH commented on Nov 29, 2026

    @XuPeng-SH
    Contributor

    Consolidated duplicate #30874 into item A (database/global GRANT parsing).

    Additional independent evidence retained:

    • On main 3ad9adbb4c, GRANT SELECT ON qa2.* TO qa_u1 returns ERROR 1064 near qa2.*.
    • GRANT SELECT ON TABLE qa2.* TO qa_u1 is accepted, isolating the optional TABLE keyword parser gap.
    • The same divergence was reproduced on the earlier 7b911aea68 base, so this is not a recent regression.
    • PR fix(parser): accept GRANT/REVOKE without object type (default TABLE) #30875 was closed without merging; it is not a fix or validation claim.

    Keep optional-TABLE parsing for db.* / *.* and the ordinary explicit-TABLE control as independent acceptance cases. User-grantee semantics remain separately tracked and are not collapsed into this parser item.

    Administrative consolidation only; the bug remains open and unverified.

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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions