Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
frankgh commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1854904855 ## 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: not really, when a connection cannot be established we return a 503 - Service Unavailable. 400 is a client making a connection with bad params. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
yifan-c merged PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148 -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1854866100 ## 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: We figured it wasn't necessary, even a empty array would work. But removed this `MtlsAuthProvider` -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
yifan-c commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1854663728 ## 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 +{ +private static final int MIN_VERSION_WITH_MTLS = 5; + +@CassandraIntegrationTest(buildCluster = false) +void testWithUsernamePassword(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +cassandraContext.configureAndStartCluster(builder -> { +builder.appendConfig(config -> config.set("authenticator", "org.apache.cassandra.auth.PasswordAuthenticator")); +}); +sidecarTestContext.refreshInstancesConfig(); +waitForSchemaReady(30, TimeUnit.SECONDS); +retrieveClientStats(context, "cassandra", false); +} + +@CassandraIntegrationTest(buildCluster = false) +void testWithSSLOnly(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +cassandraContext.configureAndStartCluster(builder -> { +builder.appendConfig(config -> + // dot-separated options are not supported in 4.0 + config.set("client_encryption_options", ImmutableMap.of("enabled", "true", + "require_client_auth", "false", + "keystore", serverKeystorePath.toAbsolutePath().toString(), + "keystore_password", serverKeystorePassword))); +}); +sidecarTestContext.setSslConfiguration(sslConfigWithTruststore()); +waitForSchemaReady(30, TimeUnit.SECONDS); +// we enable only SSL and do not set any authenticator, hence username is "anonymous" +retrieveClientStats(context, "anonymous", true); +} + +@CassandraIntegrationTest(buildCluster = false) +void testWithMTLS(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +// mTLS authentication was added in Cassandra starting 5.0 version +assumeThat(cassandraContext.version.major) Review Comment: nice assertj feature -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
bbotella commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853977667 ## 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: For example, an invalid path for keystore or truststore should return a 400, right? -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853105865 ## 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: We throw `ConfigurationException` in unexpected failures, not sure what failure scenario we want to recreate here. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853105254 ## 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: Driver doesn't allow password to be null. So I think `and` -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853085924 ## 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: Since by default `cassandra` user is created in Cassandra with `cassandra` password. Better to keep this way -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
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); + +
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853034345 ## server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java: ## @@ -137,16 +170,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 (sslContext != null) +{ +RemoteEndpointAwareJdkSSLOptions sslOptions Review Comment: Addressed this -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1853039071 ## server/src/test/integration/org/apache/cassandra/sidecar/cluster/locator/CqlSessionProviderIntegrationTest.java: ## @@ -0,0 +1,163 @@ +/* + * 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 +{ +private static final int MIN_VERSION_WITH_MTLS = 5; + +@CassandraIntegrationTest(buildCluster = false) +void testWithUsernamePassword(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +cassandraContext.configureAndStartCluster(builder -> { +builder.appendConfig(config -> config.set("authenticator", "org.apache.cassandra.auth.PasswordAuthenticator")); +}); +sidecarTestContext.refreshInstancesConfig(); +waitForSchemaReady(30, TimeUnit.SECONDS); +retrieveClientStats(context, "cassandra", false); +} + +@CassandraIntegrationTest(buildCluster = false) +void testWithSSLOnly(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +cassandraContext.configureAndStartCluster(builder -> { +builder.appendConfig(config -> + // dot-separated options are not supported in 4.0 + config.set("client_encryption_options", ImmutableMap.of("enabled", "true", + "require_client_auth", "false", + "keystore", serverKeystorePath.toAbsolutePath().toString(), + "keystore_password", serverKeystorePassword))); +}); +sidecarTestContext.setSslConfiguration(sslConfigWithTruststore()); +waitForSchemaReady(30, TimeUnit.SECONDS); +// we enable only SSL and do not set any authenticator, hence username is "anonymous" +retrieveClientStats(context, "anonymous", true); +} + +@CassandraIntegrationTest(buildCluster = false) +void testWithMTLS(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +// mTLS authentication was added in Cassandra starting 5.0 version +assumeThat(cassandraContext.version.major) +.withFailMessage("mTLS authentication is not supported in 4.0 Cassandra version") +.isGreaterThanOrEqualTo(MIN_VERSION_WITH_MTLS); + +cassandraContext.configureAndStartCluster(builder -> { +builder.appendConfig(config -> config.set("authenticator.class_name", "org.apache.cassandra.auth.MutualTlsWithPasswordFallbackAuthentic
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
yifan-c commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1852956378 ## server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java: ## @@ -137,16 +170,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 (sslContext != null) +{ +RemoteEndpointAwareJdkSSLOptions sslOptions Review Comment: nit: use `RemoteEndpointAwareNettySSLOptions` ## server/src/test/integration/org/apache/cassandra/sidecar/cluster/locator/CqlSessionProviderIntegrationTest.java: ## @@ -0,0 +1,163 @@ +/* + * 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 +{ +private static final int MIN_VERSION_WITH_MTLS = 5; + +@CassandraIntegrationTest(buildCluster = false) +void testWithUsernamePassword(VertxTestContext context, ConfigurableCassandraTestContext cassandraContext) throws Exception +{ +cassandraContext.configureAndStartCluster(builder -> { +builder.appendConfig(config -> config.set("authenticator", "org.apache.cassandra.auth.PasswordAuthenticator")); +}); +sidecarTestContext.refreshInstancesConfig(); +waitForSchemaReady(30, TimeUnit.SECONDS); +retrieveClientStats(context, "cassandra", false); +} + +@CassandraIntegrationTest(buildCl
Re: [PR] CASSSIDECAR-159: Add advanced driver settings to allow taking in credentials for Cassandra connection [cassandra-sidecar]
sarankk commented on code in PR #148: URL: https://github.com/apache/cassandra-sidecar/pull/148#discussion_r1851278488 ## server/src/main/java/org/apache/cassandra/sidecar/acl/AuthCache.java: ## @@ -133,7 +133,7 @@ private LoadingCache initCache() private void configureSidecarServerEventListener() { EventBus eventBus = vertx.eventBus(); -eventBus.localConsumer(ON_ALL_CASSANDRA_CQL_READY.address(), message -> warmUpAsync(config.warmupRetries())); +eventBus.localConsumer(ON_SIDECAR_SCHEMA_INITIALIZED.address(), message -> warmUpAsync(config.warmupRetries())); Review Comment: Because we were not starting warm up on `ON_SIDECAR_SCHEMA_INITIALIZED`, first few tries at warming up at failing. Hence switched to starting on schema initialized -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org