use of io.trino.spi.connector.ConnectorAccessControl in project trino by trinodb.
the class TestFileBasedAccessControl method testSessionPropertyRules.
@Test
public void testSessionPropertyRules() {
ConnectorAccessControl accessControl = createAccessControl("session_property.json");
accessControl.checkCanSetCatalogSessionProperty(ADMIN, "dangerous");
accessControl.checkCanSetCatalogSessionProperty(ALICE, "safe");
accessControl.checkCanSetCatalogSessionProperty(ALICE, "unsafe");
accessControl.checkCanSetCatalogSessionProperty(ALICE, "staff");
accessControl.checkCanSetCatalogSessionProperty(BOB, "safe");
accessControl.checkCanSetCatalogSessionProperty(BOB, "staff");
assertDenied(() -> accessControl.checkCanSetCatalogSessionProperty(BOB, "unsafe"));
assertDenied(() -> accessControl.checkCanSetCatalogSessionProperty(ALICE, "dangerous"));
assertDenied(() -> accessControl.checkCanSetCatalogSessionProperty(CHARLIE, "safe"));
assertDenied(() -> accessControl.checkCanSetCatalogSessionProperty(CHARLIE, "staff"));
assertDenied(() -> accessControl.checkCanSetCatalogSessionProperty(JOE, "staff"));
}
use of io.trino.spi.connector.ConnectorAccessControl in project trino by trinodb.
the class TestFileBasedAccessControl method testTableFilter.
@Test
public void testTableFilter() {
ConnectorAccessControl accessControl = createAccessControl("table-filter.json");
Set<SchemaTableName> tables = ImmutableSet.<SchemaTableName>builder().add(new SchemaTableName("restricted", "any")).add(new SchemaTableName("secret", "any")).add(new SchemaTableName("aliceschema", "any")).add(new SchemaTableName("aliceschema", "bobtable")).add(new SchemaTableName("bobschema", "bob_any")).add(new SchemaTableName("bobschema", "any")).add(new SchemaTableName("any", "any")).build();
assertEquals(accessControl.filterTables(ALICE, tables), ImmutableSet.<SchemaTableName>builder().add(new SchemaTableName("aliceschema", "any")).add(new SchemaTableName("aliceschema", "bobtable")).build());
assertEquals(accessControl.filterTables(BOB, tables), ImmutableSet.<SchemaTableName>builder().add(new SchemaTableName("aliceschema", "bobtable")).add(new SchemaTableName("bobschema", "bob_any")).build());
assertEquals(accessControl.filterTables(ADMIN, tables), ImmutableSet.<SchemaTableName>builder().add(new SchemaTableName("secret", "any")).add(new SchemaTableName("aliceschema", "any")).add(new SchemaTableName("aliceschema", "bobtable")).add(new SchemaTableName("bobschema", "bob_any")).add(new SchemaTableName("bobschema", "any")).add(new SchemaTableName("any", "any")).build());
}
use of io.trino.spi.connector.ConnectorAccessControl in project trino by trinodb.
the class TestFileBasedAccessControl method testSchemaRulesForCheckCanShowTables.
@Test
public void testSchemaRulesForCheckCanShowTables() {
ConnectorAccessControl accessControl = createAccessControl("visibility.json");
accessControl.checkCanShowTables(ADMIN, "specific-schema");
accessControl.checkCanShowTables(ADMIN, "bob-schema");
accessControl.checkCanShowTables(ADMIN, "alice-schema");
accessControl.checkCanShowTables(ADMIN, "secret");
accessControl.checkCanShowTables(ADMIN, "any");
accessControl.checkCanShowTables(ALICE, "specific-schema");
accessControl.checkCanShowTables(ALICE, "alice-schema");
assertDenied(() -> accessControl.checkCanShowTables(ALICE, "bob-schema"));
assertDenied(() -> accessControl.checkCanShowTables(ALICE, "secret"));
assertDenied(() -> accessControl.checkCanShowTables(ALICE, "any"));
accessControl.checkCanShowTables(BOB, "specific-schema");
accessControl.checkCanShowTables(BOB, "bob-schema");
assertDenied(() -> accessControl.checkCanShowTables(BOB, "alice-schema"));
assertDenied(() -> accessControl.checkCanShowTables(BOB, "secret"));
assertDenied(() -> accessControl.checkCanShowTables(BOB, "any"));
accessControl.checkCanShowTables(CHARLIE, "specific-schema");
assertDenied(() -> accessControl.checkCanShowTables(CHARLIE, "bob-schema"));
assertDenied(() -> accessControl.checkCanShowTables(CHARLIE, "alice-schema"));
assertDenied(() -> accessControl.checkCanShowTables(CHARLIE, "secret"));
assertDenied(() -> accessControl.checkCanShowTables(CHARLIE, "any"));
}
use of io.trino.spi.connector.ConnectorAccessControl in project trino by trinodb.
the class InternalIcebergConnectorFactory method createConnector.
public static Connector createConnector(String catalogName, Map<String, String> config, ConnectorContext context, Module module, Optional<HiveMetastore> metastore, Optional<FileIoProvider> fileIoProvider) {
ClassLoader classLoader = InternalIcebergConnectorFactory.class.getClassLoader();
try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
Bootstrap app = new Bootstrap(new EventModule(), new MBeanModule(), new ConnectorObjectNameGeneratorModule(catalogName, "io.trino.plugin.iceberg", "trino.plugin.iceberg"), new JsonModule(), new IcebergModule(), new IcebergSecurityModule(), new IcebergCatalogModule(metastore), new HiveHdfsModule(), new HiveS3Module(), new HiveGcsModule(), new HiveAzureModule(), new HdfsAuthenticationModule(), new MBeanServerModule(), fileIoProvider.<Module>map(provider -> binder -> binder.bind(FileIoProvider.class).toInstance(provider)).orElse(binder -> binder.bind(FileIoProvider.class).to(HdfsFileIoProvider.class).in(SINGLETON)), binder -> {
binder.bind(NodeVersion.class).toInstance(new NodeVersion(context.getNodeManager().getCurrentNode().getVersion()));
binder.bind(NodeManager.class).toInstance(context.getNodeManager());
binder.bind(TypeManager.class).toInstance(context.getTypeManager());
binder.bind(PageIndexerFactory.class).toInstance(context.getPageIndexerFactory());
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
}, module);
Injector injector = app.doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
LifeCycleManager lifeCycleManager = injector.getInstance(LifeCycleManager.class);
IcebergTransactionManager transactionManager = injector.getInstance(IcebergTransactionManager.class);
ConnectorSplitManager splitManager = injector.getInstance(ConnectorSplitManager.class);
ConnectorPageSourceProvider connectorPageSource = injector.getInstance(ConnectorPageSourceProvider.class);
ConnectorPageSinkProvider pageSinkProvider = injector.getInstance(ConnectorPageSinkProvider.class);
ConnectorNodePartitioningProvider connectorDistributionProvider = injector.getInstance(ConnectorNodePartitioningProvider.class);
Set<SessionPropertiesProvider> sessionPropertiesProviders = injector.getInstance(Key.get(new TypeLiteral<Set<SessionPropertiesProvider>>() {
}));
IcebergTableProperties icebergTableProperties = injector.getInstance(IcebergTableProperties.class);
Set<Procedure> procedures = injector.getInstance(Key.get(new TypeLiteral<Set<Procedure>>() {
}));
Set<TableProcedureMetadata> tableProcedures = injector.getInstance(Key.get(new TypeLiteral<Set<TableProcedureMetadata>>() {
}));
Optional<ConnectorAccessControl> accessControl = injector.getInstance(Key.get(new TypeLiteral<Optional<ConnectorAccessControl>>() {
}));
return new IcebergConnector(lifeCycleManager, transactionManager, new ClassLoaderSafeConnectorSplitManager(splitManager, classLoader), new ClassLoaderSafeConnectorPageSourceProvider(connectorPageSource, classLoader), new ClassLoaderSafeConnectorPageSinkProvider(pageSinkProvider, classLoader), new ClassLoaderSafeNodePartitioningProvider(connectorDistributionProvider, classLoader), sessionPropertiesProviders, IcebergSchemaProperties.SCHEMA_PROPERTIES, icebergTableProperties.getTableProperties(), accessControl, procedures, tableProcedures);
}
}
use of io.trino.spi.connector.ConnectorAccessControl in project trino by trinodb.
the class TestAccessControlManager method testColumnMaskOrdering.
@Test
public void testColumnMaskOrdering() {
try (LocalQueryRunner queryRunner = LocalQueryRunner.create(TEST_SESSION)) {
TransactionManager transactionManager = queryRunner.getTransactionManager();
AccessControlManager accessControlManager = createAccessControlManager(transactionManager);
accessControlManager.addSystemAccessControlFactory(new SystemAccessControlFactory() {
@Override
public String getName() {
return "test";
}
@Override
public SystemAccessControl create(Map<String, String> config) {
return new SystemAccessControl() {
@Override
public Optional<ViewExpression> getColumnMask(SystemSecurityContext context, CatalogSchemaTableName tableName, String column, Type type) {
return Optional.of(new ViewExpression("user", Optional.empty(), Optional.empty(), "system mask"));
}
@Override
public void checkCanSetSystemSessionProperty(SystemSecurityContext context, String propertyName) {
}
};
}
});
accessControlManager.setSystemAccessControl("test", ImmutableMap.of());
queryRunner.createCatalog("catalog", MockConnectorFactory.create(), ImmutableMap.of());
accessControlManager.addCatalogAccessControl(new CatalogName("catalog"), new ConnectorAccessControl() {
@Override
public Optional<ViewExpression> getColumnMask(ConnectorSecurityContext context, SchemaTableName tableName, String column, Type type) {
return Optional.of(new ViewExpression("user", Optional.empty(), Optional.empty(), "connector mask"));
}
@Override
public void checkCanShowCreateTable(ConnectorSecurityContext context, SchemaTableName tableName) {
}
});
transaction(transactionManager, accessControlManager).execute(transactionId -> {
List<ViewExpression> masks = accessControlManager.getColumnMasks(context(transactionId), new QualifiedObjectName("catalog", "schema", "table"), "column", BIGINT);
assertEquals(masks.get(0).getExpression(), "connector mask");
assertEquals(masks.get(1).getExpression(), "system mask");
});
}
}
Aggregations