You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by pa...@apache.org on 2017/10/20 00:19:35 UTC
[1/2] drill git commit: DRILL-5881:Java Client: [Threat Modeling]
Drillbit may be spoofed by an attacker and this may lead to data being
written to the attacker's target instead of Drillbit Also set connection to
null after its closed
Repository: drill
Updated Branches:
refs/heads/master 779703421 -> f1d1945b3
DRILL-5881:Java Client: [Threat Modeling] Drillbit may be spoofed by an attacker and this may lead to data being written to the attacker's target instead of Drillbit
Also set connection to null after its closed
This closes #999
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/40d09919
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/40d09919
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/40d09919
Branch: refs/heads/master
Commit: 40d0991998a4174cf5d4b12f695380e97aba4fd3
Parents: 7797034
Author: Sorabh Hamirwasia <sh...@maprtech.com>
Authored: Mon Oct 16 14:58:31 2017 -0700
Committer: Parth Chandra <pa...@apache.org>
Committed: Thu Oct 19 17:12:38 2017 -0700
----------------------------------------------------------------------
.../apache/drill/exec/rpc/user/UserClient.java | 69 +++-
.../security/TestUserBitSaslCompatibility.java | 317 +++++++++++++++++++
.../org/apache/drill/exec/rpc/BasicClient.java | 1 +
3 files changed, 377 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/40d09919/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
index 99614bd..fb78812 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserClient.java
@@ -202,7 +202,8 @@ public class UserClient
.checkedGet(sslConfig.getHandshakeTimeout(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
String msg = new StringBuilder().append(
- "Connecting to the server timed out. This is sometimes due to a mismatch in the SSL configuration between client and server. [ Exception: ")
+ "Connecting to the server timed out. This is sometimes due to a mismatch in the SSL configuration between" +
+ " client and server. [ Exception: ")
.append(e.getMessage()).append("]").toString();
throw new NonTransientRpcException(msg);
}
@@ -210,15 +211,8 @@ public class UserClient
connect(hsBuilder.build(), endpoint).checkedGet();
}
- // Check if client needs encryption and server is not configured for encryption.
- final boolean clientNeedsEncryption = properties.containsKey(DrillProperties.SASL_ENCRYPT) && Boolean
- .parseBoolean(properties.getProperty(DrillProperties.SASL_ENCRYPT));
-
- if (clientNeedsEncryption && !connection.isEncryptionEnabled()) {
- throw new NonTransientRpcException(
- "Client needs encrypted connection but server is not configured for "
- + "encryption. Please check connection parameter or contact your administrator");
- }
+ // Validate if both client and server are compatible in their security requirements for the connection
+ validateSaslCompatibility(properties);
if (serverAuthMechanisms != null) {
try {
@@ -229,6 +223,61 @@ public class UserClient
}
}
+ /**
+ * Validate that security requirements from client and Drillbit side is compatible. For example: It verifies if one
+ * side needs authentication / encryption then other side is also configured to support that security properties.
+ * @param properties - DrillClient connection parameters
+ * @throws NonTransientRpcException - When DrillClient security requirements doesn't match Drillbit side of security
+ * configurations.
+ */
+ private void validateSaslCompatibility(DrillProperties properties) throws NonTransientRpcException {
+
+ final boolean clientNeedsEncryption = properties.containsKey(DrillProperties.SASL_ENCRYPT)
+ && Boolean.parseBoolean(properties.getProperty(DrillProperties.SASL_ENCRYPT));
+
+ // Check if client needs encryption and server is not configured for encryption.
+ if (clientNeedsEncryption && !connection.isEncryptionEnabled()) {
+ throw new NonTransientRpcException(
+ "Client needs encrypted connection but server is not configured for encryption." +
+ " Please contact your administrator. [Warn: It may be due to wrong config or a security attack in" +
+ " progress.]");
+ }
+
+ // Check if client needs encryption and server doesn't support any security mechanisms.
+ if (clientNeedsEncryption && serverAuthMechanisms == null) {
+ throw new NonTransientRpcException(
+ "Client needs encrypted connection but server doesn't support any security mechanisms." +
+ " Please contact your administrator. [Warn: It may be due to wrong config or a security attack in" +
+ " progress.]");
+ }
+
+ // Check if client needs authentication and server doesn't support any security mechanisms.
+ if (clientNeedsAuth(properties) && serverAuthMechanisms == null) {
+ throw new NonTransientRpcException(
+ "Client needs authentication but server doesn't support any security mechanisms." +
+ " Please contact your administrator. [Warn: It may be due to wrong config or a security attack in" +
+ " progress.]");
+ }
+ }
+
+ /**
+ * Determine if client needs authenticated connection or not. It checks for following as an indication of
+ * requiring authentication from client side:
+ * 1) Any auth mechanism is provided in connection properties with DrillProperties.AUTH_MECHANISM parameter.
+ * 2) A service principal is provided in connection properties in which case we treat AUTH_MECHANISM as Kerberos
+ * 3) Username and Password is provided in connection properties in which case we treat AUTH_MECHANISM as Plain
+ * @param props - DrillClient connection parameters
+ * @return - true - If any of above 3 checks is successful.
+ * - false - If all the above 3 checks failed.
+ */
+ private boolean clientNeedsAuth(DrillProperties props) {
+
+ return !Strings.isNullOrEmpty(props.getProperty(DrillProperties.AUTH_MECHANISM)) ||
+ !Strings.isNullOrEmpty(props.getProperty(DrillProperties.SERVICE_PRINCIPAL)) ||
+ (props.containsKey(DrillProperties.USER) && !Strings.isNullOrEmpty(props.getProperty(DrillProperties.PASSWORD)));
+
+ }
+
private CheckedFuture<Void, RpcException> connect(final UserToBitHandshake handshake,
final DrillbitEndpoint endpoint) {
final SettableFuture<Void> connectionSettable = SettableFuture.create();
http://git-wip-us.apache.org/repos/asf/drill/blob/40d09919/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java
new file mode 100644
index 0000000..bbb957d
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitSaslCompatibility.java
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.drill.exec.rpc.user.security;
+
+
+import com.google.common.collect.Lists;
+import com.typesafe.config.ConfigValueFactory;
+import org.apache.drill.BaseTestQuery;
+import org.apache.drill.common.config.DrillConfig;
+import org.apache.drill.common.config.DrillProperties;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.rpc.NonTransientRpcException;
+import org.apache.drill.exec.rpc.user.security.testing.UserAuthenticatorTestImpl;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.security.sasl.SaslException;
+import java.util.Properties;
+
+import static junit.framework.TestCase.assertTrue;
+import static junit.framework.TestCase.fail;
+
+/**
+ * Helps to test different scenarios based on security configuration on client and Drillbit side with respect to SASL
+ * and specifically using PLAIN mechanism
+ */
+public class TestUserBitSaslCompatibility extends BaseTestQuery {
+ //private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TestUserClient.class);
+
+ @BeforeClass
+ public static void setup() {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
+ ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
+ .withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
+ ConfigValueFactory.fromIterable(Lists.newArrayList("plain")))
+ .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+ connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
+
+ updateTestCluster(1, newConfig, connectionProps);
+ }
+
+ /**
+ * Test showing failure before SASL handshake when Drillbit is not configured for authentication whereas client
+ * explicitly requested for authentication.
+ * @throws Exception
+ */
+ @Test
+ public void testDisableDrillbitAuth_EnableClientAuth() throws Exception {
+
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+ connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause() instanceof NonTransientRpcException);
+ assertTrue(!(ex.getCause().getCause() instanceof SaslException));
+ }
+ }
+
+ /**
+ * Test showing failure before SASL handshake when Drillbit is not configured for authentication whereas client
+ * explicitly requested for encrypted connection.
+ * @throws Exception
+ */
+ @Test
+ public void testDisableDrillbitAuth_EnableClientEncryption() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+ connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
+ connectionProps.setProperty(DrillProperties.SASL_ENCRYPT, "true");
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause() instanceof NonTransientRpcException);
+ assertTrue(!(ex.getCause().getCause() instanceof SaslException));
+ }
+ }
+
+ /**
+ * Test showing failure before SASL handshake when Drillbit is not configured for encryption whereas client explicitly
+ * requested for encrypted connection.
+ * @throws Exception
+ */
+ @Test
+ public void testDisableDrillbitEncryption_EnableClientEncryption() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
+ ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
+ .withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
+ ConfigValueFactory.fromIterable(Lists.newArrayList("plain")))
+ .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+ connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
+ connectionProps.setProperty(DrillProperties.SASL_ENCRYPT, "true");
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause() instanceof NonTransientRpcException);
+ assertTrue(!(ex.getCause().getCause() instanceof SaslException));
+ }
+ }
+
+ /**
+ * Test showing failure in SASL handshake when Drillbit is configured for authentication only whereas client doesn't
+ * provide any security properties like username/password in this case.
+ * @throws Exception
+ */
+ @Test
+ public void testEnableDrillbitAuth_DisableClientAuth() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
+ ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
+ .withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
+ ConfigValueFactory.fromIterable(Lists.newArrayList("plain")))
+ .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause() instanceof NonTransientRpcException);
+ assertTrue(ex.getCause().getCause() instanceof SaslException);
+ }
+ }
+
+ /**
+ * Test showing failure in SASL handshake when Drillbit is configured for encryption whereas client doesn't provide any
+ * security properties like username/password in this case.
+ * @throws Exception
+ */
+ @Test
+ public void testEnableDrillbitEncryption_DisableClientAuth() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
+ ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
+ .withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
+ ConfigValueFactory.fromIterable(Lists.newArrayList("plain")))
+ .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED,
+ ConfigValueFactory.fromAnyRef(true)),
+ false);
+
+ final Properties connectionProps = new Properties();
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause() instanceof NonTransientRpcException);
+ assertTrue(ex.getCause().getCause() instanceof SaslException);
+ }
+ }
+
+ /**
+ * Test showing successful SASL handshake when both Drillbit and client side authentication is enabled using PLAIN
+ * mechanism.
+ * @throws Exception
+ */
+ @Test
+ public void testEnableDrillbitClientAuth() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
+ ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
+ .withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
+ ConfigValueFactory.fromIterable(Lists.newArrayList("plain")))
+ .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+ connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ } catch (Exception ex) {
+ fail();
+ }
+ }
+
+ /**
+ * Below test shows the failure in Sasl layer with client and Drillbit side encryption enabled using PLAIN
+ * mechanism. This is expected since PLAIN mechanism doesn't support encryption using SASL. Whereas same test
+ * setup using Kerberos or any other mechanism with encryption support will result in successful SASL handshake.
+ * @throws Exception
+ */
+ @Test
+ public void testEnableDrillbitClientEncryption_UsingPlain() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
+ ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
+ .withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
+ ConfigValueFactory.fromIterable(Lists.newArrayList("plain")))
+ .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED,
+ ConfigValueFactory.fromAnyRef(true)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+ connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
+ connectionProps.setProperty(DrillProperties.SASL_ENCRYPT, "true");
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ fail();
+ } catch (Exception ex) {
+ assertTrue(ex.getCause() instanceof NonTransientRpcException);
+ assertTrue(ex.getCause().getCause() instanceof SaslException);
+ }
+ }
+
+ /**
+ * Test showing successful handshake when authentication is disabled on Drillbit side and client also
+ * doesn't provide any security properties in connection URL.
+ * @throws Exception
+ */
+ @Test
+ public void testDisableDrillbitClientAuth() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(false)),
+ false);
+
+ final Properties connectionProps = new Properties();
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ } catch (Exception ex) {
+ fail();
+ }
+ }
+
+ /**
+ * Test showing successful handshake when authentication is disabled but impersonation is enabled on Drillbit side
+ * and client only provides USERNAME as a security property in connection URL.
+ * @throws Exception
+ */
+ @Test
+ public void testEnableDrillbitImpersonation_DisableClientAuth() throws Exception {
+ final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
+ .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(false))
+ .withValue(ExecConstants.IMPERSONATION_ENABLED,
+ ConfigValueFactory.fromAnyRef(true))
+ .withValue(ExecConstants.IMPERSONATION_MAX_CHAINED_USER_HOPS,
+ ConfigValueFactory.fromAnyRef(3)),
+ false);
+
+ final Properties connectionProps = new Properties();
+ connectionProps.setProperty(DrillProperties.USER, "anonymous");
+
+ try {
+ updateTestCluster(1, newConfig, connectionProps);
+ } catch (Exception ex) {
+ fail();
+ }
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/drill/blob/40d09919/exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java
----------------------------------------------------------------------
diff --git a/exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java b/exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java
index 0d80df6..0f4ef1b 100644
--- a/exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java
+++ b/exec/rpc/src/main/java/org/apache/drill/exec/rpc/BasicClient.java
@@ -254,6 +254,7 @@ public abstract class BasicClient<T extends EnumLite, CC extends ClientConnectio
if (connection != null) {
connection.close();
+ connection = null;
}
}
}
[2/2] drill git commit: DRILL-5582: C++ Client: [Threat Modeling]
Drillbit may be spoofed by an attacker and this may lead to data being
written to the attacker's target instead of Drillbit
Posted by pa...@apache.org.
DRILL-5582: C++ Client: [Threat Modeling] Drillbit may be spoofed by an attacker and this may lead to data being written to the attacker's target instead of Drillbit
This closes #997
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/f1d1945b
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/f1d1945b
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/f1d1945b
Branch: refs/heads/master
Commit: f1d1945b3772bb782039fd6811e34a7de66441c8
Parents: 40d0991
Author: karthik <km...@maprtech.com>
Authored: Tue Oct 17 16:18:45 2017 -0700
Committer: Parth Chandra <pa...@apache.org>
Committed: Thu Oct 19 17:13:05 2017 -0700
----------------------------------------------------------------------
.../client/src/clientlib/drillClientImpl.cpp | 22 ++++++++++++++++++--
.../client/src/clientlib/drillClientImpl.hpp | 3 +++
contrib/native/client/src/clientlib/errmsgs.cpp | 6 ++++++
contrib/native/client/src/clientlib/errmsgs.hpp | 4 +++-
.../src/clientlib/saslAuthenticatorImpl.cpp | 2 ++
5 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/f1d1945b/contrib/native/client/src/clientlib/drillClientImpl.cpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/drillClientImpl.cpp b/contrib/native/client/src/clientlib/drillClientImpl.cpp
index f0bb636..9fdd725 100644
--- a/contrib/native/client/src/clientlib/drillClientImpl.cpp
+++ b/contrib/native/client/src/clientlib/drillClientImpl.cpp
@@ -518,6 +518,21 @@ bool DrillClientImpl::clientNeedsEncryption(const DrillUserProperties* userPrope
return needsEncryption;
}
+/*
+ * Checks if the client has explicitly expressed interest in authenticated connections only.
+ * If the USERPROP_PASSWORD or USERPROP_AUTH_MECHANISM connection string properties are
+ * non-empty, then it is implied that the client wants authentication.
+ */
+bool DrillClientImpl::clientNeedsAuthentication(const DrillUserProperties* userProperties) {
+ bool needsAuthentication = false;
+ if(!userProperties) { return false; }
+ std::string passwd = "";
+ userProperties->getProp(USERPROP_PASSWORD, passwd);
+ std::string authMech = "";
+ userProperties->getProp(USERPROP_AUTH_MECHANISM, authMech);
+ return !passwd.empty() || !authMech.empty();
+}
+
connectionStatus_t DrillClientImpl::validateHandshake(DrillUserProperties* properties){
DRILL_MT_LOG(DRILL_LOG(LOG_TRACE) << "validateHandShake\n";)
@@ -595,6 +610,10 @@ connectionStatus_t DrillClientImpl::validateHandshake(DrillUserProperties* prope
switch(this->m_handshakeStatus) {
case exec::user::SUCCESS:
+ // Check if client needs auth/encryption and server is not requiring it
+ if(clientNeedsAuthentication(properties) || clientNeedsEncryption(properties)) {
+ return handleConnError(CONN_AUTH_FAILED, getMessage(ERR_CONN_NOSERVERAUTH));
+ }
// reset io_service after handshake is validated before running queries
m_io_service.reset();
return CONN_SUCCESS;
@@ -630,8 +649,7 @@ connectionStatus_t DrillClientImpl::handleAuthentication(const DrillUserProperti
// Check if client needs encryption and server is configured for encryption or not before starting handshake
if(clientNeedsEncryption(userProperties) && !m_encryptionCtxt.isEncryptionReqd()) {
- return handleConnError(CONN_AUTH_FAILED, "Client needs encryption but on server side encryption is disabled."
- " Please check connection parameters or contact administrator?");
+ return handleConnError(CONN_AUTH_FAILED, getMessage(ERR_CONN_NOSERVERENC));
}
try {
http://git-wip-us.apache.org/repos/asf/drill/blob/f1d1945b/contrib/native/client/src/clientlib/drillClientImpl.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/drillClientImpl.hpp b/contrib/native/client/src/clientlib/drillClientImpl.hpp
index dc4a67e..2e7623e 100644
--- a/contrib/native/client/src/clientlib/drillClientImpl.hpp
+++ b/contrib/native/client/src/clientlib/drillClientImpl.hpp
@@ -474,6 +474,9 @@ class DrillClientImpl : public DrillClientImplBase{
void freeMetadata(meta::DrillMetadata* metadata);
+ static bool clientNeedsAuthentication(const DrillUserProperties* userProperties);
+
+
private:
friend class meta::DrillMetadata;
friend class DrillClientQueryHandle;
http://git-wip-us.apache.org/repos/asf/drill/blob/f1d1945b/contrib/native/client/src/clientlib/errmsgs.cpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/errmsgs.cpp b/contrib/native/client/src/clientlib/errmsgs.cpp
index d2d8c18..a5d4a44 100644
--- a/contrib/native/client/src/clientlib/errmsgs.cpp
+++ b/contrib/native/client/src/clientlib/errmsgs.cpp
@@ -52,6 +52,12 @@ static Drill::ErrorMessages errorMessages[]={
{ERR_CONN_NOCONNSTR, ERR_CATEGORY_CONN, 0, "Cannot connect if either host name or port number are empty."},
{ERR_CONN_SSLCERTFAIL, ERR_CATEGORY_CONN, 0, "SSL certificate file %s could not be loaded (exception message: %s)."},
{ERR_CONN_NOSOCKET, ERR_CATEGORY_CONN, 0, "Failed to open socket connection."},
+ {ERR_CONN_NOSERVERAUTH, ERR_CATEGORY_CONN, 0, "Client needs a secure connection but server does not"
+ " support any security mechanisms. Please contact an administrator. [Warn: This"
+ " could be due to a bad configuration or a security attack is in progress.]"},
+ {ERR_CONN_NOSERVERENC, ERR_CATEGORY_CONN, 0, "Client needs encryption but encryption is disabled on the server."
+ " Please check connection parameters or contact administrator. [Warn: This"
+ " could be due to a bad configuration or a security attack is in progress.]"},
{ERR_QRY_OUTOFMEM, ERR_CATEGORY_QRY, 0, "Out of memory."},
{ERR_QRY_COMMERR, ERR_CATEGORY_QRY, 0, "Communication error. %s"},
{ERR_QRY_INVREADLEN, ERR_CATEGORY_QRY, 0, "Internal Error: Received a message with an invalid read length."},
http://git-wip-us.apache.org/repos/asf/drill/blob/f1d1945b/contrib/native/client/src/clientlib/errmsgs.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/errmsgs.hpp b/contrib/native/client/src/clientlib/errmsgs.hpp
index 246e4bb..c4a0080 100644
--- a/contrib/native/client/src/clientlib/errmsgs.hpp
+++ b/contrib/native/client/src/clientlib/errmsgs.hpp
@@ -54,7 +54,9 @@ namespace Drill{
#define ERR_CONN_NOCONNSTR DRILL_ERR_START+21
#define ERR_CONN_SSLCERTFAIL DRILL_ERR_START+22
#define ERR_CONN_NOSOCKET DRILL_ERR_START+23
-#define ERR_CONN_MAX DRILL_ERR_START+23
+#define ERR_CONN_NOSERVERAUTH DRILL_ERR_START+24
+#define ERR_CONN_NOSERVERENC DRILL_ERR_START+25
+#define ERR_CONN_MAX DRILL_ERR_START+25
#define ERR_QRY_OUTOFMEM ERR_CONN_MAX+1
#define ERR_QRY_COMMERR ERR_CONN_MAX+2
http://git-wip-us.apache.org/repos/asf/drill/blob/f1d1945b/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp b/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp
index 78f99b6..9057a37 100644
--- a/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp
+++ b/contrib/native/client/src/clientlib/saslAuthenticatorImpl.cpp
@@ -145,6 +145,8 @@ int SaslAuthenticatorImpl::init(const std::vector<std::string>& mechanisms, exec
authMechanismToUse = value;
}
}
+ // clientNeedsAuthentication() cannot be false if the code above picks an authMechanism
+ assert (authMechanismToUse.empty() || DrillClientImpl::clientNeedsAuthentication(m_pUserProperties));
if (authMechanismToUse.empty()) return SASL_NOMECH;
// check if requested mechanism is supported by server