Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import org.apache.polaris.service.catalog.io.FileIOFactory;
import org.apache.polaris.service.config.DefaultConfigurationStore;
import org.apache.polaris.service.config.RealmEntityManagerFactory;
import org.apache.polaris.service.context.CallContextCatalogFactory;
import org.apache.polaris.service.context.PolarisCallContextCatalogFactory;
import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory;
import org.apache.polaris.service.quarkus.catalog.io.TestFileIOFactory;
import org.apache.polaris.service.storage.PolarisStorageIntegrationProviderImpl;
Expand Down Expand Up @@ -98,28 +96,19 @@ public static TestServices inMemory(FileIOFactory ioFactory, Map<String, Object>
PolarisEntityManager entityManager =
realmEntityManagerFactory.getOrCreateEntityManager(testRealm);

CallContextCatalogFactory callContextFactory =
new PolarisCallContextCatalogFactory(
entityManager,
metaStoreManager,
session,
configurationStore,
polarisDiagnostics,
Mockito.mock(TaskExecutor.class),
ioFactory);

PolarisAuthorizer authorizer = Mockito.mock(PolarisAuthorizer.class);

IcebergRestCatalogApiService service =
new IcebergCatalogAdapter(
testRealm,
callContextFactory,
entityManager,
metaStoreManager,
session,
configurationStore,
polarisDiagnostics,
authorizer);
authorizer,
Mockito.mock(TaskExecutor.class),
ioFactory);

