Search in sources :

Example 71 with DrillConfig

use of org.apache.drill.common.config.DrillConfig in project drill by apache.

the class TestExpirationHandler method tables.

private IcebergTables tables(String name, boolean shouldExpire, int retainNumber) {
    Config config = baseIcebergConfig(new File(defaultFolder.getRoot(), name)).withValue(IcebergConfigConstants.COMPONENTS_COMMON_PROPERTIES + "." + TableProperties.METADATA_PREVIOUS_VERSIONS_MAX, ConfigValueFactory.fromAnyRef(retainNumber)).withValue(IcebergConfigConstants.COMPONENTS_COMMON_PROPERTIES + "." + TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED, ConfigValueFactory.fromAnyRef(shouldExpire));
    DrillConfig drillConfig = new DrillConfig(config);
    return (IcebergTables) new IcebergMetastore(drillConfig).tables();
}
Also used : IcebergTables(org.apache.drill.metastore.iceberg.components.tables.IcebergTables) DrillConfig(org.apache.drill.common.config.DrillConfig) Config(com.typesafe.config.Config) DrillConfig(org.apache.drill.common.config.DrillConfig) IcebergMetastore(org.apache.drill.metastore.iceberg.IcebergMetastore) File(java.io.File)

Example 72 with DrillConfig

use of org.apache.drill.common.config.DrillConfig in project drill by apache.

the class DrillRoot method getPortNum.

@GET
@Path("/portNum")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Integer> getPortNum() {
    final DrillConfig config = work.getContext().getConfig();
    final int port = config.getInt(ExecConstants.HTTP_PORT);
    Map<String, Integer> portMap = new HashMap<String, Integer>();
    portMap.put("port", port);
    return portMap;
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) HashMap(java.util.HashMap) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 73 with DrillConfig

use of org.apache.drill.common.config.DrillConfig in project drill by apache.

the class BaseQueryRunner method applyUserName.

protected void applyUserName(String userName) {
    if (!Strings.isNullOrEmpty(userName)) {
        DrillConfig config = workManager.getContext().getConfig();
        if (!config.getBoolean(ExecConstants.IMPERSONATION_ENABLED)) {
            throw UserException.permissionError().message("User impersonation is not enabled").build(logger);
        }
        InboundImpersonationManager inboundImpersonationManager = new InboundImpersonationManager();
        boolean isAdmin = !config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED) || ImpersonationUtil.hasAdminPrivileges(webUserConnection.getSession().getCredentials().getUserName(), ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(options), ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(options));
        if (isAdmin) {
            // Admin user can impersonate any user they want to (when authentication is disabled, all users are admin)
            webUserConnection.getSession().replaceUserCredentials(inboundImpersonationManager, UserBitShared.UserCredentials.newBuilder().setUserName(userName).build());
        } else {
            // Check configured impersonation rules to see if this user is allowed to impersonate the given user
            inboundImpersonationManager.replaceUserOnSession(userName, webUserConnection.getSession());
        }
    }
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) InboundImpersonationManager(org.apache.drill.exec.rpc.user.InboundImpersonationManager)

Example 74 with DrillConfig

use of org.apache.drill.common.config.DrillConfig in project drill by apache.

the class TestDrillSpnegoAuthenticator method setupTest.

