Skip to content

Commit 7c7b75c

Browse files
xiao-chenraviprak-altiscale
authored andcommitted
HDFS-10860. Switch HttpFS from Tomcat to Jetty. Contributed by John Zhuge.
(cherry picked from commit 69b2363)
1 parent 3611f10 commit 7c7b75c

File tree

23 files changed

+990
-426
lines changed

23 files changed

+990
-426
lines changed

hadoop-assemblies/src/main/resources/assemblies/hadoop-httpfs-dist.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
</formats>
2020
<includeBaseDirectory>false</includeBaseDirectory>
2121
<fileSets>
22+
<!-- Jar file -->
23+
<fileSet>
24+
<directory>target</directory>
25+
<outputDirectory>/share/hadoop/hdfs</outputDirectory>
26+
<includes>
27+
<include>${project.artifactId}-${project.version}.jar</include>
28+
</includes>
29+
</fileSet>
2230
<!-- Configuration files -->
2331
<fileSet>
2432
<directory>${basedir}/src/main/conf</directory>
@@ -39,7 +47,7 @@
3947
<directory>${basedir}/src/main/libexec</directory>
4048
<outputDirectory>/libexec</outputDirectory>
4149
<includes>
42-
<include>*</include>
50+
<include>**/*</include>
4351
</includes>
4452
<fileMode>0755</fileMode>
4553
</fileSet>
@@ -49,4 +57,19 @@
4957
<outputDirectory>/share/doc/hadoop/httpfs</outputDirectory>
5058
</fileSet>
5159
</fileSets>
60+
<dependencySets>
61+
<dependencySet>
62+
<useProjectArtifact>false</useProjectArtifact>
63+
<outputDirectory>/share/hadoop/hdfs/lib</outputDirectory>
64+
<!-- Exclude hadoop artifacts. They will be found via HADOOP* env -->
65+
<excludes>
66+
<exclude>org.apache.hadoop:hadoop-common</exclude>
67+
<exclude>org.apache.hadoop:hadoop-hdfs</exclude>
68+
<!-- use slf4j from common to avoid multiple binding warnings -->
69+
<exclude>org.slf4j:slf4j-api</exclude>
70+
<exclude>org.slf4j:slf4j-log4j12</exclude>
71+
<exclude>org.hsqldb:hsqldb</exclude>
72+
</excludes>
73+
</dependencySet>
74+
</dependencySets>
5275
</assembly>

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.hadoop.security.authentication.util.RandomSignerSecretProvider;
6060
import org.apache.hadoop.security.authentication.util.SignerSecretProvider;
6161
import org.apache.hadoop.security.authentication.util.ZKSignerSecretProvider;
62+
import org.apache.hadoop.security.ssl.SSLFactory;
6263
import org.apache.hadoop.security.ssl.SslSelectChannelConnectorSecure;
6364
import org.apache.hadoop.jmx.JMXJsonServlet;
6465
import org.apache.hadoop.log.LogLevel;
@@ -114,6 +115,9 @@
114115
public final class HttpServer2 implements FilterContainer {
115116
public static final Log LOG = LogFactory.getLog(HttpServer2.class);
116117

118+
public static final String HTTP_SCHEME = "http";
119+
public static final String HTTPS_SCHEME = "https";
120+
117121
static final String FILTER_INITIALIZER_PROPERTY
118122
= "hadoop.http.filter.initializers";
119123
public static final String HTTP_MAX_THREADS = "hadoop.http.max.threads";
@@ -149,6 +153,7 @@ public static class Builder {
149153
private ArrayList<URI> endpoints = Lists.newArrayList();
150154
private String name;
151155
private Configuration conf;
156+
private Configuration sslConf;
152157
private String[] pathSpecs;
153158
private AccessControlList adminsAcl;
154159
private boolean securityEnabled = false;
@@ -241,6 +246,15 @@ public Builder setConf(Configuration conf) {
241246
return this;
242247
}
243248

249+
/**
250+
* Specify the SSL configuration to load. This API provides an alternative
251+
* to keyStore/keyPassword/trustStore.
252+
*/
253+
public Builder setSSLConf(Configuration sslCnf) {
254+
this.sslConf = sslCnf;
255+
return this;
256+
}
257+
244258
public Builder setPathSpec(String[] pathSpec) {
245259
this.pathSpecs = pathSpec;
246260
return this;
@@ -281,6 +295,56 @@ public Builder excludeCiphers(String pExcludeCiphers) {
281295
return this;
282296
}
283297

298+
/**
299+
* A wrapper of {@link Configuration#getPassword(String)}. It returns
300+
* <code>String</code> instead of <code>char[]</code>.
301+
*
302+
* @param conf the configuration
303+
* @param name the property name
304+
* @return the password string or null
305+
*/
306+
private static String getPasswordString(Configuration conf, String name)
307+
throws IOException {
308+
char[] passchars = conf.getPassword(name);
309+
if (passchars == null) {
310+
return null;
311+
}
312+
return new String(passchars);
313+
}
314+
315+
/**
316+
* Load SSL properties from the SSL configuration.
317+
*/
318+
private void loadSSLConfiguration() throws IOException {
319+
if (sslConf == null) {
320+
return;
321+
}
322+
needsClientAuth = sslConf.getBoolean(
323+
SSLFactory.SSL_SERVER_NEED_CLIENT_AUTH,
324+
SSLFactory.SSL_SERVER_NEED_CLIENT_AUTH_DEFAULT);
325+
keyStore = sslConf.getTrimmed(SSLFactory.SSL_SERVER_KEYSTORE_LOCATION);
326+
if (keyStore == null || keyStore.isEmpty()) {
327+
throw new IOException(String.format("Property %s not specified",
328+
SSLFactory.SSL_SERVER_KEYSTORE_LOCATION));
329+
}
330+
keyStorePassword = getPasswordString(sslConf,
331+
SSLFactory.SSL_SERVER_KEYSTORE_PASSWORD);
332+
if (keyStorePassword == null) {
333+
throw new IOException(String.format("Property %s not specified",
334+
SSLFactory.SSL_SERVER_KEYSTORE_PASSWORD));
335+
}
336+
keyStoreType = sslConf.get(SSLFactory.SSL_SERVER_KEYSTORE_TYPE,
337+
SSLFactory.SSL_SERVER_KEYSTORE_TYPE_DEFAULT);
338+
keyPassword = getPasswordString(sslConf,
339+
SSLFactory.SSL_SERVER_KEYSTORE_KEYPASSWORD);
340+
trustStore = sslConf.get(SSLFactory.SSL_SERVER_TRUSTSTORE_LOCATION);
341+
trustStorePassword = getPasswordString(sslConf,
342+
SSLFactory.SSL_SERVER_TRUSTSTORE_PASSWORD);
343+
trustStoreType = sslConf.get(SSLFactory.SSL_SERVER_TRUSTSTORE_TYPE,
344+
SSLFactory.SSL_SERVER_TRUSTSTORE_TYPE_DEFAULT);
345+
excludeCiphers = sslConf.get(SSLFactory.SSL_SERVER_EXCLUDE_CIPHER_LIST);
346+
}
347+
284348
public HttpServer2 build() throws IOException {
285349
Preconditions.checkNotNull(name, "name is not set");
286350
Preconditions.checkState(!endpoints.isEmpty(), "No endpoints specified");
@@ -305,6 +369,7 @@ public HttpServer2 build() throws IOException {
305369
if ("http".equals(scheme)) {
306370
listener = HttpServer2.createDefaultChannelConnector();
307371
} else if ("https".equals(scheme)) {
372+
loadSSLConfiguration();
308373
listener = createHttpsChannelConnector();
309374

310375
} else {

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public static enum Mode { CLIENT, SERVER }
6060
"hadoop.ssl.client.conf";
6161
public static final String SSL_SERVER_CONF_KEY =
6262
"hadoop.ssl.server.conf";
63+
public static final String SSL_SERVER_CONF_DEFAULT = "ssl-server.xml";
64+
6365
public static final String SSLCERTIFICATE = IBM_JAVA?"ibmX509":"SunX509";
6466

6567
public static final boolean DEFAULT_SSL_REQUIRE_CLIENT_CERT = false;
@@ -71,6 +73,30 @@ public static enum Mode { CLIENT, SERVER }
7173
"hadoop.ssl.enabled.protocols";
7274
public static final String DEFAULT_SSL_ENABLED_PROTOCOLS = "TLSv1";
7375

76+
public static final String SSL_SERVER_NEED_CLIENT_AUTH =
77+
"ssl.server.need.client.auth";
78+
public static final boolean SSL_SERVER_NEED_CLIENT_AUTH_DEFAULT = false;
79+
80+
public static final String SSL_SERVER_KEYSTORE_LOCATION =
81+
"ssl.server.keystore.location";
82+
public static final String SSL_SERVER_KEYSTORE_PASSWORD =
83+
"ssl.server.keystore.password";
84+
public static final String SSL_SERVER_KEYSTORE_TYPE =
85+
"ssl.server.keystore.type";
86+
public static final String SSL_SERVER_KEYSTORE_TYPE_DEFAULT = "jks";
87+
public static final String SSL_SERVER_KEYSTORE_KEYPASSWORD =
88+
"ssl.server.keystore.keypassword";
89+
90+
public static final String SSL_SERVER_TRUSTSTORE_LOCATION =
91+
"ssl.server.truststore.location";
92+
public static final String SSL_SERVER_TRUSTSTORE_PASSWORD =
93+
"ssl.server.truststore.password";
94+
public static final String SSL_SERVER_TRUSTSTORE_TYPE =
95+
"ssl.server.truststore.type";
96+
public static final String SSL_SERVER_TRUSTSTORE_TYPE_DEFAULT = "jks";
97+
public static final String SSL_SERVER_EXCLUDE_CIPHER_LIST =
98+
"ssl.server.exclude.cipher.list";
99+
74100
private Configuration conf;
75101
private Mode mode;
76102
private boolean requireClientCert;
@@ -95,7 +121,7 @@ public SSLFactory(Mode mode, Configuration conf) {
95121
this.mode = mode;
96122
requireClientCert = conf.getBoolean(SSL_REQUIRE_CLIENT_CERT_KEY,
97123
DEFAULT_SSL_REQUIRE_CLIENT_CERT);
98-
Configuration sslConf = readSSLConfiguration(mode);
124+
Configuration sslConf = readSSLConfiguration(mode, conf);
99125

100126
Class<? extends KeyStoresFactory> klass
101127
= conf.getClass(KEYSTORES_FACTORY_CLASS_KEY,
@@ -106,9 +132,10 @@ public SSLFactory(Mode mode, Configuration conf) {
106132
DEFAULT_SSL_ENABLED_PROTOCOLS);
107133
}
108134

109-
private Configuration readSSLConfiguration(Mode mode) {
135+
public static Configuration readSSLConfiguration(Mode mode, Configuration conf) {
110136
Configuration sslConf = new Configuration(false);
111-
sslConf.setBoolean(SSL_REQUIRE_CLIENT_CERT_KEY, requireClientCert);
137+
sslConf.setBoolean(SSL_REQUIRE_CLIENT_CERT_KEY, conf.getBoolean(
138+
SSL_REQUIRE_CLIENT_CERT_KEY, false));
112139
String sslConfResource;
113140
if (mode == Mode.CLIENT) {
114141
sslConfResource = conf.get(SSL_CLIENT_CONF_KEY, "ssl-client.xml");

0 commit comments

Comments
 (0)