IcebergRestCatalogApi restApi = new IcebergRestCatalogApi(service);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTestProfile;
import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Alternative;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.SecurityContext;
import java.io.IOException;
Expand All @@ -39,7 +37,6 @@
import java.util.stream.Collectors;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.Schema;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.ForbiddenException;
Expand Down Expand Up @@ -68,17 +65,13 @@
import org.apache.polaris.core.persistence.PolarisEntityManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.service.admin.PolarisAdminService;
import org.apache.polaris.service.catalog.BasePolarisCatalog;
import org.apache.polaris.service.catalog.io.DefaultFileIOFactory;
import org.apache.polaris.service.catalog.io.FileIOFactory;
import org.apache.polaris.service.config.DefaultConfigurationStore;
import org.apache.polaris.service.config.RealmEntityManagerFactory;
import org.apache.polaris.service.context.PolarisCallContextCatalogFactory;
import org.apache.polaris.service.quarkus.catalog.PolarisPassthroughResolutionView;
import org.apache.polaris.service.storage.PolarisStorageIntegrationProviderImpl;
import org.apache.polaris.service.task.TaskExecutor;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -91,11 +84,6 @@ public abstract class PolarisAuthzTestBase {

public static class Profile implements QuarkusTestProfile {

@Override
public Set<Class<?>> getEnabledAlternatives() {
return Set.of(TestPolarisCallContextCatalogFactory.class);
}

@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
Expand Down Expand Up @@ -231,6 +219,8 @@ public void before(TestInfo testInfo) {
.setName(CATALOG_NAME)
.setCatalogType("INTERNAL")
.setDefaultBaseLocation(storageLocation)
.addProperty(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO")
.setStorageConfigurationInfo(storageConfigModel, storageLocation)
.build());

Expand Down Expand Up @@ -331,7 +321,7 @@ public void after() {
Mockito.when(securityContext.getUserPrincipal()).thenReturn(p);
Set<String> principalRoleNames = loadPrincipalRolesNames(p);
Mockito.when(securityContext.isUserInRole(Mockito.anyString()))
.thenAnswer(invocation -> principalRoleNames.contains(invocation.getArgument(0)));
.thenAnswer(invocation -> principalRoleNames.contains((String) invocation.getArgument(0)));
return securityContext;
}

Expand Down Expand Up @@ -413,53 +403,6 @@ private void initBaseCatalog() {
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO"));
}

@Alternative
@RequestScoped
public static class TestPolarisCallContextCatalogFactory
extends PolarisCallContextCatalogFactory {

public TestPolarisCallContextCatalogFactory() {
super(null, null, null, null, null, null, null);
}

@Inject
public TestPolarisCallContextCatalogFactory(
PolarisEntityManager entityManager,
PolarisMetaStoreManager metaStoreManager,
PolarisMetaStoreSession metaStoreSession,
PolarisConfigurationStore configurationStore,
PolarisDiagnostics diagnostics,
TaskExecutor taskExecutor,
FileIOFactory fileIOFactory) {
super(
entityManager,
metaStoreManager,
metaStoreSession,
configurationStore,
diagnostics,
taskExecutor,
fileIOFactory);
}

@Override
public Catalog createCallContextCatalog(
RealmContext realmContext,
AuthenticatedPolarisPrincipal authenticatedPolarisPrincipal,
SecurityContext securityContext,
final PolarisResolutionManifest resolvedManifest) {
// This depends on the BasePolarisCatalog allowing calling initialize multiple times
// to override the previous config.
Catalog catalog =
super.createCallContextCatalog(
realmContext, authenticatedPolarisPrincipal, securityContext, resolvedManifest);
catalog.initialize(
CATALOG_NAME,
ImmutableMap.of(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO"));
return catalog;
}
}

/**
* Tests each "sufficient" privilege individually by invoking {@code grantAction} for each set of
* privileges, running the action being tested, revoking after each test set, and also ensuring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.polaris.service.quarkus.catalog;

import com.google.common.collect.ImmutableMap;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.ws.rs.core.SecurityContext;
Expand All @@ -34,7 +33,6 @@
import org.apache.iceberg.SortOrder;
import org.apache.iceberg.TableMetadata;
import org.apache.iceberg.TableMetadataParser;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.ForbiddenException;
Expand All @@ -54,17 +52,13 @@
import org.apache.polaris.core.admin.model.PrincipalWithCredentialsCredentials;
import org.apache.polaris.core.admin.model.StorageConfigInfo;
import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.CatalogRoleEntity;
import org.apache.polaris.core.entity.PolarisPrivilege;
import org.apache.polaris.core.entity.PrincipalEntity;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.service.catalog.PolarisCatalogHandlerWrapper;
import org.apache.polaris.service.catalog.io.DefaultFileIOFactory;
import org.apache.polaris.service.context.CallContextCatalogFactory;
import org.apache.polaris.service.context.PolarisCallContextCatalogFactory;
import org.apache.polaris.service.quarkus.admin.PolarisAuthzTestBase;
import org.apache.polaris.service.types.NotificationRequest;
import org.apache.polaris.service.types.NotificationType;
Expand All @@ -90,27 +84,24 @@ private PolarisCatalogHandlerWrapper newWrapper() {
}

private PolarisCatalogHandlerWrapper newWrapper(Set<String> activatedPrincipalRoles) {
return newWrapper(activatedPrincipalRoles, CATALOG_NAME, newCatalogFactory());
return newWrapper(activatedPrincipalRoles, CATALOG_NAME);
}

private PolarisCatalogHandlerWrapper newWrapper(
Set<String> activatedPrincipalRoles, String catalogName, CallContextCatalogFactory factory) {
Set<String> activatedPrincipalRoles, String catalogName) {
final AuthenticatedPolarisPrincipal authenticatedPrincipal =
new AuthenticatedPolarisPrincipal(principalEntity, activatedPrincipalRoles);
return new PolarisCatalogHandlerWrapper(
realmContext,
metaStoreSession,
configurationStore,
diagServices,
entityManager,
metaStoreManager,
securityContext(authenticatedPrincipal, activatedPrincipalRoles),
factory,
catalogName,
polarisAuthorizer);
SecurityContext securityContext =
securityContext(authenticatedPrincipal, activatedPrincipalRoles);
return newWrapper(securityContext, catalogName);
}

private PolarisCatalogHandlerWrapper newWrapper(SecurityContext securityContext) {
return newWrapper(securityContext, CATALOG_NAME);
}

private PolarisCatalogHandlerWrapper newWrapper(
SecurityContext securityContext, String catalogName) {
return new PolarisCatalogHandlerWrapper(
realmContext,
metaStoreSession,
Expand All @@ -119,18 +110,8 @@ private PolarisCatalogHandlerWrapper newWrapper(SecurityContext securityContext)
entityManager,
metaStoreManager,
securityContext,
newCatalogFactory(),
CATALOG_NAME,
polarisAuthorizer);
}

private CallContextCatalogFactory newCatalogFactory() {
return new TestPolarisCallContextCatalogFactory(
entityManager,
metaStoreManager,
metaStoreSession,
configurationStore,
diagServices,
catalogName,
polarisAuthorizer,
Mockito.mock(),
new DefaultFileIOFactory());
}
Expand Down Expand Up @@ -1637,6 +1618,8 @@ public void testSendNotificationSufficientPrivileges() {
.setName(externalCatalog)
.setDefaultBaseLocation(storageLocation)
.setStorageConfigurationInfo(storageConfigModel, storageLocation)
.addProperty(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO")
.setCatalogType("EXTERNAL")
.build());
adminService.createCatalogRole(
Expand Down Expand Up @@ -1699,48 +1682,23 @@ public void testSendNotificationSufficientPrivileges() {
validatePayload.setTimestamp(530950845L);
validateRequest.setPayload(validatePayload);

PolarisCallContextCatalogFactory factory =
new PolarisCallContextCatalogFactory(
entityManager,
metaStoreManager,
metaStoreSession,
configurationStore,
diagServices,
Mockito.mock(),
new DefaultFileIOFactory()) {
@Override
public Catalog createCallContextCatalog(
RealmContext realmContext,
AuthenticatedPolarisPrincipal authenticatedPolarisPrincipal,
SecurityContext securityContext,
PolarisResolutionManifest resolvedManifest) {
Catalog catalog =
super.createCallContextCatalog(
realmContext, authenticatedPolarisPrincipal, securityContext, resolvedManifest);
String fileIoImpl = "org.apache.iceberg.inmemory.InMemoryFileIO";
catalog.initialize(
externalCatalog, ImmutableMap.of(CatalogProperties.FILE_IO_IMPL, fileIoImpl));

try (FileIO fileIO =
CatalogUtil.loadFileIO(fileIoImpl, Map.of(), new Configuration())) {
TableMetadata tableMetadata =
TableMetadata.buildFromEmpty()
.addSchema(SCHEMA, SCHEMA.highestFieldId())
.setLocation(
String.format(
"%s/bucket/table/metadata/v1.metadata.json", storageLocation))
.addPartitionSpec(PartitionSpec.unpartitioned())
.addSortOrder(SortOrder.unsorted())
.assignUUID()
.build();
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(createPayload.getMetadataLocation()));
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(updatePayload.getMetadataLocation()));
}
return catalog;
}
};
try (FileIO fileIO =
CatalogUtil.loadFileIO(
"org.apache.iceberg.inmemory.InMemoryFileIO", Map.of(), new Configuration())) {
TableMetadata tableMetadata =
TableMetadata.buildFromEmpty()
.addSchema(SCHEMA, SCHEMA.highestFieldId())
.setLocation(
String.format("%s/bucket/table/metadata/v1.metadata.json", storageLocation))
.addPartitionSpec(PartitionSpec.unpartitioned())
.addSortOrder(SortOrder.unsorted())
.assignUUID()
.build();
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(createPayload.getMetadataLocation()));
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(updatePayload.getMetadataLocation()));
}

List<Set<PolarisPrivilege>> sufficientPrivilegeSets =
List.of(
Expand All @@ -1764,19 +1722,18 @@ public Catalog createCallContextCatalog(
doTestSufficientPrivilegeSets(
sufficientPrivilegeSets,
() -> {
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, createRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, updateRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
.sendNotification(table, dropRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog).sendNotification(table, dropRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, validateRequest);
},
() -> {
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog)
.dropNamespace(Namespace.of("extns1", "extns2"));
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog)
.dropNamespace(Namespace.of("extns1"));
},
PRINCIPAL_NAME,
Expand All @@ -1786,7 +1743,7 @@ public Catalog createCallContextCatalog(
doTestSufficientPrivilegeSets(
sufficientPrivilegeSets,
() -> {
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, validateRequest);
},
null /* cleanupAction */,
Expand Down
Loading
Loading