Skip to content
Draft
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 @@ -95,6 +95,7 @@ public AccessControlManager(TransactionManager transactionManager)
addSystemAccessControlFactory(new AllowAllSystemAccessControl.Factory());
addSystemAccessControlFactory(new ReadOnlySystemAccessControl.Factory());
addSystemAccessControlFactory(new FileBasedSystemAccessControl.Factory());
addSystemAccessControlFactory(new DenyQueryIntegrityCheckSystemAccessControl.Factory());
}

public void addSystemAccessControlFactory(SystemAccessControlFactory accessControlFactory)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.security;

import com.facebook.presto.common.QualifiedObjectName;
import com.facebook.presto.spi.CatalogSchemaTableName;
import com.facebook.presto.spi.MaterializedViewDefinition;
import com.facebook.presto.spi.analyzer.ViewDefinition;
import com.facebook.presto.spi.security.AccessControlContext;
import com.facebook.presto.spi.security.Identity;
import com.facebook.presto.spi.security.SystemAccessControl;
import com.facebook.presto.spi.security.SystemAccessControlFactory;

import java.security.Principal;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static com.facebook.presto.spi.security.AccessDeniedException.denyQueryIntegrityCheck;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;

public class DenyQueryIntegrityCheckSystemAccessControl
implements SystemAccessControl
{
public static final String NAME = "deny-query-integrity-check";

private static final DenyQueryIntegrityCheckSystemAccessControl INSTANCE = new DenyQueryIntegrityCheckSystemAccessControl();

public static class Factory
implements SystemAccessControlFactory
{
@Override
public String getName()
{
return NAME;
}

@Override
public SystemAccessControl create(Map<String, String> config)
{
requireNonNull(config, "config is null");
checkArgument(config.isEmpty(), "This access controller does not support any configuration properties");
return INSTANCE;
}
}

@Override
public void checkQueryIntegrity(Identity identity, AccessControlContext context, String query, Map<QualifiedObjectName, ViewDefinition> viewDefinitions, Map<QualifiedObjectName, MaterializedViewDefinition> materializedViewDefinitions)
{
denyQueryIntegrityCheck();
}

@Override
public void checkCanSetUser(Identity identity, AccessControlContext context, Optional<Principal> principal, String userName)
{
}

@Override
public void checkCanSetSystemSessionProperty(Identity identity, AccessControlContext context, String propertyName)
{
}

@Override
public void checkCanAccessCatalog(Identity identity, AccessControlContext context, String catalogName)
{
}

@Override
public Set<String> filterCatalogs(Identity identity, AccessControlContext context, Set<String> catalogs)
{
return catalogs;
}

@Override
public Set<String> filterSchemas(Identity identity, AccessControlContext context, String catalogName, Set<String> schemaNames)
{
return schemaNames;
}

@Override
public void checkCanCreateTable(Identity identity, AccessControlContext context, CatalogSchemaTableName table)
{
}

@Override
public void checkCanShowCreateTable(Identity identity, AccessControlContext context, CatalogSchemaTableName table)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,16 @@ public class TestingAccessControlManager

@Inject
public TestingAccessControlManager(TransactionManager transactionManager)
{
this(transactionManager, true);
}

public TestingAccessControlManager(TransactionManager transactionManager, boolean loadDefaultSystemAccessControl)
{
super(transactionManager);
setSystemAccessControl(AllowAllSystemAccessControl.NAME, ImmutableMap.of());
if (loadDefaultSystemAccessControl) {
setSystemAccessControl(AllowAllSystemAccessControl.NAME, ImmutableMap.of());
}
}

public static TestingPrivilege privilege(String entityName, TestingPrivilegeType type)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.testing;

import com.facebook.presto.eventlistener.EventListenerConfig;
import com.facebook.presto.eventlistener.EventListenerManager;
import com.facebook.presto.security.AccessControlManager;
import com.facebook.presto.server.GracefulShutdownHandler;
import com.facebook.presto.server.security.PrestoAuthenticatorManager;
import com.facebook.presto.spi.security.AccessControl;
import com.facebook.presto.storage.TempStorageManager;
import com.facebook.presto.transaction.TransactionManager;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;

import static java.util.Objects.requireNonNull;

public class TestingPrestoServerModule
implements Module
{
private final boolean loadDefaultSystemAccessControl;

public TestingPrestoServerModule(boolean loadDefaultSystemAccessControl)
{
this.loadDefaultSystemAccessControl = loadDefaultSystemAccessControl;
}

@Override
public void configure(Binder binder)
{
binder.bind(PrestoAuthenticatorManager.class).in(Scopes.SINGLETON);
binder.bind(TestingEventListenerManager.class).in(Scopes.SINGLETON);
binder.bind(TestingTempStorageManager.class).in(Scopes.SINGLETON);
binder.bind(EventListenerManager.class).to(TestingEventListenerManager.class).in(Scopes.SINGLETON);
binder.bind(EventListenerConfig.class).in(Scopes.SINGLETON);
binder.bind(TempStorageManager.class).to(TestingTempStorageManager.class).in(Scopes.SINGLETON);
binder.bind(AccessControl.class).to(AccessControlManager.class).in(Scopes.SINGLETON);
binder.bind(GracefulShutdownHandler.class).in(Scopes.SINGLETON);
binder.bind(ProcedureTester.class).in(Scopes.SINGLETON);
}

@Provides
@Singleton
public AccessControlManager createAccessControlManager(TransactionManager transactionManager)
{
requireNonNull(transactionManager, "transactionManager is null");
return new TestingAccessControlManager(transactionManager, loadDefaultSystemAccessControl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.facebook.presto.cost.StatsCalculator;
import com.facebook.presto.dispatcher.DispatchManager;
import com.facebook.presto.dispatcher.QueryPrerequisitesManagerModule;
import com.facebook.presto.eventlistener.EventListenerConfig;
import com.facebook.presto.eventlistener.EventListenerManager;
import com.facebook.presto.execution.QueryInfo;
import com.facebook.presto.execution.QueryManager;
Expand Down Expand Up @@ -74,7 +73,6 @@
import com.facebook.presto.spi.eventlistener.EventListener;
import com.facebook.presto.spi.function.SqlFunction;
import com.facebook.presto.spi.memory.ClusterMemoryPoolManager;
import com.facebook.presto.spi.security.AccessControl;
import com.facebook.presto.split.PageSourceManager;
import com.facebook.presto.split.SplitManager;
import com.facebook.presto.sql.analyzer.FeaturesConfig;
Expand All @@ -85,11 +83,10 @@
import com.facebook.presto.sql.planner.NodePartitioningManager;
import com.facebook.presto.sql.planner.Plan;
import com.facebook.presto.sql.planner.sanity.PlanCheckerProviderManager;
import com.facebook.presto.storage.TempStorageManager;
import com.facebook.presto.testing.ProcedureTester;
import com.facebook.presto.testing.TestingAccessControlManager;
import com.facebook.presto.testing.TestingEventListenerManager;
import com.facebook.presto.testing.TestingTempStorageManager;
import com.facebook.presto.testing.TestingPrestoServerModule;
import com.facebook.presto.testing.TestingWarningCollectorModule;
import com.facebook.presto.transaction.TransactionManager;
import com.facebook.presto.ttl.clusterttlprovidermanagers.ClusterTtlProviderManagerModule;
Expand Down Expand Up @@ -289,6 +286,42 @@ public TestingPrestoServer(
List<Module> additionalModules,
Optional<Path> dataDirectory)
throws Exception
{
this(
resourceManager,
resourceManagerEnabled,
catalogServer,
catalogServerEnabled,
coordinatorSidecar,
coordinatorSidecarEnabled,
coordinator,
skipLoadingResourceGroupConfigurationManager,
true,
properties,
environment,
discoveryUri,
parserOptions,
additionalModules,
dataDirectory);
}

public TestingPrestoServer(
boolean resourceManager,
boolean resourceManagerEnabled,
boolean catalogServer,
boolean catalogServerEnabled,
boolean coordinatorSidecar,
boolean coordinatorSidecarEnabled,
boolean coordinator,
boolean skipLoadingResourceGroupConfigurationManager,
boolean loadDefaultSystemAccessControl,
Map<String, String> properties,
String environment,
URI discoveryUri,
SqlParserOptions parserOptions,
List<Module> additionalModules,
Optional<Path> dataDirectory)
throws Exception
{
this.resourceManager = resourceManager;
this.catalogServer = catalogServer;
Expand Down Expand Up @@ -328,18 +361,9 @@ public TestingPrestoServer(
.add(new NodeTtlFetcherManagerModule())
.add(new ClusterTtlProviderManagerModule())
.add(new ClientRequestFilterModule())
.add(new TestingPrestoServerModule(loadDefaultSystemAccessControl))
.add(binder -> {
binder.bind(TestingAccessControlManager.class).in(Scopes.SINGLETON);
binder.bind(TestingEventListenerManager.class).in(Scopes.SINGLETON);
binder.bind(TestingTempStorageManager.class).in(Scopes.SINGLETON);
binder.bind(AccessControlManager.class).to(TestingAccessControlManager.class).in(Scopes.SINGLETON);
binder.bind(EventListenerManager.class).to(TestingEventListenerManager.class).in(Scopes.SINGLETON);
binder.bind(EventListenerConfig.class).in(Scopes.SINGLETON);
binder.bind(TempStorageManager.class).to(TestingTempStorageManager.class).in(Scopes.SINGLETON);
binder.bind(AccessControl.class).to(AccessControlManager.class).in(Scopes.SINGLETON);
binder.bind(ShutdownAction.class).to(TestShutdownAction.class).in(Scopes.SINGLETON);
binder.bind(GracefulShutdownHandler.class).in(Scopes.SINGLETON);
binder.bind(ProcedureTester.class).in(Scopes.SINGLETON);
binder.bind(RequestBlocker.class).in(Scopes.SINGLETON);
newSetBinder(binder, Filter.class, TheServlet.class).addBinding()
.to(RequestBlocker.class).in(Scopes.SINGLETON);
Expand Down Expand Up @@ -385,7 +409,7 @@ public TestingPrestoServer(
transactionManager = injector.getInstance(TransactionManager.class);
sqlParser = injector.getInstance(SqlParser.class);
metadata = injector.getInstance(Metadata.class);
accessControl = injector.getInstance(TestingAccessControlManager.class);
accessControl = (TestingAccessControlManager) injector.getInstance(AccessControlManager.class);
procedureTester = injector.getInstance(ProcedureTester.class);
splitManager = injector.getInstance(SplitManager.class);
pageSourceManager = injector.getInstance(PageSourceManager.class);
Expand Down
Loading
Loading