Search in sources :

Example 26 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class SpnegoConfig method loginAndReturnUgi.

// Performs the Server login to KDC for SPNEGO
private UserGroupInformation loginAndReturnUgi() throws DrillException {
    validateSpnegoConfig();
    UserGroupInformation ugi;
    try {
        // After the login is performed reset the static UGI state.
        if (!UserGroupInformation.isSecurityEnabled()) {
            final Configuration newConfig = new Configuration();
            newConfig.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, UserGroupInformation.AuthenticationMethod.KERBEROS.toString());
            if (clientNameMapping != null) {
                newConfig.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTH_TO_LOCAL, clientNameMapping);
            }
            UserGroupInformation.setConfiguration(newConfig);
            ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab);
            // Reset the original configuration for static UGI
            UserGroupInformation.setConfiguration(new Configuration());
        } else {
            // Let's not overwrite the rules here since it might be possible that CUSTOM security is configured for
            // JDBC/ODBC with default rules. If Kerberos was enabled then the correct rules must already be set
            ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab);
        }
    } catch (Exception e) {
        throw new DrillException(String.format("Login failed for %s with given keytab", principal), e);
    }
    return ugi;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 27 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class SSLConfigClient method initNettySslContext.

@Override
public SslContext initNettySslContext() throws DrillException {
    final SslContext sslCtx;
    if (!userSslEnabled) {
        return null;
    }
    TrustManagerFactory tmf;
    try {
        tmf = initializeTrustManagerFactory();
        sslCtx = SslContextBuilder.forClient().sslProvider(getProvider()).trustManager(tmf).protocols(protocol).build();
    } catch (Exception e) {
        // Catch any SSL initialization Exceptions here and abort.
        throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized due to the following exception: ").append("[ ").append(e.getMessage()).append("]. ").toString());
    }
    this.nettySslContext = sslCtx;
    return sslCtx;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) SslContext(io.netty.handler.ssl.SslContext)

Example 28 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class SSLConfigClient method initJDKSSLContext.

@Override
public SSLContext initJDKSSLContext() throws DrillException {
    final SSLContext sslCtx;
    if (!userSslEnabled) {
        return null;
    }
    TrustManagerFactory tmf;
    try {
        tmf = initializeTrustManagerFactory();
        sslCtx = SSLContext.getInstance(protocol);
        sslCtx.init(null, tmf.getTrustManagers(), null);
    } catch (Exception e) {
        // Catch any SSL initialization Exceptions here and abort.
        throw new DrillException(new StringBuilder().append("SSL is enabled but cannot be initialized due to the following exception: ").append("[ ").append(e.getMessage()).append("]. ").toString());
    }
    this.jdkSSlContext = sslCtx;
    return sslCtx;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException)

Aggregations

DrillException (org.apache.drill.common.exceptions.DrillException)28 SecurityTest (org.apache.drill.categories.SecurityTest)12 Test (org.junit.Test)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)10 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)6 DrillConfig (org.apache.drill.common.config.DrillConfig)6 SpnegoConfig (org.apache.drill.exec.server.rest.auth.SpnegoConfig)6 SSLConfig (org.apache.drill.exec.ssl.SSLConfig)6 SSLConfigBuilder (org.apache.drill.exec.ssl.SSLConfigBuilder)6 BaseTest (org.apache.drill.test.BaseTest)6 ConfigBuilder (org.apache.drill.test.ConfigBuilder)6 SslContext (io.netty.handler.ssl.SslContext)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 KeyStore (java.security.KeyStore)4 SSLContext (javax.net.ssl.SSLContext)4 Configuration (org.apache.hadoop.conf.Configuration)4 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2