Search in sources :

Example 1 with SystemAccessControl

use of io.trino.spi.security.SystemAccessControl in project trino by trinodb.

the class AccessControlManager method createSystemAccessControl.

private SystemAccessControl createSystemAccessControl(File configFile) {
    log.info("-- Loading system access control %s --", configFile);
    configFile = configFile.getAbsoluteFile();
    Map<String, String> properties;
    try {
        properties = new HashMap<>(loadPropertiesFrom(configFile.getPath()));
    } catch (IOException e) {
        throw new UncheckedIOException("Failed to read configuration file: " + configFile, e);
    }
    String name = properties.remove(NAME_PROPERTY);
    checkState(!isNullOrEmpty(name), "Access control configuration does not contain '%s' property: %s", NAME_PROPERTY, configFile);
    SystemAccessControlFactory factory = systemAccessControlFactories.get(name);
    checkState(factory != null, "Access control '%s' is not registered: %s", name, configFile);
    SystemAccessControl systemAccessControl;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        systemAccessControl = factory.create(ImmutableMap.copyOf(properties));
    }
    log.info("-- Loaded system access control %s --", name);
    return systemAccessControl;
}
Also used : SystemAccessControlFactory(io.trino.spi.security.SystemAccessControlFactory) ReadOnlySystemAccessControl(io.trino.plugin.base.security.ReadOnlySystemAccessControl) FileBasedSystemAccessControl(io.trino.plugin.base.security.FileBasedSystemAccessControl) SystemAccessControl(io.trino.spi.security.SystemAccessControl) ForwardingSystemAccessControl(io.trino.plugin.base.security.ForwardingSystemAccessControl) DefaultSystemAccessControl(io.trino.plugin.base.security.DefaultSystemAccessControl) AllowAllSystemAccessControl(io.trino.plugin.base.security.AllowAllSystemAccessControl) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Example 2 with SystemAccessControl

use of io.trino.spi.security.SystemAccessControl in project trino by trinodb.

the class AccessControlManager method filterSchemas.

@Override
public Set<String> filterSchemas(SecurityContext securityContext, String catalogName, Set<String> schemaNames) {
    requireNonNull(securityContext, "securityContext is null");
    requireNonNull(catalogName, "catalogName is null");
    requireNonNull(schemaNames, "schemaNames is null");
    if (filterCatalogs(securityContext, ImmutableSet.of(catalogName)).isEmpty()) {
        return ImmutableSet.of();
    }
    for (SystemAccessControl systemAccessControl : getSystemAccessControls()) {
        schemaNames = systemAccessControl.filterSchemas(securityContext.toSystemSecurityContext(), catalogName, schemaNames);
    }
    CatalogAccessControlEntry entry = getConnectorAccessControl(securityContext.getTransactionId(), catalogName);
    if (entry != null) {
        schemaNames = entry.getAccessControl().filterSchemas(entry.toConnectorSecurityContext(securityContext), schemaNames);
    }
    return schemaNames;
}
Also used : ReadOnlySystemAccessControl(io.trino.plugin.base.security.ReadOnlySystemAccessControl) FileBasedSystemAccessControl(io.trino.plugin.base.security.FileBasedSystemAccessControl) SystemAccessControl(io.trino.spi.security.SystemAccessControl) ForwardingSystemAccessControl(io.trino.plugin.base.security.ForwardingSystemAccessControl) DefaultSystemAccessControl(io.trino.plugin.base.security.DefaultSystemAccessControl) AllowAllSystemAccessControl(io.trino.plugin.base.security.AllowAllSystemAccessControl)

Example 3 with SystemAccessControl

use of io.trino.spi.security.SystemAccessControl in project trino by trinodb.

the class AccessControlManager method setSystemAccessControl.

@VisibleForTesting
protected void setSystemAccessControl(String name, Map<String, String> properties) {
    requireNonNull(name, "name is null");
    requireNonNull(properties, "properties is null");
    SystemAccessControlFactory factory = systemAccessControlFactories.get(name);
    checkState(factory != null, "Access control '%s' is not registered", name);
    SystemAccessControl systemAccessControl;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        systemAccessControl = factory.create(ImmutableMap.copyOf(properties));
    }
    setSystemAccessControls(ImmutableList.of(systemAccessControl));
}
Also used : SystemAccessControlFactory(io.trino.spi.security.SystemAccessControlFactory) ReadOnlySystemAccessControl(io.trino.plugin.base.security.ReadOnlySystemAccessControl) FileBasedSystemAccessControl(io.trino.plugin.base.security.FileBasedSystemAccessControl) SystemAccessControl(io.trino.spi.security.SystemAccessControl) ForwardingSystemAccessControl(io.trino.plugin.base.security.ForwardingSystemAccessControl) DefaultSystemAccessControl(io.trino.plugin.base.security.DefaultSystemAccessControl) AllowAllSystemAccessControl(io.trino.plugin.base.security.AllowAllSystemAccessControl) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with SystemAccessControl

