bbotella commented on code in PR #148:
URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853066755
##########
server/src/main/dist/conf/sidecar.yaml:
##########
@@ -173,6 +167,18 @@ driver_parameters:
contact_points:
- "127.0.0.1:9042"
- "127.0.0.2:9042"
+ username: cassandra
+ password: cassandra
Review Comment:
Super nit: `password: password` to keep consistency with the password fields
for keystore and truststore?
##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java:
##########
@@ -203,4 +248,85 @@ public void close()
}
}
}
+
+ private SslContext createSslContext(SslConfiguration sslConfiguration)
+ {
+ if (sslConfiguration == null || !sslConfiguration.enabled())
+ {
+ return null;
+ }
+
+ SslContextBuilder sslContextBuilder;
+ try
+ {
+ sslContextBuilder = SslContextBuilder.forClient()
+
.protocols(sslConfiguration.secureTransportProtocols());
+
+ if (sslConfiguration.isKeystoreConfigured())
+ {
+ KeyStore keyStore =
createKeystore(sslConfiguration.keystore());
+ KeyManagerFactory kmf =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmf.init(keyStore,
sslConfiguration.keystore().password().toCharArray());
+ sslContextBuilder.keyManager(kmf);
+ }
+
+ if (sslConfiguration.isTrustStoreConfigured())
+ {
+ KeyStore truststore =
createKeystore(sslConfiguration.truststore());
+ TrustManagerFactory tmf =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(truststore);
+ sslContextBuilder.trustManager(tmf);
+ }
+ return sslContextBuilder.build();
+ }
+ catch (Exception e)
+ {
+ throw new ConfigurationException("Error creating SsLContext for
Cassandra connections", e);
+ }
+ }
+
+ private KeyStore createKeystore(KeyStoreConfiguration config)
+ throws KeyStoreException, IOException, CertificateException,
NoSuchAlgorithmException
+ {
+ KeyStore keystore = KeyStore.getInstance(config.type());
+ try (FileInputStream inputStream = new FileInputStream(config.path()))
+ {
+ keystore.load(inputStream, config.password().toCharArray());
+ }
+ return keystore;
+ }
+
+ /**
+ * {@link MtlsAuthProvider} is a custom AuthProvider. It is required when
driver needs to connect to Cassandra with
+ * mutual TLS.
+ */
+ private static class MtlsAuthProvider implements AuthProvider
+ {
+ @Override
+ public Authenticator newAuthenticator(InetSocketAddress
inetSocketAddress, String s) throws AuthenticationException
+ {
+ return new MutualTLSAuthenticator();
+ }
+
+ private static class MutualTLSAuthenticator implements Authenticator
+ {
+ @Override
+ public byte[] initialResponse()
+ {
+ return new byte[]{ 0, 0 };
Review Comment:
Just curious. Why is the initial response a `0, 0` here?
##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java:
##########
@@ -137,16 +168,30 @@ public synchronized Session get()
driverUtils);
// Prevent spurious reconnects of ignored down nodes on `onUp`
events
QueryOptions queryOptions = new
QueryOptions().setReprepareOnUp(false);
- cluster = Cluster.builder()
- .addContactPointsWithPorts(contactPoints)
- .withReconnectionPolicy(reconnectionPolicy)
- .withoutMetrics()
- .withLoadBalancingPolicy(lbp)
- .withQueryOptions(queryOptions)
- // tests can create a lot of these Cluster
objects, to avoid creating HWTs and
- // event thread pools for each we have the
override
- .withNettyOptions(nettyOptions)
- .build();
+ Cluster.Builder builder
+ = Cluster.builder()
+ .addContactPointsWithPorts(contactPoints)
+ .withReconnectionPolicy(reconnectionPolicy)
+ .withoutMetrics()
+ .withLoadBalancingPolicy(lbp)
+ .withQueryOptions(queryOptions)
+ // tests can create a lot of these Cluster objects, to
avoid creating HWTs and
+ // event thread pools for each we have the override
+ .withNettyOptions(nettyOptions);
+
+ if (username != null && password != null)
Review Comment:
Should this be an `or` instead of an `and`?
##########
server/src/test/integration/org/apache/cassandra/sidecar/cluster/locator/CqlSessionProviderIntegrationTest.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.sidecar.cluster.locator;
+
+import java.util.Collections;
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import com.datastax.driver.core.Session;
+import io.vertx.ext.web.client.WebClient;
+import io.vertx.junit5.VertxExtension;
+import io.vertx.junit5.VertxTestContext;
+import
org.apache.cassandra.sidecar.common.response.ConnectedClientStatsResponse;
+import org.apache.cassandra.sidecar.common.response.data.ClientConnectionEntry;
+import org.apache.cassandra.sidecar.config.SslConfiguration;
+import org.apache.cassandra.sidecar.config.yaml.KeyStoreConfigurationImpl;
+import org.apache.cassandra.sidecar.config.yaml.SslConfigurationImpl;
+import org.apache.cassandra.sidecar.testing.IntegrationTestBase;
+import org.apache.cassandra.testing.CassandraIntegrationTest;
+import org.apache.cassandra.testing.ConfigurableCassandraTestContext;
+import software.amazon.awssdk.utils.ImmutableMap;
+
+import static
org.apache.cassandra.sidecar.testing.IntegrationTestModule.ADMIN_IDENTITY;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assumptions.assumeThat;
+
+/**
+ * Test for authenticated {@link
org.apache.cassandra.sidecar.cluster.CQLSessionProviderImpl}
+ */
+@ExtendWith(VertxExtension.class)
+class CqlSessionProviderIntegrationTest extends IntegrationTestBase
Review Comment:
Add a test with failed ssl configuration? Basically, with `createSslContext`
method returning a `ConfigurationException`?
--
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]