You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "mateczagany (via GitHub)" <gi...@apache.org> on 2026/01/22 08:07:15 UTC
[PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
mateczagany opened a new pull request, #27457:
URL: https://github.com/apache/flink/pull/27457
## What is the purpose of the change
As described in this [ML thread](https://lists.apache.org/thread/4z3gpm4hg82m5vz2330zv9b93q9hcr2d), the SSL endpoint verification configuration is not working as expected. This was mitigated in #27407 but the change in that PR enables endpoint verification for internal communication as well.
This PR will address that according to the ML thread, and only REST client will use hostname verification using the new configuration.
## Brief change log
- Remove configuration `security.ssl.verify-hostname` which is not used in any recent released Flink version
- Add `security.ssl.rest.verify-hostname` which will only add hostname verification for REST connections
- Add test cases
## Verifying this change
- By adding new tests with the already existing certificates found in the test suite
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): no
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? yes
- If yes, how is the feature documented? Updated documentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2716079197
##########
flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java:
##########
@@ -514,15 +523,6 @@ public static Configuration forProvider(Configuration configuration, String prov
"here"))
.build());
- /** Flag to enable/disable hostname verification for the ssl connections. */
- @Documentation.Section(Documentation.Sections.SECURITY_SSL)
- public static final ConfigOption<Boolean> SSL_VERIFY_HOSTNAME =
Review Comment:
If you prefer to have it marked as deprecated, we can do that, but overall this configuration should have no effect to stay consistent with previous Flink releases.
We can note in the description that the user should use the new configuration option to have hostname verification for external connections.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on PR #27457:
URL: https://github.com/apache/flink/pull/27457#issuecomment-3884126607
@flinkbot run azure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2716010468
##########
flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java:
##########
@@ -514,15 +523,6 @@ public static Configuration forProvider(Configuration configuration, String prov
"here"))
.build());
- /** Flag to enable/disable hostname verification for the ssl connections. */
- @Documentation.Section(Documentation.Sections.SECURITY_SSL)
- public static final ConfigOption<Boolean> SSL_VERIFY_HOSTNAME =
Review Comment:
I do not think we should remove options. We should deprecate the old option and still allow it to work and have the documentation reference the new option as the preferred way of now doing things. Otherwise we get a failure when adopting this code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2719740346
##########
flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java:
##########
@@ -514,15 +523,6 @@ public static Configuration forProvider(Configuration configuration, String prov
"here"))
.build());
- /** Flag to enable/disable hostname verification for the ssl connections. */
- @Documentation.Section(Documentation.Sections.SECURITY_SSL)
- public static final ConfigOption<Boolean> SSL_VERIFY_HOSTNAME =
Review Comment:
I have re-added the old configuration as deprecated, and hidden from the docs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27457:
URL: https://github.com/apache/flink/pull/27457#issuecomment-3783107598
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "3a34a45be95d42cc9d5300a1807a3fda76111686",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "3a34a45be95d42cc9d5300a1807a3fda76111686",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 3a34a45be95d42cc9d5300a1807a3fda76111686 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "gaborgsomogyi (via GitHub)" <gi...@apache.org>.
gaborgsomogyi merged PR #27457:
URL: https://github.com/apache/flink/pull/27457
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on PR #27457:
URL: https://github.com/apache/flink/pull/27457#issuecomment-3907028778
@flinkbot run azure
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2792128899
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestSSLEndpointVerificationITCase.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.flink.runtime.rest;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.util.TestMessageHeaders;
+import org.apache.flink.runtime.rest.util.TestRestHandler;
+import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.security.cert.CertificateException;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+
+/**
+ * This test validates that REST SSL endpoint verification works as expected and will fail the
+ * request if the endpoint certificate does not match the REST server hostname.
+ */
+public class RestSSLEndpointVerificationITCase {
+
+ private static final File KEY_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.keystore")
+ .getFile());
+ private static final File TRUST_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.truststore")
+ .getFile());
+
+ private static final TestMessageHeaders<
+ EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters>
+ TEST_MESSAGE_HEADERS =
+ TestMessageHeaders.emptyBuilder()
+ .setTargetRestEndpointURL("/test-handler")
+ .build();
+
+ private final Configuration config;
+
+ public RestSSLEndpointVerificationITCase() {
+ config = new Configuration();
+ config.set(RestOptions.BIND_PORT, "0");
+ config.set(RestOptions.ADDRESS, "localhost");
+ config.set(SecurityOptions.SSL_REST_ENABLED, true);
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE, TRUST_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEYSTORE, KEY_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEY_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_VERIFY_HOSTNAME, true);
+ }
+
+ /**
+ * With hostname verification turned on, this should execute fine as "127.0.0.1" is part of the
+ * Subject Alternative Names.
+ */
+ @Test
+ void testConnectSuccess() throws Exception {
+ try (RestServerEndpoint serverEndpoint = getRestServerEndpoint();
+ RestClient restClient = getRestClient("127.0.0.1", serverEndpoint.getRestPort())) {
+ restClient
+ .sendRequest(
+ serverEndpoint.getServerAddress().getHostName(),
+ serverEndpoint.getServerAddress().getPort(),
+ TEST_MESSAGE_HEADERS,
+ EmptyMessageParameters.getInstance(),
+ EmptyRequestBody.getInstance(),
+ Collections.emptyList())
+ .get();
+ }
+ }
+
+ /** This should fail as "127.0.0.2" is not part of the Subject Alternative Names. */
+ @Test
+ void testConnectFailure() throws Exception {
+ try (RestServerEndpoint serverEndpoint = getRestServerEndpoint();
+ RestClient restClient = getRestClient("127.0.0.2", serverEndpoint.getRestPort())) {
+ assertThatFuture(
+ restClient.sendRequest(
+ serverEndpoint.getServerAddress().getHostName(),
+ serverEndpoint.getServerAddress().getPort(),
+ TEST_MESSAGE_HEADERS,
+ EmptyMessageParameters.getInstance(),
+ EmptyRequestBody.getInstance(),
+ Collections.emptyList()))
+ .failsWithin(60, TimeUnit.SECONDS)
+ .withThrowableOfType(ExecutionException.class)
+ .satisfies(anyCauseMatches(CertificateException.class));
Review Comment:
yes, good idea!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2716047585
##########
flink-core/src/main/java/org/apache/flink/configuration/SecurityOptions.java:
##########
@@ -514,15 +523,6 @@ public static Configuration forProvider(Configuration configuration, String prov
"here"))
.build());
- /** Flag to enable/disable hostname verification for the ssl connections. */
- @Documentation.Section(Documentation.Sections.SECURITY_SSL)
- public static final ConfigOption<Boolean> SSL_VERIFY_HOSTNAME =
Review Comment:
Thank you for reviewing this PR, I've tried to explain this as best as I could in the description of the PR. This configuration was not used before the mentioned PR merged yesterday. However in the ML discussion it's clear that the implementation in that PR is wrong, and we should not have hostname verification for internal communication.
There will be a migration guide probably in the release blog post that this configuration was not working properly in any other recent release, and that users should use the new configuration.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "gaborgsomogyi (via GitHub)" <gi...@apache.org>.
gaborgsomogyi commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2791765254
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestSSLEndpointVerificationITCase.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.flink.runtime.rest;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.util.TestMessageHeaders;
+import org.apache.flink.runtime.rest.util.TestRestHandler;
+import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.security.cert.CertificateException;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+
+/**
+ * This test validates that REST SSL endpoint verification works as expected and will fail the
+ * request if the endpoint certificate does not match the REST server hostname.
+ */
+public class RestSSLEndpointVerificationITCase {
+
+ private static final File KEY_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.keystore")
+ .getFile());
+ private static final File TRUST_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.truststore")
+ .getFile());
+
+ private static final TestMessageHeaders<
+ EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters>
+ TEST_MESSAGE_HEADERS =
+ TestMessageHeaders.emptyBuilder()
+ .setTargetRestEndpointURL("/test-handler")
+ .build();
+
+ private final Configuration config;
+
+ public RestSSLEndpointVerificationITCase() {
+ config = new Configuration();
+ config.set(RestOptions.BIND_PORT, "0");
+ config.set(RestOptions.ADDRESS, "localhost");
+ config.set(SecurityOptions.SSL_REST_ENABLED, true);
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE, TRUST_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEYSTORE, KEY_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEY_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_VERIFY_HOSTNAME, true);
+ }
+
+ /**
+ * With hostname verification turned on, this should execute fine as "127.0.0.1" is part of the
+ * Subject Alternative Names.
+ */
+ @Test
+ void testConnectSuccess() throws Exception {
Review Comment:
I always suggest to have at least one assertion on tests. Maybe we can add here something like:
```
// Extract and verify the certificate SANs
SSLContext sslContext = SSLContext.getDefault();
SSLSocketFactory factory = sslContext.getSocketFactory();
try (SSLSocket socket = (SSLSocket) factory.createSocket(
serverEndpoint.getServerAddress().getHostName(),
serverEndpoint.getServerAddress().getPort())) {
socket.startHandshake();
Certificate[] certs = socket.getSession().getPeerCertificates();
X509Certificate x509 = (X509Certificate) certs[0];
// Extract Subject Alternative Names
Collection<List<?>> sans = x509.getSubjectAlternativeNames();
List<String> ipAddresses = sans.stream()
.filter(san -> (Integer) san.get(0) == 7) // Type 7 is IP address
.map(san -> (String) san.get(1))
.collect(Collectors.toList());
// Assert that 127.0.0.1 is in the certificate
assertThat(ipAddresses).contains("127.0.0.1");
}
```
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestSSLEndpointVerificationITCase.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.flink.runtime.rest;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.util.TestMessageHeaders;
+import org.apache.flink.runtime.rest.util.TestRestHandler;
+import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.security.cert.CertificateException;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+
+/**
+ * This test validates that REST SSL endpoint verification works as expected and will fail the
+ * request if the endpoint certificate does not match the REST server hostname.
+ */
+public class RestSSLEndpointVerificationITCase {
+
+ private static final File KEY_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.keystore")
+ .getFile());
+ private static final File TRUST_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.truststore")
+ .getFile());
+
+ private static final TestMessageHeaders<
+ EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters>
+ TEST_MESSAGE_HEADERS =
+ TestMessageHeaders.emptyBuilder()
+ .setTargetRestEndpointURL("/test-handler")
+ .build();
+
+ private final Configuration config;
+
+ public RestSSLEndpointVerificationITCase() {
+ config = new Configuration();
+ config.set(RestOptions.BIND_PORT, "0");
+ config.set(RestOptions.ADDRESS, "localhost");
+ config.set(SecurityOptions.SSL_REST_ENABLED, true);
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE, TRUST_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEYSTORE, KEY_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEY_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_VERIFY_HOSTNAME, true);
+ }
+
+ /**
+ * With hostname verification turned on, this should execute fine as "127.0.0.1" is part of the
+ * Subject Alternative Names.
+ */
+ @Test
+ void testConnectSuccess() throws Exception {
+ try (RestServerEndpoint serverEndpoint = getRestServerEndpoint();
+ RestClient restClient = getRestClient("127.0.0.1", serverEndpoint.getRestPort())) {
+ restClient
+ .sendRequest(
+ serverEndpoint.getServerAddress().getHostName(),
+ serverEndpoint.getServerAddress().getPort(),
+ TEST_MESSAGE_HEADERS,
+ EmptyMessageParameters.getInstance(),
+ EmptyRequestBody.getInstance(),
+ Collections.emptyList())
+ .get();
+ }
+ }
+
+ /** This should fail as "127.0.0.2" is not part of the Subject Alternative Names. */
+ @Test
+ void testConnectFailure() throws Exception {
+ try (RestServerEndpoint serverEndpoint = getRestServerEndpoint();
+ RestClient restClient = getRestClient("127.0.0.2", serverEndpoint.getRestPort())) {
+ assertThatFuture(
Review Comment:
Same SAN check can be done here for clarity(next dev's life will be easier) and safety.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestSSLEndpointVerificationITCase.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.flink.runtime.rest;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.util.TestMessageHeaders;
+import org.apache.flink.runtime.rest.util.TestRestHandler;
+import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.security.cert.CertificateException;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+
+/**
+ * This test validates that REST SSL endpoint verification works as expected and will fail the
+ * request if the endpoint certificate does not match the REST server hostname.
+ */
+public class RestSSLEndpointVerificationITCase {
+
+ private static final File KEY_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.keystore")
+ .getFile());
+ private static final File TRUST_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.truststore")
+ .getFile());
+
+ private static final TestMessageHeaders<
+ EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters>
+ TEST_MESSAGE_HEADERS =
+ TestMessageHeaders.emptyBuilder()
+ .setTargetRestEndpointURL("/test-handler")
+ .build();
+
+ private final Configuration config;
+
+ public RestSSLEndpointVerificationITCase() {
+ config = new Configuration();
+ config.set(RestOptions.BIND_PORT, "0");
+ config.set(RestOptions.ADDRESS, "localhost");
+ config.set(SecurityOptions.SSL_REST_ENABLED, true);
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE, TRUST_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEYSTORE, KEY_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEY_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_VERIFY_HOSTNAME, true);
+ }
+
+ /**
+ * With hostname verification turned on, this should execute fine as "127.0.0.1" is part of the
+ * Subject Alternative Names.
+ */
+ @Test
+ void testConnectSuccess() throws Exception {
+ try (RestServerEndpoint serverEndpoint = getRestServerEndpoint();
+ RestClient restClient = getRestClient("127.0.0.1", serverEndpoint.getRestPort())) {
+ restClient
+ .sendRequest(
+ serverEndpoint.getServerAddress().getHostName(),
+ serverEndpoint.getServerAddress().getPort(),
+ TEST_MESSAGE_HEADERS,
+ EmptyMessageParameters.getInstance(),
+ EmptyRequestBody.getInstance(),
+ Collections.emptyList())
+ .get();
+ }
+ }
+
+ /** This should fail as "127.0.0.2" is not part of the Subject Alternative Names. */
+ @Test
+ void testConnectFailure() throws Exception {
+ try (RestServerEndpoint serverEndpoint = getRestServerEndpoint();
+ RestClient restClient = getRestClient("127.0.0.2", serverEndpoint.getRestPort())) {
+ assertThatFuture(
+ restClient.sendRequest(
+ serverEndpoint.getServerAddress().getHostName(),
+ serverEndpoint.getServerAddress().getPort(),
+ TEST_MESSAGE_HEADERS,
+ EmptyMessageParameters.getInstance(),
+ EmptyRequestBody.getInstance(),
+ Collections.emptyList()))
+ .failsWithin(60, TimeUnit.SECONDS)
+ .withThrowableOfType(ExecutionException.class)
+ .satisfies(anyCauseMatches(CertificateException.class));
Review Comment:
Can we add something like `message.contains("hostname verification failed")` because cert verification can blow up many ways?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-38953] Cleanup configurations for SSL hostname verification [flink]
Posted by "mateczagany (via GitHub)" <gi...@apache.org>.
mateczagany commented on code in PR #27457:
URL: https://github.com/apache/flink/pull/27457#discussion_r2792129777
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/RestSSLEndpointVerificationITCase.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.flink.runtime.rest;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.RestOptions;
+import org.apache.flink.configuration.SecurityOptions;
+import org.apache.flink.runtime.rest.messages.EmptyMessageParameters;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.EmptyResponseBody;
+import org.apache.flink.runtime.rest.util.TestMessageHeaders;
+import org.apache.flink.runtime.rest.util.TestRestHandler;
+import org.apache.flink.runtime.rest.util.TestRestServerEndpoint;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.TestingRestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.util.ConfigurationException;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.security.cert.CertificateException;
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.apache.flink.core.testutils.FlinkAssertions.assertThatFuture;
+
+/**
+ * This test validates that REST SSL endpoint verification works as expected and will fail the
+ * request if the endpoint certificate does not match the REST server hostname.
+ */
+public class RestSSLEndpointVerificationITCase {
+
+ private static final File KEY_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.keystore")
+ .getFile());
+ private static final File TRUST_STORE_FILE =
+ new File(
+ RestSSLEndpointVerificationITCase.class
+ .getResource("/local127.truststore")
+ .getFile());
+
+ private static final TestMessageHeaders<
+ EmptyRequestBody, EmptyResponseBody, EmptyMessageParameters>
+ TEST_MESSAGE_HEADERS =
+ TestMessageHeaders.emptyBuilder()
+ .setTargetRestEndpointURL("/test-handler")
+ .build();
+
+ private final Configuration config;
+
+ public RestSSLEndpointVerificationITCase() {
+ config = new Configuration();
+ config.set(RestOptions.BIND_PORT, "0");
+ config.set(RestOptions.ADDRESS, "localhost");
+ config.set(SecurityOptions.SSL_REST_ENABLED, true);
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE, TRUST_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_TRUSTSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEYSTORE, KEY_STORE_FILE.getAbsolutePath());
+ config.set(SecurityOptions.SSL_REST_KEYSTORE_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_KEY_PASSWORD, "password");
+ config.set(SecurityOptions.SSL_REST_VERIFY_HOSTNAME, true);
+ }
+
+ /**
+ * With hostname verification turned on, this should execute fine as "127.0.0.1" is part of the
+ * Subject Alternative Names.
+ */
+ @Test
+ void testConnectSuccess() throws Exception {
Review Comment:
Thank you, I've added this for both methods.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org