Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
92f42f6
feat: support GRANT/REVOKE privileges on VIEWs
gouhongshen Jan 6, 2026
50f044e
test: add BVT case for granting privileges on views
gouhongshen Jan 6, 2026
8a35301
test: add non-sys tenant test case for GRANT VIEW
gouhongshen Jan 6, 2026
00c45be
test: add BVT tests and results for GRANT/REVOKE on VIEW
gouhongshen Jan 6, 2026
ac495aa
test: add complex BVT cases for GRANT/REVOKE on VIEW
gouhongshen Jan 6, 2026
a7eeb86
feat: implement view privilege short-circuit logic and fix enforcement
gouhongshen Jan 6, 2026
e6a1b18
docs: add RFC/design document for view grant support
gouhongshen Jan 6, 2026
fcba162
docs: add completion status and limitations to view grant RFC
gouhongshen Jan 6, 2026
bfc8237
test: sync BVT results for view grant feature
gouhongshen Jan 6, 2026
c6037c0
docs: finalize view grant support RFC with detailed technical findings
gouhongshen Jan 6, 2026
60715ac
fix view grant privilege checks
gouhongshen Jan 7, 2026
b02f02f
docs: finalize view grant design
gouhongshen Jan 7, 2026
52cebbe
docs: switch view grant RFC to English
gouhongshen Jan 7, 2026
fc8f7b1
feat: refine view privilege checks and tests
gouhongshen Jan 8, 2026
d81f1d6
fix: align view privilege checks with snapshot views
gouhongshen Jan 9, 2026
9e7040d
Merge branch 'main' into feat/grant_view
gouhongshen Jan 12, 2026
4251dd0
Merge branch 'main' into feat/grant_view
gouhongshen Jan 13, 2026
87bd874
Merge branch 'main' into feat/grant_view
gouhongshen Jan 15, 2026
1f34301
Merge branch 'main' into feat/grant_view
gouhongshen Jan 16, 2026
33de8ef
Merge branch 'main' into feat/grant_view
gouhongshen Jan 21, 2026
2cb8ce7
Merge branch 'main' into feat/grant_view
gouhongshen Jan 26, 2026
33a3c25
Merge branch 'main' into feat/grant_view
gouhongshen Jan 28, 2026
a15820b
Merge branch 'main' into feat/grant_view
gouhongshen Jan 30, 2026
a85dae5
Merge branch 'main' into feat/grant_view
gouhongshen Feb 3, 2026
c62a960
Merge branch 'main' into feat/grant_view
gouhongshen Feb 4, 2026
955eba1
Merge branch 'main' into feat/grant_view
gouhongshen Feb 5, 2026
d5edab2
Merge upstream/main into feat/grant_view
gouhongshen Mar 5, 2026
032bf24
remove log
gouhongshen Mar 5, 2026
4b9c69b
remove log 2
gouhongshen Mar 5, 2026
60d0743
fix: gofmt formatting
gouhongshen Mar 5, 2026
7740927
Merge remote-tracking branch 'upstream/main' into feat/grant_view
gouhongshen Mar 5, 2026
a73127c
Merge branch 'main' into feat/grant_view
gouhongshen Mar 9, 2026
efaaf30
Merge branch 'main' into feat/grant_view
mergify[bot] Mar 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions docs/rfcs/view_grant_support_design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# MatrixOne View Privilege Support (GRANT/REVOKE ON VIEW): Final Design and Implementation

## Final Design

### 1. Goals and Scope
Provide `GRANT/REVOKE ... ON VIEW` with correct authorization semantics so users can access view results safely while respecting `SQL SECURITY` behavior.

### 2. Privilege Object and Levels
- Introduce `objectTypeView` alongside `objectTypeTable`.
- Privilege levels match table privileges: `*.*`, `db.*`, `db.view`, `view` (current database).
- Privilege types match table privileges (e.g., `SELECT/INSERT/UPDATE/DELETE/OWNERSHIP/ALL`), and `SHOW GRANTS` displays `ON VIEW`.

