This is an automated email from the ASF dual-hosted git repository.
anton-vinogradov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new b40a4147588 IGNITE-29210 Reload TLS certificates on running nodes
(#13785)
b40a4147588 is described below
commit b40a41475886fb65676250dfe4d0ce89989f5ddb
Author: Anton Vinogradov <[email protected]>
AuthorDate: Wed Nov 11 16:38:43 2026 +0300
IGNITE-29210 Reload TLS certificates on running nodes (#13785)
---
docs/_docs/security/ssl-tls.adoc | 49 ++--
docs/_docs/tools/control-script.adoc | 38 +++
.../ignite/ssl/AbstractSslContextFactory.java | 20 +-
.../commandline/CommandHandlerParsingTest.java | 4 +-
.../SecurityCommandHandlerPermissionsTest.java | 39 +++
.../testsuites/IgniteControlUtilityTestSuite.java | 2 +
.../util/GridCommandHandlerSslReloadTest.java | 285 +++++++++++++++++++++
.../apache/ignite/internal/GridKernalContext.java | 4 +
.../ignite/internal/GridKernalContextImpl.java | 10 +
.../internal/management/IgniteCommandRegistry.java | 4 +-
.../ignite/internal/management/ssl/SslCommand.java | 29 +++
.../internal/management/ssl/SslReloadCommand.java | 58 +++++
.../internal/management/ssl/SslReloadTask.java | 181 +++++++++++++
.../wal/reader/StandaloneGridKernalContext.java | 6 +
.../processors/odbc/ClientListenerProcessor.java | 11 +-
.../rest/protocols/tcp/GridTcpRestProtocol.java | 15 +-
.../processors/ssl/SslFactoryRegistry.java | 40 +++
.../spi/communication/tcp/TcpCommunicationSpi.java | 3 +
.../ignite/spi/discovery/tcp/TcpDiscoverySpi.java | 3 +
.../internal/management/ssl/SslReloadTaskTest.java | 92 +++++++
.../processors/ssl/SslFactoryRegistryTest.java | 39 +++
.../ignite/ssl/SslContextFactoryInitTest.java | 133 ++++++++++
.../ignite/testframework/junits/IgniteMock.java | 9 +
.../ignite/testsuites/SecurityTestSuite.java | 4 +
...ridCommandHandlerClusterByClassTest_help.output | 3 +
...andHandlerClusterByClassWithSSLTest_help.output | 3 +
26 files changed, 1044 insertions(+), 40 deletions(-)
diff --git a/docs/_docs/security/ssl-tls.adoc b/docs/_docs/security/ssl-tls.adoc
index b56b2094d58..9ede647e3ed 100644
--- a/docs/_docs/security/ssl-tls.adoc
+++ b/docs/_docs/security/ssl-tls.adoc
@@ -157,27 +157,36 @@ include::{javaFile}[tag=disable-validation,indent=0]
--
== Upgrading Certificates
-If your SSL certificates are about to expire or have been compromised, you can
install new certificates without shutting down the whole cluster.
-The following is a procedure for updating certificate.
-
-. First of all, make sure the new certificates are trusted by all cluster
nodes.
-This step may not be necessary if your trusted stores contain the root
certificate and the new certificates are signed by the same CA.
-+
---
-Repeat the following procedure for the nodes where the certificate is not
trusted:
-
-.. Import the new certificate to the trusted store of the node.
-.. Gracefully restart the node.
-.. Repeat these steps for all server nodes.
-
-Now all nodes trust the new certificates.
---
-
-. Import the new certificate (including the private key) to the key store of
the corresponding node and remove the old certificate. Then gracefully restart
the node. Repeat this procedure for all certificates you want to update.
-
-
-//Otherwise, first you have to push the trust store to all nodes one by one.
It will contain trusts for both new and old certificates while you transition.
+You can replace certificate files and reload them without restarting nodes
that use `SslContextFactory`.
+The link:tools/control-script#reloading-tls-certificates[`--ssl reload`
command] updates TCP transports on all server and thick-client nodes.
+It does not reload TLS for the HTTP REST endpoint (Jetty) or external client
applications.
+
+. Back up the key and trust store files before replacing them.
+Keep their configured paths, store types, and passwords unchanged; changing
node configuration requires a restart.
+. Make sure every peer trusts both the current and replacement certificates
before changing any key store.
+This includes cluster nodes and client applications, including the control
script.
+If the replacement certificates use an already trusted CA, no trust store
change is needed.
+Otherwise, add the required certificates to the trust stores, replace the
files, and run `control.sh --ssl reload`.
+Reload trust in external client applications using their own procedures.
+Continue only after every affected peer has loaded the updated trust store.
+. Replace each key store with the new certificate and its private key, then
run `control.sh --ssl reload` again.
+Use the link:tools/control-script#connecting-to-cluster[connection parameters]
required by your cluster.
+The command asks for confirmation; use `--yes` to skip it.
+. Check the command result and the reload logs of any failed nodes, then
verify a new connection with the replacement certificates.
+Established connections continue using their existing TLS context.
+
+If a factory fails to reload, it keeps its previous context, and that node
stops reloading its remaining factories.
+Successful reloads remain in effect; other nodes continue independently.
+Check the affected node's log for error details.
+Correct the failed store and run the command again.
+To restore the previous certificates, restore the backed-up files and reload
again while peers still trust those certificates.
+
+Custom factories must extend
javadoc:org.apache.ignite.ssl.AbstractSslContextFactory[].
+They must reread key and trust data from their sources on reload and supply
the updated context for new connections.
+If any factory on a node has another type, the command reports it as
unsupported and reloads nothing on that node.
+For these factories, follow the same trust-first sequence and restart affected
nodes one at a time instead of running reload.
+If you configured `trustManagers` directly, the command reuses them instead of
reloading a trust store.
== SslContextFactory Properties
diff --git a/docs/_docs/tools/control-script.adoc
b/docs/_docs/tools/control-script.adoc
index ac52f55792d..54fff9048be 100644
--- a/docs/_docs/tools/control-script.adoc
+++ b/docs/_docs/tools/control-script.adoc
@@ -160,6 +160,44 @@ control.bat --state --ssl-factory
client-connector-ssl-factory.xml
Enable it in the configuration
(`IgniteConfiguration#setClientConnectorConfiguration`).
+== Reloading TLS Certificates
+
+Use `--ssl reload` to load replaced key and trust stores on all server and
thick-client nodes in the current topology.
+It reloads discovery, communication, client connector, and binary REST
transports that started with TLS.
+New connections use the replacement context; established connections stay open.
+The command does not reload TLS for the HTTP REST endpoint (Jetty).
+
+Follow link:security/ssl-tls#upgrading-certificates[Upgrading Certificates] to
prepare peer trust, replace the files, and verify the result.
+Add the <<connecting-to-cluster,connection parameters>> required by your
cluster:
+
+[tabs]
+--
+tab:Unix[]
+[source,shell]
+----
+control.sh --ssl reload [--yes]
+----
+tab:Windows[]
+[source,shell]
+----
+control.bat --ssl reload [--yes]
+----
+--
+
+The command requires `ADMIN_OPS` permission when security is enabled and asks
for confirmation unless `--yes` is given.
+Each node logs its reload results.
+When security is enabled, logs identify the initiator by login and subject ID.
+This is the control-script user, or the node receiving a JMX call.
+
+The report lists every target node, even if none of its TCP transports use TLS.
+Each node first checks that all registered factories extend
`AbstractSslContextFactory`.
+If any factory is unsupported, that node reloads none of its factories.
+Otherwise, it reloads them until the first failure and reports the error.
+Other nodes continue independently.
+It exits with code `4` if any reload fails, any factory is unsupported, or a
target node leaves before responding.
+A result received from a node stays in the report even if the node leaves
later.
+Successful reloads remain in effect even if a later reload fails; their
results are recorded in the node logs.
+
== Activation, Deactivation and Topology Management
You can use the control script to activate or deactivate your cluster, and
manage the link:clustering/baseline-topology[Baseline Topology].
diff --git
a/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
b/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
index 5139f98bc39..15306f1d2b9 100644
---
a/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
+++
b/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
@@ -182,7 +182,7 @@ public abstract class AbstractSslContextFactory implements
Factory<SSLContext> {
*
* @throws IgniteException If the context cannot be initialized.
*/
- protected final void init() {
+ public final synchronized void init() {
try {
sslCtx.set(createSslContext());
}
@@ -195,18 +195,14 @@ public abstract class AbstractSslContextFactory
implements Factory<SSLContext> {
@Override public SSLContext create() {
SSLContext ctx = sslCtx.get();
- if (ctx == null) {
- try {
- ctx = createSslContext();
+ if (ctx != null)
+ return ctx;
- if (!sslCtx.compareAndSet(null, ctx))
- ctx = sslCtx.get();
- }
- catch (SSLException e) {
- throw new IgniteException(e);
- }
- }
+ synchronized (this) {
+ if (sslCtx.get() == null)
+ init();
- return ctx;
+ return sslCtx.get();
+ }
}
}
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
index 9ed84b06acd..c170f8acc1f 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/CommandHandlerParsingTest.java
@@ -86,6 +86,7 @@ import
org.apache.ignite.internal.management.property.PropertyCommand;
import org.apache.ignite.internal.management.snapshot.SnapshotCommand;
import org.apache.ignite.internal.management.snapshot.SnapshotDeleteCommand;
import org.apache.ignite.internal.management.snapshot.SnapshotRestoreCommand;
+import org.apache.ignite.internal.management.ssl.SslCommand;
import org.apache.ignite.internal.management.tx.TxCommand;
import org.apache.ignite.internal.management.tx.TxCommandArg;
import org.apache.ignite.internal.management.tx.TxSortOrder;
@@ -1278,6 +1279,7 @@ public class CommandHandlerParsingTest {
cmd == ConsistencyCommand.class ||
cmd == CdcCommand.class ||
cmd == IoTestCommand.class ||
- cmd == EventCommand.class;
+ cmd == EventCommand.class ||
+ cmd == SslCommand.class;
}
}
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java
index 902bc9797d7..d9f5a37b714 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/internal/commandline/SecurityCommandHandlerPermissionsTest.java
@@ -52,6 +52,8 @@ import
org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
import org.apache.ignite.services.ServiceConfiguration;
import org.apache.ignite.services.ServiceDescriptor;
import org.apache.ignite.spi.systemview.view.ComputeTaskView;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
import org.apache.ignite.util.GridCommandHandlerAbstractTest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -67,6 +69,7 @@ import static
org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UN
import static
org.apache.ignite.internal.processors.job.GridJobProcessor.JOBS_VIEW;
import static
org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW;
import static org.apache.ignite.internal.util.IgniteUtils.resolveIgnitePath;
+import static org.apache.ignite.plugin.security.SecurityPermission.ADMIN_OPS;
import static
org.apache.ignite.plugin.security.SecurityPermission.CACHE_CREATE;
import static
org.apache.ignite.plugin.security.SecurityPermission.CACHE_DESTROY;
import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_READ;
@@ -132,6 +135,42 @@ public class SecurityCommandHandlerPermissionsTest extends
GridCommandHandlerAbs
assertTrue(out.contains("Cluster tag: " + clTag));
}
+ /** */
+ @Test
+ public void testSslReloadRequiresAdminOps() throws Exception {
+ startGrid(
+ 0,
+ userData(TEST_NO_PERMISSIONS_LOGIN, NO_PERMISSIONS),
+ userData(TEST_LOGIN, systemPermissions(ADMIN_OPS))
+ );
+
+ List<String> cmdArgs = asList("--ssl", "reload");
+
+ assertEquals(EXIT_CODE_UNEXPECTED_ERROR, executeOnBehalf(cmdArgs,
TEST_NO_PERMISSIONS_LOGIN));
+ assertTrue(testOut.toString().contains("Authorization failed"));
+
+ assertEquals(EXIT_CODE_OK, executeOnBehalf(cmdArgs, TEST_LOGIN));
+ }
+
+ /** */
+ @Test
+ public void testSslReloadLogsAuthenticatedInitiator() throws Exception {
+ LogListener reloadLog = LogListener.matches(msg -> msg.contains("TLS
reload: ")
+ && msg.contains(": reloaded [initiator=" + TEST_LOGIN + ",
subjectId=")).build();
+
+ IgniteConfiguration cfg =
getConfiguration(getTestIgniteInstanceName(0));
+
+ cfg.setGridLogger(new ListeningTestLogger(log, reloadLog));
+ cfg.setSslContextFactory(sslFactory());
+ cfg.setPluginProviders(new
TestSecurityPluginProvider(cfg.getIgniteInstanceName(), DEFAULT_PWD,
ALL_PERMISSIONS, false,
+ userData(TEST_LOGIN, systemPermissions(ADMIN_OPS))));
+
+ startGrid(cfg);
+
+ assertEquals(EXIT_CODE_OK, executeOnBehalf(asList("--ssl", "reload"),
TEST_LOGIN));
+ assertTrue(reloadLog.check());
+ }
+
/** */
@Test
public void testCacheScan() throws Exception {
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java
b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java
index 6528d919f61..d5950db85e5 100644
---
a/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java
+++
b/modules/control-utility/src/test/java/org/apache/ignite/testsuites/IgniteControlUtilityTestSuite.java
@@ -36,6 +36,7 @@ import
org.apache.ignite.util.GridCommandHandlerIndexingWithSSLTest;
import org.apache.ignite.util.GridCommandHandlerLegacyClientTest;
import org.apache.ignite.util.GridCommandHandlerManagementPoolTest;
import org.apache.ignite.util.GridCommandHandlerMetadataTest;
+import org.apache.ignite.util.GridCommandHandlerSslReloadTest;
import org.apache.ignite.util.GridCommandHandlerSslTest;
import org.apache.ignite.util.GridCommandHandlerTest;
import org.apache.ignite.util.GridCommandHandlerWalTest;
@@ -61,6 +62,7 @@ import org.junit.runners.Suite;
GridCommandHandlerClusterByClassTest.class,
GridCommandHandlerClusterByClassWithSSLTest.class,
GridCommandHandlerSslTest.class,
+ GridCommandHandlerSslReloadTest.class,
GridPersistenceCommandsTest.class,
GridCommandHandlerSslWithSecurityTest.class,
diff --git
a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslReloadTest.java
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslReloadTest.java
new file mode 100644
index 00000000000..81809a7fc91
--- /dev/null
+++
b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerSslReloadTest.java
@@ -0,0 +1,285 @@
+/*
+ * 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.ignite.util;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.GridJobExecuteResponse;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.TestRecordingCommunicationSpi;
+import
org.apache.ignite.internal.processors.rest.client.message.GridClientPingPacket;
+import org.apache.ignite.ssl.SslContextFactory;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.LogListener;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static
org.apache.ignite.internal.IgniteNodeAttributes.ATTR_REST_TCP_PORT;
+import static
org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
+import static
org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR;
+import static org.apache.ignite.testframework.GridTestUtils.assertContains;
+import static org.apache.ignite.testframework.GridTestUtils.keyStorePassword;
+import static org.apache.ignite.testframework.GridTestUtils.keyStorePath;
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
+import static org.apache.ignite.testframework.GridTestUtils.sslTrustedFactory;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assume.assumeTrue;
+
+/** */
+public class GridCommandHandlerSslReloadTest extends
GridCommandHandlerClusterPerMethodAbstractTest {
+ /** */
+ @Rule
+ public final TemporaryFolder stores = new TemporaryFolder();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ persistenceEnable(false);
+ injectTestSystemOut();
+ }
+
+ /** */
+ @Test
+ public void testSharedFactoryReloadedOnceOnServerAndClient() throws
Exception {
+ List<IgniteEx> nodes = new ArrayList<>();
+ List<CountingSslContextFactory> factories = new ArrayList<>();
+
+ for (String name : new String[] {getTestIgniteInstanceName(0),
"client"}) {
+ CountingSslContextFactory factory = new
CountingSslContextFactory(keyStorePath("node01"));
+ IgniteConfiguration cfg =
getConfiguration(name).setSslContextFactory(factory);
+
+ cfg.getClientConnectorConfiguration().setSslEnabled(true);
+ cfg.getConnectorConfiguration().setSslEnabled(true);
+
+ nodes.add(startGrid(cfg));
+ factories.add(factory);
+ }
+
+ int[] loads = factories.stream().mapToInt(factory ->
factory.loads.get()).toArray();
+
+ assertEquals(EXIT_CODE_OK, executeTlsReload());
+
+ for (int i = 0; i < nodes.size(); i++) {
+ assertEquals(loads[i] + 1, factories.get(i).loads.get());
+ String transports = nodes.get(i).configuration().isClientMode()
+ ? "communication, client connector, discovery"
+ : "communication, client connector, binary REST, discovery";
+
+ assertContains(log, testOut.toString(),
nodes.get(i).localNode().id() + ": " + transports + ": reloaded");
+ }
+ }
+
+ /** */
+ @Test
+ public void testReloadedFilesApplyToNewConnections() throws Exception {
+ Path keys = stores.newFile("keys.jks").toPath();
+ Path trust = stores.newFile("trust.jks").toPath();
+
+ Files.copy(Path.of(keyStorePath("node01")), keys, REPLACE_EXISTING);
+ Files.copy(Path.of(keyStorePath("trustone")), trust, REPLACE_EXISTING);
+
+ SslContextFactory factory = new SslContextFactory();
+
+ factory.setKeyStoreFilePath(keys.toString());
+ factory.setKeyStorePassword(keyStorePassword().toCharArray());
+ factory.setTrustStoreFilePath(trust.toString());
+ factory.setTrustStorePassword(keyStorePassword().toCharArray());
+
+ IgniteConfiguration cfg =
getConfiguration(getTestIgniteInstanceName(0));
+
+
cfg.getConnectorConfiguration().setSslEnabled(true).setSslClientAuth(true).setSslFactory(factory);
+
+ IgniteEx node = startGrid(cfg);
+ int port = node.localNode().attribute(ATTR_REST_TCP_PORT);
+
+ connectAndPing(port, sslTrustedFactory("node01", "trustone").create());
+
+ Files.copy(Path.of(keyStorePath("node02")), keys, REPLACE_EXISTING);
+ Files.copy(Path.of(keyStorePath("trusttwo")), trust, REPLACE_EXISTING);
+
+ assertEquals(EXIT_CODE_OK, execute("--ssl", "reload"));
+
+ connectAndPing(port, sslTrustedFactory("node02", "trusttwo").create());
+ }
+
+ /** */
+ @Test
+ public void testStopsReloadingNodeAfterFailure() throws Exception {
+ Path keys = stores.newFile("keys.jks").toPath();
+ LogListener loadFailure =
LogListener.matches(EOFException.class.getName()).build();
+
+ Files.copy(Path.of(keyStorePath("node01")), keys, REPLACE_EXISTING);
+
+ CountingSslContextFactory failing = new
CountingSslContextFactory(keys.toString());
+ CountingSslContextFactory working = new
CountingSslContextFactory(keyStorePath("node01"));
+ SSLContext clientCtx = working.create();
+ IgniteConfiguration cfg =
getConfiguration(getTestIgniteInstanceName(0)).setSslContextFactory(failing);
+
+ cfg.setGridLogger(new ListeningTestLogger(log, loadFailure));
+
cfg.getClientConnectorConfiguration().setSslEnabled(true).setUseIgniteSslContextFactory(false).setSslContextFactory(working);
+
+ IgniteEx node = startGrid(cfg);
+
+ Files.write(keys, new byte[0]);
+
+ assertEquals(EXIT_CODE_UNEXPECTED_ERROR, executeTlsReload());
+
+ String report = testOut.toString();
+ String nodeId = node.localNode().id().toString();
+
+ assertSame(clientCtx, working.create());
+ assertContains(log, report, nodeId + ": failed: communication,
discovery:");
+ assertTrue(loadFailure.check());
+ }
+
+ /** */
+ @Test
+ public void testUnsupportedFactoryPreventsNodeReload() throws Exception {
+ CountingSslContextFactory factory = new
CountingSslContextFactory(keyStorePath("node01"));
+ SSLContext ctx = factory.create();
+ IgniteConfiguration cfg =
getConfiguration(getTestIgniteInstanceName(0)).setSslContextFactory(factory);
+
+ cfg.getConnectorConfiguration().setSslEnabled(true).setSslFactory(()
-> ctx);
+
+ IgniteEx node = startGrid(cfg);
+
+ assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--ssl", "reload"));
+ assertSame(ctx, factory.create());
+ assertContains(log, testOut.toString(), node.localNode().id() + ":
failed: binary REST: unsupported:");
+ }
+
+ /** */
+ @Test
+ public void testDoesNotReloadRestFactoryWhenListenerFailedToStart() throws
Exception {
+ CountingSslContextFactory factory = new
CountingSslContextFactory(keyStorePath("node01"));
+
+ try (ServerSocket occupied = new ServerSocket()) {
+ occupied.bind(new InetSocketAddress("127.0.0.1", 0));
+
+ IgniteConfiguration cfg =
getConfiguration(getTestIgniteInstanceName(0));
+
+
cfg.getConnectorConfiguration().setPort(occupied.getLocalPort()).setPortRange(0).setSslEnabled(true).setSslFactory(factory);
+
+ IgniteEx node = startGrid(cfg);
+ int loads = factory.loads.get();
+
+ assertEquals(EXIT_CODE_OK, execute("--ssl", "reload"));
+ assertEquals(loads, factory.loads.get());
+ assertContains(log, testOut.toString(), node.localNode().id() + ":
no TCP transports started with TLS");
+ }
+ }
+
+ /** */
+ @Test
+ public void testReportsNodeLeavingBeforeReloadResponse() throws Exception {
+ IgniteEx node = startGrid(0);
+ IgniteEx departing = startGrid(1);
+ UUID departingId = departing.localNode().id();
+ TestRecordingCommunicationSpi departingSpi =
TestRecordingCommunicationSpi.spi(departing);
+
+ departingSpi.blockMessages((dest, msg) -> msg instanceof
GridJobExecuteResponse);
+
+ IgniteInternalFuture<Integer> cmd = runAsync(() -> execute("--ssl",
"reload"));
+
+ assertTrue(departingSpi.waitForBlocked(1, 10_000));
+
+ departing.close();
+
+ assertEquals(EXIT_CODE_UNEXPECTED_ERROR, cmd.get(30_000).intValue());
+ assertContains(log, testOut.toString(), departingId + ": left the
topology");
+ assertContains(log, testOut.toString(), node.localNode().id() + ": no
TCP transports started with TLS");
+ }
+
+ /** */
+ @Test
+ public void testDeclinedConfirmationDoesNotReload() throws Exception {
+ assumeTrue(cliCommandHandler());
+
+ CountingSslContextFactory factory = new
CountingSslContextFactory(keyStorePath("node01"));
+
+
startGrid(getConfiguration(getTestIgniteInstanceName(0)).setSslContextFactory(factory));
+
+ int loads = factory.loads.get();
+
+ autoConfirmation = false;
+ injectTestSystemIn("n");
+
+ assertEquals(EXIT_CODE_OK, execute("--ssl", "reload"));
+ assertContains(log, testOut.toString(),
+ "Make sure that all nodes and client applications trust the new
certificates before reloading.");
+ assertEquals(loads, factory.loads.get());
+ }
+
+ /** */
+ private int executeTlsReload() {
+ return execute("--ssl", "reload", "--keystore",
keyStorePath("node01"), "--keystore-password", keyStorePassword(),
+ "--truststore", keyStorePath("trustone"), "--truststore-password",
keyStorePassword());
+ }
+
+ /** */
+ private static void connectAndPing(int port, SSLContext ctx) throws
Exception {
+ try (SSLSocket sock =
(SSLSocket)ctx.getSocketFactory().createSocket()) {
+ sock.connect(new InetSocketAddress("127.0.0.1", port), 10_000);
+ sock.setSoTimeout(10_000);
+ sock.startHandshake();
+ sock.getOutputStream().write(GridClientPingPacket.PING_PACKET);
+
+ assertArrayEquals(GridClientPingPacket.PING_PACKET,
+
sock.getInputStream().readNBytes(GridClientPingPacket.PING_PACKET.length));
+ }
+ }
+
+ /** */
+ private static class CountingSslContextFactory extends SslContextFactory {
+ /** */
+ private static final long serialVersionUID = 0;
+
+ /** */
+ private final AtomicInteger loads = new AtomicInteger();
+
+ /** */
+ private CountingSslContextFactory(String path) {
+ setKeyStoreFilePath(path);
+ setKeyStorePassword(keyStorePassword().toCharArray());
+ setTrustManagers(getDisabledTrustManager());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected InputStream openFileInputStream(String path)
throws IOException {
+ loads.incrementAndGet();
+
+ return super.openFileInputStream(path);
+ }
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
index ebc321f9606..734222d4e89 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContext.java
@@ -74,6 +74,7 @@ import
org.apache.ignite.internal.processors.security.IgniteSecurity;
import
org.apache.ignite.internal.processors.segmentation.GridSegmentationProcessor;
import org.apache.ignite.internal.processors.service.IgniteServiceProcessor;
import org.apache.ignite.internal.processors.session.GridTaskSessionProcessor;
+import org.apache.ignite.internal.processors.ssl.SslFactoryRegistry;
import
org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor;
import org.apache.ignite.internal.processors.task.GridTaskProcessor;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
@@ -298,6 +299,9 @@ public interface GridKernalContext extends
Iterable<GridComponent> {
*/
public GridPortProcessor ports();
+ /** */
+ public SslFactoryRegistry ssl();
+
/**
* Gets schedule processor.
*
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 773efe5a99d..8718e51a231 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -96,6 +96,7 @@ import
org.apache.ignite.internal.processors.security.IgniteSecurity;
import
org.apache.ignite.internal.processors.segmentation.GridSegmentationProcessor;
import org.apache.ignite.internal.processors.service.IgniteServiceProcessor;
import org.apache.ignite.internal.processors.session.GridTaskSessionProcessor;
+import org.apache.ignite.internal.processors.ssl.SslFactoryRegistry;
import
org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor;
import org.apache.ignite.internal.processors.task.GridTaskProcessor;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
@@ -263,6 +264,10 @@ public class GridKernalContextImpl implements
GridKernalContext, Externalizable
@GridToStringInclude
private GridPortProcessor portProc;
+ /** */
+ @GridToStringExclude
+ private final SslFactoryRegistry sslFactories = new SslFactoryRegistry();
+
/** */
@GridToStringInclude
private IgniteScheduleProcessorAdapter scheduleProc;
@@ -743,6 +748,11 @@ public class GridKernalContextImpl implements
GridKernalContext, Externalizable
return portProc;
}
+ /** {@inheritDoc} */
+ @Override public SslFactoryRegistry ssl() {
+ return sslFactories;
+ }
+
/** {@inheritDoc} */
@Override public IgniteScheduleProcessorAdapter schedule() {
return scheduleProc;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/IgniteCommandRegistry.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/IgniteCommandRegistry.java
index cfe4fe6deb8..c69bdb7b01f 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/management/IgniteCommandRegistry.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/IgniteCommandRegistry.java
@@ -38,6 +38,7 @@ import
org.apache.ignite.internal.management.performancestatistics.PerformanceSt
import org.apache.ignite.internal.management.persistence.PersistenceCommand;
import org.apache.ignite.internal.management.property.PropertyCommand;
import org.apache.ignite.internal.management.snapshot.SnapshotCommand;
+import org.apache.ignite.internal.management.ssl.SslCommand;
import org.apache.ignite.internal.management.tx.TxCommand;
import org.apache.ignite.internal.management.wal.WalCommand;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -77,7 +78,8 @@ public class IgniteCommandRegistry extends
CommandRegistryImpl<NoArg, Void> {
new CdcCommand(),
new ConsistencyCommand(),
new EventCommand(),
- new IoTestCommand()
+ new IoTestCommand(),
+ new SslCommand()
);
U.loadService(CommandsProvider.class).forEach(p ->
p.commands().forEach(this::register));
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslCommand.java
new file mode 100644
index 00000000000..908d5b02b50
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslCommand.java
@@ -0,0 +1,29 @@
+/*
+ * 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.ignite.internal.management.ssl;
+
+import org.apache.ignite.internal.management.api.CommandRegistryImpl;
+import org.apache.ignite.internal.management.api.NoArg;
+
+/** */
+public class SslCommand extends CommandRegistryImpl<NoArg, Void> {
+ /** */
+ public SslCommand() {
+ super(new SslReloadCommand());
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslReloadCommand.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslReloadCommand.java
new file mode 100644
index 00000000000..d3d750a0b96
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslReloadCommand.java
@@ -0,0 +1,58 @@
+/*
+ * 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.ignite.internal.management.ssl;
+
+import java.util.Collection;
+import java.util.function.Consumer;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.management.api.ComputeCommand;
+import org.apache.ignite.internal.management.api.NoArg;
+
+/** */
+public class SslReloadCommand implements ComputeCommand<NoArg, String> {
+ /** {@inheritDoc} */
+ @Override public String description() {
+ return "Reload TLS key and trust stores on all nodes";
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<NoArg> argClass() {
+ return NoArg.class;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Class<SslReloadTask> taskClass() {
+ return SslReloadTask.class;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Collection<ClusterNode> nodes(Collection<ClusterNode>
nodes, NoArg arg) {
+ return nodes;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String confirmationPrompt(NoArg arg) {
+ return "Warning: new connections will use the replaced key and trust
stores. "
+ + "Make sure that all nodes and client applications trust the new
certificates before reloading.";
+ }
+
+ /** {@inheritDoc} */
+ @Override public void printResult(NoArg arg, String res, Consumer<String>
printer) {
+ printer.accept(res);
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslReloadTask.java
b/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslReloadTask.java
new file mode 100644
index 00000000000..17315635271
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/management/ssl/SslReloadTask.java
@@ -0,0 +1,181 @@
+/*
+ * 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.ignite.internal.management.ssl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import javax.cache.configuration.Factory;
+import javax.net.ssl.SSLContext;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterTopologyException;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.ComputeJobResult;
+import org.apache.ignite.internal.management.api.NoArg;
+import org.apache.ignite.internal.processors.task.GridInternal;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.visor.VisorJob;
+import org.apache.ignite.internal.visor.VisorMultiNodeTask;
+import org.apache.ignite.internal.visor.VisorTaskArgument;
+import org.apache.ignite.plugin.security.SecuritySubject;
+import org.apache.ignite.ssl.AbstractSslContextFactory;
+
+import static java.util.stream.Collectors.joining;
+
+/** */
+@GridInternal
+public class SslReloadTask extends VisorMultiNodeTask<NoArg, String, String> {
+ /** */
+ private static final long serialVersionUID = 0;
+
+ /** */
+ private Collection<UUID> targetNodes;
+
+ /** {@inheritDoc} */
+ @Override protected Map<? extends ComputeJob, ClusterNode>
map0(List<ClusterNode> subgrid, VisorTaskArgument<NoArg> arg) {
+ targetNodes = arg.getNodes();
+
+ Map<? extends ComputeJob, ClusterNode> jobs = super.map0(subgrid, arg);
+
+ if (jobs.isEmpty())
+ throw new IgniteException(targetNodes.stream().map(id -> id + ":
left the topology").collect(joining("\n")));
+
+ return jobs;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected VisorJob<NoArg, String> job(NoArg arg) {
+ return new SslReloadJob(arg, debug);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected String reduce0(List<ComputeJobResult> results) {
+ Map<UUID, ComputeJobResult> nodeResults = new HashMap<>();
+
+ for (ComputeJobResult res : results)
+ nodeResults.put(res.getNode().id(), res);
+
+ List<String> reports = new ArrayList<>();
+ boolean failed = false;
+
+ for (UUID id : targetNodes) {
+ ComputeJobResult res = nodeResults.get(id);
+
+ if (res == null || X.hasCause(res.getException(),
ClusterTopologyException.class)) {
+ reports.add(id + ": left the topology");
+ failed = true;
+ }
+ else if (res.getException() != null) {
+ reports.add(id + ": failed: " +
errorMessage(res.getException()));
+ failed = true;
+ }
+ else
+ reports.add(res.getData());
+ }
+
+ String report = String.join("\n", reports);
+
+ if (failed)
+ throw new IgniteException(report);
+
+ return report;
+ }
+
+ /** */
+ private static String errorMessage(Throwable err) {
+ return err.getMessage() == null ? err.getClass().getName() :
err.getMessage();
+ }
+
+ /** */
+ private static class SslReloadJob extends VisorJob<NoArg, String> {
+ /** */
+ private static final long serialVersionUID = 0;
+
+ /** */
+ private SslReloadJob(NoArg arg, boolean debug) {
+ super(arg, debug);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected String run(NoArg arg) {
+ Map<String, Factory<SSLContext>> factories =
ignite.context().ssl().factories();
+ UUID nodeId = ignite.localNode().id();
+ String initiator = "";
+
+ if (ignite.context().security().enabled()) {
+ SecuritySubject subj =
ignite.context().security().securityContext().subject();
+
+ initiator = " [initiator=" + subj.login() + ", subjectId=" +
subj.id() + ']';
+ }
+
+ if (factories.isEmpty()) {
+ String report = nodeId + ": no TCP transports started with
TLS";
+
+ ignite.log().info("TLS reload: " + report + initiator);
+
+ return report;
+ }
+
+ for (Map.Entry<String, Factory<SSLContext>> entry :
factories.entrySet()) {
+ if (!(entry.getValue() instanceof AbstractSslContextFactory)) {
+ String report = entry.getKey() + ": unsupported: " +
entry.getValue().getClass().getName();
+
+ ignite.log().warning("TLS reload: " + nodeId + ": " +
report + initiator);
+
+ throw new IgniteException(report);
+ }
+ }
+
+ Set<Factory<SSLContext>> processed = Collections.newSetFromMap(new
IdentityHashMap<>());
+ List<String> reports = new ArrayList<>();
+
+ for (Factory<SSLContext> factory : factories.values()) {
+ if (!processed.add(factory))
+ continue;
+
+ String transports = factories.entrySet().stream()
+ .filter(entry -> entry.getValue() == factory)
+ .map(Map.Entry::getKey)
+ .collect(joining(", "));
+
+ try {
+ ((AbstractSslContextFactory)factory).init();
+ }
+ catch (Exception e) {
+ ignite.log().warning("TLS reload: " + nodeId + ": " +
transports + ": failed" + initiator, e);
+
+ throw new IgniteException(transports + ": " +
errorMessage(e), e);
+ }
+
+ String report = nodeId + ": " + transports + ": reloaded";
+
+ reports.add(report);
+ ignite.log().info("TLS reload: " + report + initiator);
+ }
+
+ return String.join("\n", reports);
+ }
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneGridKernalContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneGridKernalContext.java
index 8f11ca68b96..07950c553ad 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneGridKernalContext.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/wal/reader/StandaloneGridKernalContext.java
@@ -98,6 +98,7 @@ import
org.apache.ignite.internal.processors.security.NoOpIgniteSecurityProcesso
import
org.apache.ignite.internal.processors.segmentation.GridSegmentationProcessor;
import org.apache.ignite.internal.processors.service.IgniteServiceProcessor;
import org.apache.ignite.internal.processors.session.GridTaskSessionProcessor;
+import org.apache.ignite.internal.processors.ssl.SslFactoryRegistry;
import
org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor;
import org.apache.ignite.internal.processors.task.GridTaskProcessor;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
@@ -443,6 +444,11 @@ public class StandaloneGridKernalContext implements
GridKernalContext {
return null;
}
+ /** {@inheritDoc} */
+ @Override public SslFactoryRegistry ssl() {
+ return null;
+ }
+
/** {@inheritDoc} */
@Override public IgniteScheduleProcessorAdapter schedule() {
return null;
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/ClientListenerProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/ClientListenerProcessor.java
index 2ec17e552c1..61fd90fa90c 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/ClientListenerProcessor.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/odbc/ClientListenerProcessor.java
@@ -271,6 +271,9 @@ public class ClientListenerProcessor extends
GridProcessorAdapter {
distrThinCfg = new DistributedThinClientConfiguration(ctx);
srv.start();
+
+ if (cliConnCfg.isSslEnabled())
+ ctx.ssl().register("client connector",
sslContextFactory(cliConnCfg));
}
catch (Exception e) {
throw new IgniteCheckedException("Failed to start client
connector processor.", e);
@@ -530,8 +533,7 @@ public class ClientListenerProcessor extends
GridProcessorAdapter {
GridNioFilter codecFilter = new GridNioCodecFilter(new
ClientListenerNioMessageParser(log), log, true);
if (cliConnCfg.isSslEnabled()) {
- Factory<SSLContext> sslCtxFactory =
cliConnCfg.isUseIgniteSslContextFactory() ?
- ctx.config().getSslContextFactory() :
cliConnCfg.getSslContextFactory();
+ Factory<SSLContext> sslCtxFactory = sslContextFactory(cliConnCfg);
if (sslCtxFactory == null)
throw new IgniteCheckedException("Failed to create client
listener " +
@@ -561,6 +563,11 @@ public class ClientListenerProcessor extends
GridProcessorAdapter {
}
}
+ /** */
+ private Factory<SSLContext> sslContextFactory(ClientConnectorConfiguration
cfg) {
+ return cfg.isUseIgniteSslContextFactory() ?
ctx.config().getSslContextFactory() : cfg.getSslContextFactory();
+ }
+
/** {@inheritDoc} */
@Override public void onKernalStop(boolean cancel) {
if (srv != null) {
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
index bd36d384b82..d7e7328adca 100644
---
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestProtocol.java
@@ -168,10 +168,7 @@ public class GridTcpRestProtocol extends
GridRestProtocolAdapter {
if (!cfg.isSslEnabled())
return new GridNioFilter[] { codec };
- Factory<SSLContext> sslCtxFactory = cfg.getSslFactory();
-
- if (sslCtxFactory == null)
- sslCtxFactory = ctx.config().getSslContextFactory();
+ Factory<SSLContext> sslCtxFactory = sslContextFactory(cfg);
if (sslCtxFactory == null)
// Thrown SSL exception instead of IgniteCheckedException for
writing correct warning message into log.
@@ -190,6 +187,13 @@ public class GridTcpRestProtocol extends
GridRestProtocolAdapter {
return new GridNioFilter[] { codec, sslFilter };
}
+ /** */
+ private Factory<SSLContext> sslContextFactory(ConnectorConfiguration cfg) {
+ Factory<SSLContext> factory = cfg.getSslFactory();
+
+ return factory != null ? factory : ctx.config().getSslContextFactory();
+ }
+
/**
* Tries to start server with given parameters.
*
@@ -233,6 +237,9 @@ public class GridTcpRestProtocol extends
GridRestProtocolAdapter {
ctx.ports().registerPort(port, IgnitePortProtocol.TCP, getClass());
+ if (cfg.isSslEnabled())
+ ctx.ssl().register("binary REST", sslContextFactory(cfg));
+
return true;
}
catch (IgniteCheckedException e) {
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
new file mode 100644
index 00000000000..ae3db72a664
--- /dev/null
+++
b/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
@@ -0,0 +1,40 @@
+/*
+ * 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.ignite.internal.processors.ssl;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import javax.cache.configuration.Factory;
+import javax.net.ssl.SSLContext;
+
+/** SSL factories used by running transports. */
+public class SslFactoryRegistry {
+ /** */
+ private final Map<String, Factory<SSLContext>> factories = new
LinkedHashMap<>();
+
+ /** */
+ public synchronized void register(String transport, Factory<SSLContext>
factory) {
+ if (factories.putIfAbsent(transport, factory) != null)
+ throw new IllegalStateException("SSL factory is already registered
[transport=" + transport + ']');
+ }
+
+ /** @return Snapshot of active transport factories. */
+ public synchronized Map<String, Factory<SSLContext>> factories() {
+ return new LinkedHashMap<>(factories);
+ }
+}
diff --git
a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index b73d65497a8..f3040330420 100755
---
a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++
b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -777,6 +777,9 @@ public class TcpCommunicationSpi extends
TcpCommunicationConfigInitializer {
conStateHnd.start();
+ if (stateProvider.isSslEnabled())
+ ignite.context().ssl().register("communication",
ignite.configuration().getSslContextFactory());
+
// Ack start.
if (log.isDebugEnabled())
log.debug(startInfo());
diff --git
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index de6d0ed6692..a0d7fbdfcbe 100644
---
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -2105,6 +2105,9 @@ public class TcpDiscoverySpi extends IgniteSpiAdapter
implements IgniteDiscovery
registerMBean(igniteInstanceName, new TcpDiscoverySpiMBeanImpl(this),
TcpDiscoverySpiMBean.class);
impl.spiStart(igniteInstanceName);
+
+ if (isSslEnabled())
+ ignite.context().ssl().register("discovery", sslCtxFactory);
}
/** */
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/management/ssl/SslReloadTaskTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/management/ssl/SslReloadTaskTest.java
new file mode 100644
index 00000000000..3908d717721
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/management/ssl/SslReloadTaskTest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.ignite.internal.management.ssl;
+
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.GridTestJobResult;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.cluster.IgniteClusterEx;
+import org.apache.ignite.internal.management.api.NoArg;
+import org.apache.ignite.internal.visor.VisorMultiNodeTask;
+import org.apache.ignite.internal.visor.VisorTaskArgument;
+import org.apache.ignite.logger.NullLogger;
+import org.apache.ignite.testframework.GridTestNode;
+import org.junit.Test;
+
+import static org.apache.ignite.testframework.GridTestUtils.setFieldValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/** */
+public class SslReloadTaskTest {
+ /** */
+ @Test
+ public void testReportsTargetThatLeftBeforeMapping() {
+ GridTestNode node = new GridTestNode(UUID.randomUUID());
+ UUID departedId = UUID.randomUUID();
+ SslReloadTask task = new SslReloadTask();
+
+ task.map(List.of(node), new VisorTaskArgument<>(List.of(node.id(),
departedId), new NoArg(), false));
+
+ String nodeReport = node.id() + ": no TCP transports started with TLS";
+ GridTestJobResult res = new GridTestJobResult(nodeReport, null, null,
node, null);
+
+ IgniteException err = assertThrows(IgniteException.class, () ->
task.reduce(List.of(res)).result());
+
+ assertEquals(nodeReport + '\n' + departedId + ": left the topology",
err.getMessage());
+ }
+
+ /** */
+ @Test
+ public void testReportsAllTargetsThatLeftBeforeMapping() {
+ GridTestNode replacement = new GridTestNode(UUID.randomUUID());
+ UUID first = UUID.randomUUID();
+ UUID second = UUID.randomUUID();
+ SslReloadTask task = new SslReloadTask();
+ IgniteEx ignite = mock(IgniteEx.class);
+
+ when(ignite.log()).thenReturn(NullLogger.INSTANCE);
+ when(ignite.cluster()).thenReturn(mock(IgniteClusterEx.class));
+ setFieldValue(task, VisorMultiNodeTask.class, "ignite", ignite);
+
+ IgniteException err = assertThrows(IgniteException.class, () ->
task.map(List.of(replacement),
+ new VisorTaskArgument<>(List.of(first, second), new NoArg(),
false)));
+
+ assertEquals(first + ": left the topology\n" + second + ": left the
topology", err.getMessage());
+ }
+
+ /** */
+ @Test
+ public void testReportsJobFailure() {
+ GridTestNode node = new GridTestNode(UUID.randomUUID());
+ SslReloadTask task = new SslReloadTask();
+
+ task.map(List.of(node), new VisorTaskArgument<>(List.of(node.id()),
new NoArg(), false));
+
+ IgniteException jobErr = new IgniteException("Job failed");
+ GridTestJobResult res = new GridTestJobResult(null, jobErr, null,
node, null);
+
+ IgniteException err = assertThrows(IgniteException.class, () ->
task.reduce(List.of(res)).result());
+
+ assertEquals(node.id() + ": failed: " + jobErr.getMessage(),
err.getMessage());
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
new file mode 100644
index 00000000000..fe517fe19f1
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.ignite.internal.processors.ssl;
+
+import org.apache.ignite.ssl.SslContextFactory;
+import org.junit.Test;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+
+/** */
+public class SslFactoryRegistryTest {
+ /** */
+ @Test
+ public void testDuplicateRegistrationKeepsOriginalFactory() {
+ SslFactoryRegistry registry = new SslFactoryRegistry();
+ SslContextFactory factory = new SslContextFactory();
+
+ registry.register("communication", factory);
+
+ assertThrows(IllegalStateException.class, () ->
registry.register("communication", new SslContextFactory()));
+ assertSame(factory, registry.factories().get("communication"));
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
b/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
index 5c3b9564b09..1e58daa79a3 100644
---
a/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
@@ -17,14 +17,29 @@
package org.apache.ignite.ssl;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.SSLContext;
import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestThread;
import org.junit.Test;
+import static java.lang.Thread.State.BLOCKED;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.apache.ignite.testframework.GridTestUtils.keyStorePassword;
+import static org.apache.ignite.testframework.GridTestUtils.keyStorePath;
+import static org.apache.ignite.testframework.GridTestUtils.runAsync;
import static org.apache.ignite.testframework.GridTestUtils.sslTrustedFactory;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
/** */
public class SslContextFactoryInitTest {
@@ -53,4 +68,122 @@ public class SslContextFactoryInitTest {
assertThrows(IgniteException.class, factory::init);
assertSame(original, factory.create());
}
+
+ /** */
+ @Test
+ public void testConcurrentCreateLoadsKeyStoreOnce() throws Exception {
+ BlockingSslContextFactory factory = new BlockingSslContextFactory();
+ GridTestThread first = new GridTestThread(factory::create);
+ GridTestThread second = new GridTestThread(factory::create);
+
+ first.start();
+
+ try {
+ assertTrue(factory.firstLoadStarted.await(10, SECONDS));
+
+ second.start();
+
+ assertTrue(waitForCondition(() -> second.getState() == BLOCKED ||
factory.loads.get() > 1, 10_000));
+ assertEquals(1, factory.loads.get());
+ }
+ finally {
+ factory.allowFirstLoad.countDown();
+ first.join(10_000);
+ second.join(10_000);
+ }
+
+ assertFalse(first.isAlive());
+ assertFalse(second.isAlive());
+ first.checkError();
+ second.checkError();
+ assertEquals(1, factory.loads.get());
+ }
+
+ /** */
+ @Test
+ public void testInitWaitsForInitialContextLoad() throws Exception {
+ BlockingSslContextFactory factory = new BlockingSslContextFactory();
+ GridTestThread first = new GridTestThread(factory::create);
+ GridTestThread second = new GridTestThread(factory::init);
+
+ first.start();
+
+ try {
+ assertTrue(factory.firstLoadStarted.await(10, SECONDS));
+
+ second.start();
+
+ assertTrue(waitForCondition(() -> second.getState() == BLOCKED ||
factory.loads.get() > 1, 10_000));
+ assertEquals(1, factory.loads.get());
+ }
+ finally {
+ factory.allowFirstLoad.countDown();
+ first.join(10_000);
+ second.join(10_000);
+ }
+
+ assertFalse(first.isAlive());
+ assertFalse(second.isAlive());
+ first.checkError();
+ second.checkError();
+ assertEquals(2, factory.loads.get());
+ }
+
+ /** */
+ @Test
+ public void testCreateDoesNotWaitForReload() throws Exception {
+ BlockingSslContextFactory factory = new BlockingSslContextFactory();
+ SSLContext ctx = sslTrustedFactory("node01", "trustone").create();
+
+ factory.sslCtx.set(ctx);
+
+ GridTestThread reload = new GridTestThread(factory::init);
+
+ reload.start();
+
+ try {
+ assertTrue(factory.firstLoadStarted.await(10, SECONDS));
+ assertSame(ctx, runAsync(factory::create).get(10_000));
+ }
+ finally {
+ factory.allowFirstLoad.countDown();
+ reload.join(10_000);
+ }
+
+ assertFalse(reload.isAlive());
+ reload.checkError();
+ }
+
+ /** */
+ private static class BlockingSslContextFactory extends SslContextFactory {
+ /** */
+ private static final long serialVersionUID = 0;
+
+ /** */
+ private final CountDownLatch firstLoadStarted = new CountDownLatch(1);
+
+ /** */
+ private final CountDownLatch allowFirstLoad = new CountDownLatch(1);
+
+ /** */
+ private final AtomicInteger loads = new AtomicInteger();
+
+ /** */
+ private BlockingSslContextFactory() {
+ setKeyStoreFilePath(keyStorePath("node01"));
+ setKeyStorePassword(keyStorePassword().toCharArray());
+ setTrustManagers(getDisabledTrustManager());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected InputStream openFileInputStream(String path)
throws IOException {
+ if (loads.incrementAndGet() == 1) {
+ firstLoadStarted.countDown();
+
+ U.awaitQuiet(allowFirstLoad);
+ }
+
+ return super.openFileInputStream(path);
+ }
+ }
}
diff --git
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index 19e63c8a785..6e75075e75c 100644
---
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -76,6 +76,7 @@ import
org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
import
org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext;
import org.apache.ignite.internal.processors.cacheobject.NoOpBinary;
+import org.apache.ignite.internal.processors.ssl.SslFactoryRegistry;
import
org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor;
import
org.apache.ignite.internal.processors.tracing.configuration.NoopTracingConfigurationManager;
import org.apache.ignite.internal.util.typedef.internal.CU;
@@ -157,6 +158,14 @@ public class IgniteMock implements IgniteEx {
try {
kernalCtx = new StandaloneGridKernalContext(new
GridTestLog4jLogger(), null) {
+ /** */
+ private final SslFactoryRegistry ssl = new
SslFactoryRegistry();
+
+ /** {@inheritDoc} */
+ @Override public SslFactoryRegistry ssl() {
+ return ssl;
+ }
+
@Override public GridInternalSubscriptionProcessor
internalSubscriptionProcessor() {
return new GridInternalSubscriptionProcessor(this);
}
diff --git
a/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
index 22fec30c574..7b207d1226a 100644
---
a/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
+++
b/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
@@ -18,6 +18,7 @@
package org.apache.ignite.testsuites;
import org.apache.ignite.internal.client.thin.ClientSslUtilsTest;
+import org.apache.ignite.internal.management.ssl.SslReloadTaskTest;
import
org.apache.ignite.internal.processors.security.IgniteSecurityProcessorTest;
import org.apache.ignite.internal.processors.security.InvalidServerTest;
import
org.apache.ignite.internal.processors.security.NodeConnectionCertificateCapturingTest;
@@ -75,6 +76,7 @@ import
org.apache.ignite.internal.processors.security.scheduler.SchedulerRemoteS
import
org.apache.ignite.internal.processors.security.service.ServiceAuthorizationTest;
import
org.apache.ignite.internal.processors.security.service.ServiceStaticConfigTest;
import
org.apache.ignite.internal.processors.security.snapshot.SnapshotPermissionCheckTest;
+import org.apache.ignite.internal.processors.ssl.SslFactoryRegistryTest;
import
org.apache.ignite.internal.thread.context.ComputeTaskOperationContextPropagationTest;
import
org.apache.ignite.internal.thread.context.OperationContextAttributePropagationTest;
import
org.apache.ignite.internal.thread.context.OperationContextAttributesTest;
@@ -147,6 +149,8 @@ import org.junit.runners.Suite;
MultipleSSLContextsTest.class,
SSLContextWrapperTest.class,
SslContextFactoryInitTest.class,
+ SslFactoryRegistryTest.class,
+ SslReloadTaskTest.class,
SslContextReloadTest.class,
ClientSslUtilsTest.class,
MaintenanceModeNodeSecurityTest.class,
diff --git
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
index fcae8c518d0..91fead434ad 100644
---
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
+++
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassTest_help.output
@@ -490,6 +490,9 @@ If the file name isn't specified the output file name is:
'<typeId>.bin':
--interval interval - Interval between samples (millis, 10 to
60000, 100 by default).
--payload-size payload_size - Payload size (bytes, max 64 KiB, 100 by
default).
+ Reload TLS key and trust stores on all nodes:
+ control.(sh|bat) --ssl reload
+
By default commands affecting the cluster require interactive confirmation.
Use --yes option to disable it.
diff --git
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
index 301b5563e65..158f8d3b5f4 100644
---
a/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
+++
b/modules/core/src/test/resources/org.apache.ignite.util/GridCommandHandlerClusterByClassWithSSLTest_help.output
@@ -490,6 +490,9 @@ If the file name isn't specified the output file name is:
'<typeId>.bin':
--interval interval - Interval between samples (millis, 10 to
60000, 100 by default).
--payload-size payload_size - Payload size (bytes, max 64 KiB, 100 by
default).
+ Reload TLS key and trust stores on all nodes:
+ control.(sh|bat) --ssl reload
+
By default commands affecting the cluster require interactive confirmation.
Use --yes option to disable it.