You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by nk...@apache.org on 2019/06/15 23:03:00 UTC
[flink] branch master updated (8558548 -> 11a7b3f)
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git.
from 8558548 [hotfix] Small code cleanups for Persistent Intermediate Results
new e24d670 [hotfix][tests] remove rogue comment in common_ssl.sh
new 500c133 [hotfix][docs] make LineBreakElement also implement InlineElement
new 65e822b [FLINK-12838][network] netty-fy SSL configuration
new ddfd4b8 [FLINK-9816][network] allow configuring the SSL engine provider
new c4ec9be6 [FLINK-12839][dist] package flink-shaded-netty-tcnative-dynamic into opt/
new d11be33 [FLINK-12517][tests] enable openSSL tests via openSSL-enhanced flink-shaded version
new e5b4a57 [FLINK-12518][tests][e2e] enable openSSL for test_streaming_file_sink
new 9a376ff [hotfix][docs] correctly escape ampersands
new 11a7b3f [FLINK-12446][docs] update openSSL option documentation
The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../generated/security_configuration.html | 5 +
.../flink/configuration/SecurityOptions.java | 37 +++
.../configuration/description/HtmlFormatter.java | 1 +
.../description/LineBreakElement.java | 2 +-
flink-dist/pom.xml | 6 +
flink-dist/src/main/assemblies/opt.xml | 10 +
flink-end-to-end-tests/test-scripts/common_ssl.sh | 45 ++-
.../test-scripts/test_streaming_file_sink.sh | 7 +-
.../flink/mesos/util/MesosArtifactServer.java | 4 +-
.../webmonitor/utils/WebFrontendBootstrap.java | 3 +-
flink-runtime/pom.xml | 6 +
.../runtime/io/network/netty/NettyClient.java | 1 +
.../runtime/io/network/netty/NettyServer.java | 43 ++-
.../io/network/netty/SSLHandlerFactory.java | 52 +---
.../flink/runtime/net/RedirectingSslHandler.java | 2 +-
.../org/apache/flink/runtime/net/SSLUtils.java | 309 ++++++++++++---------
.../org/apache/flink/runtime/rest/RestClient.java | 2 +-
.../flink/runtime/blob/BlobClientSslTest.java | 7 +-
.../io/network/netty/NettyClientServerSslTest.java | 81 +++++-
.../runtime/io/network/netty/NettyTestUtil.java | 18 ++
.../org/apache/flink/runtime/net/SSLUtilsTest.java | 88 +++++-
.../runtime/rest/RestServerEndpointITCase.java | 2 +-
.../rest/handler/job/JobSubmitHandlerTest.java | 17 +-
pom.xml | 7 +
tools/travis_watchdog.sh | 2 +-
25 files changed, 537 insertions(+), 220 deletions(-)
[flink] 04/09: [FLINK-9816][network] allow configuring the SSL
engine provider
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit ddfd4b89e06a4c89fa39f79ad2d3633c9dd09a85
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Mon Feb 11 23:42:16 2019 +0100
[FLINK-9816][network] allow configuring the SSL engine provider
[FLINK-9816][network][tests] add openSSL-based SSL tests if available
[FLINK-9816][network] use OpenSslX509KeyManagerFactory for openSSL back-end
According to https://netty.io/news/2018/07/10/4-1-26-Final.html, this will
vastly reduce handshake latency and CPU use.
[FLINK-9816][network][tests] allow forcing openSSL tests to run
For forcing openSSL tests to run (or fail if not available), specify the
following system property: '-D flink.tests.force-openssl'
---
.../generated/security_configuration.html | 5 ++
.../flink/configuration/SecurityOptions.java | 21 ++++++
.../runtime/io/network/netty/NettyServer.java | 44 ++++++++---
.../org/apache/flink/runtime/net/SSLUtils.java | 49 ++++++++++---
.../flink/runtime/blob/BlobClientSslTest.java | 7 +-
.../io/network/netty/NettyClientServerSslTest.java | 81 +++++++++++++++++++--
.../runtime/io/network/netty/NettyTestUtil.java | 18 +++++
.../org/apache/flink/runtime/net/SSLUtilsTest.java | 85 +++++++++++++++++++---
.../rest/handler/job/JobSubmitHandlerTest.java | 17 +++--
9 files changed, 279 insertions(+), 48 deletions(-)
diff --git a/docs/_includes/generated/security_configuration.html b/docs/_includes/generated/security_configuration.html
index 8999336..5537042 100644
--- a/docs/_includes/generated/security_configuration.html
+++ b/docs/_includes/generated/security_configuration.html
@@ -83,6 +83,11 @@
<td>The SSL protocol version to be supported for the ssl transport. Note that it doesn’t support comma separated list.</td>
</tr>
<tr>
+ <td><h5>security.ssl.provider</h5></td>
+ <td style="word-wrap: break-word;">"JDK"</td>
+ <td>The SSL engine provider to use for the ssl transport:<ul><li><span markdown="span">`JDK`</span>: default Java-based SSL engine</li><li><span markdown="span">`OPENSSL`</span>: openSSL-based SSL engine using system libraries</li></ul>Please note: OPENSSL requires a custom build of <a href="http://netty.io/wiki/forked-tomcat-native.html#wiki-h2-4">netty-tcnative</a> in our shaded package namespace which is not (yet) available but can be built manually (see <a href="https://i [...]
+ </tr>
+ <tr>
<td><h5>security.ssl.rest.authentication-enabled</h5></td>
<td style="word-wrap: break-word;">false</td>
<td>Turns on mutual SSL authentication for external communication via the REST endpoints.</td>
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java b/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java
index 87ab171..ad3b194 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java
@@ -23,6 +23,7 @@ import org.apache.flink.annotation.docs.ConfigGroup;
import org.apache.flink.annotation.docs.ConfigGroups;
import org.apache.flink.annotation.docs.Documentation;
import org.apache.flink.configuration.description.Description;
+import org.apache.flink.configuration.description.TextElement;
import static org.apache.flink.configuration.ConfigOptions.key;
import static org.apache.flink.configuration.description.LinkElement.link;
@@ -299,6 +300,26 @@ public class SecurityOptions {
.defaultValue(true)
.withDescription("Flag to enable peer’s hostname verification during ssl handshake.");
+ /**
+ * SSL engine provider.
+ */
+ public static final ConfigOption<String> SSL_PROVIDER =
+ key("security.ssl.provider")
+ .defaultValue("JDK")
+ .withDescription(Description.builder()
+ .text("The SSL engine provider to use for the ssl transport:")
+ .list(
+ TextElement.text("%s: default Java-based SSL engine", TextElement.code("JDK")),
+ TextElement.text("%s: openSSL-based SSL engine using system libraries",
+ TextElement.code("OPENSSL"))
+ )
+ .text("Please note: OPENSSL requires a custom build of %s in our " +
+ "shaded package namespace which is not (yet) available but can be built manually (see %s).",
+ link("http://netty.io/wiki/forked-tomcat-native.html#wiki-h2-4", "netty-tcnative"),
+ link("https://issues.apache.org/jira/browse/FLINK-11579", "FLINK-11579"))
+ .build()
+ );
+
// ------------------------ ssl parameters --------------------------------
/**
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java
index 3fe62c7..c687bfb 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java
@@ -18,6 +18,7 @@
package org.apache.flink.runtime.io.network.netty;
+import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.runtime.util.FatalExitExceptionHandler;
import org.apache.flink.shaded.guava18.com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -38,6 +39,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.ThreadFactory;
+import java.util.function.Function;
import static org.apache.flink.util.Preconditions.checkNotNull;
import static org.apache.flink.util.Preconditions.checkState;
@@ -65,6 +67,14 @@ class NettyServer {
}
int init(final NettyProtocol protocol, NettyBufferPool nettyBufferPool) throws IOException {
+ return init(
+ nettyBufferPool,
+ sslHandlerFactory -> new ServerChannelInitializer(protocol, sslHandlerFactory));
+ }
+
+ int init(
+ NettyBufferPool nettyBufferPool,
+ Function<SSLHandlerFactory, ServerChannelInitializer> channelInitializer) throws IOException {
checkState(bootstrap == null, "Netty server has already been initialized.");
final long start = System.nanoTime();
@@ -143,17 +153,7 @@ class NettyServer {
// Child channel pipeline for accepted connections
// --------------------------------------------------------------------
- bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
- @Override
- public void initChannel(SocketChannel channel) throws Exception {
- if (sslHandlerFactory != null) {
- channel.pipeline().addLast("ssl",
- sslHandlerFactory.createNettySSLHandler(channel.alloc()));
- }
-
- channel.pipeline().addLast(protocol.getServerChannelHandlers());
- }
- });
+ bootstrap.childHandler(channelInitializer.apply(sslHandlerFactory));
// --------------------------------------------------------------------
// Start Server
@@ -215,4 +215,26 @@ class NettyServer {
public static ThreadFactory getNamedThreadFactory(String name) {
return THREAD_FACTORY_BUILDER.setNameFormat(name + " Thread %d").build();
}
+
+ @VisibleForTesting
+ static class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
+ private final NettyProtocol protocol;
+ private final SSLHandlerFactory sslHandlerFactory;
+
+ public ServerChannelInitializer(
+ NettyProtocol protocol, SSLHandlerFactory sslHandlerFactory) {
+ this.protocol = protocol;
+ this.sslHandlerFactory = sslHandlerFactory;
+ }
+
+ @Override
+ public void initChannel(SocketChannel channel) throws Exception {
+ if (sslHandlerFactory != null) {
+ channel.pipeline().addLast("ssl",
+ sslHandlerFactory.createNettySSLHandler(channel.alloc()));
+ }
+
+ channel.pipeline().addLast(protocol.getServerChannelHandlers());
+ }
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
index dd9e7e7..1b3c9e5 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
@@ -27,6 +27,8 @@ import org.apache.flink.runtime.io.network.netty.SSLHandlerFactory;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.ClientAuth;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.JdkSslContext;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSsl;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSslX509KeyManagerFactory;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContextBuilder;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslProvider;
@@ -54,6 +56,9 @@ import java.security.cert.CertificateException;
import java.util.Arrays;
import java.util.List;
+import static org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslProvider.JDK;
+import static org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslProvider.OPENSSL;
+import static org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslProvider.OPENSSL_REFCNT;
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
@@ -194,6 +199,23 @@ public class SSLUtils {
return config.getString(SecurityOptions.SSL_ALGORITHMS).split(",");
}
+ @VisibleForTesting
+ static SslProvider getSSLProvider(final Configuration config) {
+ checkNotNull(config, "config must not be null");
+ String providerString = config.getString(SecurityOptions.SSL_PROVIDER);
+ if (providerString.equalsIgnoreCase("OPENSSL")) {
+ if (OpenSsl.isAvailable()) {
+ return OPENSSL;
+ } else {
+ throw new IllegalConfigurationException("openSSL not available", OpenSsl.unavailabilityCause());
+ }
+ } else if (providerString.equalsIgnoreCase("JDK")) {
+ return JDK;
+ } else {
+ throw new IllegalConfigurationException("Unknown SSL provider: %s", providerString);
+ }
+ }
+
private static TrustManagerFactory getTrustManagerFactory(Configuration config, boolean internal)
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
String trustStoreFilePath = getAndCheckOption(
@@ -219,7 +241,10 @@ public class SSLUtils {
return tmf;
}
- private static KeyManagerFactory getKeyManagerFactory(Configuration config, boolean internal)
+ private static KeyManagerFactory getKeyManagerFactory(
+ Configuration config,
+ boolean internal,
+ SslProvider provider)
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
UnrecoverableKeyException {
String keystoreFilePath = getAndCheckOption(
@@ -242,8 +267,12 @@ public class SSLUtils {
keyStore.load(keyStoreFile, keystorePassword.toCharArray());
}
- KeyManagerFactory kmf =
- KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ final KeyManagerFactory kmf;
+ if (provider == OPENSSL || provider == OPENSSL_REFCNT) {
+ kmf = new OpenSslX509KeyManagerFactory();
+ } else {
+ kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ }
kmf.init(keyStore, certPassword.toCharArray());
return kmf;
@@ -257,7 +286,7 @@ public class SSLUtils {
@Nullable
private static SSLContext createInternalSSLContext(Configuration config, boolean clientMode) throws Exception {
JdkSslContext nettySSLContext =
- (JdkSslContext) createInternalNettySSLContext(config, clientMode, SslProvider.JDK);
+ (JdkSslContext) createInternalNettySSLContext(config, clientMode, JDK);
if (nettySSLContext != null) {
return nettySSLContext.context();
} else {
@@ -268,7 +297,7 @@ public class SSLUtils {
@Nullable
private static SslContext createInternalNettySSLContext(Configuration config, boolean clientMode)
throws Exception {
- return createInternalNettySSLContext(config, clientMode, SslProvider.JDK);
+ return createInternalNettySSLContext(config, clientMode, getSSLProvider(config));
}
/**
@@ -291,7 +320,7 @@ public class SSLUtils {
int sessionCacheSize = config.getInteger(SecurityOptions.SSL_INTERNAL_SESSION_CACHE_SIZE);
int sessionTimeoutMs = config.getInteger(SecurityOptions.SSL_INTERNAL_SESSION_TIMEOUT);
- KeyManagerFactory kmf = getKeyManagerFactory(config, true);
+ KeyManagerFactory kmf = getKeyManagerFactory(config, true, provider);
TrustManagerFactory tmf = getTrustManagerFactory(config, true);
ClientAuth clientAuth = ClientAuth.REQUIRE;
@@ -321,7 +350,7 @@ public class SSLUtils {
public static SSLContext createRestSSLContext(Configuration config, boolean clientMode) throws Exception {
ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
JdkSslContext nettySSLContext =
- (JdkSslContext) createRestNettySSLContext(config, clientMode, clientAuth, SslProvider.JDK);
+ (JdkSslContext) createRestNettySSLContext(config, clientMode, clientAuth, JDK);
if (nettySSLContext != null) {
return nettySSLContext.context();
} else {
@@ -333,7 +362,7 @@ public class SSLUtils {
private static SslContext createRestNettySSLContext(
Configuration config, boolean clientMode, ClientAuth clientAuth)
throws Exception {
- return createRestNettySSLContext(config, clientMode, clientAuth, SslProvider.JDK);
+ return createRestNettySSLContext(config, clientMode, clientAuth, getSSLProvider(config));
}
/**
@@ -356,11 +385,11 @@ public class SSLUtils {
if (clientMode) {
sslContextBuilder = SslContextBuilder.forClient();
if (clientAuth != ClientAuth.NONE) {
- KeyManagerFactory kmf = getKeyManagerFactory(config, false);
+ KeyManagerFactory kmf = getKeyManagerFactory(config, false, provider);
sslContextBuilder.keyManager(kmf);
}
} else {
- KeyManagerFactory kmf = getKeyManagerFactory(config, false);
+ KeyManagerFactory kmf = getKeyManagerFactory(config, false, provider);
sslContextBuilder = SslContextBuilder.forServer(kmf);
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/blob/BlobClientSslTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/blob/BlobClientSslTest.java
index a46a6df..f4b9251 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/blob/BlobClientSslTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/blob/BlobClientSslTest.java
@@ -20,6 +20,7 @@ package org.apache.flink.runtime.blob;
import org.apache.flink.configuration.BlobServerOptions;
import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.SecurityOptions;
import org.apache.flink.runtime.net.SSLUtilsTest;
import org.junit.AfterClass;
@@ -55,7 +56,8 @@ public class BlobClientSslTest extends BlobClientTest {
*/
@BeforeClass
public static void startSSLServer() throws IOException {
- Configuration config = SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores();
+ Configuration config = SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores(
+ SecurityOptions.SSL_PROVIDER.defaultValue());
config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporarySslFolder.newFolder().getAbsolutePath());
blobSslServer = new TestBlobServer(config, new VoidBlobStore());
@@ -66,7 +68,8 @@ public class BlobClientSslTest extends BlobClientTest {
@BeforeClass
public static void startNonSSLServer() throws IOException {
- Configuration config = SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores();
+ Configuration config = SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores(
+ SecurityOptions.SSL_PROVIDER.defaultValue());
config.setString(BlobServerOptions.STORAGE_DIRECTORY, temporarySslFolder.newFolder().getAbsolutePath());
config.setBoolean(BlobServerOptions.SSL_ENABLED, false);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyClientServerSslTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyClientServerSslTest.java
index 6ec7a23..24e8fbd 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyClientServerSslTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyClientServerSslTest.java
@@ -21,6 +21,7 @@ package org.apache.flink.runtime.io.network.netty;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.core.testutils.OneShotLatch;
import org.apache.flink.runtime.io.network.netty.NettyTestUtil.NettyServerAndClient;
import org.apache.flink.runtime.net.SSLUtilsTest;
import org.apache.flink.util.NetUtils;
@@ -28,16 +29,20 @@ import org.apache.flink.util.TestLogger;
import org.apache.flink.shaded.netty4.io.netty.channel.Channel;
import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler;
+import org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel;
import org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringDecoder;
import org.apache.flink.shaded.netty4.io.netty.handler.codec.string.StringEncoder;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import javax.net.ssl.SSLSessionContext;
import java.net.InetAddress;
+import java.util.List;
import static org.apache.flink.configuration.SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT;
import static org.apache.flink.configuration.SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT;
@@ -52,8 +57,17 @@ import static org.junit.Assert.assertTrue;
* Tests for the SSL connection between Netty Server and Client used for the
* data plane.
*/
+@RunWith(Parameterized.class)
public class NettyClientServerSslTest extends TestLogger {
+ @Parameterized.Parameter
+ public String sslProvider;
+
+ @Parameterized.Parameters(name = "SSL provider = {0}")
+ public static List<String> parameters() {
+ return SSLUtilsTest.AVAILABLE_SSL_PROVIDERS;
+ }
+
/**
* Verify valid ssl configuration and connection.
*/
@@ -77,25 +91,46 @@ public class NettyClientServerSslTest extends TestLogger {
}
private void testValidSslConnection(Configuration sslConfig) throws Exception {
+ OneShotLatch serverChannelInitComplete = new OneShotLatch();
+ final SslHandler[] serverSslHandler = new SslHandler[1];
+
NettyProtocol protocol = new NoOpProtocol();
NettyConfig nettyConfig = createNettyConfig(sslConfig);
- NettyTestUtil.NettyServerAndClient serverAndClient = NettyTestUtil.initServerAndClient(protocol, nettyConfig);
+ final NettyBufferPool bufferPool = new NettyBufferPool(1);
+ final NettyServer server = NettyTestUtil.initServer(
+ nettyConfig,
+ bufferPool,
+ sslHandlerFactory ->
+ new TestingServerChannelInitializer(
+ protocol,
+ sslHandlerFactory,
+ serverChannelInitComplete,
+ serverSslHandler));
+ final NettyClient client = NettyTestUtil.initClient(nettyConfig, protocol, bufferPool);
+ final NettyServerAndClient serverAndClient = new NettyServerAndClient(server, client);
Channel ch = NettyTestUtil.connect(serverAndClient);
- SslHandler sslHandler = (SslHandler) ch.pipeline().get("ssl");
- assertEqualsOrDefault(sslConfig, SSL_INTERNAL_HANDSHAKE_TIMEOUT, sslHandler.getHandshakeTimeoutMillis());
- assertEqualsOrDefault(sslConfig, SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT, sslHandler.getCloseNotifyFlushTimeoutMillis());
+ SslHandler clientSslHandler = (SslHandler) ch.pipeline().get("ssl");
+ assertEqualsOrDefault(sslConfig, SSL_INTERNAL_HANDSHAKE_TIMEOUT, clientSslHandler.getHandshakeTimeoutMillis());
+ assertEqualsOrDefault(sslConfig, SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT, clientSslHandler.getCloseNotifyFlushTimeoutMillis());
// should be able to send text data
ch.pipeline().addLast(new StringDecoder()).addLast(new StringEncoder());
- assertTrue(ch.writeAndFlush("test").await().isSuccess());
+ ch.writeAndFlush("test").sync();
// session context is only be available after a session was setup -> this should be true after data was sent
- SSLSessionContext sessionContext = sslHandler.engine().getSession().getSessionContext();
+ serverChannelInitComplete.await();
+ assertNotNull(serverSslHandler[0]);
+
+ // verify server parameters
+ assertEqualsOrDefault(sslConfig, SSL_INTERNAL_HANDSHAKE_TIMEOUT, serverSslHandler[0].getHandshakeTimeoutMillis());
+ assertEqualsOrDefault(sslConfig, SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT, serverSslHandler[0].getCloseNotifyFlushTimeoutMillis());
+ SSLSessionContext sessionContext = serverSslHandler[0].engine().getSession().getSessionContext();
assertNotNull("bug in unit test setup: session context not available", sessionContext);
+ // note: can't verify session cache setting at the client - delegate to server instead (with our own channel initializer)
assertEqualsOrDefault(sslConfig, SSL_INTERNAL_SESSION_CACHE_SIZE, sessionContext.getSessionCacheSize());
int sessionTimeout = sslConfig.getInteger(SSL_INTERNAL_SESSION_TIMEOUT);
if (sessionTimeout != -1) {
@@ -194,8 +229,8 @@ public class NettyClientServerSslTest extends TestLogger {
NettyTestUtil.shutdown(serverAndClient);
}
- private static Configuration createSslConfig() {
- return SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores();
+ private Configuration createSslConfig() {
+ return SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores(sslProvider);
}
private static NettyConfig createNettyConfig(Configuration config) {
@@ -223,4 +258,34 @@ public class NettyClientServerSslTest extends TestLogger {
return new ChannelHandler[0];
}
}
+
+ /**
+ * Wrapper around {@link NettyServer.ServerChannelInitializer} making the server's SSL handler
+ * available for the tests.
+ */
+ private static class TestingServerChannelInitializer extends NettyServer.ServerChannelInitializer {
+ private final OneShotLatch latch;
+ private final SslHandler[] serverHandler;
+
+ TestingServerChannelInitializer(
+ NettyProtocol protocol,
+ SSLHandlerFactory sslHandlerFactory,
+ OneShotLatch latch,
+ SslHandler[] serverHandler) {
+ super(protocol, sslHandlerFactory);
+ this.latch = latch;
+ this.serverHandler = serverHandler;
+ }
+
+ @Override
+ public void initChannel(SocketChannel channel) throws Exception {
+ super.initChannel(channel);
+
+ SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
+ assertNotNull(sslHandler);
+ serverHandler[0] = sslHandler;
+
+ latch.trigger();
+ }
+ }
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyTestUtil.java b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyTestUtil.java
index f0c1b80..7d0138b 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyTestUtil.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/io/network/netty/NettyTestUtil.java
@@ -26,6 +26,7 @@ import org.apache.flink.shaded.netty4.io.netty.channel.Channel;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
import static org.apache.flink.util.Preconditions.checkArgument;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -55,6 +56,23 @@ public class NettyTestUtil {
return server;
}
+ static NettyServer initServer(
+ NettyConfig config,
+ NettyBufferPool bufferPool,
+ Function<SSLHandlerFactory, NettyServer.ServerChannelInitializer> channelInitializer) throws Exception {
+ final NettyServer server = new NettyServer(config);
+
+ try {
+ server.init(bufferPool, channelInitializer);
+ }
+ catch (Exception e) {
+ server.shutdown();
+ throw e;
+ }
+
+ return server;
+ }
+
static NettyClient initClient(NettyConfig config, NettyProtocol protocol, NettyBufferPool bufferPool) throws Exception {
final NettyClient client = new NettyClient(config);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
index 17d9ec8..1e4b217 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
@@ -25,18 +25,25 @@ import org.apache.flink.runtime.io.network.netty.SSLHandlerFactory;
import org.apache.flink.util.TestLogger;
import org.apache.flink.shaded.netty4.io.netty.buffer.UnpooledByteBufAllocator;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.OpenSsl;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
import javax.net.ssl.SSLServerSocket;
import java.net.ServerSocket;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -44,6 +51,7 @@ import static org.junit.Assert.fail;
/**
* Tests for the {@link SSLUtils}.
*/
+@RunWith(Parameterized.class)
public class SSLUtilsTest extends TestLogger {
private static final String TRUST_STORE_PATH = SSLUtilsTest.class.getResource("/local127.truststore").getFile();
@@ -53,6 +61,26 @@ public class SSLUtilsTest extends TestLogger {
private static final String KEY_STORE_PASSWORD = "password";
private static final String KEY_PASSWORD = "password";
+ public static final List<String> AVAILABLE_SSL_PROVIDERS;
+ static {
+ if (OpenSsl.isAvailable()) {
+ AVAILABLE_SSL_PROVIDERS = Arrays.asList("JDK", "OPENSSL");
+ } else {
+ assertNull(
+ "openSSL not available but required (property 'flink.tests.force-openssl' is set)",
+ System.getProperty("flink.tests.force-openssl"));
+ AVAILABLE_SSL_PROVIDERS = Collections.singletonList("JDK");
+ }
+ }
+
+ @Parameterized.Parameter
+ public String sslProvider;
+
+ @Parameterized.Parameters(name = "SSL provider = {0}")
+ public static List<String> parameters() {
+ return AVAILABLE_SSL_PROVIDERS;
+ }
+
/**
* Tests whether activation of internal / REST SSL evaluates the config flags correctly.
*/
@@ -381,68 +409,101 @@ public class SSLUtilsTest extends TestLogger {
@Test
public void testCreateSSLEngineFactory() throws Exception {
Configuration serverConfig = createInternalSslConfigWithKeyAndTrustStores();
+ final String[] sslAlgorithms;
+ final String[] expectedSslProtocols;
+ if (sslProvider.equalsIgnoreCase("OPENSSL")) {
+ // openSSL does not support the same set of cipher algorithms!
+ sslAlgorithms = new String[] {"TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_AES_256_GCM_SHA384"};
+ expectedSslProtocols = new String[] {"SSLv2Hello", "TLSv1"};
+ } else {
+ sslAlgorithms = new String[] {"TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"};
+ expectedSslProtocols = new String[] {"TLSv1"};
+ }
// set custom protocol and cipher suites
serverConfig.setString(SecurityOptions.SSL_PROTOCOL, "TLSv1");
- serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256");
+ serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, String.join(",", sslAlgorithms));
final SSLHandlerFactory serverSSLHandlerFactory = SSLUtils.createInternalServerSSLEngineFactory(serverConfig);
final SslHandler sslHandler = serverSSLHandlerFactory.createNettySSLHandler(UnpooledByteBufAllocator.DEFAULT);
- assertEquals(1, sslHandler.engine().getEnabledProtocols().length);
- assertEquals("TLSv1", sslHandler.engine().getEnabledProtocols()[0]);
+ assertEquals(expectedSslProtocols.length, sslHandler.engine().getEnabledProtocols().length);
+ assertThat(
+ sslHandler.engine().getEnabledProtocols(),
+ arrayContainingInAnyOrder(expectedSslProtocols));
- assertEquals(2, sslHandler.engine().getEnabledCipherSuites().length);
- assertThat(sslHandler.engine().getEnabledCipherSuites(), arrayContainingInAnyOrder(
- "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"));
+ assertEquals(sslAlgorithms.length, sslHandler.engine().getEnabledCipherSuites().length);
+ assertThat(
+ sslHandler.engine().getEnabledCipherSuites(),
+ arrayContainingInAnyOrder(sslAlgorithms));
}
// ------------------------------- utils ----------------------------------
- public static Configuration createRestSslConfigWithKeyStore() {
+ private Configuration createRestSslConfigWithKeyStore() {
final Configuration config = new Configuration();
config.setBoolean(SecurityOptions.SSL_REST_ENABLED, true);
+ addSslProviderConfig(config, sslProvider);
addRestKeyStoreConfig(config);
return config;
}
- public static Configuration createRestSslConfigWithTrustStore() {
+ private Configuration createRestSslConfigWithTrustStore() {
final Configuration config = new Configuration();
config.setBoolean(SecurityOptions.SSL_REST_ENABLED, true);
+ addSslProviderConfig(config, sslProvider);
addRestTrustStoreConfig(config);
return config;
}
- public static Configuration createRestSslConfigWithKeyAndTrustStores() {
+ public static Configuration createRestSslConfigWithKeyAndTrustStores(String sslProvider) {
final Configuration config = new Configuration();
config.setBoolean(SecurityOptions.SSL_REST_ENABLED, true);
+ addSslProviderConfig(config, sslProvider);
addRestKeyStoreConfig(config);
addRestTrustStoreConfig(config);
return config;
}
- public static Configuration createInternalSslConfigWithKeyStore() {
+ private Configuration createInternalSslConfigWithKeyStore() {
final Configuration config = new Configuration();
config.setBoolean(SecurityOptions.SSL_INTERNAL_ENABLED, true);
+ addSslProviderConfig(config, sslProvider);
addInternalKeyStoreConfig(config);
return config;
}
- public static Configuration createInternalSslConfigWithTrustStore() {
+ private Configuration createInternalSslConfigWithTrustStore() {
final Configuration config = new Configuration();
config.setBoolean(SecurityOptions.SSL_INTERNAL_ENABLED, true);
+ addSslProviderConfig(config, sslProvider);
addInternalTrustStoreConfig(config);
return config;
}
- public static Configuration createInternalSslConfigWithKeyAndTrustStores() {
+ private Configuration createInternalSslConfigWithKeyAndTrustStores() {
+ return createInternalSslConfigWithKeyAndTrustStores(sslProvider);
+ }
+
+ public static Configuration createInternalSslConfigWithKeyAndTrustStores(String sslProvider) {
final Configuration config = new Configuration();
config.setBoolean(SecurityOptions.SSL_INTERNAL_ENABLED, true);
+ addSslProviderConfig(config, sslProvider);
addInternalKeyStoreConfig(config);
addInternalTrustStoreConfig(config);
return config;
}
+ private static void addSslProviderConfig(Configuration config, String sslProvider) {
+ if (sslProvider.equalsIgnoreCase("OPENSSL")) {
+ assertTrue("openSSL not available", OpenSsl.isAvailable());
+
+ // Flink's default algorithm set is not available for openSSL - choose a different one:
+ config.setString(SecurityOptions.SSL_ALGORITHMS, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384");
+ }
+ config.setString(SecurityOptions.SSL_PROVIDER, sslProvider);
+ }
+
private static void addRestKeyStoreConfig(Configuration config) {
config.setString(SecurityOptions.SSL_REST_KEYSTORE, KEY_STORE_PATH);
config.setString(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, KEY_STORE_PASSWORD);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobSubmitHandlerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobSubmitHandlerTest.java
index ed2b4cd..afaf8f4 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobSubmitHandlerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobSubmitHandlerTest.java
@@ -19,6 +19,7 @@
package org.apache.flink.runtime.rest.handler.job;
import org.apache.flink.api.common.cache.DistributedCache;
+import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.configuration.BlobServerOptions;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.runtime.blob.BlobServer;
@@ -53,6 +54,7 @@ import java.io.IOException;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
@@ -64,8 +66,13 @@ import java.util.concurrent.CompletableFuture;
public class JobSubmitHandlerTest extends TestLogger {
@Parameterized.Parameters(name = "SSL enabled: {0}")
- public static Iterable<Boolean> data() {
- return Arrays.asList(true, false);
+ public static Iterable<Tuple2<Boolean, String>> data() {
+ ArrayList<Tuple2<Boolean, String>> parameters = new ArrayList<>(3);
+ parameters.add(Tuple2.of(false, "no SSL"));
+ for (String sslProvider : SSLUtilsTest.AVAILABLE_SSL_PROVIDERS) {
+ parameters.add(Tuple2.of(true, sslProvider));
+ }
+ return parameters;
}
@ClassRule
@@ -75,9 +82,9 @@ public class JobSubmitHandlerTest extends TestLogger {
private BlobServer blobServer;
- public JobSubmitHandlerTest(boolean withSsl) {
- this.configuration = withSsl
- ? SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores()
+ public JobSubmitHandlerTest(Tuple2<Boolean, String> withSsl) {
+ this.configuration = withSsl.f0
+ ? SSLUtilsTest.createInternalSslConfigWithKeyAndTrustStores(withSsl.f1)
: new Configuration();
}
[flink] 09/09: [FLINK-12446][docs] update openSSL option
documentation
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 11a7b3f5802ed9aa0ad151ae3ff80244875cb4b5
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Thu May 23 08:52:13 2019 +0200
[FLINK-12446][docs] update openSSL option documentation
Mention all steps necessary to get openSSL-based SSL running, based on
flink-shaded 7.0.
---
.../generated/security_configuration.html | 2 +-
.../flink/configuration/SecurityOptions.java | 32 ++++++++++++++++------
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/docs/_includes/generated/security_configuration.html b/docs/_includes/generated/security_configuration.html
index 5537042..f23212e 100644
--- a/docs/_includes/generated/security_configuration.html
+++ b/docs/_includes/generated/security_configuration.html
@@ -85,7 +85,7 @@
<tr>
<td><h5>security.ssl.provider</h5></td>
<td style="word-wrap: break-word;">"JDK"</td>
- <td>The SSL engine provider to use for the ssl transport:<ul><li><span markdown="span">`JDK`</span>: default Java-based SSL engine</li><li><span markdown="span">`OPENSSL`</span>: openSSL-based SSL engine using system libraries</li></ul>Please note: OPENSSL requires a custom build of <a href="http://netty.io/wiki/forked-tomcat-native.html#wiki-h2-4">netty-tcnative</a> in our shaded package namespace which is not (yet) available but can be built manually (see <a href="https://i [...]
+ <td>The SSL engine provider to use for the ssl transport:<ul><li><span markdown="span">`JDK`</span>: default Java-based SSL engine</li><li><span markdown="span">`OPENSSL`</span>: openSSL-based SSL engine using system libraries</li></ul><span markdown="span">`OPENSSL`</span> is based on <a href="http://netty.io/wiki/forked-tomcat-native.html#wiki-h2-4">netty-tcnative</a> and comes in two flavours:<ul><li>dynamically linked: This will use your system's openSSL libraries (if com [...]
</tr>
<tr>
<td><h5>security.ssl.rest.authentication-enabled</h5></td>
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java b/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java
index ad3b194..53da887 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java
@@ -23,10 +23,12 @@ import org.apache.flink.annotation.docs.ConfigGroup;
import org.apache.flink.annotation.docs.ConfigGroups;
import org.apache.flink.annotation.docs.Documentation;
import org.apache.flink.configuration.description.Description;
-import org.apache.flink.configuration.description.TextElement;
import static org.apache.flink.configuration.ConfigOptions.key;
+import static org.apache.flink.configuration.description.LineBreakElement.linebreak;
import static org.apache.flink.configuration.description.LinkElement.link;
+import static org.apache.flink.configuration.description.TextElement.code;
+import static org.apache.flink.configuration.description.TextElement.text;
/**
* The set of configuration options relating to security.
@@ -309,14 +311,28 @@ public class SecurityOptions {
.withDescription(Description.builder()
.text("The SSL engine provider to use for the ssl transport:")
.list(
- TextElement.text("%s: default Java-based SSL engine", TextElement.code("JDK")),
- TextElement.text("%s: openSSL-based SSL engine using system libraries",
- TextElement.code("OPENSSL"))
+ text("%s: default Java-based SSL engine", code("JDK")),
+ text("%s: openSSL-based SSL engine using system libraries",
+ code("OPENSSL"))
+ )
+ .text("%s is based on %s and comes in two flavours:",
+ code("OPENSSL"),
+ link("http://netty.io/wiki/forked-tomcat-native.html#wiki-h2-4", "netty-tcnative"))
+ .list(
+ text("dynamically linked: This will use your system's openSSL libraries " +
+ "(if compatible) and requires %s to be copied to %s",
+ code("opt/flink-shaded-netty-tcnative-dynamic-*.jar"),
+ code("lib/")),
+ text("statically linked: Due to potential licensing issues with " +
+ "openSSL (see %s), we cannot ship pre-built libraries. However, " +
+ "you can build the required library yourself and put it into %s:%s%s",
+ link("https://issues.apache.org/jira/browse/LEGAL-393", "LEGAL-393"),
+ code("lib/"),
+ linebreak(),
+ code("git clone https://github.com/apache/flink-shaded.git && " +
+ "cd flink-shaded && " +
+ "mvn clean package -Pinclude-netty-tcnative-static -pl flink-shaded-netty-tcnative-static"))
)
- .text("Please note: OPENSSL requires a custom build of %s in our " +
- "shaded package namespace which is not (yet) available but can be built manually (see %s).",
- link("http://netty.io/wiki/forked-tomcat-native.html#wiki-h2-4", "netty-tcnative"),
- link("https://issues.apache.org/jira/browse/FLINK-11579", "FLINK-11579"))
.build()
);
[flink] 01/09: [hotfix][tests] remove rogue comment in common_ssl.sh
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit e24d670a9f28c00115f9e880acfc96aa1f4b293b
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Tue May 21 13:50:08 2019 +0200
[hotfix][tests] remove rogue comment in common_ssl.sh
---
flink-end-to-end-tests/test-scripts/common_ssl.sh | 2 --
1 file changed, 2 deletions(-)
diff --git a/flink-end-to-end-tests/test-scripts/common_ssl.sh b/flink-end-to-end-tests/test-scripts/common_ssl.sh
index 677a713..5a1c194 100644
--- a/flink-end-to-end-tests/test-scripts/common_ssl.sh
+++ b/flink-end-to-end-tests/test-scripts/common_ssl.sh
@@ -59,8 +59,6 @@ function _set_conf_ssl_helper {
openssl pkcs12 -passin pass:${password} -in "${ssl_dir}/node.keystore" -out "${ssl_dir}/node.pem" -nodes
# adapt config
- # (here we rely on security.ssl.enabled enabling SSL for all components and internal as well as
- # external communication channels)
set_config_key security.ssl.${type}.enabled true
set_config_key security.ssl.${type}.keystore ${ssl_dir}/node.keystore
set_config_key security.ssl.${type}.keystore-password ${password}
[flink] 08/09: [hotfix][docs] correctly escape ampersands
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 9a376ffb5ba1b05cd173e6683c81713ec8d1aba7
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Thu Jun 13 09:58:11 2019 +0200
[hotfix][docs] correctly escape ampersands
---
.../java/org/apache/flink/configuration/description/HtmlFormatter.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/description/HtmlFormatter.java b/flink-core/src/main/java/org/apache/flink/configuration/description/HtmlFormatter.java
index 53f540e..710d832 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/description/HtmlFormatter.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/description/HtmlFormatter.java
@@ -70,6 +70,7 @@ public class HtmlFormatter extends Formatter {
private static String escapeCharacters(String value) {
return value
+ .replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">");
}
[flink] 07/09: [FLINK-12518][tests][e2e] enable openSSL for
test_streaming_file_sink
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit e5b4a57b0cdd6b01ac279c70b510c2f05e4e361b
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Wed May 22 15:22:36 2019 +0200
[FLINK-12518][tests][e2e] enable openSSL for test_streaming_file_sink
This test (run nightly) will use a dynamically or statically linked openSSL
library at random during runtime, in order to eventually verify both.
---
flink-end-to-end-tests/test-scripts/common_ssl.sh | 43 ++++++++++++++++++++--
.../test-scripts/test_streaming_file_sink.sh | 7 +++-
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/flink-end-to-end-tests/test-scripts/common_ssl.sh b/flink-end-to-end-tests/test-scripts/common_ssl.sh
index 5a1c194..b3a892f 100644
--- a/flink-end-to-end-tests/test-scripts/common_ssl.sh
+++ b/flink-end-to-end-tests/test-scripts/common_ssl.sh
@@ -22,6 +22,8 @@
function _set_conf_ssl_helper {
local type=$1 # 'internal' or external 'rest'
+ local provider=$2 # 'JDK' or 'OPENSSL'
+ local provider_lib=$3 # if using OPENSSL, choose: 'dynamic' or 'static' (how openSSL is linked to our packaged jar)
local ssl_dir="${TEST_DATA_DIR}/ssl/${type}"
local password="${type}.password"
@@ -29,6 +31,16 @@ function _set_conf_ssl_helper {
echo "Unknown type of ssl connectivity: ${type}. It can be either 'internal' or external 'rest'"
exit 1
fi
+ if [ "${provider}" != "JDK" ] && [ "${provider}" != "OPENSSL" ]; then
+ echo "Unknown SSL provider: ${provider}. It can be either 'JDK' or 'OPENSSL'"
+ exit 1
+ fi
+ if [ "${provider_lib}" != "dynamic" ] && [ "${provider_lib}" != "static" ]; then
+ echo "Unknown library type for openSSL: ${provider_lib}. It can be either 'dynamic' or 'static'"
+ exit 1
+ fi
+
+ echo "Setting up SSL with: ${type} ${provider} ${provider_lib}"
# clean up the dir that will be used for SSL certificates and trust stores
if [ -e "${ssl_dir}" ]; then
@@ -58,7 +70,24 @@ function _set_conf_ssl_helper {
# keystore is converted into a pem format to use it as node.pem with curl in Flink REST API queries, see also $CURL_SSL_ARGS
openssl pkcs12 -passin pass:${password} -in "${ssl_dir}/node.keystore" -out "${ssl_dir}/node.pem" -nodes
+ if [ "${provider}" = "OPENSSL" -a "${provider_lib}" = "dynamic" ]; then
+ cp $FLINK_DIR/opt/flink-shaded-netty-tcnative-dynamic-*.jar $FLINK_DIR/lib/
+ elif [ "${provider}" = "OPENSSL" -a "${provider_lib}" = "static" ]; then
+ # Flink is not providing the statically-linked library because of potential licensing issues
+ # -> we need to build it ourselves
+ FLINK_SHADED_VERSION=$(cat ${END_TO_END_DIR}/../pom.xml | sed -n 's/.*<flink.shaded.version>\(.*\)<\/flink.shaded.version>/\1/p')
+ echo "BUILDING flink-shaded-netty-tcnative-static"
+ git clone https://github.com/apache/flink-shaded.git
+ cd flink-shaded
+ git checkout "release-${FLINK_SHADED_VERSION}"
+ mvn clean package -Pinclude-netty-tcnative-static -pl flink-shaded-netty-tcnative-static
+ cp flink-shaded-netty-tcnative-static/target/flink-shaded-netty-tcnative-static-*.jar $FLINK_DIR/lib/
+ cd ..
+ rm -rf flink-shaded
+ fi
+
# adapt config
+ set_config_key security.ssl.provider ${provider}
set_config_key security.ssl.${type}.enabled true
set_config_key security.ssl.${type}.keystore ${ssl_dir}/node.keystore
set_config_key security.ssl.${type}.keystore-password ${password}
@@ -81,8 +110,10 @@ function _set_conf_mutual_rest_ssl {
function set_conf_rest_ssl {
local auth="${1:-server}" # only 'server' or 'mutual'
+ local provider="${2:-JDK}" # 'JDK' or 'OPENSSL'
+ local provider_lib="${3:-dynamic}" # for OPENSSL: 'dynamic' or 'static'
local ssl_dir="${TEST_DATA_DIR}/ssl/rest"
- _set_conf_ssl_helper "rest"
+ _set_conf_ssl_helper "rest" "${provider}" "${provider_lib}"
_set_conf_mutual_rest_ssl ${auth}
REST_PROTOCOL="https"
CURL_SSL_ARGS="${CURL_SSL_ARGS} --cacert ${ssl_dir}/node.pem"
@@ -90,6 +121,12 @@ function set_conf_rest_ssl {
function set_conf_ssl {
local auth="${1:-server}" # only 'server' or 'mutual'
- _set_conf_ssl_helper "internal"
- set_conf_rest_ssl ${auth}
+ local provider="${2:-JDK}" # 'JDK' or 'OPENSSL'
+ local provider_lib="${3:-dynamic}" # for OPENSSL: 'dynamic' or 'static'
+ _set_conf_ssl_helper "internal" "${provider}" "${provider_lib}"
+ set_conf_rest_ssl ${auth} "${provider}" "${provider_lib}"
+}
+
+function rollback_openssl_lib() {
+ rm $FLINK_DIR/lib/flink-shaded-netty-tcnative-{dynamic,static}-*.jar
}
diff --git a/flink-end-to-end-tests/test-scripts/test_streaming_file_sink.sh b/flink-end-to-end-tests/test-scripts/test_streaming_file_sink.sh
index 6989bf3..f6624c0 100755
--- a/flink-end-to-end-tests/test-scripts/test_streaming_file_sink.sh
+++ b/flink-end-to-end-tests/test-scripts/test_streaming_file_sink.sh
@@ -22,8 +22,12 @@ OUT_TYPE="${1:-local}" # other type: s3
source "$(dirname "$0")"/common.sh
source "$(dirname "$0")"/common_s3.sh
+# randomly set up openSSL with dynamically/statically linked libraries
+OPENSSL_LINKAGE=$(if (( RANDOM % 2 )) ; then echo "dynamic"; else echo "static"; fi)
+echo "Executing test with ${OPENSSL_LINKAGE} openSSL linkage (random selection between 'dynamic' and 'static')"
+
s3_setup hadoop
-set_conf_ssl "mutual"
+set_conf_ssl "mutual" "OPENSSL" "${OPENSSL_LINKAGE}"
set_config_key "metrics.fetcher.update-interval" "2000"
OUT=temp/test_streaming_file_sink-$(uuidgen)
@@ -46,6 +50,7 @@ fi
# make sure we delete the file at the end
function out_cleanup {
s3_delete_by_full_path_prefix $OUT
+ rollback_openssl_lib
}
if [ "${OUT_TYPE}" == "s3" ]; then
on_exit out_cleanup
[flink] 02/09: [hotfix][docs] make LineBreakElement also implement
InlineElement
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 500c133d97ca5da0cc64da39785c4976452f56c4
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Thu May 23 08:42:53 2019 +0200
[hotfix][docs] make LineBreakElement also implement InlineElement
This allows line breaks in text block elements and may be useful, for example,
in starting a new line inside a list description element.
---
.../org/apache/flink/configuration/description/LineBreakElement.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flink-core/src/main/java/org/apache/flink/configuration/description/LineBreakElement.java b/flink-core/src/main/java/org/apache/flink/configuration/description/LineBreakElement.java
index 4a3de9c..4d55b18 100644
--- a/flink-core/src/main/java/org/apache/flink/configuration/description/LineBreakElement.java
+++ b/flink-core/src/main/java/org/apache/flink/configuration/description/LineBreakElement.java
@@ -21,7 +21,7 @@ package org.apache.flink.configuration.description;
/**
* Represents a line break in the {@link Description}.
*/
-public class LineBreakElement implements BlockElement {
+public class LineBreakElement implements InlineElement, BlockElement {
/**
* Creates a line break in the description.
[flink] 03/09: [FLINK-12838][network] netty-fy SSL configuration
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 65e822b67ec93e5cf50e6303c838c3b30935834a
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Mon Feb 11 15:23:59 2019 +0100
[FLINK-12838][network] netty-fy SSL configuration
Refactor the SSL configuration done for Netty to have it more like the way
Netty intends it to be: using its SslContextBuilder. This will make it much
easier to set a different Netty SSL engine provider.
[hotfix][network] extract key and trust manager factory creation
---
.../flink/mesos/util/MesosArtifactServer.java | 4 +-
.../webmonitor/utils/WebFrontendBootstrap.java | 3 +-
.../runtime/io/network/netty/NettyClient.java | 1 +
.../runtime/io/network/netty/NettyServer.java | 3 +-
.../io/network/netty/SSLHandlerFactory.java | 52 +---
.../flink/runtime/net/RedirectingSslHandler.java | 2 +-
.../org/apache/flink/runtime/net/SSLUtils.java | 280 +++++++++++----------
.../org/apache/flink/runtime/rest/RestClient.java | 2 +-
.../org/apache/flink/runtime/net/SSLUtilsTest.java | 3 +-
.../runtime/rest/RestServerEndpointITCase.java | 2 +-
10 files changed, 176 insertions(+), 176 deletions(-)
diff --git a/flink-mesos/src/main/java/org/apache/flink/mesos/util/MesosArtifactServer.java b/flink-mesos/src/main/java/org/apache/flink/mesos/util/MesosArtifactServer.java
index 89a32f1..af928a0 100644
--- a/flink-mesos/src/main/java/org/apache/flink/mesos/util/MesosArtifactServer.java
+++ b/flink-mesos/src/main/java/org/apache/flink/mesos/util/MesosArtifactServer.java
@@ -126,7 +126,6 @@ public class MesosArtifactServer implements MesosArtifactResolver {
router = new Router();
- final Configuration sslConfig = config;
ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() {
@Override
@@ -135,7 +134,8 @@ public class MesosArtifactServer implements MesosArtifactResolver {
// SSL should be the first handler in the pipeline
if (sslFactory != null) {
- ch.pipeline().addLast("ssl", sslFactory.createNettySSLHandler());
+ ch.pipeline().addLast("ssl",
+ sslFactory.createNettySSLHandler(ch.alloc()));
}
ch.pipeline()
diff --git a/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrap.java b/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrap.java
index cf30fac..82ed405 100644
--- a/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrap.java
+++ b/flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/utils/WebFrontendBootstrap.java
@@ -79,7 +79,8 @@ public class WebFrontendBootstrap {
// SSL should be the first handler in the pipeline
if (serverSSLFactory != null) {
- ch.pipeline().addLast("ssl", serverSSLFactory.createNettySSLHandler());
+ ch.pipeline().addLast("ssl",
+ serverSSLFactory.createNettySSLHandler(ch.alloc()));
}
ch.pipeline()
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyClient.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyClient.java
index d7cad7f..21ef4ca 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyClient.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyClient.java
@@ -179,6 +179,7 @@ class NettyClient {
// SSL handler should be added first in the pipeline
if (clientSSLFactory != null) {
SslHandler sslHandler = clientSSLFactory.createNettySSLHandler(
+ channel.alloc(),
serverSocketAddress.getAddress().getCanonicalHostName(),
serverSocketAddress.getPort());
channel.pipeline().addLast("ssl", sslHandler);
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java
index 8bbda5b..3fe62c7 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/NettyServer.java
@@ -147,7 +147,8 @@ class NettyServer {
@Override
public void initChannel(SocketChannel channel) throws Exception {
if (sslHandlerFactory != null) {
- channel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler());
+ channel.pipeline().addLast("ssl",
+ sslHandlerFactory.createNettySSLHandler(channel.alloc()));
}
channel.pipeline().addLast(protocol.getServerChannelHandlers());
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/SSLHandlerFactory.java b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/SSLHandlerFactory.java
index 583f038..48b9460 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/SSLHandlerFactory.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/io/network/netty/SSLHandlerFactory.java
@@ -18,9 +18,10 @@
package org.apache.flink.runtime.io.network.netty;
+import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufAllocator;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler;
-import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import static java.util.Objects.requireNonNull;
@@ -30,15 +31,7 @@ import static java.util.Objects.requireNonNull;
*/
public class SSLHandlerFactory {
- private final SSLContext sslContext;
-
- private final String[] enabledProtocols;
-
- private final String[] enabledCipherSuites;
-
- private final boolean clientMode;
-
- private final boolean clientAuthentication;
+ private final SslContext sslContext;
private final int handshakeTimeoutMs;
@@ -54,29 +47,21 @@ public class SSLHandlerFactory {
* default)
*/
public SSLHandlerFactory(
- final SSLContext sslContext,
- final String[] enabledProtocols,
- final String[] enabledCipherSuites,
- final boolean clientMode,
- final boolean clientAuthentication,
+ final SslContext sslContext,
final int handshakeTimeoutMs,
final int closeNotifyFlushTimeoutMs) {
this.sslContext = requireNonNull(sslContext, "sslContext must not be null");
- this.enabledProtocols = requireNonNull(enabledProtocols, "enabledProtocols must not be null");
- this.enabledCipherSuites = requireNonNull(enabledCipherSuites, "cipherSuites must not be null");
- this.clientMode = clientMode;
- this.clientAuthentication = clientAuthentication;
this.handshakeTimeoutMs = handshakeTimeoutMs;
this.closeNotifyFlushTimeoutMs = closeNotifyFlushTimeoutMs;
}
- public SslHandler createNettySSLHandler() {
- return createNettySSLHandler(createSSLEngine());
+ public SslHandler createNettySSLHandler(ByteBufAllocator allocator) {
+ return createNettySSLHandler(createSSLEngine(allocator));
}
- public SslHandler createNettySSLHandler(String hostname, int port) {
- return createNettySSLHandler(createSSLEngine(hostname, port));
+ public SslHandler createNettySSLHandler(ByteBufAllocator allocator, String hostname, int port) {
+ return createNettySSLHandler(createSSLEngine(allocator, hostname, port));
}
private SslHandler createNettySSLHandler(SSLEngine sslEngine) {
@@ -91,24 +76,11 @@ public class SSLHandlerFactory {
return sslHandler;
}
- private SSLEngine createSSLEngine() {
- final SSLEngine sslEngine = sslContext.createSSLEngine();
- configureSSLEngine(sslEngine);
- return sslEngine;
+ private SSLEngine createSSLEngine(ByteBufAllocator allocator) {
+ return sslContext.newEngine(allocator);
}
- private SSLEngine createSSLEngine(String hostname, int port) {
- final SSLEngine sslEngine = sslContext.createSSLEngine(hostname, port);
- configureSSLEngine(sslEngine);
- return sslEngine;
- }
-
- private void configureSSLEngine(SSLEngine sslEngine) {
- sslEngine.setEnabledProtocols(enabledProtocols);
- sslEngine.setEnabledCipherSuites(enabledCipherSuites);
- sslEngine.setUseClientMode(clientMode);
- if (!clientMode) {
- sslEngine.setNeedClientAuth(clientAuthentication);
- }
+ private SSLEngine createSSLEngine(ByteBufAllocator allocator, String hostname, int port) {
+ return sslContext.newEngine(allocator, hostname, port);
}
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/net/RedirectingSslHandler.java b/flink-runtime/src/main/java/org/apache/flink/runtime/net/RedirectingSslHandler.java
index 0e6103d..bb0f1b3 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/net/RedirectingSslHandler.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/net/RedirectingSslHandler.java
@@ -78,7 +78,7 @@ public class RedirectingSslHandler extends ByteToMessageDecoder {
}
private void handleSsl(ChannelHandlerContext context) {
- SslHandler sslHandler = sslHandlerFactory.createNettySSLHandler();
+ SslHandler sslHandler = sslHandlerFactory.createNettySSLHandler(context.alloc());
try {
context.pipeline().replace(this, SSL_HANDLER_NAME, sslHandler);
} catch (Throwable t) {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java b/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
index c756fab..dd9e7e7 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
@@ -18,21 +18,26 @@
package org.apache.flink.runtime.net;
+import org.apache.flink.annotation.VisibleForTesting;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.IllegalConfigurationException;
import org.apache.flink.configuration.SecurityOptions;
import org.apache.flink.runtime.io.network.netty.SSLHandlerFactory;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.ClientAuth;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.JdkSslContext;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContext;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslContextBuilder;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslProvider;
+
import javax.annotation.Nullable;
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
-import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLServerSocketFactory;
-import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import java.io.File;
@@ -42,6 +47,12 @@ import java.net.InetAddress;
import java.net.ServerSocket;
import java.nio.file.Files;
import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import java.util.Arrays;
+import java.util.List;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -82,7 +93,7 @@ public class SSLUtils {
* SSL Server Sockets are always part of internal communication.
*/
public static ServerSocketFactory createSSLServerSocketFactory(Configuration config) throws Exception {
- SSLContext sslContext = createInternalSSLContext(config);
+ SSLContext sslContext = createInternalSSLContext(config, false);
if (sslContext == null) {
throw new IllegalConfigurationException("SSL is not enabled");
}
@@ -99,7 +110,7 @@ public class SSLUtils {
* SSL Client Sockets are always part of internal communication.
*/
public static SocketFactory createSSLClientSocketFactory(Configuration config) throws Exception {
- SSLContext sslContext = createInternalSSLContext(config);
+ SSLContext sslContext = createInternalSSLContext(config, true);
if (sslContext == null) {
throw new IllegalConfigurationException("SSL is not enabled");
}
@@ -111,17 +122,13 @@ public class SSLUtils {
* Creates a SSLEngineFactory to be used by internal communication server endpoints.
*/
public static SSLHandlerFactory createInternalServerSSLEngineFactory(final Configuration config) throws Exception {
- SSLContext sslContext = createInternalSSLContext(config);
+ SslContext sslContext = createInternalNettySSLContext(config, false);
if (sslContext == null) {
throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
}
return new SSLHandlerFactory(
sslContext,
- getEnabledProtocols(config),
- getEnabledCipherSuites(config),
- false,
- true,
config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
@@ -130,17 +137,13 @@ public class SSLUtils {
* Creates a SSLEngineFactory to be used by internal communication client endpoints.
*/
public static SSLHandlerFactory createInternalClientSSLEngineFactory(final Configuration config) throws Exception {
- SSLContext sslContext = createInternalSSLContext(config);
+ SslContext sslContext = createInternalNettySSLContext(config, true);
if (sslContext == null) {
throw new IllegalConfigurationException("SSL is not enabled for internal communication.");
}
return new SSLHandlerFactory(
sslContext,
- getEnabledProtocols(config),
- getEnabledCipherSuites(config),
- true,
- true,
config.getInteger(SecurityOptions.SSL_INTERNAL_HANDSHAKE_TIMEOUT),
config.getInteger(SecurityOptions.SSL_INTERNAL_CLOSE_NOTIFY_FLUSH_TIMEOUT));
}
@@ -151,17 +154,14 @@ public class SSLUtils {
* @param config The application configuration.
*/
public static SSLHandlerFactory createRestServerSSLEngineFactory(final Configuration config) throws Exception {
- SSLContext sslContext = createRestServerSSLContext(config);
+ ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
+ SslContext sslContext = createRestNettySSLContext(config, false, clientAuth);
if (sslContext == null) {
throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
}
return new SSLHandlerFactory(
sslContext,
- getEnabledProtocols(config),
- getEnabledCipherSuites(config),
- false,
- isRestSSLAuthenticationEnabled(config),
-1,
-1);
}
@@ -172,17 +172,14 @@ public class SSLUtils {
* @param config The application configuration.
*/
public static SSLHandlerFactory createRestClientSSLEngineFactory(final Configuration config) throws Exception {
- SSLContext sslContext = createRestClientSSLContext(config);
+ ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
+ SslContext sslContext = createRestNettySSLContext(config, true, clientAuth);
if (sslContext == null) {
throw new IllegalConfigurationException("SSL is not enabled for REST endpoints.");
}
return new SSLHandlerFactory(
sslContext,
- getEnabledProtocols(config),
- getEnabledCipherSuites(config),
- true,
- isRestSSLAuthenticationEnabled(config),
-1,
-1);
}
@@ -197,159 +194,186 @@ public class SSLUtils {
return config.getString(SecurityOptions.SSL_ALGORITHMS).split(",");
}
- /**
- * Creates the SSL Context for internal SSL, if internal SSL is configured.
- * For internal SSL, the client and server side configuration are identical, because
- * of mutual authentication.
- */
- @Nullable
- private static SSLContext createInternalSSLContext(Configuration config) throws Exception {
- checkNotNull(config, "config");
+ private static TrustManagerFactory getTrustManagerFactory(Configuration config, boolean internal)
+ throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
+ String trustStoreFilePath = getAndCheckOption(
+ config,
+ internal ? SecurityOptions.SSL_INTERNAL_TRUSTSTORE : SecurityOptions.SSL_REST_TRUSTSTORE,
+ SecurityOptions.SSL_TRUSTSTORE);
- if (!isInternalSSLEnabled(config)) {
- return null;
+ String trustStorePassword = getAndCheckOption(
+ config,
+ internal ? SecurityOptions.SSL_INTERNAL_TRUSTSTORE_PASSWORD : SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD,
+ SecurityOptions.SSL_TRUSTSTORE_PASSWORD);
+
+ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ try (InputStream trustStoreFile = Files
+ .newInputStream(new File(trustStoreFilePath).toPath())) {
+ trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
}
- String keystoreFilePath = getAndCheckOption(
- config, SecurityOptions.SSL_INTERNAL_KEYSTORE, SecurityOptions.SSL_KEYSTORE);
- String keystorePassword = getAndCheckOption(
- config, SecurityOptions.SSL_INTERNAL_KEYSTORE_PASSWORD, SecurityOptions.SSL_KEYSTORE_PASSWORD);
+ TrustManagerFactory tmf =
+ TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(trustStore);
- String certPassword = getAndCheckOption(
- config, SecurityOptions.SSL_INTERNAL_KEY_PASSWORD, SecurityOptions.SSL_KEY_PASSWORD);
+ return tmf;
+ }
- String trustStoreFilePath = getAndCheckOption(
- config, SecurityOptions.SSL_INTERNAL_TRUSTSTORE, SecurityOptions.SSL_TRUSTSTORE);
+ private static KeyManagerFactory getKeyManagerFactory(Configuration config, boolean internal)
+ throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException,
+ UnrecoverableKeyException {
+ String keystoreFilePath = getAndCheckOption(
+ config,
+ internal ? SecurityOptions.SSL_INTERNAL_KEYSTORE : SecurityOptions.SSL_REST_KEYSTORE,
+ SecurityOptions.SSL_KEYSTORE);
- String trustStorePassword = getAndCheckOption(
- config, SecurityOptions.SSL_INTERNAL_TRUSTSTORE_PASSWORD, SecurityOptions.SSL_TRUSTSTORE_PASSWORD);
+ String keystorePassword = getAndCheckOption(
+ config,
+ internal ? SecurityOptions.SSL_INTERNAL_KEYSTORE_PASSWORD : SecurityOptions.SSL_REST_KEYSTORE_PASSWORD,
+ SecurityOptions.SSL_KEYSTORE_PASSWORD);
- String sslProtocolVersion = config.getString(SecurityOptions.SSL_PROTOCOL);
- int sessionCacheSize = config.getInteger(SecurityOptions.SSL_INTERNAL_SESSION_CACHE_SIZE);
- int sessionTimeoutMs = config.getInteger(SecurityOptions.SSL_INTERNAL_SESSION_TIMEOUT);
+ String certPassword = getAndCheckOption(
+ config,
+ internal ? SecurityOptions.SSL_INTERNAL_KEY_PASSWORD : SecurityOptions.SSL_REST_KEY_PASSWORD,
+ SecurityOptions.SSL_KEY_PASSWORD);
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream keyStoreFile = Files.newInputStream(new File(keystoreFilePath).toPath())) {
keyStore.load(keyStoreFile, keystorePassword.toCharArray());
}
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- try (InputStream trustStoreFile = Files.newInputStream(new File(trustStoreFilePath).toPath())) {
- trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
- }
-
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ KeyManagerFactory kmf =
+ KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, certPassword.toCharArray());
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(trustStore);
+ return kmf;
+ }
- SSLContext sslContext = SSLContext.getInstance(sslProtocolVersion);
- sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
- if (sessionCacheSize >= 0) {
- sslContext.getClientSessionContext().setSessionCacheSize(sessionCacheSize);
- }
- if (sessionTimeoutMs >= 0) {
- sslContext.getClientSessionContext().setSessionTimeout(sessionTimeoutMs / 1000);
+ /**
+ * Creates the SSL Context for internal SSL, if internal SSL is configured.
+ * For internal SSL, the client and server side configuration are identical, because
+ * of mutual authentication.
+ */
+ @Nullable
+ private static SSLContext createInternalSSLContext(Configuration config, boolean clientMode) throws Exception {
+ JdkSslContext nettySSLContext =
+ (JdkSslContext) createInternalNettySSLContext(config, clientMode, SslProvider.JDK);
+ if (nettySSLContext != null) {
+ return nettySSLContext.context();
+ } else {
+ return null;
}
-
- return sslContext;
}
- private enum RestSSLContextConfigMode {
- CLIENT,
- SERVER,
- MUTUAL
+ @Nullable
+ private static SslContext createInternalNettySSLContext(Configuration config, boolean clientMode)
+ throws Exception {
+ return createInternalNettySSLContext(config, clientMode, SslProvider.JDK);
}
/**
- * Creates an SSL context for the external REST SSL.
- * If mutual authentication is configured the client and the server side configuration are identical.
+ * Creates the SSL Context for internal SSL, if internal SSL is configured.
+ * For internal SSL, the client and server side configuration are identical, because
+ * of mutual authentication.
*/
@Nullable
- private static SSLContext createRestSSLContext(Configuration config, RestSSLContextConfigMode configMode) throws Exception {
+ private static SslContext createInternalNettySSLContext(
+ Configuration config, boolean clientMode, SslProvider provider)
+ throws Exception {
checkNotNull(config, "config");
- if (!isRestSSLEnabled(config)) {
+ if (!isInternalSSLEnabled(config)) {
return null;
}
- KeyManager[] keyManagers = null;
- if (configMode == RestSSLContextConfigMode.SERVER || configMode == RestSSLContextConfigMode.MUTUAL) {
- String keystoreFilePath = getAndCheckOption(
- config, SecurityOptions.SSL_REST_KEYSTORE, SecurityOptions.SSL_KEYSTORE);
-
- String keystorePassword = getAndCheckOption(
- config, SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, SecurityOptions.SSL_KEYSTORE_PASSWORD);
-
- String certPassword = getAndCheckOption(
- config, SecurityOptions.SSL_REST_KEY_PASSWORD, SecurityOptions.SSL_KEY_PASSWORD);
-
- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
- try (InputStream keyStoreFile = Files.newInputStream(new File(keystoreFilePath).toPath())) {
- keyStore.load(keyStoreFile, keystorePassword.toCharArray());
- }
-
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- kmf.init(keyStore, certPassword.toCharArray());
-
- keyManagers = kmf.getKeyManagers();
- }
-
- TrustManager[] trustManagers = null;
- if (configMode == RestSSLContextConfigMode.CLIENT || configMode == RestSSLContextConfigMode.MUTUAL) {
- String trustStoreFilePath = getAndCheckOption(
- config, SecurityOptions.SSL_REST_TRUSTSTORE, SecurityOptions.SSL_TRUSTSTORE);
-
- String trustStorePassword = getAndCheckOption(
- config, SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, SecurityOptions.SSL_TRUSTSTORE_PASSWORD);
-
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- try (InputStream trustStoreFile = Files.newInputStream(new File(trustStoreFilePath).toPath())) {
- trustStore.load(trustStoreFile, trustStorePassword.toCharArray());
- }
+ String[] sslProtocols = getEnabledProtocols(config);
+ List<String> ciphers = Arrays.asList(getEnabledCipherSuites(config));
+ int sessionCacheSize = config.getInteger(SecurityOptions.SSL_INTERNAL_SESSION_CACHE_SIZE);
+ int sessionTimeoutMs = config.getInteger(SecurityOptions.SSL_INTERNAL_SESSION_TIMEOUT);
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(trustStore);
+ KeyManagerFactory kmf = getKeyManagerFactory(config, true);
+ TrustManagerFactory tmf = getTrustManagerFactory(config, true);
+ ClientAuth clientAuth = ClientAuth.REQUIRE;
- trustManagers = tmf.getTrustManagers();
+ final SslContextBuilder sslContextBuilder;
+ if (clientMode) {
+ sslContextBuilder = SslContextBuilder.forClient().keyManager(kmf);
+ } else {
+ sslContextBuilder = SslContextBuilder.forServer(kmf);
}
- String sslProtocolVersion = config.getString(SecurityOptions.SSL_PROTOCOL);
- SSLContext sslContext = SSLContext.getInstance(sslProtocolVersion);
- sslContext.init(keyManagers, trustManagers, null);
-
- return sslContext;
+ return sslContextBuilder
+ .sslProvider(provider)
+ .protocols(sslProtocols)
+ .ciphers(ciphers)
+ .trustManager(tmf)
+ .clientAuth(clientAuth)
+ .sessionCacheSize(sessionCacheSize)
+ .sessionTimeout(sessionTimeoutMs / 1000)
+ .build();
}
/**
- * Creates an SSL context for the external REST endpoint server.
+ * Creates an SSL context for clients against the external REST endpoint.
*/
@Nullable
- public static SSLContext createRestServerSSLContext(Configuration config) throws Exception {
- final RestSSLContextConfigMode configMode;
- if (isRestSSLAuthenticationEnabled(config)) {
- configMode = RestSSLContextConfigMode.MUTUAL;
+ @VisibleForTesting
+ public static SSLContext createRestSSLContext(Configuration config, boolean clientMode) throws Exception {
+ ClientAuth clientAuth = isRestSSLAuthenticationEnabled(config) ? ClientAuth.REQUIRE : ClientAuth.NONE;
+ JdkSslContext nettySSLContext =
+ (JdkSslContext) createRestNettySSLContext(config, clientMode, clientAuth, SslProvider.JDK);
+ if (nettySSLContext != null) {
+ return nettySSLContext.context();
} else {
- configMode = RestSSLContextConfigMode.SERVER;
+ return null;
}
+ }
- return createRestSSLContext(config, configMode);
+ @Nullable
+ private static SslContext createRestNettySSLContext(
+ Configuration config, boolean clientMode, ClientAuth clientAuth)
+ throws Exception {
+ return createRestNettySSLContext(config, clientMode, clientAuth, SslProvider.JDK);
}
/**
- * Creates an SSL context for clients against the external REST endpoint.
+ * Creates an SSL context for the external REST SSL.
+ * If mutual authentication is configured the client and the server side configuration are identical.
*/
@Nullable
- public static SSLContext createRestClientSSLContext(Configuration config) throws Exception {
- final RestSSLContextConfigMode configMode;
- if (isRestSSLAuthenticationEnabled(config)) {
- configMode = RestSSLContextConfigMode.MUTUAL;
+ public static SslContext createRestNettySSLContext(
+ Configuration config, boolean clientMode, ClientAuth clientAuth, SslProvider provider)
+ throws Exception {
+ checkNotNull(config, "config");
+
+ if (!isRestSSLEnabled(config)) {
+ return null;
+ }
+
+ String[] sslProtocols = getEnabledProtocols(config);
+
+ final SslContextBuilder sslContextBuilder;
+ if (clientMode) {
+ sslContextBuilder = SslContextBuilder.forClient();
+ if (clientAuth != ClientAuth.NONE) {
+ KeyManagerFactory kmf = getKeyManagerFactory(config, false);
+ sslContextBuilder.keyManager(kmf);
+ }
} else {
- configMode = RestSSLContextConfigMode.CLIENT;
+ KeyManagerFactory kmf = getKeyManagerFactory(config, false);
+ sslContextBuilder = SslContextBuilder.forServer(kmf);
+ }
+
+ if (clientMode || clientAuth != ClientAuth.NONE) {
+ TrustManagerFactory tmf = getTrustManagerFactory(config, false);
+ sslContextBuilder.trustManager(tmf);
}
- return createRestSSLContext(config, configMode);
+ return sslContextBuilder
+ .sslProvider(provider)
+ .protocols(sslProtocols)
+ .clientAuth(clientAuth)
+ .build();
}
// ------------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
index c478cf5..524197e 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestClient.java
@@ -124,7 +124,7 @@ public class RestClient implements AutoCloseableAsync {
try {
// SSL should be the first handler in the pipeline
if (sslHandlerFactory != null) {
- socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler());
+ socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler(socketChannel.alloc()));
}
socketChannel.pipeline()
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
index 5031acc..17d9ec8 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/net/SSLUtilsTest.java
@@ -24,6 +24,7 @@ import org.apache.flink.configuration.SecurityOptions;
import org.apache.flink.runtime.io.network.netty.SSLHandlerFactory;
import org.apache.flink.util.TestLogger;
+import org.apache.flink.shaded.netty4.io.netty.buffer.UnpooledByteBufAllocator;
import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler;
import org.junit.Test;
@@ -386,7 +387,7 @@ public class SSLUtilsTest extends TestLogger {
serverConfig.setString(SecurityOptions.SSL_ALGORITHMS, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256");
final SSLHandlerFactory serverSSLHandlerFactory = SSLUtils.createInternalServerSSLEngineFactory(serverConfig);
- final SslHandler sslHandler = serverSSLHandlerFactory.createNettySSLHandler();
+ final SslHandler sslHandler = serverSSLHandlerFactory.createNettySSLHandler(UnpooledByteBufAllocator.DEFAULT);
assertEquals(1, sslHandler.engine().getEnabledProtocols().length);
assertEquals("TLSv1", sslHandler.engine().getEnabledProtocols()[0]);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java
index 51d1d2e..a99ec44 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestServerEndpointITCase.java
@@ -184,7 +184,7 @@ public class RestServerEndpointITCase extends TestLogger {
defaultSSLContext = SSLContext.getDefault();
defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
- final SSLContext sslClientContext = SSLUtils.createRestClientSSLContext(config);
+ final SSLContext sslClientContext = SSLUtils.createRestSSLContext(config, true);
if (sslClientContext != null) {
SSLContext.setDefault(sslClientContext);
HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getSocketFactory());
[flink] 06/09: [FLINK-12517][tests] enable openSSL tests via
openSSL-enhanced flink-shaded version
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit d11be3358ac67f11d2859176412834d16a547301
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Tue May 21 13:37:46 2019 +0200
[FLINK-12517][tests] enable openSSL tests via openSSL-enhanced flink-shaded version
This uses the dynamically-linked openSSL for the unit tests since this is the
artifact that we distribute.
TODO: e2e tests for dynamically and statically linked openSSL
---
flink-runtime/pom.xml | 6 ++++++
pom.xml | 7 +++++++
tools/travis_watchdog.sh | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/flink-runtime/pom.xml b/flink-runtime/pom.xml
index 1a3fd20..a679cea 100644
--- a/flink-runtime/pom.xml
+++ b/flink-runtime/pom.xml
@@ -278,6 +278,12 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-shaded-netty-tcnative-dynamic</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
<version>${curator.version}</version>
diff --git a/pom.xml b/pom.xml
index 0d4bc2d..edfdcc9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -274,6 +274,13 @@ under the License.
<version>4.1.32.Final-${flink.shaded.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-shaded-netty-tcnative-dynamic</artifactId>
+ <version>2.0.25.Final-${flink.shaded.version}</version>
+ <scope>test</scope>
+ </dependency>
+
<!-- This manages the 'javax.annotation' annotations (JSR305) -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
diff --git a/tools/travis_watchdog.sh b/tools/travis_watchdog.sh
index 36b984d..fe629bb 100755
--- a/tools/travis_watchdog.sh
+++ b/tools/travis_watchdog.sh
@@ -62,7 +62,7 @@ MVN_TEST_MODULES=$(get_test_modules_for_stage ${TEST})
MVN_LOGGING_OPTIONS="-Dlog.dir=${ARTIFACTS_DIR} -Dlog4j.configuration=file://$LOG4J_PROPERTIES -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
MVN_COMMON_OPTIONS="-nsu -Dflink.forkCount=2 -Dflink.forkCountTestPackage=2 -Dfast -B -Pskip-webui-build $MVN_LOGGING_OPTIONS"
MVN_COMPILE_OPTIONS="-DskipTests"
-MVN_TEST_OPTIONS="$MVN_LOGGING_OPTIONS"
+MVN_TEST_OPTIONS="$MVN_LOGGING_OPTIONS -Dflink.tests.force-openssl"
MVN_COMPILE="mvn $MVN_COMMON_OPTIONS $MVN_COMPILE_OPTIONS $PROFILE $MVN_COMPILE_MODULES install"
MVN_TEST="mvn $MVN_COMMON_OPTIONS $MVN_TEST_OPTIONS $PROFILE $MVN_TEST_MODULES verify"
[flink] 05/09: [FLINK-12839][dist] package
flink-shaded-netty-tcnative-dynamic into opt/
Posted by nk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nkruber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit c4ec9be6c8c1fca9633bb25a2a26f94338988445
Author: Nico Kruber <ni...@ververica.com>
AuthorDate: Tue May 21 16:22:21 2019 +0200
[FLINK-12839][dist] package flink-shaded-netty-tcnative-dynamic into opt/
Please note that there is also a static version of netty-tcnative but we
currently do not distribute it due to licensing issues. Once openSSL completes
its switch to Apache License v2, we can provide this as well and maybe even
make that one default (by putting it into lib/). Since there are to many things
which may go wrong with the dynamically-linked library (based on the system you
run on), we provide this only in opt/.
---
flink-dist/pom.xml | 6 ++++++
flink-dist/src/main/assemblies/opt.xml | 10 ++++++++++
2 files changed, 16 insertions(+)
diff --git a/flink-dist/pom.xml b/flink-dist/pom.xml
index 59c2b77..8dd16bd 100644
--- a/flink-dist/pom.xml
+++ b/flink-dist/pom.xml
@@ -376,6 +376,12 @@ under the License.
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-shaded-netty-tcnative-dynamic</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- end optional Flink libraries -->
<!-- test dependencies -->
diff --git a/flink-dist/src/main/assemblies/opt.xml b/flink-dist/src/main/assemblies/opt.xml
index 7f872d4..84593ac 100644
--- a/flink-dist/src/main/assemblies/opt.xml
+++ b/flink-dist/src/main/assemblies/opt.xml
@@ -200,4 +200,14 @@
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
+ <dependencySets>
+ <dependencySet>
+ <unpack>false</unpack>
+ <outputDirectory>opt</outputDirectory>
+ <includes>
+ <include>org.apache.flink:flink-shaded-netty-tcnative-dynamic</include>
+ </includes>
+ <scope>provided</scope>
+ </dependencySet>
+ </dependencySets>
</assembly>