diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 8c7c19e81a..57bc9e0fb9 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -432,6 +432,9 @@ Release 0.23.3 - UNRELEASED HADOOP-8014. ViewFileSystem does not correctly implement getDefaultBlockSize, getDefaultReplication, getContentSummary (John George via bobby) + HADOOP-7510. Tokens should use original hostname provided instead of ip + (Daryn Sharp via bobby) + Release 0.23.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java index e5a2d7f15a..cb999f3c41 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java @@ -53,7 +53,6 @@ import org.apache.hadoop.ipc.RpcPayloadHeader.*; import org.apache.hadoop.ipc.protobuf.IpcConnectionContextProtos.IpcConnectionContextProto; import org.apache.hadoop.io.IOUtils; -import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.WritableUtils; import org.apache.hadoop.io.DataOutputBuffer; @@ -243,8 +242,8 @@ public Connection(ConnectionId remoteId) throws IOException { this.remoteId = remoteId; this.server = remoteId.getAddress(); if (server.isUnresolved()) { - throw NetUtils.wrapException(remoteId.getAddress().getHostName(), - remoteId.getAddress().getPort(), + throw NetUtils.wrapException(server.getHostName(), + server.getPort(), null, 0, new UnknownHostException()); @@ -274,9 +273,8 @@ public Connection(ConnectionId remoteId) throws IOException { } catch (IllegalAccessException e) { throw new IOException(e.toString()); } - InetSocketAddress addr = remoteId.getAddress(); - token = tokenSelector.selectToken(new Text(addr.getAddress() - .getHostAddress() + ":" + addr.getPort()), + token = tokenSelector.selectToken( + SecurityUtil.buildTokenService(server), ticket.getTokens()); } KerberosInfo krbInfo = SecurityUtil.getKerberosInfo(protocol, conf); @@ -305,7 +303,7 @@ public Connection(ConnectionId remoteId) throws IOException { + protocol.getSimpleName()); this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " + - remoteId.getAddress().toString() + + server.toString() + " from " + ((ticket==null)?"an unknown user":ticket.getUserName())); this.setDaemon(true); } @@ -751,7 +749,6 @@ private synchronized boolean waitForWork() { } } - @SuppressWarnings("unused") public InetSocketAddress getRemoteAddress() { return server; } @@ -1159,7 +1156,7 @@ public Writable call(RpcKind rpcKind, Writable rpcRequest, call.error.fillInStackTrace(); throw call.error; } else { // local exception - InetSocketAddress address = remoteId.getAddress(); + InetSocketAddress address = connection.getRemoteAddress(); throw NetUtils.wrapException(address.getHostName(), address.getPort(), NetUtils.getHostname(), diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java index b6a9eac108..9bf4a88e42 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java @@ -344,8 +344,8 @@ public static List getAllStaticResolutions() { /** * Returns InetSocketAddress that a client can use to * connect to the server. Server.getListenerAddress() is not correct when - * the server binds to "0.0.0.0". This returns "127.0.0.1:port" when - * the getListenerAddress() returns "0.0.0.0:port". + * the server binds to "0.0.0.0". This returns "hostname:port" of the server, + * or "127.0.0.1:port" when the getListenerAddress() returns "0.0.0.0:port". * * @param server * @return socket address that a client can use to connect to the server. @@ -353,7 +353,12 @@ public static List getAllStaticResolutions() { public static InetSocketAddress getConnectAddress(Server server) { InetSocketAddress addr = server.getListenerAddress(); if (addr.getAddress().isAnyLocalAddress()) { - addr = createSocketAddrForHost("127.0.0.1", addr.getPort()); + try { + addr = new InetSocketAddress(InetAddress.getLocalHost(), addr.getPort()); + } catch (UnknownHostException uhe) { + // shouldn't get here unless the host doesn't have a loopback iface + addr = createSocketAddrForHost("127.0.0.1", addr.getPort()); + } } return addr; } @@ -655,7 +660,7 @@ public static InetAddress getLocalInetAddress(String host) } InetAddress addr = null; try { - addr = InetAddress.getByName(host); + addr = SecurityUtil.getByName(host); if (NetworkInterface.getByInetAddress(addr) == null) { addr = null; // Not a local address } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java index 5b2c6d5884..f22cd61410 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java @@ -21,6 +21,7 @@ import java.io.Closeable; import java.io.IOException; import java.net.ConnectException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; @@ -41,6 +42,8 @@ import org.apache.hadoop.io.retry.RetryPolicies; import org.apache.hadoop.io.retry.RetryProxy; import org.apache.hadoop.ipc.Client.ConnectionId; +import org.apache.hadoop.ipc.TestSaslRPC.TestSaslImpl; +import org.apache.hadoop.ipc.TestSaslRPC.TestSaslProtocol; import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.authorize.AuthorizationException; @@ -542,6 +545,19 @@ private void doRPCs(Configuration conf, boolean expectFailure) throws Exception } } + @Test + public void testServerAddress() throws IOException { + Server server = RPC.getServer(TestProtocol.class, + new TestImpl(), ADDRESS, 0, 5, true, conf, null); + InetSocketAddress bindAddr = null; + try { + bindAddr = NetUtils.getConnectAddress(server); + } finally { + server.stop(); + } + assertEquals(bindAddr.getAddress(), InetAddress.getLocalHost()); + } + @Test public void testAuthorization() throws Exception { Configuration conf = new Configuration();