Skip to content

Commit 6d04be2

Browse files
committed
Clean up an IPC error message. Contributed by Aaron T. Myers.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1494702 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5543c00 commit 6d04be2

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/CommonConfigurationKeys.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,8 @@ public class CommonConfigurationKeys extends CommonConfigurationKeysPublic {
202202

203203
public static final long HADOOP_SECURITY_UID_NAME_CACHE_TIMEOUT_DEFAULT =
204204
4*60*60; // 4 hours
205+
206+
public static final String IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY = "ipc.client.fallback-to-simple-auth-allowed";
207+
public static final boolean IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT = false;
205208

206209
}

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public class Client {
110110
private int refCount = 1;
111111

112112
private final int connectionTimeout;
113+
114+
private final boolean fallbackAllowed;
113115

114116
final static int PING_CALL_ID = -1;
115117

@@ -456,7 +458,8 @@ private synchronized boolean shouldAuthenticateOverKrb() throws IOException {
456458
private synchronized boolean setupSaslConnection(final InputStream in2,
457459
final OutputStream out2)
458460
throws IOException {
459-
saslRpcClient = new SaslRpcClient(authMethod, token, serverPrincipal);
461+
saslRpcClient = new SaslRpcClient(authMethod, token, serverPrincipal,
462+
fallbackAllowed);
460463
return saslRpcClient.saslConnect(in2, out2);
461464
}
462465

@@ -1078,6 +1081,8 @@ public Client(Class<? extends Writable> valueClass, Configuration conf,
10781081
this.socketFactory = factory;
10791082
this.connectionTimeout = conf.getInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_TIMEOUT_KEY,
10801083
CommonConfigurationKeys.IPC_CLIENT_CONNECT_TIMEOUT_DEFAULT);
1084+
this.fallbackAllowed = conf.getBoolean(CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_KEY,
1085+
CommonConfigurationKeys.IPC_CLIENT_FALLBACK_TO_SIMPLE_AUTH_ALLOWED_DEFAULT);
10811086
}
10821087

10831088
/**

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SaslRpcClient.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class SaslRpcClient {
5959
public static final Log LOG = LogFactory.getLog(SaslRpcClient.class);
6060

6161
private final SaslClient saslClient;
62+
private final boolean fallbackAllowed;
6263

6364
/**
6465
* Create a SaslRpcClient for an authentication method
@@ -69,8 +70,10 @@ public class SaslRpcClient {
6970
* token to use if needed by the authentication method
7071
*/
7172
public SaslRpcClient(AuthMethod method,
72-
Token<? extends TokenIdentifier> token, String serverPrincipal)
73+
Token<? extends TokenIdentifier> token, String serverPrincipal,
74+
boolean fallbackAllowed)
7375
throws IOException {
76+
this.fallbackAllowed = fallbackAllowed;
7477
String saslUser = null;
7578
String saslProtocol = null;
7679
String saslServerName = null;
@@ -155,6 +158,11 @@ public boolean saslConnect(InputStream inS, OutputStream outS)
155158
readStatus(inStream);
156159
int len = inStream.readInt();
157160
if (len == SaslRpcServer.SWITCH_TO_SIMPLE_AUTH) {
161+
if (!fallbackAllowed) {
162+
throw new IOException("Server asks us to fall back to SIMPLE " +
163+
"auth, but this client is configured to only allow secure " +
164+
"connections.");
165+
}
158166
if (LOG.isDebugEnabled())
159167
LOG.debug("Server asks us to fall back to simple auth.");
160168
saslClient.dispose();

hadoop-common-project/hadoop-common/src/main/resources/core-default.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,4 +1196,17 @@
11961196
</description>
11971197
</property>
11981198

1199+
<property>
1200+
<name>ipc.client.fallback-to-simple-auth-allowed</name>
1201+
<value>false</value>
1202+
<description>
1203+
When a client is configured to attempt a secure connection, but attempts to
1204+
connect to an insecure server, that server may instruct the client to
1205+
switch to SASL SIMPLE (unsecure) authentication. This setting controls
1206+
whether or not the client will accept this instruction from the server.
1207+
When false (the default), the client will not allow the fallback to SIMPLE
1208+
authentication, and will abort the connection.
1209+
</description>
1210+
</property>
1211+
11991212
</configuration>

0 commit comments

Comments
 (0)