[BugFix] Fix GRANT on ALL VIEWS/MVs failing for external catalogs#71295
[BugFix] Fix GRANT on ALL VIEWS/MVs failing for external catalogs#71295VijayShekhawat7 wants to merge 2 commits into
Conversation
2a9903b to
f8388d3
Compare
a87e993 to
f4b556b
Compare
ViewPEntryObject and MaterializedViewPEntryObject resolved databases exclusively through the local (internal) metastore, causing "cannot find db" errors when granting on views or materialized views in external catalogs such as Iceberg. The analyzer also did not prepend the current catalog name for VIEW and MATERIALIZED_VIEW object types, unlike TABLE which already did. Mirror the catalog-aware resolution pattern from TablePEntryObject: - Accept 3-element token lists [catalog, db, object] - Resolve catalog ID via CatalogMgr - Use DbPEntryObject.getDatabaseUUID() which returns the DB name directly for external catalogs without local metastore lookup - Return view/MV name directly as UUID for external catalogs - Handle ResourceMappingCatalog edge case (same as TablePEntryObject) - Add Preconditions guard and StarRocksConnectorException catch for consistency with TablePEntryObject.getTableUUID() Update initPrivilegeCollectionAllObjects to pass 3 tokens (["*","*","*"]) for VIEW and MATERIALIZED_VIEW so built-in roles (root, db_admin) receive ALL_CATALOGS_ID and correctly match external catalog objects. Add test cases for GRANT/REVOKE on ALL VIEWS, ALL MATERIALIZED VIEWS, and ALL TABLES in external catalog databases, internal catalog views, specific view grant on external catalog, and invalid catalog handling. Fixes StarRocks#71211 Signed-off-by: Vijay Shekhawat <vijayshekhawat1995@gmail.com> Made-with: Cursor
f4b556b to
9c6a62e
Compare
There was a problem hiding this comment.
Pull request overview
Fixes GRANT/REVOKE on ALL VIEWS / ALL MATERIALIZED VIEWS when the session is using an external catalog by making view/MV privilege object resolution catalog-aware (mirroring existing table behavior).
Changes:
- Update
AuthorizationAnalyzer.analyzeTokensto prependsession.getCurrentCatalog()for VIEW/MATERIALIZED_VIEW (and to consistently emit[catalog, db, object]tokens for non-ALL paths). - Extend
ViewPEntryObjectandMaterializedViewPEntryObjectto accept 3-part tokens and resolve external catalogs viaCatalogMgr, using external names as privilege “UUIDs” similarly to external tables. - Add analyzer tests covering GRANT/REVOKE of ALL views/MVs in external catalogs (plus a negative case for a non-existent catalog).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| fe/fe-core/src/test/java/com/starrocks/sql/analyzer/PrivilegeStmtAnalyzerV2Test.java | Adds parsing/analyzer regression tests for GRANT/REVOKE on ALL views/MVs in an external (mocked hive) catalog. |
| fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizationAnalyzer.java | Ensures VIEW/MV token analysis is catalog-aware and aligns token shapes with TABLE behavior. |
| fe/fe-core/src/main/java/com/starrocks/authorization/ViewPEntryObject.java | Implements 3-token [catalog, db, view] generation and external-catalog resolution/ID strategy for views. |
| fe/fe-core/src/main/java/com/starrocks/authorization/MaterializedViewPEntryObject.java | Implements 3-token [catalog, db, mv] generation and external-catalog resolution/ID strategy for materialized views. |
| fe/fe-core/src/main/java/com/starrocks/authorization/AuthorizationMgr.java | Updates built-in “ALL objects” initialization for VIEW/MV to use 3-token wildcards consistent with catalog-aware generation. |
HangyuanLiu
left a comment
There was a problem hiding this comment.
Thanks for working on this. I don't think this is ready yet.
The main issue is that this patch only fixes the GRANT/REVOKE statement analysis and PEntryObject generation path for external-catalog VIEW / MATERIALIZED_VIEW privileges, but it does not appear to wire the runtime authorization path through consistently.
Specifically:
AuthorizationAnalyzernow produces catalog-aware tokens for VIEW / MATERIALIZED_VIEW in the grant path, andViewPEntryObject/MaterializedViewPEntryObjectnow accept external-catalog objects.- However, the authorization check path still does not appear to consume those privileges consistently. In
Authorizer.doCheckTableLikeObject, external view types such asHIVE_VIEW/ICEBERG_VIEW/PAIMON_VIEWstill go through the TABLE privilege branch instead of the VIEW privilege branch. - On the native auth side,
NativeAccessController.checkViewAction/checkAnyActionOnViewand the MV equivalents still build objects from[db, object]without catalog information, so they still default back to the internal catalog semantics. Authorizer.checkAnyActionOnOrInDbalso only applies the VIEW / MV “extra checkers” for the internal catalog path.
So with the current patch, GRANT ... ON VIEW/MATERIALIZED_VIEW against an external catalog may succeed syntactically and may even persist a privilege entry, but I do not see evidence that the granted privilege will actually be matched by the real authorization flow when the system checks access later.
The second issue is test coverage:
- The new tests only assert parser/analyzer success or failure via
parseStmtWithNewParser(...). - They do not verify the generated privilege object shape, and more importantly they do not verify that a user who receives the external VIEW / MV privilege can actually pass a later authorization check.
Please add a real end-to-end authorization test for the actual privilege enforcement path, not just parser coverage. I strongly recommend deploying this against a real external catalog and verifying the full workflow in a running system as well: grant the privilege, then validate the downstream access checks that are supposed to consume it. Right now this looks very likely to fix statement acceptance without fully fixing correctness.
|
@VijayShekhawat7 are you able to update this PR - we would love a fix for the issue |
…n path The previous commit fixed GRANT/REVOKE statement analysis for external catalog views and MVs, but the runtime authorization checks still routed external view types (HIVE_VIEW, ICEBERG_VIEW, PAIMON_VIEW) through the TABLE privilege branch and hardcoded internal catalog. - Move HIVE_VIEW/ICEBERG_VIEW/PAIMON_VIEW to the VIEW case in Authorizer.doCheckTableLikeObject so they check VIEW privileges - Make Authorizer.checkViewAction/checkAnyActionOnView (and MV equivalents) catalog-aware instead of hardcoding internal catalog - Make NativeAccessController view/MV check methods pass 3-token [catalog, db, object] lists matching the table pattern - Add catalog-aware checkAnyActionOnAnyView/MV overloads to AccessController interface and NativeAccessController - Include VIEW/MV privilege checkers for external catalogs in Authorizer.checkAnyActionOnOrInDb (used by SHOW DATABASES / USE) - Pass tbl.getCatalogName() consistently for all branches in doCheckTableLikeObject - Add end-to-end authorization tests that grant privileges on external catalog views/MVs and verify the runtime check path works Signed-off-by: Vijay Shekhawat <vijayshekhawat1995@gmail.com> Made-with: Cursor
|
Thanks for the thorough review @HangyuanLiu, You're right that the original patch only fixed the grant/revoke statement path without wiring the runtime authorization checks. I've pushed a follow-up commit that addresses all the issues you raised: 1. External view types now route through VIEW privilege branch 2. NativeAccessController view/MV methods are now catalog-aware 3. 4. End-to-end authorization tests
Also fixed a pre-existing inconsistency in |
|
@HangyuanLiu , possible to review please? |
|
@jaogoy please add you review |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 116 / 136 (85.29%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
Why I'm doing:
GRANT ALL ON ALL VIEWS IN DATABASEfails withcannot find db: <db_name>whenthe current session is connected to an external catalog (e.g., Iceberg via REST).
The equivalent
GRANT ALL ON ALL TABLES IN DATABASEworks correctly.This happens because
ViewPEntryObjectandMaterializedViewPEntryObjectresolvedatabases exclusively through the local (internal) metastore, while
TablePEntryObjectalready has catalog-aware resolution that supports externalcatalogs.
What I'm doing:
Mirror the catalog-aware resolution pattern from
TablePEntryObjectintoViewPEntryObjectandMaterializedViewPEntryObject:AuthorizationAnalyzer.analyzeTokens: Prependsession.getCurrentCatalog()for
VIEWandMATERIALIZED_VIEWobject types (matching existingTABLEbehavior) in both the ALL and non-ALL grant paths.
ViewPEntryObject.generate: Accept 3-element token lists[catalog, db, view],resolve catalog ID via
CatalogMgr, useDbPEntryObject.getDatabaseUUID()forexternal catalogs (returns DB name directly without local metastore lookup), and
return view names directly as UUIDs for external catalogs.
MaterializedViewPEntryObject.generate: Same fix asViewPEntryObject.Fixes #71211
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: