You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "roryqi (via GitHub)" <gi...@apache.org> on 2026/08/19 08:53:31 UTC

[PR] [#8674] fix(authz): Isolate Ranger catalog owner roles by catalog ID [gravitino]

roryqi opened a new pull request, #12517:
URL: https://github.com/apache/gravitino/pull/12517

   ### What changes were proposed in this pull request?
   
   Pass the stable catalog entity ID to authorization plugins and use it to create catalog-specific Ranger owner roles.
   
   Catalog owner roles now follow this format:
   
   `GRAVITINO_CATALOG_OWNER_ROLE_<catalog_id>`
   
   The chained authorization plugin also propagates the catalog ID to its child plugins.
   
   ### Why are the changes needed?
   
   Ranger previously used one shared `GRAVITINO_CATALOG_OWNER_ROLE` for every catalog. As a result, the owner of one catalog could receive owner permissions on other catalogs using the same Ranger service.
   
   Using the stable catalog ID isolates role membership without depending on the mutable catalog name.
   
   Fix: #8674
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Ranger creates a separate catalog owner role for each catalog using the catalog ID as the role-name suffix.
   
   No user-configurable property is added.
   
   ### How was this patch tested?
   
   - Added unit tests for passing catalog IDs to authorization plugins.
   - Added unit tests for generating and creating catalog-specific Ranger owner roles.
   - Updated the Ranger integration test expectation.
   - Ran Spotless successfully.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8674] fix(authz): Isolate Ranger catalog owner roles by catalog ID [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi commented on code in PR #12517:
URL: https://github.com/apache/gravitino/pull/12517#discussion_r3820395040


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -523,9 +535,9 @@ public Boolean onOwnerSet(MetadataObject metadataObject, Owner preOwner, Owner n
       case CATALOG:
         // The metalake and catalog use role to manage the owner
         if (metadataObject.type() == MetadataObject.Type.METALAKE) {
-          ownerRoleName = RangerHelper.GRAVITINO_METALAKE_OWNER_ROLE;
+          ownerRoleName = RangerHelper.generateMetalakeOwnerRoleName(metalakeId);
         } else {
-          ownerRoleName = RangerHelper.GRAVITINO_CATALOG_OWNER_ROLE;
+          ownerRoleName = RangerHelper.generateCatalogOwnerRoleName(catalogId);

Review Comment:
   Fixed in 603075d33. `updatePolicyOwnerRole` now removes the exact legacy shared owner role from each matching owner policy item before adding the entity-specific role. Reapplying the same owner therefore migrates an existing policy idempotently instead of leaving the shared role active.



##########
core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java:
##########
@@ -280,7 +280,13 @@ public AuthorizationPlugin getAuthorizationPlugin() {
     return authorizationPlugin;
   }
 
-  public void initAuthorizationPluginInstance(IsolatedClassLoader classLoader) {
+  /**
+   * Initializes the authorization plugin for this catalog.
+   *
+   * @param classLoader the catalog isolated class loader
+   * @param metalakeId the stable entity ID of the metalake containing this catalog
+   */
+  public void initAuthorizationPluginInstance(IsolatedClassLoader classLoader, long metalakeId) {

Review Comment:
   This change is for Gravitino 2.0, where this lifecycle signature can change. A repository-wide search found only `CatalogManager` and internal tests calling `initAuthorizationPluginInstance`; catalog connector modules do not call it. I kept the two-argument method so initialization always supplies the stable metalake ID required by the Ranger role isolation. Custom code compiled against the old internal lifecycle method will need to rebuild/update for 2.0.



##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -1301,14 +1302,26 @@ private Map<String, String> getResolvedProperties(CatalogEntity entity) {
   }
 
   private BaseCatalog<?> createBaseCatalog(IsolatedClassLoader classLoader, CatalogEntity entity) {
+    BaseMetalake metalakeEntity;
+    try {
+      metalakeEntity =
+          store.get(
+              NameIdentifier.of(entity.namespace().levels()),
+              EntityType.METALAKE,
+              BaseMetalake.class);
+    } catch (IOException e) {
+      throw new RuntimeException(
+          String.format("Failed to load metalake for catalog %s", entity.nameIdentifier()), e);
+    }
+
     // Load Catalog class instance
     BaseCatalog<?> catalog = createCatalogInstance(classLoader, entity.getProvider());
     // Resolve secret URNs to plaintext for connector init only; entity storage keeps URNs.
     // Fileset FS merge assumes catalog conf is already plaintext at this boundary.
     catalog
         .withCatalogConf(secretManager.toPlaintextProperties(entity.getProperties()))
         .withCatalogEntity(entity);
-    catalog.initAuthorizationPluginInstance(classLoader);
+    catalog.initAuthorizationPluginInstance(classLoader, metalakeEntity.id());

Review Comment:
   This targets the 2.0 upgrade, so I added an explicit idempotent reconciliation procedure instead of an automatic startup migration. The authorization pushdown documentation now instructs administrators to GET each current metalake/catalog owner and PUT the same owner again. That creates the ID-specific role, grants the current member, and replaces the legacy role in matching policies. I also separated revoke and grant error handling so a revoke failure on a newly created role cannot skip the grant. After every object is reconciled, administrators verify that no policy references the exact legacy role names and then delete those roles.



##########
authorizations/authorization-ranger/src/test/java/org/apache/gravitino/authorization/ranger/integration/test/RangerHiveIT.java:
##########
@@ -1492,8 +1493,8 @@ public void testOnOwnerSetCatalog() {
                   null,
                   null,
                   Lists.newArrayList(
-                      RangerHelper.GRAVITINO_METALAKE_OWNER_ROLE,
-                      RangerHelper.GRAVITINO_CATALOG_OWNER_ROLE));
+                      RangerHelper.generateMetalakeOwnerRoleName(RangerITEnv.METALAKE_ID),
+                      RangerHelper.generateCatalogOwnerRoleName(RangerITEnv.CATALOG_ID)));

Review Comment:
   Added `testMigrateLegacyOwnerRolesForCatalogsSharingRangerService` in 603075d33. It uses two catalog IDs and two different owners against the same Ranger service, prepares legacy shared role membership and policies, removes the new roles, and then runs same-owner reconciliation. The test verifies isolated role membership, replacement of the legacy policy role, and idempotency. The targeted Ranger Docker test passes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8674] fix(authz): Isolate Ranger catalog owner roles by catalog ID [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #12517:
URL: https://github.com/apache/gravitino/pull/12517#issuecomment-5344049828

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|67.46% **`-0.17%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|62.52%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|49.18%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |authorization-ranger|1.73% **`+1.73%`**|:red_circle:|
   |aws|42.04%|:green_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|9.92%|:red_circle:|
   |catalog-fileset|79.77%|:green_circle:|
   |catalog-glue|68.95%|:green_circle:|
   |catalog-hive|82.96%|:green_circle:|
   |catalog-jdbc-common|45.7%|:green_circle:|
   |catalog-jdbc-doris|81.8%|:green_circle:|
   |catalog-jdbc-mysql|79.33%|:green_circle:|
   |catalog-jdbc-postgresql|83.39%|:green_circle:|
   |catalog-jdbc-starrocks|79.16%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|59.18%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.86%|:green_circle:|
   |catalog-lakehouse-paimon|84.23%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.48%|:green_circle:|
   |client-java|78.57%|:green_circle:|
   |common|52.39%|:green_circle:|
   |core|83.54% **`-0.22%`**|:green_circle:|
   |filesystem-hadoop3|77.28%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|48.68%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-auth|68.0%|:green_circle:|
   |hadoop-common|12.7%|:red_circle:|
   |hive-metastore-common|53.4%|:green_circle:|
   |iceberg-aliyun-bundle|0.0%|:red_circle:|
   |iceberg-common|64.75%|:green_circle:|
   |iceberg-rest-server|75.0%|:green_circle:|
   |idp-basic|85.98%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|62.92%|:green_circle:|
   |lance-common|31.63%|:red_circle:|
   |lance-rest-server|63.47%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|83.24%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|87.44%|:green_circle:|
   |server-common|79.57%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|45.89%|:green_circle:|
   |tencent|69.84%|:green_circle:|
   |trino-connector|41.56%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |authorization-ranger|[RangerHelper.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerHelper.java)|14.55%|:red_circle:|
   ||[RangerAuthorizationPlugin.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java)|0.0%|:red_circle:|
   |core|[MetalakeMetaSQLProviderFactory.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java)|100.0%|:green_circle:|
   ||[MetalakeMetaBaseSQLProvider.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/MetalakeMetaBaseSQLProvider.java)|100.0%|:green_circle:|
   ||[CatalogMetaService.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java)|98.65%|:green_circle:|
   ||[MetalakeMetaService.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/service/MetalakeMetaService.java)|98.65%|:green_circle:|
   ||[POConverters.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java)|88.33%|:green_circle:|
   ||[CatalogMetaSQLProviderFactory.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaSQLProviderFactory.java)|85.71%|:green_circle:|
   ||[CatalogMetaBaseSQLProvider.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/CatalogMetaBaseSQLProvider.java)|83.33%|:green_circle:|
   ||[CatalogMetaPostgreSQLProvider.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/CatalogMetaPostgreSQLProvider.java)|83.33%|:green_circle:|
   ||[MetalakeMetaPostgreSQLProvider.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/MetalakeMetaPostgreSQLProvider.java)|80.0%|:green_circle:|
   ||[SchemaMetaPostgreSQLProvider.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/SchemaMetaPostgreSQLProvider.java)|75.0%|:green_circle:|
   ||[SchemaMetaSQLProviderFactory.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaSQLProviderFactory.java)|72.73%|:green_circle:|
   ||[CatalogManager.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java)|70.43%|:green_circle:|
   ||[SchemaMetaBaseSQLProvider.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/SchemaMetaBaseSQLProvider.java)|65.22%|:green_circle:|
   ||[BaseCatalog.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java)|63.45%|:green_circle:|
   ||[BaseAuthorization.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/connector/authorization/BaseAuthorization.java)|50.0%|:red_circle:|
   ||[CatalogMetaMapper.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaMapper.java)|0.0%|:red_circle:|
   ||[MetalakeMetaMapper.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaMapper.java)|0.0%|:red_circle:|
   ||[SchemaMetaMapper.java](https://github.com/roryqi/gravitino/blob/ec091fbc68d8367dd7dee1a05091e59ef9f6eefa/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaMapper.java)|0.0%|:red_circle:|
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8674] fix(authz): Isolate Ranger catalog owner roles by catalog ID [gravitino]

Posted by "roryqi (via GitHub)" <gi...@apache.org>.
roryqi merged PR #12517:
URL: https://github.com/apache/gravitino/pull/12517


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#8674] fix(authz): Isolate Ranger catalog owner roles by catalog ID [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #12517:
URL: https://github.com/apache/gravitino/pull/12517#discussion_r3819979828


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -523,9 +535,9 @@ public Boolean onOwnerSet(MetadataObject metadataObject, Owner preOwner, Owner n
       case CATALOG:
         // The metalake and catalog use role to manage the owner
         if (metadataObject.type() == MetadataObject.Type.METALAKE) {
-          ownerRoleName = RangerHelper.GRAVITINO_METALAKE_OWNER_ROLE;
+          ownerRoleName = RangerHelper.generateMetalakeOwnerRoleName(metalakeId);
         } else {
-          ownerRoleName = RangerHelper.GRAVITINO_CATALOG_OWNER_ROLE;
+          ownerRoleName = RangerHelper.generateCatalogOwnerRoleName(catalogId);

Review Comment:
   For an existing Ranger policy, updatePolicyOwnerRole only adds this new ID-specific role. It does not remove the old shared GRAVITINO_CATALOG_OWNER_ROLE or GRAVITINO_METALAKE_OWNER_ROLE. After an upgrade, users in the old shared role can still access other catalogs. Please remove the matching old shared role when migrating an existing policy.



##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -1301,14 +1302,26 @@ private Map<String, String> getResolvedProperties(CatalogEntity entity) {
   }
 
   private BaseCatalog<?> createBaseCatalog(IsolatedClassLoader classLoader, CatalogEntity entity) {
+    BaseMetalake metalakeEntity;
+    try {
+      metalakeEntity =
+          store.get(
+              NameIdentifier.of(entity.namespace().levels()),
+              EntityType.METALAKE,
+              BaseMetalake.class);
+    } catch (IOException e) {
+      throw new RuntimeException(
+          String.format("Failed to load metalake for catalog %s", entity.nameIdentifier()), e);
+    }
+
     // Load Catalog class instance
     BaseCatalog<?> catalog = createCatalogInstance(classLoader, entity.getProvider());
     // Resolve secret URNs to plaintext for connector init only; entity storage keeps URNs.
     // Fileset FS merge assumes catalog conf is already plaintext at this boundary.
     catalog
         .withCatalogConf(secretManager.toPlaintextProperties(entity.getProperties()))
         .withCatalogEntity(entity);
-    catalog.initAuthorizationPluginInstance(classLoader);
+    catalog.initAuthorizationPluginInstance(classLoader, metalakeEntity.id());

Review Comment:
   How are existing owners migrated? Passing the IDs here only affects newly created plugin actions. If a catalog owner does not change after an upgrade, the new role is not granted and the old policy is not updated. Please add an idempotent migration or reconciliation path for existing roles, members, and policies.



##########
authorizations/authorization-ranger/src/test/java/org/apache/gravitino/authorization/ranger/integration/test/RangerHiveIT.java:
##########
@@ -1492,8 +1493,8 @@ public void testOnOwnerSetCatalog() {
                   null,
                   null,
                   Lists.newArrayList(
-                      RangerHelper.GRAVITINO_METALAKE_OWNER_ROLE,
-                      RangerHelper.GRAVITINO_CATALOG_OWNER_ROLE));
+                      RangerHelper.generateMetalakeOwnerRoleName(RangerITEnv.METALAKE_ID),
+                      RangerHelper.generateCatalogOwnerRoleName(RangerITEnv.CATALOG_ID)));

Review Comment:
   Could we add a regression test with two catalogs using the same Ranger service, different IDs, and different owners? Please also start with a legacy shared owner role and policy, then verify that they are migrated. The current test uses one fresh catalog, so it does not reproduce issue #8674 or the upgrade case.



##########
core/src/main/java/org/apache/gravitino/connector/BaseCatalog.java:
##########
@@ -280,7 +280,13 @@ public AuthorizationPlugin getAuthorizationPlugin() {
     return authorizationPlugin;
   }
 
-  public void initAuthorizationPluginInstance(IsolatedClassLoader classLoader) {
+  /**
+   * Initializes the authorization plugin for this catalog.
+   *
+   * @param classLoader the catalog isolated class loader
+   * @param metalakeId the stable entity ID of the metalake containing this catalog
+   */
+  public void initAuthorizationPluginInstance(IsolatedClassLoader classLoader, long metalakeId) {

Review Comment:
   This removes the old public one-argument method. Please confirm that external catalog connectors do not use it. If it is part of the connector API, please keep a compatible overload or use another way to pass the metalake ID.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org