Repository navigation
fix(frontend): enforce and revoke view privileges across stored spellings - #32573
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Queue requested — the merge queue status continues in this comment ↓. |
|
mo-bot review · Commit: Review completed. Read the assessment. |
|
Review P2 addressed ( The case now follows the
Local proof on head dfdb0cd (issue-owned LOG+TN+CN launch of this head, mo-tester normal comparison mode):
|
…ings A SELECT granted on a view with the ON TABLE spelling (or the bare MySQL spelling) is stored in mo_catalog.mo_role_privs under the table object class against the view's relation id, but query-time view enforcement only matched view-class rows, so the granted privilege never authorized the SELECT (issue matrixorigin#32444). Honor the legacy table-class grant at the exact-relation privilege levels ("d.t" and "t"), which resolve the view by database, name and object identity; wildcard table-class grants (db.*, *, *.*) stay distinct from view access, and the honored result is cached under the view class. Make the revocation path symmetric with that storage model: an exact-relation revoke written with any qualification spelling or any object wording removes the granted rows at both stored levels and both object classes of the resolved relation, and REVOKE ALL clears every privilege row on the exact object identity instead of only the table-all row. Wildcard scopes (d.*, *, *.*) keep the class-specific delete so a wildcard revoke of one object class cannot remove an independent wildcard grant of the other class. Related to matrixorigin#32444
…BVT cleanup The case cleanup persisted `set global enable_privilege_cache = on` unconditionally, so running the case while the sys-account global was already OFF leaked ON into subsequent sessions and cases (review finding on PR matrixorigin#32573). Mirror the tenant/privilege/bare_object_grant.sql pattern: snapshot the sys-account global into @saved_enable_privilege_cache with a value oracle at entry, and restore the genuine original value with a restore oracle at cleanup; record the new statements and their default-state oracle rows in the .result. Every pre-fix behavioral expectation stays unchanged.
dfdb0cd to
d03ab9c
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: d03ab9c7536257c835dfabfbaa4a9db9a8fbc3be
Assessment: approve
The fix reuses existing authorization, cache and transaction owners while preserving exact-relation and wildcard boundaries. The prior BVT global-state leak is resolved. No actionable findings remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all five changed files, affected consumers, seven discussion entries and linked issue context.
-
Source identity, Go formatting and extracted SQLite predicates passed: 240-row revoke matrix, 240 grant-boundary checks and 110 matching BVT commands.
-
Final evidence audit passed: checks/1794463992492240934-4.json and assessment-audit.log. Source remains unchanged.
-
Reused frozen current-head CI successes: UT, SCA, coverage, shared build and active BVT lanes. Overall snapshot: 14 successful, 14 skipped, 2 neutral.
-
Considered author-reported focused tests, two 110/110 BVT runs and OFF-entry cleanup verification.
Limitations:
-
No local Go/native, MatrixOne service, race or performance execution; SQLite checks establish predicate semantics only.
-
Raw runtime and CI logs were unavailable for independent inspection.
-
git diff --check reports nonblocking whitespace warnings inside the new raw SQL literals.
✅ Merged into
|
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32444
What this PR does / why we need it:
Root cause
GRANT SELECT ON TABLE <view>(and the bareGRANT SELECT ON <db>.<view>spelling) stores the privilege inmo_catalog.mo_role_privsunder the table object class against the view's relation id, butverifyViewPrivilegeForRoleonly matched view-class rows, so a granted, role-activated SELECT was still rejected at query time withinternal error: do not have privilege to execute the statement(issue [Bug]: SELECT privilege on a VIEW is stored but never enforced #32444).privilege_level("d.t" or "t"), while enforcement honors both, so a revoke written in one qualification spelling (qualified vs unqualified) left the row stored under the other spelling and the object stayed authorized for fresh sessions;db.*) also used it and wrongly removed independent wildcard grants of the other object class on the same database, andREVOKE ALLonly deleted the table-all row instead of every privilege row of the exact object.Exact change
pkg/frontend/authenticate.goverifyViewPrivilegeForRolere-probes the legacy table-class grant at the exact-relation privilege levels (exactRelationPrivilegeLevels: "d.t"/"t") after the view-class sweep misses, and caches the honored result under the view class; table-class wildcard grants (db.*,*,*.*) stay distinct from view access.deleteRelationRolePrivsFormat,deleteRelationAllRolePrivsFormat) delete rows of both stored object classes (obj_type in ("table","view")) and both qualification spellings (privilege_level in ("d.t","t")) for the resolved relation id;REVOKE ALLon an exact relation drops theprivilege_idfilter and clears every privilege row on that identity; wildcard scopes and account/database-class scopes keep the legacy class-specific delete.pkg/frontend/authenticate_test.go/pkg/frontend/select_lock_privilege_test.go— focused UT regressions: exact-relation TABLE/VIEW revokes (SELECT and ALL, both spellings), unqualified exact revoke, class-specific legacy deletes fordb.*/*.*/account with negative asserts, and catalog-lock fixtures.test/distributed/cases/zz_accesscontrol/grant_view_table_spelling.sql(+ generated.result) — user-visible BVT: grants through every accepted spelling authorize a fresh session; a revoke in the other qualification spelling or the other object wording ends authorization in a fresh session;REVOKE ALLremoves layered SELECT+ALL grants on views and base tables; wildcard grants of one object class survive the other class's wildcard revokes and end only at the same-class revoke; denials recorded as the documented privilege error. The case snapshots the sys-accountenable_privilege_cacheglobal at entry with a value oracle and restores the genuine captured original value at cleanup (thetenant/privilege/bare_object_grant.sqlpattern), so running the case with the cache already OFF no longer persists ON into later sessions and cases.Proof (issue to test)
ON TABLEto an activated role, root can query the view,SELECT * FROMthe view by the granted user fails) fails on the assigned base binary and passes with this change. The stored authorization row is visible inmo_catalog.mo_role_privswithobj_type='table'against the view'sobj_id, and the granted user's SELECT returns the view's rows.Test_doRevokePrivilege(pkg/frontend) asserts the emitted catalog delete SQL for every revoke routing — exact-relation TABLE/VIEW SELECT and ALL at both qualification spellings, the unqualified table-select case, and the unchanged legacy class-specific path fordb.*,*.*and account scopes, with explicit negative asserts that the wildcard deletes contain neither the cross-class nor the both-level in-clause; focused run PASS (137 convey assertions), fullpkg/frontendsuite PASS.grant_view_table_spelling.sqlpasses 110/110 with this change; the same BVT fails 7 rows on the true-base binary (5 rows = the original view-enforcement defect, 2 rows = authorization survivingREVOKE ALLthrough a leftover row). The regenerated.resultwas inspected statement-by-statement: authorizations, fresh-session denials and preserved wildcard grants match the intended semantics. Review-cleanup revision re-validated locally: the case is green 110/110 twice in a row on one instance, and under the review's counterexample (sys-accountenable_privilege_cachealready OFF) the pre-fix cleanup left the global ON while the fixed case restores the captured OFF, which its restore oracle records.enable_privilege_cacheoff/on and after an off-to-on switch): fail pre-repair, pass post-repair; pre-PR review counterexample probe (cross-spelling and cross-class revokes) reproduces both defects pre-fix and shows both fixed post-fix.zz_accesscontrol/revoke_privs_role.sql58/58,tenant/privilege/role3.sql200/200, both green.Test commands
cd pkg/frontend && go test -run 'Test_doRevokePrivilege' -count=1(focused),go test -count=1(full package) — both PASS on macOS arm64 with the repository CGo environment.test/distributed/cases/zz_accesscontrol/grant_view_table_spelling.sqlruns in CI via mo-tester against the committed.result.gofmt -lclean,go vet ./pkg/frontend/...exit 0,golangci-lint run -c .golangci.yml --new-from-rev HEAD ./pkg/frontend0 issues.Residual risks
REVOKE ALLclears every privilege row on the object identity; anyone relying on a cross-spelling leftover to keep a role authorized will lose that access.ON TABLE/ON VIEWwording (documented); an exact-relation revoke does not remove database- or account-level grants.SHOW GRANTSrendering for view grants (literald.t) is a separately reported display issue and is unchanged here.Base update (2026-11-12)
Rebased onto
mainat4760bcaa88to pick up the merged CI-stabilization fixes for #32424 and #32563 (PR #32574); this PR's own diff is unchanged (same five files, 968 insertions / 2 deletions). Focused UT re-validated on the new base viamo-cgo-test -count=1 -run ... ./pkg/frontend(macOS arm64, repository CGo wrapper):TestVerifyViewPrivilegeForRoleHonorsTableSpellingGrant,TestVerifyViewPrivilegeForRoleTableSpellingGrantCachePromotion, the extendedTestSelectLockViewAlternativesAndErrors, and theTest_doRevokePrivilegerevoke-routing case set all PASS.