JeetKunDoug commented on code in PR #3457: URL: https://github.com/apache/cassandra/pull/3457#discussion_r1799699162
########## test/distributed/org/apache/cassandra/distributed/test/JMXEncryptionOptionsTest.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.cassandra.distributed.test; + +import com.google.common.collect.ImmutableMap; +import org.junit.Test; + +import org.apache.cassandra.distributed.Cluster; +import org.apache.cassandra.distributed.api.Feature; +import org.apache.cassandra.distributed.test.jmx.JMXGetterCheckTest; + +public class JMXEncryptionOptionsTest extends AbstractEncryptionOptionsImpl +{ + @Test + public void testDefaultSettings() throws Throwable + { + try (Cluster cluster = builder().withNodes(1).withConfig(c -> { + c.with(Feature.JMX); + c.set("jmx_encryption_options", + ImmutableMap.builder().putAll(validKeystore) + .put("enabled", true) + .put("require_client_auth", false) + .build()); + }).start()) + { + // Invoke the same code vs duplicating any code from the JMXGetterCheckTest + JMXGetterCheckTest.testAllValidGetters(cluster); + } + } + + @Test + public void testPEMBasedEncryptionOptions() throws Throwable + { + try (Cluster cluster = builder().withNodes(1).withConfig(c -> { + c.with(Feature.JMX); + c.set("jmx_encryption_options", + ImmutableMap.builder().putAll(validPEMKeystore) + .put("enabled", true) + .put("require_client_auth", false) + .build()); + }).start()) + { + // Invoke the same code vs duplicating any code from the JMXGetterCheckTest + JMXGetterCheckTest.testAllValidGetters(cluster); + } + } + + @Test + public void testInvalidKeystorePath() throws Throwable Review Comment: When running the whole class of tests in IntelliJ, this test runs first, which causes all of the other tests to fail because we actually start up the JMX instance _before_ checking the config, leaving the JMX server running in the test after the instance startup fails. The startup failure happens, as you know, in `DatabaseDescriptor#daemonInitialization` around line 712 in `Instance.java` - I realize this isn't the fault of your PR (and is in fact _my_ fault) but it seems like `daemonInitialization` should be called _before_ the call to `startJmx`. This would both fix the failing test and also mirror how the CassandraDaemon code works. ########## test/distributed/org/apache/cassandra/distributed/test/JMXEncryptionOptionsTest.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.cassandra.distributed.test; Review Comment: NIT: Please move to `org.apache.cassandra.distributed.test.jmx` with the other JMX-related tests. ########## src/java/org/apache/cassandra/config/DatabaseDescriptor.java: ########## @@ -1253,7 +1256,14 @@ public static void applySslContext() { SSLFactory.validateSslContext("Internode messaging", conf.server_encryption_options, REQUIRED, true); SSLFactory.validateSslContext("Native transport", conf.client_encryption_options, conf.client_encryption_options.getClientAuth(), true); + // For JMX SSL the validation is pretty much the same as the Native transport + SSLFactory.validateSslContext("JMX transport", conf.jmx_encryption_options, conf.jmx_encryption_options.getClientAuth(), true); SSLFactory.initHotReloading(conf.server_encryption_options, conf.client_encryption_options, false); + /* + For JMX SSL, the hot reloading of the SSLContext is out of scope for CASSANDRA-18508. Review Comment: Can you please file a JIRA to handle this - I understand why it may not be doable at this time, and the issue pre-existed your change, but it would be good to be able to handle hot reloading and we should look at it soon. ########## src/java/org/apache/cassandra/utils/JMXServerUtils.java: ########## @@ -243,10 +254,18 @@ private static Map<String, Object> configureJmxSocketFactories(InetAddress serve SslRMIClientSocketFactory clientFactory = new SslRMIClientSocketFactory(); SslRMIServerSocketFactory serverFactory = new SslRMIServerSocketFactory(ciphers, protocols, requireClientAuth); - env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, serverFactory); - env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, clientFactory); - env.put("com.sun.jndi.rmi.factory.socket", clientFactory); - logJmxSslConfig(serverFactory); + setSocketFactoriesInEnv(env, clientFactory, serverFactory); + } + else if (jmxEncryptionOptions != null && jmxEncryptionOptions.getEnabled() != null && jmxEncryptionOptions.getEnabled()) + { + logger.info("Enabling JMX SSL using jmx_encryption_options from cassandra.yaml"); + // Here we can continue to use the SslRMIClientSocketFactory for client sockets. + // However, we should still set System properties for cipher_suites and enabled_protocols + // to have the same behavior as cassandra-env.sh based JMX SSL settings + setJmxSystemProperties(jmxEncryptionOptions); Review Comment: What behavior are you preserving by setting the system properties? Just so that they are set in case some other code ends up using them? If we need to set the appropriate system properties anyway, could we not rearrange this code a bit so that we check & log which way we're getting the configuration first and, if we end up in this case, set the properties... and then just run the same code for both paths since the props will be set appropriately? I don't see any "ssl optional" tests for the JMX stuff, which I think would be the only reason to have the separate code paths - do we intend to support optional SSL with this patch? If not, I think we can simplify this code some, and eliminate the `JMXSslRMIServerSocketFactory` class all together, as it _seems_ to essentially end up doing the same thing (minus the optional SLL support). If we do intend to support optional SSL, can you add a test for it please? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

