-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9320: Enable TLSv1.3 by default (KIP-573) #8695
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
18a1bca
KAFKA-9320: Initial commit.
nizhikov 1076e51
KAFKA-9320: Initial commit.
nizhikov 7dec0d6
KAFKA-9320: Test added
nizhikov f6afbb9
KAFKA-9320: Test added
nizhikov 142e487
KAFKA-9320: Test added
nizhikov ac448d1
KAFKA-9320: Test added
nizhikov e1287c6
KAFKA-9320: SslVersionsTransportLayerTest added.
nizhikov b310e60
KAFKA-9320: Tests fix.
nizhikov 518eb77
KAFKA-9320: system tests updated.
nizhikov 5b5f37e
KAFKA-9320: system tests updated.
nizhikov c7000d9
KAFKA-9320: system tests updated.
nizhikov 862f7ae
KAFKA-9320: code review fixes
nizhikov d1dd114
Merge branch 'trunk' into KAFKA-9320
nizhikov 5578192
KAFKA-9320: code review fixes
nizhikov c1847e7
KAFKA-9320: code review fixes
nizhikov c901254
KAFKA-9320: code review fixes
nizhikov 61cd6c5
KAFKA-9320: code review fixes
nizhikov fd1f48b
KAFKA-9320: code review fixes
nizhikov e1a2fe4
Merge branch 'trunk' into KAFKA-9320
nizhikov 4e7eaec
KAFKA-9320: test fix.
nizhikov c756720
KAFKA-9320: code review fixes.
nizhikov a231e2f
KAFKA-9320: code review fixes.
nizhikov 7ab2f39
KAFKA-9320: code review fixes.
nizhikov 17612ac
KAFKA-9320: code review fixes.
nizhikov ebb20e1
KAFKA-9320: revert test changes.
nizhikov 1b55587
KAFKA-9320: fix test duration.
nizhikov 9da1c21
KAFKA-9320: unused code removed.
nizhikov 3e6c445
KAFKA-9320: code review fixes.
nizhikov 14bf85a
KAFKA-9320: TLSv1.3 vs TLSv1.2 explanation comments.
nizhikov 67f0ef9
Merge branch 'trunk' into KAFKA-9320
nizhikov 869e342
KAFKA-9320: code review fixes.
nizhikov ca81fcd
KAFKA-9320: code review fixes.
nizhikov 6a82441
KAFKA-9320: SSL_PROTOCOL_DOC updated.
nizhikov ce7505f
Documentation tweaks
ijuma b293578
Merge branch 'trunk' into KAFKA-9320
nizhikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
clients/src/test/java/org/apache/kafka/common/network/SslTransportTls12Tls13Test.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.common.network; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.InetSocketAddress; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import org.apache.kafka.common.config.SslConfigs; | ||
| import org.apache.kafka.common.metrics.Metrics; | ||
| import org.apache.kafka.common.security.TestSecurityConfig; | ||
| import org.apache.kafka.common.security.auth.SecurityProtocol; | ||
| import org.apache.kafka.common.utils.Java; | ||
| import org.apache.kafka.common.utils.LogContext; | ||
| import org.apache.kafka.common.utils.Time; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assume.assumeTrue; | ||
|
|
||
| public class SslTransportTls12Tls13Test { | ||
| private static final int BUFFER_SIZE = 4 * 1024; | ||
| private static final Time TIME = Time.SYSTEM; | ||
|
|
||
| private NioEchoServer server; | ||
| private Selector selector; | ||
| private Map<String, Object> sslClientConfigs; | ||
| private Map<String, Object> sslServerConfigs; | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| // Create certificates for use by client and server. Add server cert to client truststore and vice versa. | ||
| CertStores serverCertStores = new CertStores(true, "server", "localhost"); | ||
| CertStores clientCertStores = new CertStores(false, "client", "localhost"); | ||
| sslServerConfigs = serverCertStores.getTrustingConfig(clientCertStores); | ||
| sslClientConfigs = clientCertStores.getTrustingConfig(serverCertStores); | ||
|
|
||
| LogContext logContext = new LogContext(); | ||
| ChannelBuilder channelBuilder = new SslChannelBuilder(Mode.CLIENT, null, false, logContext); | ||
| channelBuilder.configure(sslClientConfigs); | ||
| this.selector = new Selector(5000, new Metrics(), TIME, "MetricGroup", channelBuilder, logContext); | ||
| } | ||
|
|
||
| @After | ||
| public void teardown() throws Exception { | ||
| if (selector != null) | ||
| this.selector.close(); | ||
| if (server != null) | ||
| this.server.close(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that connections fails if TLSv1.3 enabled but cipher suite suitable only for TLSv1.2 used. | ||
| */ | ||
| @Test | ||
| public void testCiphersSuiteForTls12FailsForTls13() throws Exception { | ||
| assumeTrue(Java.IS_JAVA11_COMPATIBLE); | ||
|
|
||
| String cipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"; | ||
|
|
||
| sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Collections.singletonList("TLSv1.3")); | ||
| sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite)); | ||
| server = NetworkTestUtils.createEchoServer(ListenerName.forSecurityProtocol(SecurityProtocol.SSL), | ||
| SecurityProtocol.SSL, new TestSecurityConfig(sslServerConfigs), null, TIME); | ||
|
|
||
| sslClientConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Collections.singletonList("TLSv1.3")); | ||
| sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite)); | ||
|
|
||
| checkAuthentiationFailed(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that connections can't be made if server uses TLSv1.2 with custom cipher suite and client uses TLSv1.3. | ||
| */ | ||
| @Test | ||
| public void testCiphersSuiteFailForServerTls12ClientTls13() throws Exception { | ||
| assumeTrue(Java.IS_JAVA11_COMPATIBLE); | ||
|
|
||
| String tls12CipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"; | ||
| String tls13CipherSuite = "TLS_AES_128_GCM_SHA256"; | ||
|
|
||
| sslServerConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.2"); | ||
| sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Collections.singletonList("TLSv1.2")); | ||
| sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(tls12CipherSuite)); | ||
| server = NetworkTestUtils.createEchoServer(ListenerName.forSecurityProtocol(SecurityProtocol.SSL), | ||
| SecurityProtocol.SSL, new TestSecurityConfig(sslServerConfigs), null, TIME); | ||
|
|
||
| sslClientConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.3"); | ||
| sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(tls13CipherSuite)); | ||
|
|
||
| checkAuthentiationFailed(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that connections can be made with TLSv1.3 cipher suite. | ||
| */ | ||
| @Test | ||
| public void testCiphersSuiteForTls13() throws Exception { | ||
| assumeTrue(Java.IS_JAVA11_COMPATIBLE); | ||
|
|
||
| String cipherSuite = "TLS_AES_128_GCM_SHA256"; | ||
|
|
||
| sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite)); | ||
| server = NetworkTestUtils.createEchoServer(ListenerName.forSecurityProtocol(SecurityProtocol.SSL), | ||
| SecurityProtocol.SSL, new TestSecurityConfig(sslServerConfigs), null, TIME); | ||
|
|
||
| sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite)); | ||
| checkAuthenticationSucceed(); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that connections can be made with TLSv1.2 cipher suite. | ||
| */ | ||
| @Test | ||
| public void testCiphersSuiteForTls12() throws Exception { | ||
| String cipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"; | ||
|
|
||
| sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS.split(","))); | ||
| sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite)); | ||
| server = NetworkTestUtils.createEchoServer(ListenerName.forSecurityProtocol(SecurityProtocol.SSL), | ||
| SecurityProtocol.SSL, new TestSecurityConfig(sslServerConfigs), null, TIME); | ||
|
|
||
| sslClientConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS.split(","))); | ||
| sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite)); | ||
| checkAuthenticationSucceed(); | ||
| } | ||
|
|
||
| /** Checks connection failed using the specified {@code tlsVersion}. */ | ||
| private void checkAuthentiationFailed() throws IOException, InterruptedException { | ||
| sslClientConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList("TLSv1.3")); | ||
| createSelector(sslClientConfigs); | ||
| InetSocketAddress addr = new InetSocketAddress("localhost", server.port()); | ||
| selector.connect("0", addr, BUFFER_SIZE, BUFFER_SIZE); | ||
|
|
||
| NetworkTestUtils.waitForChannelClose(selector, "0", ChannelState.State.AUTHENTICATION_FAILED); | ||
| server.verifyAuthenticationMetrics(0, 1); | ||
| } | ||
|
|
||
| private void checkAuthenticationSucceed() throws IOException, InterruptedException { | ||
| createSelector(sslClientConfigs); | ||
| InetSocketAddress addr = new InetSocketAddress("localhost", server.port()); | ||
| selector.connect("0", addr, BUFFER_SIZE, BUFFER_SIZE); | ||
| NetworkTestUtils.waitForChannelReady(selector, "0"); | ||
| server.verifyAuthenticationMetrics(1, 0); | ||
| } | ||
|
|
||
| private void createSelector(Map<String, Object> sslClientConfigs) { | ||
| SslTransportLayerTest.TestSslChannelBuilder channelBuilder = new SslTransportLayerTest.TestSslChannelBuilder(Mode.CLIENT); | ||
| channelBuilder.configureBufferSizes(null, null, null); | ||
| channelBuilder.configure(sslClientConfigs); | ||
| this.selector = new Selector(100 * 5000, new Metrics(), TIME, "MetricGroup", channelBuilder, new LogContext()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.