HADOOP-6892. Common component of HDFS-1150 (Verify datanodes' identities to clients in secure clusters).
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@981688 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
666a8e1600
commit
1035138b4c
@ -30,6 +30,9 @@ Trunk (unreleased changes)
|
||||
file systems associated with a particular UGI. (Devaraj Das and Kan Zhang
|
||||
via szetszwo)
|
||||
|
||||
HADOOP-6892. Common component of HDFS-1150 (Verify datanodes' identities
|
||||
to clients in secure clusters) (jghoman)
|
||||
|
||||
IMPROVEMENTS
|
||||
|
||||
HADOOP-6644. util.Shell getGROUPS_FOR_USER_COMMAND method name
|
||||
|
@ -77,20 +77,29 @@ if [ -f "${HADOOP_CONF_DIR}/hadoop-env.sh" ]; then
|
||||
. "${HADOOP_CONF_DIR}/hadoop-env.sh"
|
||||
fi
|
||||
|
||||
# Determine if we're starting a secure datanode, and if so, redefine appropriate variables
|
||||
if [ "$command" == "datanode" ] && [ "$EUID" -eq 0 ] && [ -n "$HADOOP_SECURE_DN_USER" ]; then
|
||||
export HADOOP_PID_DIR=$HADOOP_SECURE_DN_PID_DIR
|
||||
export HADOOP_LOG_DIR=$HADOOP_SECURE_DN_LOG_DIR
|
||||
export HADOOP_IDENT_STRING=$HADOOP_SECURE_DN_USER
|
||||
fi
|
||||
|
||||
if [ "$HADOOP_IDENT_STRING" = "" ]; then
|
||||
export HADOOP_IDENT_STRING="$USER"
|
||||
fi
|
||||
|
||||
|
||||
# get log directory
|
||||
if [ "$HADOOP_LOG_DIR" = "" ]; then
|
||||
export HADOOP_LOG_DIR="$HADOOP_HOME/logs"
|
||||
fi
|
||||
mkdir -p "$HADOOP_LOG_DIR"
|
||||
chown $HADOOP_IDENT_STRING $HADOOP_LOG_DIR
|
||||
|
||||
if [ "$HADOOP_PID_DIR" = "" ]; then
|
||||
HADOOP_PID_DIR=/tmp
|
||||
fi
|
||||
|
||||
if [ "$HADOOP_IDENT_STRING" = "" ]; then
|
||||
export HADOOP_IDENT_STRING="$USER"
|
||||
fi
|
||||
|
||||
# some variables
|
||||
export HADOOP_LOGFILE=hadoop-$HADOOP_IDENT_STRING-$command-$HOSTNAME.log
|
||||
export HADOOP_ROOT_LOGGER="INFO,DRFA"
|
||||
|
@ -17,9 +17,9 @@
|
||||
*/
|
||||
package org.apache.hadoop.http;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.BindException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URL;
|
||||
@ -43,17 +43,21 @@
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.conf.ConfServlet;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||
import org.apache.hadoop.http.AdminAuthorizedServlet;
|
||||
import org.apache.hadoop.http.FilterContainer;
|
||||
import org.apache.hadoop.http.FilterInitializer;
|
||||
import org.apache.hadoop.http.HtmlQuoting;
|
||||
import org.apache.hadoop.log.LogLevel;
|
||||
import org.apache.hadoop.metrics.MetricsServlet;
|
||||
import org.apache.hadoop.security.Krb5AndCertsSslSocketConnector;
|
||||
import org.apache.hadoop.security.Krb5AndCertsSslSocketConnector.MODE;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
import org.apache.hadoop.security.Krb5AndCertsSslSocketConnector.MODE;
|
||||
import org.apache.hadoop.security.authorize.AccessControlList;
|
||||
import org.apache.hadoop.util.ReflectionUtils;
|
||||
import org.apache.hadoop.conf.ConfServlet;
|
||||
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||
|
||||
import org.mortbay.jetty.Connector;
|
||||
import org.mortbay.jetty.Handler;
|
||||
import org.mortbay.jetty.Server;
|
||||
@ -103,12 +107,19 @@ public class HttpServer implements FilterContainer {
|
||||
static final String STATE_DESCRIPTION_ALIVE = " - alive";
|
||||
static final String STATE_DESCRIPTION_NOT_LIVE = " - not live";
|
||||
|
||||
private final boolean listenerStartedExternally;
|
||||
|
||||
/** Same as this(name, bindAddress, port, findPort, null); */
|
||||
public HttpServer(String name, String bindAddress, int port, boolean findPort
|
||||
) throws IOException {
|
||||
this(name, bindAddress, port, findPort, new Configuration());
|
||||
}
|
||||
|
||||
public HttpServer(String name, String bindAddress, int port,
|
||||
boolean findPort, Configuration conf, Connector connector) throws IOException {
|
||||
this(name, bindAddress, port, findPort, conf, null, connector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a status server on the given port.
|
||||
* The jsp scripts are taken from src/webapps/<name>.
|
||||
@ -120,7 +131,13 @@ public HttpServer(String name, String bindAddress, int port, boolean findPort
|
||||
*/
|
||||
public HttpServer(String name, String bindAddress, int port,
|
||||
boolean findPort, Configuration conf) throws IOException {
|
||||
this(name, bindAddress, port, findPort, conf, null);
|
||||
this(name, bindAddress, port, findPort, conf, null, null);
|
||||
}
|
||||
|
||||
public HttpServer(String name, String bindAddress, int port,
|
||||
boolean findPort, Configuration conf, AccessControlList adminsAcl)
|
||||
throws IOException {
|
||||
this(name, bindAddress, port, findPort, conf, adminsAcl, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,14 +151,22 @@ public HttpServer(String name, String bindAddress, int port,
|
||||
* @param adminsAcl {@link AccessControlList} of the admins
|
||||
*/
|
||||
public HttpServer(String name, String bindAddress, int port,
|
||||
boolean findPort, Configuration conf, AccessControlList adminsAcl)
|
||||
throws IOException {
|
||||
boolean findPort, Configuration conf, AccessControlList adminsAcl,
|
||||
Connector connector) throws IOException {
|
||||
webServer = new Server();
|
||||
this.findPort = findPort;
|
||||
this.adminsAcl = adminsAcl;
|
||||
|
||||
if(connector == null) {
|
||||
listenerStartedExternally = false;
|
||||
listener = createBaseListener(conf);
|
||||
listener.setHost(bindAddress);
|
||||
listener.setPort(port);
|
||||
} else {
|
||||
listenerStartedExternally = true;
|
||||
listener = connector;
|
||||
}
|
||||
|
||||
webServer.addConnector(listener);
|
||||
|
||||
int maxThreads = conf.getInt(HTTP_MAX_THREADS, -1);
|
||||
@ -184,8 +209,12 @@ public HttpServer(String name, String bindAddress, int port,
|
||||
* provided. This wrapper and all subclasses must create at least one
|
||||
* listener.
|
||||
*/
|
||||
protected Connector createBaseListener(Configuration conf)
|
||||
throws IOException {
|
||||
public Connector createBaseListener(Configuration conf) throws IOException {
|
||||
return HttpServer.createDefaultChannelConnector();
|
||||
}
|
||||
|
||||
@InterfaceAudience.Private
|
||||
public static Connector createDefaultChannelConnector() {
|
||||
SelectChannelConnector ret = new SelectChannelConnector();
|
||||
ret.setLowResourceMaxIdleTime(10000);
|
||||
ret.setAcceptQueueSize(128);
|
||||
@ -532,6 +561,13 @@ else if (!needCertsAuth && needKrbAuth)
|
||||
*/
|
||||
public void start() throws IOException {
|
||||
try {
|
||||
if(listenerStartedExternally) { // Expect that listener was started securely
|
||||
if(listener.getLocalPort() == -1) // ... and verify
|
||||
throw new Exception("Exepected webserver's listener to be started " +
|
||||
"previously but wasn't");
|
||||
// And skip all the port rolling issues.
|
||||
webServer.start();
|
||||
} else {
|
||||
int port = 0;
|
||||
int oriPort = listener.getPort(); // The original requested port
|
||||
while (true) {
|
||||
@ -599,6 +635,7 @@ public void start() throws IOException {
|
||||
}
|
||||
listener.setPort((oriPort += 1));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user