svn merge -c 1408473
FIXES: HADOOP-9021. Enforce configured SASL method on the server (daryn via bobby)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1408475 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
32850b486b
commit
8bad6b3eb3
|
@ -76,6 +76,9 @@ Release 2.0.3-alpha - Unreleased
|
||||||
|
|
||||||
HADOOP-9015. Standardize creation of SaslRpcServers (daryn via bobby)
|
HADOOP-9015. Standardize creation of SaslRpcServers (daryn via bobby)
|
||||||
|
|
||||||
|
HADOOP-9021. Enforce configured SASL method on the server (daryn via
|
||||||
|
bobby)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang
|
HADOOP-8866. SampleQuantiles#query is O(N^2) instead of O(N). (Andrew Wang
|
||||||
|
|
|
@ -45,6 +45,7 @@ import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -84,7 +85,9 @@ import org.apache.hadoop.security.SaslRpcServer.AuthMethod;
|
||||||
import org.apache.hadoop.security.SaslRpcServer.SaslDigestCallbackHandler;
|
import org.apache.hadoop.security.SaslRpcServer.SaslDigestCallbackHandler;
|
||||||
import org.apache.hadoop.security.SaslRpcServer.SaslGssCallbackHandler;
|
import org.apache.hadoop.security.SaslRpcServer.SaslGssCallbackHandler;
|
||||||
import org.apache.hadoop.security.SaslRpcServer.SaslStatus;
|
import org.apache.hadoop.security.SaslRpcServer.SaslStatus;
|
||||||
|
import org.apache.hadoop.security.SecurityUtil;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
|
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
|
||||||
import org.apache.hadoop.security.authentication.util.KerberosName;
|
import org.apache.hadoop.security.authentication.util.KerberosName;
|
||||||
import org.apache.hadoop.security.authorize.AuthorizationException;
|
import org.apache.hadoop.security.authorize.AuthorizationException;
|
||||||
import org.apache.hadoop.security.authorize.PolicyProvider;
|
import org.apache.hadoop.security.authorize.PolicyProvider;
|
||||||
|
@ -108,7 +111,7 @@ import com.google.common.annotations.VisibleForTesting;
|
||||||
*/
|
*/
|
||||||
public abstract class Server {
|
public abstract class Server {
|
||||||
private final boolean authorize;
|
private final boolean authorize;
|
||||||
private boolean isSecurityEnabled;
|
private EnumSet<AuthMethod> enabledAuthMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The first four bytes of Hadoop RPC connections
|
* The first four bytes of Hadoop RPC connections
|
||||||
|
@ -1293,34 +1296,9 @@ public abstract class Server {
|
||||||
if (authMethod == null) {
|
if (authMethod == null) {
|
||||||
throw new IOException("Unable to read authentication method");
|
throw new IOException("Unable to read authentication method");
|
||||||
}
|
}
|
||||||
boolean useSaslServer = isSecurityEnabled;
|
|
||||||
final boolean clientUsingSasl;
|
// this may create a SASL server, or switch us into SIMPLE
|
||||||
switch (authMethod) {
|
authMethod = initializeAuthContext(authMethod);
|
||||||
case SIMPLE: { // no sasl for simple
|
|
||||||
clientUsingSasl = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DIGEST: { // always allow tokens if there's a secret manager
|
|
||||||
useSaslServer |= (secretManager != null);
|
|
||||||
clientUsingSasl = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
clientUsingSasl = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (useSaslServer) {
|
|
||||||
saslServer = createSaslServer(authMethod);
|
|
||||||
} else if (clientUsingSasl) { // security is off
|
|
||||||
doSaslReply(SaslStatus.SUCCESS, new IntWritable(
|
|
||||||
SaslRpcServer.SWITCH_TO_SIMPLE_AUTH), null, null);
|
|
||||||
authMethod = AuthMethod.SIMPLE;
|
|
||||||
// client has already sent the initial Sasl message and we
|
|
||||||
// should ignore it. Both client and server should fall back
|
|
||||||
// to simple auth from now on.
|
|
||||||
skipInitialSaslHandshake = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
connectionHeaderBuf = null;
|
connectionHeaderBuf = null;
|
||||||
connectionHeaderRead = true;
|
connectionHeaderRead = true;
|
||||||
|
@ -1368,10 +1346,24 @@ public abstract class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SaslServer createSaslServer(AuthMethod authMethod)
|
private AuthMethod initializeAuthContext(AuthMethod authMethod)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
return createSaslServerInternal(authMethod);
|
if (enabledAuthMethods.contains(authMethod)) {
|
||||||
|
saslServer = createSaslServer(authMethod);
|
||||||
|
} else if (enabledAuthMethods.contains(AuthMethod.SIMPLE)) {
|
||||||
|
doSaslReply(SaslStatus.SUCCESS, new IntWritable(
|
||||||
|
SaslRpcServer.SWITCH_TO_SIMPLE_AUTH), null, null);
|
||||||
|
authMethod = AuthMethod.SIMPLE;
|
||||||
|
// client has already sent the initial Sasl message and we
|
||||||
|
// should ignore it. Both client and server should fall back
|
||||||
|
// to simple auth from now on.
|
||||||
|
skipInitialSaslHandshake = true;
|
||||||
|
} else {
|
||||||
|
throw new AccessControlException(
|
||||||
|
authMethod + " authentication is not enabled."
|
||||||
|
+ " Available:" + enabledAuthMethods);
|
||||||
|
}
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
final String ioeClass = ioe.getClass().getName();
|
final String ioeClass = ioe.getClass().getName();
|
||||||
final String ioeMessage = ioe.getLocalizedMessage();
|
final String ioeMessage = ioe.getLocalizedMessage();
|
||||||
|
@ -1384,9 +1376,10 @@ public abstract class Server {
|
||||||
}
|
}
|
||||||
throw ioe;
|
throw ioe;
|
||||||
}
|
}
|
||||||
|
return authMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SaslServer createSaslServerInternal(AuthMethod authMethod)
|
private SaslServer createSaslServer(AuthMethod authMethod)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
SaslServer saslServer = null;
|
SaslServer saslServer = null;
|
||||||
String hostname = null;
|
String hostname = null;
|
||||||
|
@ -1395,18 +1388,9 @@ public abstract class Server {
|
||||||
|
|
||||||
switch (authMethod) {
|
switch (authMethod) {
|
||||||
case SIMPLE: {
|
case SIMPLE: {
|
||||||
throw new AccessControlException("Authorization ("
|
return null; // no sasl for simple
|
||||||
+ CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION
|
|
||||||
+ ") is enabled but authentication ("
|
|
||||||
+ CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION
|
|
||||||
+ ") is configured as simple. Please configure another method "
|
|
||||||
+ "like kerberos or digest.");
|
|
||||||
}
|
}
|
||||||
case DIGEST: {
|
case DIGEST: {
|
||||||
if (secretManager == null) {
|
|
||||||
throw new AccessControlException(
|
|
||||||
"Server is not configured to do DIGEST authentication.");
|
|
||||||
}
|
|
||||||
secretManager.checkAvailableForRead();
|
secretManager.checkAvailableForRead();
|
||||||
hostname = SaslRpcServer.SASL_DEFAULT_REALM;
|
hostname = SaslRpcServer.SASL_DEFAULT_REALM;
|
||||||
saslCallback = new SaslDigestCallbackHandler(secretManager, this);
|
saslCallback = new SaslDigestCallbackHandler(secretManager, this);
|
||||||
|
@ -1428,6 +1412,7 @@ public abstract class Server {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
// we should never be able to get here
|
||||||
throw new AccessControlException(
|
throw new AccessControlException(
|
||||||
"Server does not support SASL " + authMethod);
|
"Server does not support SASL " + authMethod);
|
||||||
}
|
}
|
||||||
|
@ -1867,7 +1852,9 @@ public abstract class Server {
|
||||||
this.authorize =
|
this.authorize =
|
||||||
conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
|
conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
|
||||||
false);
|
false);
|
||||||
this.isSecurityEnabled = UserGroupInformation.isSecurityEnabled();
|
|
||||||
|
// configure supported authentications
|
||||||
|
this.enabledAuthMethods = getAuthMethods(secretManager, conf);
|
||||||
|
|
||||||
// Start the listener here and let it bind to the port
|
// Start the listener here and let it bind to the port
|
||||||
listener = new Listener();
|
listener = new Listener();
|
||||||
|
@ -1886,6 +1873,31 @@ public abstract class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the security type from the conf. implicitly include token support
|
||||||
|
// if a secret manager is provided, or fail if token is the conf value but
|
||||||
|
// there is no secret manager
|
||||||
|
private EnumSet<AuthMethod> getAuthMethods(SecretManager<?> secretManager,
|
||||||
|
Configuration conf) {
|
||||||
|
AuthenticationMethod confAuthenticationMethod =
|
||||||
|
SecurityUtil.getAuthenticationMethod(conf);
|
||||||
|
EnumSet<AuthMethod> authMethods =
|
||||||
|
EnumSet.of(confAuthenticationMethod.getAuthMethod());
|
||||||
|
|
||||||
|
if (confAuthenticationMethod == AuthenticationMethod.TOKEN) {
|
||||||
|
if (secretManager == null) {
|
||||||
|
throw new IllegalArgumentException(AuthenticationMethod.TOKEN +
|
||||||
|
" authentication requires a secret manager");
|
||||||
|
}
|
||||||
|
} else if (secretManager != null) {
|
||||||
|
LOG.debug(AuthenticationMethod.TOKEN +
|
||||||
|
" authentication enabled for secret manager");
|
||||||
|
authMethods.add(AuthenticationMethod.TOKEN.getAuthMethod());
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.debug("Server accepts auth methods:" + authMethods);
|
||||||
|
return authMethods;
|
||||||
|
}
|
||||||
|
|
||||||
private void closeConnection(Connection connection) {
|
private void closeConnection(Connection connection) {
|
||||||
synchronized (connectionList) {
|
synchronized (connectionList) {
|
||||||
if (connectionList.remove(connection))
|
if (connectionList.remove(connection))
|
||||||
|
@ -2002,16 +2014,6 @@ public abstract class Server {
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** for unit testing only, should be called before server is started */
|
|
||||||
void disableSecurity() {
|
|
||||||
this.isSecurityEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** for unit testing only, should be called before server is started */
|
|
||||||
void enableSecurity() {
|
|
||||||
this.isSecurityEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sets the socket buffer size used for responding to RPCs */
|
/** Sets the socket buffer size used for responding to RPCs */
|
||||||
public void setSocketSendBufSize(int size) { this.socketSendBufferSize = size; }
|
public void setSocketSendBufSize(int size) { this.socketSendBufferSize = size; }
|
||||||
|
|
||||||
|
|
|
@ -239,6 +239,7 @@ public class UserGroupInformation {
|
||||||
AuthenticationMethod auth = SecurityUtil.getAuthenticationMethod(conf);
|
AuthenticationMethod auth = SecurityUtil.getAuthenticationMethod(conf);
|
||||||
switch (auth) {
|
switch (auth) {
|
||||||
case SIMPLE:
|
case SIMPLE:
|
||||||
|
case TOKEN:
|
||||||
useKerberos = false;
|
useKerberos = false;
|
||||||
break;
|
break;
|
||||||
case KERBEROS:
|
case KERBEROS:
|
||||||
|
|
|
@ -569,10 +569,13 @@ public class TestSaslRPC {
|
||||||
private static Pattern KrbFailed =
|
private static Pattern KrbFailed =
|
||||||
Pattern.compile(".*Failed on local exception:.* " +
|
Pattern.compile(".*Failed on local exception:.* " +
|
||||||
"Failed to specify server's Kerberos principal name.*");
|
"Failed to specify server's Kerberos principal name.*");
|
||||||
private static Pattern Denied =
|
private static Pattern Denied(AuthenticationMethod method) {
|
||||||
Pattern.compile(".*Authorization .* is enabled .*");
|
return Pattern.compile(".*RemoteException.*AccessControlException.*: "
|
||||||
private static Pattern NoDigest =
|
+method.getAuthMethod() + " authentication is not enabled.*");
|
||||||
Pattern.compile(".*Server is not configured to do DIGEST auth.*");
|
}
|
||||||
|
private static Pattern NoTokenAuth =
|
||||||
|
Pattern.compile(".*IllegalArgumentException: " +
|
||||||
|
"TOKEN authentication requires a secret manager");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* simple server
|
* simple server
|
||||||
|
@ -604,12 +607,39 @@ public class TestSaslRPC {
|
||||||
assertAuthEquals(SIMPLE, getAuthMethod(KERBEROS, SIMPLE, false));
|
assertAuthEquals(SIMPLE, getAuthMethod(KERBEROS, SIMPLE, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* token server
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testTokenOnlyServer() throws Exception {
|
||||||
|
assertAuthEquals(Denied(SIMPLE), getAuthMethod(SIMPLE, TOKEN));
|
||||||
|
assertAuthEquals(KrbFailed, getAuthMethod(KERBEROS, TOKEN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTokenOnlyServerWithTokens() throws Exception {
|
||||||
|
assertAuthEquals(TOKEN, getAuthMethod(SIMPLE, TOKEN, true));
|
||||||
|
assertAuthEquals(TOKEN, getAuthMethod(KERBEROS, TOKEN, true));
|
||||||
|
forceSecretManager = false;
|
||||||
|
assertAuthEquals(NoTokenAuth, getAuthMethod(SIMPLE, TOKEN, true));
|
||||||
|
assertAuthEquals(NoTokenAuth, getAuthMethod(KERBEROS, TOKEN, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTokenOnlyServerWithInvalidTokens() throws Exception {
|
||||||
|
assertAuthEquals(BadToken, getAuthMethod(SIMPLE, TOKEN, false));
|
||||||
|
assertAuthEquals(BadToken, getAuthMethod(KERBEROS, TOKEN, false));
|
||||||
|
forceSecretManager = false;
|
||||||
|
assertAuthEquals(NoTokenAuth, getAuthMethod(SIMPLE, TOKEN, false));
|
||||||
|
assertAuthEquals(NoTokenAuth, getAuthMethod(KERBEROS, TOKEN, false));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* kerberos server
|
* kerberos server
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testKerberosServer() throws Exception {
|
public void testKerberosServer() throws Exception {
|
||||||
assertAuthEquals(Denied, getAuthMethod(SIMPLE, KERBEROS));
|
assertAuthEquals(Denied(SIMPLE), getAuthMethod(SIMPLE, KERBEROS));
|
||||||
assertAuthEquals(KrbFailed, getAuthMethod(KERBEROS, KERBEROS));
|
assertAuthEquals(KrbFailed, getAuthMethod(KERBEROS, KERBEROS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,8 +650,8 @@ public class TestSaslRPC {
|
||||||
assertAuthEquals(TOKEN, getAuthMethod(KERBEROS, KERBEROS, true));
|
assertAuthEquals(TOKEN, getAuthMethod(KERBEROS, KERBEROS, true));
|
||||||
// can't fallback to simple when using kerberos w/o tokens
|
// can't fallback to simple when using kerberos w/o tokens
|
||||||
forceSecretManager = false;
|
forceSecretManager = false;
|
||||||
assertAuthEquals(NoDigest, getAuthMethod(SIMPLE, KERBEROS, true));
|
assertAuthEquals(Denied(TOKEN), getAuthMethod(SIMPLE, KERBEROS, true));
|
||||||
assertAuthEquals(NoDigest, getAuthMethod(KERBEROS, KERBEROS, true));
|
assertAuthEquals(Denied(TOKEN), getAuthMethod(KERBEROS, KERBEROS, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -629,8 +659,8 @@ public class TestSaslRPC {
|
||||||
assertAuthEquals(BadToken, getAuthMethod(SIMPLE, KERBEROS, false));
|
assertAuthEquals(BadToken, getAuthMethod(SIMPLE, KERBEROS, false));
|
||||||
assertAuthEquals(BadToken, getAuthMethod(KERBEROS, KERBEROS, false));
|
assertAuthEquals(BadToken, getAuthMethod(KERBEROS, KERBEROS, false));
|
||||||
forceSecretManager = false;
|
forceSecretManager = false;
|
||||||
assertAuthEquals(NoDigest, getAuthMethod(SIMPLE, KERBEROS, true));
|
assertAuthEquals(Denied(TOKEN), getAuthMethod(SIMPLE, KERBEROS, false));
|
||||||
assertAuthEquals(NoDigest, getAuthMethod(KERBEROS, KERBEROS, true));
|
assertAuthEquals(Denied(TOKEN), getAuthMethod(KERBEROS, KERBEROS, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue