Skip to content

Commit 41968a7

Browse files
authored
Make ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS configurable per catalog (#2688)
* Update ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS to be configurable per catalog
1 parent 7f5c2a8 commit 41968a7

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

polaris-core/src/main/java/org/apache/polaris/core/config/FeatureConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public static void enforceFeatureEnabledOrThrow(
277277
.description(
278278
"When enabled, allows RBAC operations to create synthetic entities for"
279279
+ " entities in federated catalogs that don't exist in the local metastore.")
280+
.catalogConfig("polaris.config.enable-sub-catalog-rbac-for-federated-catalogs")
280281
.defaultValue(false)
281282
.buildFeatureConfiguration();
282283

runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,18 @@ private void authorizeGrantOnTableLikeOperationOrThrow(
511511
}
512512
}
513513

514+
CatalogEntity catalogEntity =
515+
CatalogEntity.of(
516+
findCatalogByName(catalogName)
517+
.orElseThrow(() -> new NotFoundException("Catalog %s not found", catalogName)));
514518
PolarisResolvedPathWrapper tableLikeWrapper =
515519
resolutionManifest.getResolvedPath(
516520
identifier, PolarisEntityType.TABLE_LIKE, PolarisEntitySubType.ANY_SUBTYPE, true);
517521
boolean rbacForFederatedCatalogsEnabled =
518522
getCurrentPolarisContext()
519523
.getRealmConfig()
520-
.getConfig(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS);
524+
.getConfig(
525+
FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS, catalogEntity);
521526
if (!(resolutionManifest.getIsPassthroughFacade() && rbacForFederatedCatalogsEnabled)
522527
&& !subTypes.contains(tableLikeWrapper.getRawLeafEntity().getSubType())) {
523528
CatalogHandler.throwNotFoundExceptionForTableLikeEntity(identifier, subTypes);
@@ -1710,7 +1715,9 @@ public PrivilegeResult grantPrivilegeOnNamespaceToRole(
17101715
boolean rbacForFederatedCatalogsEnabled =
17111716
getCurrentPolarisContext()
17121717
.getRealmConfig()
1713-
.getConfig(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS);
1718+
.getConfig(
1719+
FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS,
1720+
catalogEntity);
17141721
if (resolutionManifest.getIsPassthroughFacade() && rbacForFederatedCatalogsEnabled) {
17151722
resolvedPathWrapper =
17161723
createSyntheticNamespaceEntities(catalogEntity, namespace, resolvedPathWrapper);
@@ -2136,7 +2143,9 @@ private PrivilegeResult grantPrivilegeOnTableLikeToRole(
21362143
boolean rbacForFederatedCatalogsEnabled =
21372144
getCurrentPolarisContext()
21382145
.getRealmConfig()
2139-
.getConfig(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS);
2146+
.getConfig(
2147+
FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS,
2148+
catalogEntity);
21402149
if (resolutionManifest.getIsPassthroughFacade() && rbacForFederatedCatalogsEnabled) {
21412150
resolvedPathWrapper =
21422151
createSyntheticTableLikeEntities(

runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAdminServiceTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.junit.jupiter.api.BeforeEach;
6262
import org.junit.jupiter.api.Test;
6363
import org.mockito.Mock;
64+
import org.mockito.Mockito;
6465
import org.mockito.MockitoAnnotations;
6566

6667
public class PolarisAdminServiceTest {
@@ -90,6 +91,9 @@ void setUp() throws Exception {
9091
// Default feature configuration - enabled by default
9192
when(realmConfig.getConfig(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS))
9293
.thenReturn(true);
94+
when(realmConfig.getConfig(
95+
eq(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS), Mockito.any()))
96+
.thenReturn(true);
9397

9498
when(resolutionManifestFactory.createResolutionManifest(any(), any(), any()))
9599
.thenReturn(resolutionManifest);
@@ -358,6 +362,9 @@ void testGrantPrivilegeOnNamespaceToRole_PassthroughFacade_FeatureDisabled() thr
358362
// Disable the feature configuration
359363
when(realmConfig.getConfig(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS))
360364
.thenReturn(false);
365+
when(realmConfig.getConfig(
366+
eq(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS), Mockito.any()))
367+
.thenReturn(false);
361368

362369
PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
363370
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);
@@ -522,6 +529,9 @@ void testGrantPrivilegeOnTableLikeToRole_PassthroughFacade_FeatureDisabled() thr
522529
// Disable the feature configuration
523530
when(realmConfig.getConfig(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS))
524531
.thenReturn(false);
532+
when(realmConfig.getConfig(
533+
eq(FeatureConfiguration.ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS), Mockito.any()))
534+
.thenReturn(false);
525535

526536
PolarisEntity catalogEntity = createEntity(catalogName, PolarisEntityType.CATALOG);
527537
PolarisResolvedPathWrapper catalogWrapper = mock(PolarisResolvedPathWrapper.class);

runtime/service/src/test/java/org/apache/polaris/service/admin/PolarisAuthzTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ public Map<String, String> getConfigOverrides() {
128128
.put("polaris.features.\"DROP_WITH_PURGE_ENABLED\"", "true")
129129
.put("polaris.behavior-changes.\"ALLOW_NAMESPACE_CUSTOM_LOCATION\"", "true")
130130
.put("polaris.features.\"ENABLE_CATALOG_FEDERATION\"", "true")
131-
.put("polaris.features.\"ENABLE_SUB_CATALOG_RBAC_FOR_FEDERATED_CATALOGS\"", "true")
132131
.build();
133132
}
134133
}
@@ -303,6 +302,7 @@ public void before(TestInfo testInfo) {
303302
realmConfig,
304303
storageConfigModelForFederatedCatalog,
305304
storageLocationForFederatedCatalog)
305+
.addProperty("polaris.config.enable-sub-catalog-rbac-for-federated-catalogs", "true")
306306
.build();
307307
ExternalCatalog externalCatalog =
308308
ExternalCatalog.builder()

0 commit comments

Comments
 (0)