Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-4259 - Allow AdminServer to force https #1652

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,15 @@ Both subsystems need to have sufficient amount of threads to achieve peak read t

#### AdminServer configuration

**New in 3.7.1:** The following
options are used to configure the [AdminServer](#sc_adminserver).

* *admin.forceHttps* :
(Java system property: **zookeeper.admin.forceHttps**)
Force AdminServer to use SSL, thus allowing only HTTPS traffic.
Defaults to disabled.
Overwrites **admin.portUnification** settings.

**New in 3.6.0:** The following
options are used to configure the [AdminServer](#sc_adminserver).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.security.Constraint;
Expand Down Expand Up @@ -85,7 +86,8 @@ public JettyAdminServer() throws AdminServerException, IOException, GeneralSecur
Integer.getInteger("zookeeper.admin.idleTimeout", DEFAULT_IDLE_TIMEOUT),
System.getProperty("zookeeper.admin.commandURL", DEFAULT_COMMAND_URL),
Integer.getInteger("zookeeper.admin.httpVersion", DEFAULT_HTTP_VERSION),
Boolean.getBoolean("zookeeper.admin.portUnification"));
Boolean.getBoolean("zookeeper.admin.portUnification"),
Boolean.getBoolean("zookeeper.admin.forceHttps"));
}

public JettyAdminServer(
Expand All @@ -94,7 +96,8 @@ public JettyAdminServer(
int timeout,
String commandUrl,
int httpVersion,
boolean portUnification) throws IOException, GeneralSecurityException {
boolean portUnification,
boolean forceHttps) throws IOException, GeneralSecurityException {

this.port = port;
this.idleTimeout = timeout;
Expand All @@ -104,7 +107,7 @@ public JettyAdminServer(
server = new Server();
ServerConnector connector = null;

if (!portUnification) {
if (!portUnification && !forceHttps) {
connector = new ServerConnector(server);
} else {
SecureRequestCustomizer customizer = new SecureRequestCustomizer();
Expand Down Expand Up @@ -140,10 +143,16 @@ public JettyAdminServer(
sslContextFactory.setTrustStore(trustStore);
sslContextFactory.setTrustStorePassword(certAuthPassword);

connector = new ServerConnector(
server,
new UnifiedConnectionFactory(sslContextFactory, HttpVersion.fromVersion(httpVersion).asString()),
new HttpConnectionFactory(config));
if (forceHttps) {
connector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.fromVersion(httpVersion).asString()),
new HttpConnectionFactory(config));
} else {
connector = new ServerConnector(
server,
new UnifiedConnectionFactory(sslContextFactory, HttpVersion.fromVersion(httpVersion).asString()),
new HttpConnectionFactory(config));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.Security;
Expand Down Expand Up @@ -143,6 +145,7 @@ public void cleanUp() {
System.clearProperty("zookeeper.ssl.quorum.trustStore.password");
System.clearProperty("zookeeper.ssl.quorum.trustStore.type");
System.clearProperty("zookeeper.admin.portUnification");
System.clearProperty("zookeeper.admin.forceHttps");
}

/**
Expand Down Expand Up @@ -234,6 +237,36 @@ public void testQuorum() throws Exception {
"waiting for server 2 down");
}

@Test
public void testForceHttpsPortUnificationEnabled() throws Exception {
testForceHttps(true);
}

@Test
public void testForceHttpsPortUnificationDisabled() throws Exception {
testForceHttps(false);
}

private void testForceHttps(boolean portUnification) throws Exception {
System.setProperty("zookeeper.admin.forceHttps", "true");
System.setProperty("zookeeper.admin.portUnification", String.valueOf(portUnification));
boolean httpsPassed = false;

JettyAdminServer server = new JettyAdminServer();
try {
server.start();
queryAdminServer(String.format(HTTPS_URL_FORMAT, jettyAdminPort), true);
httpsPassed = true;
queryAdminServer(String.format(URL_FORMAT, jettyAdminPort), false);
nkalmar marked this conversation as resolved.
Show resolved Hide resolved
fail("http call should have failed since forceHttps=true");
} catch (SocketException se) {
//good
} finally {
server.shutdown();
}
assertTrue(httpsPassed);
}

/**
* Check that we can load the commands page of an AdminServer running at
* localhost:port. (Note that this should work even if no zk server is set.)
Expand Down