|
@@ -17,7 +17,8 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.hdfs.security.token.delegation;
|
|
package org.apache.hadoop.hdfs.security.token.delegation;
|
|
|
|
|
|
-import java.net.InetSocketAddress;
|
|
|
|
|
|
+import java.net.URI;
|
|
|
|
+import java.util.Collection;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
@@ -25,7 +26,6 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.net.NetUtils;
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
import org.apache.hadoop.security.SecurityUtil;
|
|
-import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
import org.apache.hadoop.security.token.Token;
|
|
import org.apache.hadoop.security.token.Token;
|
|
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSelector;
|
|
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSelector;
|
|
|
|
|
|
@@ -37,27 +37,36 @@ public class DelegationTokenSelector
|
|
extends AbstractDelegationTokenSelector<DelegationTokenIdentifier>{
|
|
extends AbstractDelegationTokenSelector<DelegationTokenIdentifier>{
|
|
public static final String SERVICE_NAME_KEY = "hdfs.service.host_";
|
|
public static final String SERVICE_NAME_KEY = "hdfs.service.host_";
|
|
|
|
|
|
- private static final DelegationTokenSelector INSTANCE = new DelegationTokenSelector();
|
|
|
|
-
|
|
|
|
- /** Select the delegation token for hdfs from the ugi. */
|
|
|
|
- public static Token<DelegationTokenIdentifier> selectHdfsDelegationToken(
|
|
|
|
- final InetSocketAddress nnAddr, final UserGroupInformation ugi,
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Select the delegation token for hdfs. The port will be rewritten to
|
|
|
|
+ * the port of hdfs.service.host_$nnAddr, or the default rpc namenode port.
|
|
|
|
+ * This method should only be called by non-hdfs filesystems that do not
|
|
|
|
+ * use the rpc port to acquire tokens. Ex. webhdfs, hftp
|
|
|
|
+ * @param nnUri of the remote namenode
|
|
|
|
+ * @param tokens as a collection
|
|
|
|
+ * @param conf hadoop configuration
|
|
|
|
+ * @return Token
|
|
|
|
+ */
|
|
|
|
+ public Token<DelegationTokenIdentifier> selectToken(
|
|
|
|
+ final URI nnUri, Collection<Token<?>> tokens,
|
|
final Configuration conf) {
|
|
final Configuration conf) {
|
|
// this guesses the remote cluster's rpc service port.
|
|
// this guesses the remote cluster's rpc service port.
|
|
// the current token design assumes it's the same as the local cluster's
|
|
// the current token design assumes it's the same as the local cluster's
|
|
// rpc port unless a config key is set. there should be a way to automatic
|
|
// rpc port unless a config key is set. there should be a way to automatic
|
|
// and correctly determine the value
|
|
// and correctly determine the value
|
|
- final String key = SERVICE_NAME_KEY + SecurityUtil.buildTokenService(nnAddr);
|
|
|
|
- final String nnServiceName = conf.get(key);
|
|
|
|
-
|
|
|
|
|
|
+ Text serviceName = SecurityUtil.buildTokenService(nnUri);
|
|
|
|
+ final String nnServiceName = conf.get(SERVICE_NAME_KEY + serviceName);
|
|
|
|
+
|
|
int nnRpcPort = NameNode.DEFAULT_PORT;
|
|
int nnRpcPort = NameNode.DEFAULT_PORT;
|
|
if (nnServiceName != null) {
|
|
if (nnServiceName != null) {
|
|
nnRpcPort = NetUtils.createSocketAddr(nnServiceName, nnRpcPort).getPort();
|
|
nnRpcPort = NetUtils.createSocketAddr(nnServiceName, nnRpcPort).getPort();
|
|
}
|
|
}
|
|
|
|
|
|
- final Text serviceName = SecurityUtil.buildTokenService(
|
|
|
|
- new InetSocketAddress(nnAddr.getHostName(), nnRpcPort));
|
|
|
|
- return INSTANCE.selectToken(serviceName, ugi.getTokens());
|
|
|
|
|
|
+ // use original hostname from the uri to avoid unintentional host resolving
|
|
|
|
+ serviceName = SecurityUtil.buildTokenService(
|
|
|
|
+ NetUtils.createSocketAddrForHost(nnUri.getHost(), nnRpcPort));
|
|
|
|
+
|
|
|
|
+ return selectToken(serviceName, tokens);
|
|
}
|
|
}
|
|
|
|
|
|
public DelegationTokenSelector() {
|
|
public DelegationTokenSelector() {
|