@BeforeClass
public static void setupTest() throws Exception {
    spnegoHelper = new KerberosHelper(TestSpnegoAuthentication.class.getSimpleName(), primaryName);
    spnegoHelper.setupKdc(dirTestWatcher.getTmpDir());
    sun.security.krb5.Config.refresh();
    // (2) Reset the default realm.
    final Field defaultRealm = KerberosName.class.getDeclaredField("defaultRealm");
    defaultRealm.setAccessible(true);
    defaultRealm.set(null, KerberosUtil.getDefaultRealm());
    // Create a DrillbitContext with service principal and keytab for DrillSpnegoLoginService
    final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.HTTP_AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("spnego"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())));
    // Create mock objects for optionManager and AuthConfiguration
    final SystemOptionManager optionManager = Mockito.mock(SystemOptionManager.class);
    Mockito.when(optionManager.getOption(ExecConstants.ADMIN_USERS_VALIDATOR)).thenReturn(ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
    Mockito.when(optionManager.getOption(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR)).thenReturn(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
    final DrillbitContext drillbitContext = Mockito.mock(DrillbitContext.class);
    Mockito.when(drillbitContext.getConfig()).thenReturn(newConfig);
    Mockito.when(drillbitContext.getOptionManager()).thenReturn(optionManager);
    Authenticator.AuthConfiguration authConfiguration = Mockito.mock(Authenticator.AuthConfiguration.class);
    spnegoAuthenticator = new DrillSpnegoAuthenticator("SPNEGO");
    DrillSpnegoLoginService spnegoLoginService = new DrillSpnegoLoginService(drillbitContext);
    Mockito.when(authConfiguration.getLoginService()).thenReturn(spnegoLoginService);
    Mockito.when(authConfiguration.getIdentityService()).thenReturn(new DefaultIdentityService());
    Mockito.when(authConfiguration.isSessionRenewedOnAuthentication()).thenReturn(true);
    // Set the login service and identity service inside SpnegoAuthenticator
    spnegoAuthenticator.setConfiguration(authConfiguration);
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) Field(java.lang.reflect.Field) DrillConfig(org.apache.drill.common.config.DrillConfig) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) DefaultIdentityService(org.eclipse.jetty.security.DefaultIdentityService) DrillSpnegoLoginService(org.apache.drill.exec.server.rest.auth.DrillSpnegoLoginService) KerberosHelper(org.apache.drill.exec.rpc.security.KerberosHelper) DrillSpnegoAuthenticator(org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator) Authenticator(org.eclipse.jetty.security.Authenticator) DrillSpnegoAuthenticator(org.apache.drill.exec.server.rest.auth.DrillSpnegoAuthenticator) BeforeClass(org.junit.BeforeClass)

Example 75 with DrillConfig

use of org.apache.drill.common.config.DrillConfig in project drill by apache.

the class TestSpnegoConfig method testValidSpnegoConfig.

/**
 * Valid Configuration with both keytab & principal
 * @throws Exception
 */
@Test
public void testValidSpnegoConfig() throws Exception {
    try {
        final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.HTTP_SPNEGO_KEYTAB, ConfigValueFactory.fromAnyRef(spnegoHelper.serverKeytab.toString())).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)));
        final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig);
        spnegoConfig.validateSpnegoConfig();
        UserGroupInformation ugi = spnegoConfig.getLoggedInUgi();
        assertEquals(primaryName, ugi.getShortUserName());
        assertEquals(spnegoHelper.SERVER_PRINCIPAL, ugi.getUserName());
    } catch (Exception ex) {
        fail();
    }
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) SpnegoConfig(org.apache.drill.exec.server.rest.auth.SpnegoConfig) DrillException(org.apache.drill.common.exceptions.DrillException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) SecurityTest(org.apache.drill.categories.SecurityTest)

Aggregations

DrillConfig (org.apache.drill.common.config.DrillConfig)249 Test (org.junit.Test)165 Properties (java.util.Properties)89 SecurityTest (org.apache.drill.categories.SecurityTest)88 DrillProperties (org.apache.drill.common.config.DrillProperties)77 NonTransientRpcException (org.apache.drill.exec.rpc.NonTransientRpcException)32 ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)29 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)28 BeforeClass (org.junit.BeforeClass)25 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)23 SaslException (javax.security.sasl.SaslException)20 RpcException (org.apache.drill.exec.rpc.RpcException)20 Drillbit (org.apache.drill.exec.server.Drillbit)20 DrillbitStartupException (org.apache.drill.exec.exception.DrillbitStartupException)18 RemoteServiceSet (org.apache.drill.exec.server.RemoteServiceSet)17 BaseTest (org.apache.drill.test.BaseTest)17 ExecTest (org.apache.drill.exec.ExecTest)14 IOException (java.io.IOException)12 IcebergMetastore (org.apache.drill.metastore.iceberg.IcebergMetastore)12 File (java.io.File)10