### 3. Metadata and Storage
- View object id is `mo_catalog.mo_tables.rel_logical_id` with `relkind='v'`.
- Store privileges in `mo_catalog.mo_role_privs` with `obj_type="view"` and `obj_id=rel_logical_id`.
- View privileges are read and checked through the same pipeline as table privileges, but with `obj_type` distinguishing view vs table.

### 4. Plan-Time View Lineage
Compiler records view lineage into plan nodes:
- `origin_views`: the view chain in `db#view` format, ordered from the outermost view to the innermost view.
- `direct_view`: the outermost view referenced by the user (optional, mostly for diagnostics).

### 5. Runtime Authorization Flow
For each plan node:
1. If `origin_views` is present, verify view privileges in chain order (outermost to innermost).
2. For each view in the chain, apply its `SQL SECURITY` to decide the effective role for the next hop:
- `DEFINER`: switch to the view definer role for the next hop.
- `INVOKER`: keep the current role for the next hop.
3. After the chain, check base-table privileges using the effective role.
4. If `origin_views` is empty, fall back to standard table privilege checks.

### 6. SQL SECURITY Semantics
- Session variable `view_security_type` controls `DEFINER` or `INVOKER` (default `DEFINER`).
- The `security_type` is persisted in viewdef JSON.
- For legacy views without `security_type`, treat as `DEFINER`.

### 7. Special Cases and Compatibility
- System view databases (`information_schema`, `mysql`) skip view privilege checks and remain read-only.
- Fully qualified `db.view` queries can run without `USE <db>` if view privilege passes.

### 8. Testable Behaviors
- `GRANT/REVOKE ... ON VIEW` syntax and `SHOW GRANTS` output.
- Multi-layer view chains work with grant/revoke.
- `DEFINER/INVOKER` semantics enforced.
- Role inheritance and partial revokes work for non-system tenants.

## Implementation

### 1. Syntax and Object Model
- Extend `ObjectType.String()` to include `view`.
- Add `objectTypeView` and its privilege level mappings.

### 2. Metadata and Plan Structures
- Extend plan proto and generated code to carry view lineage fields.
- Record `origin_views` and `direct_view` during view binding and plan construction.

### 3. Authorization Logic
- Extract view privilege tips from plan nodes and check them before table privileges.
- Enforce `SQL SECURITY` per view in the lineage to determine the effective role for base-table checks.
- For view chains, cache-only privilege evaluation is skipped to avoid missing view metadata checks.
- Snapshot reads resolve view metadata using the snapshot tenant and `MO_TS` to ensure view chains are validated against the correct historical catalog.
- View privilege checks use the view-level snapshot (when the view is referenced with a snapshot) rather than the underlying table scan snapshot to avoid false "view not found" errors.
- Fix privilege extraction for `INSERT/UPDATE/DELETE` paths to avoid missed checks.
- Preserve existing system view and cluster table guardrails.

### 4. Tests and Results
Updated or added BVT cases:
- `test/distributed/cases/zz_accesscontrol/grant_view.sql`
- `test/distributed/cases/zz_accesscontrol/grant_view_non_sys.sql`
- `test/distributed/cases/zz_accesscontrol/grant_view_complex.sql`
- `test/distributed/cases/zz_accesscontrol/grant_view_nested_security.sql`
- Updated related `.result` files and error messages (e.g., `grant_privs_role.result`, `revoke_privs_role.result`).

## MySQL Compatibility

### Compatible
- Syntax: `GRANT/REVOKE ... ON VIEW`, `SHOW GRANTS` shows `ON VIEW`.
- Semantics: `SQL SECURITY DEFINER/INVOKER` aligns with MySQL (view privilege plus definer/invoker base-table privilege).
- Nested views: privilege checks follow the view chain with per-view `DEFINER/INVOKER` semantics.
- Isolation: granting view privilege does not grant base-table privilege.

### Differences
- DML on views: MatrixOne rejects `INSERT/UPDATE/DELETE` on views, while MySQL allows DML on updatable views.
- SQL SECURITY declaration: MatrixOne uses session variable `view_security_type` persisted in viewdef, not `CREATE VIEW ... SQL SECURITY ...`.
- No separate `SHOW VIEW` privilege type; it follows table/database privilege categories.
Loading
Loading