use of io.trino.spi.security.SystemAccessControl in project trino by trinodb.

the class TestFileBasedSystemAccessControl method testSchemaRulesForCheckCanCreateSchema.

@Test
public void testSchemaRulesForCheckCanCreateSchema() {
    SystemAccessControl accessControl = newFileBasedSystemAccessControl("file-based-system-access-schema.json");
    accessControl.checkCanCreateSchema(ADMIN, new CatalogSchemaName("some-catalog", "bob"));
    accessControl.checkCanCreateSchema(ADMIN, new CatalogSchemaName("some-catalog", "staff"));
    accessControl.checkCanCreateSchema(ADMIN, new CatalogSchemaName("some-catalog", "authenticated"));
    accessControl.checkCanCreateSchema(ADMIN, new CatalogSchemaName("some-catalog", "test"));
    accessControl.checkCanCreateSchema(BOB, new CatalogSchemaName("some-catalog", "bob"));
    accessControl.checkCanCreateSchema(BOB, new CatalogSchemaName("some-catalog", "staff"));
    accessControl.checkCanCreateSchema(BOB, new CatalogSchemaName("some-catalog", "authenticated"));
    assertAccessDenied(() -> accessControl.checkCanCreateSchema(BOB, new CatalogSchemaName("some-catalog", "test")), CREATE_SCHEMA_ACCESS_DENIED_MESSAGE);
    accessControl.checkCanCreateSchema(CHARLIE, new CatalogSchemaName("some-catalog", "authenticated"));
    assertAccessDenied(() -> accessControl.checkCanCreateSchema(CHARLIE, new CatalogSchemaName("some-catalog", "bob")), CREATE_SCHEMA_ACCESS_DENIED_MESSAGE);
    assertAccessDenied(() -> accessControl.checkCanCreateSchema(CHARLIE, new CatalogSchemaName("some-catalog", "staff")), CREATE_SCHEMA_ACCESS_DENIED_MESSAGE);
    assertAccessDenied(() -> accessControl.checkCanCreateSchema(CHARLIE, new CatalogSchemaName("some-catalog", "test")), CREATE_SCHEMA_ACCESS_DENIED_MESSAGE);
}
Also used : SystemAccessControl(io.trino.spi.security.SystemAccessControl) CatalogSchemaName(io.trino.spi.connector.CatalogSchemaName) Test(org.testng.annotations.Test)

Example 5 with SystemAccessControl

use of io.trino.spi.security.SystemAccessControl in project trino by trinodb.

the class TestFileBasedSystemAccessControl method testTableRulesForCheckCanAddColumn.

@Test
public void testTableRulesForCheckCanAddColumn() {
    SystemAccessControl accessControl = newFileBasedSystemAccessControl("file-based-system-access-table.json");
    accessControl.checkCanAddColumn(ADMIN, new CatalogSchemaTableName("some-catalog", "bobschema", "bobtable"));
    assertAccessDenied(() -> accessControl.checkCanAddColumn(BOB, new CatalogSchemaTableName("some-catalog", "bobschema", "bobtable")), ADD_COLUMNS_ACCESS_DENIED_MESSAGE);
}
Also used : SystemAccessControl(io.trino.spi.security.SystemAccessControl) CatalogSchemaTableName(io.trino.spi.connector.CatalogSchemaTableName) Test(org.testng.annotations.Test)

Aggregations

SystemAccessControl (io.trino.spi.security.SystemAccessControl)68 Test (org.testng.annotations.Test)59 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)36 CatalogSchemaName (io.trino.spi.connector.CatalogSchemaName)12 TrinoPrincipal (io.trino.spi.security.TrinoPrincipal)12 SystemSecurityContext (io.trino.spi.security.SystemSecurityContext)10 AllowAllSystemAccessControl (io.trino.plugin.base.security.AllowAllSystemAccessControl)9 DefaultSystemAccessControl (io.trino.plugin.base.security.DefaultSystemAccessControl)9 FileBasedSystemAccessControl (io.trino.plugin.base.security.FileBasedSystemAccessControl)9 ReadOnlySystemAccessControl (io.trino.plugin.base.security.ReadOnlySystemAccessControl)9 ForwardingSystemAccessControl (io.trino.plugin.base.security.ForwardingSystemAccessControl)8 AccessDeniedException (io.trino.spi.security.AccessDeniedException)8 ViewExpression (io.trino.spi.security.ViewExpression)5 File (java.io.File)4 Files.newTemporaryFile (org.assertj.core.util.Files.newTemporaryFile)4 SchemaTableName (io.trino.spi.connector.SchemaTableName)3 SystemAccessControlFactory (io.trino.spi.security.SystemAccessControlFactory)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)2