You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "burmanm (via GitHub)" <gi...@apache.org> on 2026/02/13 10:23:44 UTC

[PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

burmanm opened a new pull request, #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318

   Add new settings under driver_parameters to support pluggable withCredentials provider. Add two possible implementations, ConfigProvider (which is the current implementation) and a new one, FileProvider which reads username and password from the disk.
   
   Also deprecate the old username/password parameters, but do not remove support for them (simply transform their input to the ConfigProvider).


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#issuecomment-4002248977

   Tests are failing. please take a look


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2886392222


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/auth/FileProvider.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+/**
+ * Loads CQL username/password from files.
+ */
+public class FileProvider implements CqlAuthProvider
+{
+    static final String USERNAME_PATH_PARAM = "username_path";
+    static final String PASSWORD_PATH_PARAM = "password_path";
+
+    private final Path usernamePath;
+    private final Path passwordPath;
+
+    public FileProvider(Map<String, String> parameters)
+    {
+        Objects.requireNonNull(parameters, "parameters must not be null");
+        this.usernamePath = resolvePath(parameters, USERNAME_PATH_PARAM);
+        this.passwordPath = resolvePath(parameters, PASSWORD_PATH_PARAM);
+    }
+
+    private static Path resolvePath(Map<String, String> parameters, String key)
+    {
+        if (!parameters.containsKey(key))
+        {
+            throw new ConfigurationException("Missing required auth_provider parameter \"" + key + "\"");
+        }
+
+        try
+        {
+            return Paths.get(parameters.get(key));
+        }
+        catch (InvalidPathException e)
+        {
+            throw new ConfigurationException("Invalid path in auth_provider parameter \"" + key + "\"", e);
+        }
+    }
+
+    private static String readSecret(Path path, String key)
+    {
+        try
+        {
+            String secret = Files.readString(path).trim();
+            if (secret.isEmpty())
+            {
+                throw new ConfigurationException("Empty content in auth_provider file for parameter \"" + key + "\"");
+            }
+            return secret;
+        }
+        catch (IOException e)
+        {
+            throw new ConfigurationException("Unable to read auth_provider file for parameter \"" + key + "\"", e);
+        }
+    }
+
+  @Override
+  public String username()
+  {
+      return readSecret(usernamePath, USERNAME_PATH_PARAM);
+  }
+
+  @Override
+  public String password()
+  {
+      return readSecret(passwordPath, PASSWORD_PATH_PARAM);
+  }

Review Comment:
   There is an "opinionated" guide on setting up the project in IntellJ (https://github.com/apache/cassandra-sidecar/blob/trunk/CONTRIBUTING.md#integration-with-intellij-idea). It should take care of the indentation. 
   There is no formatter to help, if you are not using IntelliJ, ATM.  



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "burmanm (via GitHub)" <gi...@apache.org>.
burmanm commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2803481310


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -121,11 +129,41 @@ CQLSessionProvider cqlSessionProvider(Vertx vertx,
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider(sidecarConfiguration),
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+            // Fallback to the old one
+            return new ConfigProvider(
+                Map.of("username", driverConfiguration.username(), "password", driverConfiguration.password()));
+        }
+
+        Map<String, String> namedParameters = config.namedParameters();

Review Comment:
   This looks hacky because it is. Originally I had here:
   
   ```java
   if (config.namedParameters() == null)
   {
       throw new ConfigurationException(...)
   }
   ```
   
   But the findbugs wasn't accepting that, claiming the later access to namedParameters would potentially cause NPE in the next lines in this function. So to please the findbugs, I'm creating an empty namedParameters here and letting the providers throw the 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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#issuecomment-4583630084

   Closed via https://github.com/apache/cassandra-sidecar/commit/b8ddad057c4db7b6ad061ba04323d9cc10622d96


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2843630085


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -121,11 +128,45 @@ CQLSessionProvider cqlSessionProvider(Vertx vertx,
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider(sidecarConfiguration),
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+          // Fallback to the old one
+          String username = driverConfiguration.username() != null ? driverConfiguration.username() : "";
+          String password = driverConfiguration.password() != null ? driverConfiguration.password() : "";
+
+          return new ConfigProvider(
+                Map.of("username", username, "password", password));
+        }
+
+        if (config.namedParameters() == null)
+        {
+            throw new ConfigurationException("Missing parameters for auth_provider");
+        }
+
+        Map<String, String> namedParameters = config.namedParameters();
+
+        if (config.className().equalsIgnoreCase(ConfigProvider.class.getName()))
+        {
+            return new ConfigProvider(namedParameters);
+        }
+        if (config.className().equalsIgnoreCase(FileProvider.class.getName()))
+        {
+            return new FileProvider(namedParameters);
+        }
+        throw new ConfigurationException("Unrecognized cql auth_provider " + config.className() + " set");

Review Comment:
   For the lifecycle and utilities modules, the pluggability is implemented via overriding the Guice provider. Imagining in the internal-sidecar fork, you have a internal module that provides a different `LifecycleProvider`. 
   
   So, you are right to call it out. The alternative is to update `cqlAuthProvider` to be `@Provides`



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "burmanm (via GitHub)" <gi...@apache.org>.
burmanm commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r3002650715


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -117,15 +125,51 @@ CassandraInputValidationConfiguration validationConfiguration(SidecarConfigurati
     @Singleton
     CQLSessionProvider cqlSessionProvider(Vertx vertx,
                                           SidecarConfiguration sidecarConfiguration,
+                                          CqlAuthProvider cqlAuthProvider,
                                           DriverUtils driverUtils)
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider,
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    @Provides
+    @Singleton
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+            // Fallback to the old one
+            Map<String, String> namedParameters = new HashMap<>();
+            namedParameters.put("username", driverConfiguration.username());
+            namedParameters.put("password", driverConfiguration.password());

Review Comment:
   Same as above.



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#issuecomment-3897676639

   Thanks for the patch, I will take a look at it today


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh closed pull request #318: CASSSIDECAR-407 Pluggable withCredentials provider for file access
URL: https://github.com/apache/cassandra-sidecar/pull/318


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2839449447


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/auth/CqlAuthProvider.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * 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.auth;
+
+/**
+ * Provides authentication details used by Sidecar's internal Cassandra CQL client.
+ */
+public interface CqlAuthProvider
+{
+    String username();
+    String password();

Review Comment:
   Please add javadoc, although the method name is self-explanatory. 



##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/auth/FileProvider.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+/**
+ * Loads CQL username/password from files.
+ */
+public class FileProvider implements CqlAuthProvider
+{
+    static final String USERNAME_PATH_PARAM = "username_path";
+    static final String PASSWORD_PATH_PARAM = "password_path";
+
+    private final Path usernamePath;
+    private final Path passwordPath;
+
+    public FileProvider(Map<String, String> parameters)
+    {
+        Objects.requireNonNull(parameters, "parameters must not be null");
+        this.usernamePath = resolvePath(parameters, USERNAME_PATH_PARAM);
+        this.passwordPath = resolvePath(parameters, PASSWORD_PATH_PARAM);
+    }
+
+    private static Path resolvePath(Map<String, String> parameters, String key)
+    {
+        if (!parameters.containsKey(key))
+        {
+            throw new ConfigurationException("Missing required auth_provider parameter \"" + key + "\"");
+        }
+
+        try
+        {
+            return Paths.get(parameters.get(key));
+        }
+        catch (InvalidPathException e)
+        {
+            throw new ConfigurationException("Invalid path in auth_provider parameter \"" + key + "\"", e);
+        }
+    }
+
+    private static String readSecret(Path path, String key)
+    {
+        try
+        {
+            String secret = Files.readString(path).trim();
+            if (secret.isEmpty())
+            {
+                throw new ConfigurationException("Empty content in auth_provider file for parameter \"" + key + "\"");
+            }
+            return secret;
+        }
+        catch (IOException e)
+        {
+            throw new ConfigurationException("Unable to read auth_provider file for parameter \"" + key + "\"", e);
+        }
+    }
+
+  @Override
+  public String username()
+  {
+      return readSecret(usernamePath, USERNAME_PATH_PARAM);
+  }
+
+  @Override
+  public String password()
+  {
+      return readSecret(passwordPath, PASSWORD_PATH_PARAM);
+  }

Review Comment:
   It reads from the file every single time per call. Do you expect the username/password to change? 
   
   And the indentation is wrong.



##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/auth/ConfigProvider.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.auth;
+
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+/**
+ * Loads CQL username/password directly from auth_provider parameters.
+ */
+public class ConfigProvider implements CqlAuthProvider
+{
+    static final String USERNAME_PARAM = "username";
+    static final String PASSWORD_PARAM = "password";
+
+    private final String username;
+    private final String password;
+
+    public ConfigProvider(Map<String, String> parameters)
+    {
+        Objects.requireNonNull(parameters, "parameters must not be null");
+        this.username = requiredParameter(parameters, USERNAME_PARAM);
+        this.password = requiredParameter(parameters, PASSWORD_PARAM);
+    }
+
+    private static String requiredParameter(Map<String, String> parameters, String key)
+    {
+        if (!parameters.containsKey(key))
+        {
+            throw new ConfigurationException("Missing required auth_provider parameter \"" + key + "\"");
+        }
+        return parameters.get(key);
+    }
+
+  @Override
+  public String username()
+  {
+      return username;
+  }
+
+  @Override
+  public String password()
+  {
+      return password;
+  }

Review Comment:
   indentation space is wrong - please use 4 spaces. 



##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -121,11 +128,45 @@ CQLSessionProvider cqlSessionProvider(Vertx vertx,
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider(sidecarConfiguration),
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+          // Fallback to the old one
+          String username = driverConfiguration.username() != null ? driverConfiguration.username() : "";
+          String password = driverConfiguration.password() != null ? driverConfiguration.password() : "";

Review Comment:
   I do not think defaulting to empty string is the old behavior, which allows `null` for username and password.
   The reason of defaulting to the empty string seems to only to conform the `Map.of()` constructor. A workaround could be wrap HashMap (which permits `null` value) with unmodifiable.



##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -121,11 +128,45 @@ CQLSessionProvider cqlSessionProvider(Vertx vertx,
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider(sidecarConfiguration),
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+          // Fallback to the old one
+          String username = driverConfiguration.username() != null ? driverConfiguration.username() : "";
+          String password = driverConfiguration.password() != null ? driverConfiguration.password() : "";
+
+          return new ConfigProvider(
+                Map.of("username", username, "password", password));
+        }
+
+        if (config.namedParameters() == null)
+        {
+            throw new ConfigurationException("Missing parameters for auth_provider");
+        }
+
+        Map<String, String> namedParameters = config.namedParameters();
+
+        if (config.className().equalsIgnoreCase(ConfigProvider.class.getName()))
+        {
+            return new ConfigProvider(namedParameters);
+        }
+        if (config.className().equalsIgnoreCase(FileProvider.class.getName()))
+        {
+            return new FileProvider(namedParameters);
+        }
+        throw new ConfigurationException("Unrecognized cql auth_provider " + config.className() + " set");

Review Comment:
   To truly make it pluggable, we need to use reflection to construct the instance from the supplied class name, instead of throwing.
   For example, 
   
   ```suggestion
           try 
           {
               Class<?> cls = Class.forName(config.className());
               return (CqlAuthProvider) cls.getDeclaredConstructor(Map.class).newInstance(namedParameters);
           } 
           catch (ReflectiveOperationException e) 
           {
               throw new ConfigurationException("Failed to instantiate auth_provider " + config.className(), e);
           }
   ```



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#issuecomment-4374503443

   The patch looks good. Can you rebase in order to trigger the github checks? The github actions was broken and has been fixed. 
   In addition, please share the circleCI link (in JIRA) as well. Thank you! 


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "burmanm (via GitHub)" <gi...@apache.org>.
burmanm commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r3002649249


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java:
##########
@@ -119,8 +122,10 @@ public CQLSessionProviderImpl(List<InetSocketAddress> contactPoints,
         this.localInstances = localInstances;
         this.localDc = localDc;
         this.numAdditionalConnections = numAdditionalConnections;
-        this.username = username;
-        this.password = password;
+        Map<String, String> namedParameters = new HashMap<>();
+        namedParameters.put("username", username);
+        namedParameters.put("password", password);

Review Comment:
   This would cause NPE if the username/password is null, which is acceptable (and something the tests do). Map.of requires non-null for all values.



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "burmanm (via GitHub)" <gi...@apache.org>.
burmanm commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2877007940


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/auth/FileProvider.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+/**
+ * Loads CQL username/password from files.
+ */
+public class FileProvider implements CqlAuthProvider
+{
+    static final String USERNAME_PATH_PARAM = "username_path";
+    static final String PASSWORD_PATH_PARAM = "password_path";
+
+    private final Path usernamePath;
+    private final Path passwordPath;
+
+    public FileProvider(Map<String, String> parameters)
+    {
+        Objects.requireNonNull(parameters, "parameters must not be null");
+        this.usernamePath = resolvePath(parameters, USERNAME_PATH_PARAM);
+        this.passwordPath = resolvePath(parameters, PASSWORD_PATH_PARAM);
+    }
+
+    private static Path resolvePath(Map<String, String> parameters, String key)
+    {
+        if (!parameters.containsKey(key))
+        {
+            throw new ConfigurationException("Missing required auth_provider parameter \"" + key + "\"");
+        }
+
+        try
+        {
+            return Paths.get(parameters.get(key));
+        }
+        catch (InvalidPathException e)
+        {
+            throw new ConfigurationException("Invalid path in auth_provider parameter \"" + key + "\"", e);
+        }
+    }
+
+    private static String readSecret(Path path, String key)
+    {
+        try
+        {
+            String secret = Files.readString(path).trim();
+            if (secret.isEmpty())
+            {
+                throw new ConfigurationException("Empty content in auth_provider file for parameter \"" + key + "\"");
+            }
+            return secret;
+        }
+        catch (IOException e)
+        {
+            throw new ConfigurationException("Unable to read auth_provider file for parameter \"" + key + "\"", e);
+        }
+    }
+
+  @Override
+  public String username()
+  {
+      return readSecret(usernamePath, USERNAME_PATH_PARAM);
+  }
+
+  @Override
+  public String password()
+  {
+      return readSecret(passwordPath, PASSWORD_PATH_PARAM);
+  }

Review Comment:
   I'd expect the password/username to be modifiable, yes. Same as with TLS secrets. But if you want, I can modify this to be read-once and need to restart sidecar for changes.
   
   Why isn't there automated test for the indentations and a formatter?



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2968315592


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -117,15 +125,51 @@ CassandraInputValidationConfiguration validationConfiguration(SidecarConfigurati
     @Singleton
     CQLSessionProvider cqlSessionProvider(Vertx vertx,
                                           SidecarConfiguration sidecarConfiguration,
+                                          CqlAuthProvider cqlAuthProvider,
                                           DriverUtils driverUtils)
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider,
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    @Provides
+    @Singleton
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+            // Fallback to the old one
+            Map<String, String> namedParameters = new HashMap<>();
+            namedParameters.put("username", driverConfiguration.username());
+            namedParameters.put("password", driverConfiguration.password());

Review Comment:
   minor NIT:
   ```suggestion
               Map<String, String> namedParameters = Map<String, String> namedParameters = Map.of("username", driverConfiguration.username(),
                                                            "password", driverConfiguration.password());
   ```



##########
integration-tests/src/integrationTest/resources/config/sidecar.yaml.template:
##########
@@ -267,8 +267,19 @@ access_control:
 driver_parameters:
   contact_points:
     - "127.0.0.1:9042"
-  username: cassandra
-  password: cassandra
+  auth_provider:
+  # Authentication information, implementing org.apache.cassandra.sidecar.cluster.auth.CqlAuthProvider;
+  # used to provide username/password to connect to the Cassandra cluster.
+  #   class_name: org.apache.cassandra.sidecar.cluster.auth.FileProvider
+  #   parameters:
+  #     username_path: /opt/sidecar/superuser/username
+  #     password_path: /opt/sidecar/superuser/password
+    class_name: org.apache.cassandra.sidecar.cluster.auth.ConfigProvider
+    parameters:
+      username: cassandra
+      password: cassandra
+#  username: cassandra
+#  password: cassandra

Review Comment:
   NIT, not required to keep :
   
   ```suggestion
   ```



##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java:
##########
@@ -119,8 +122,10 @@ public CQLSessionProviderImpl(List<InetSocketAddress> contactPoints,
         this.localInstances = localInstances;
         this.localDc = localDc;
         this.numAdditionalConnections = numAdditionalConnections;
-        this.username = username;
-        this.password = password;
+        Map<String, String> namedParameters = new HashMap<>();
+        namedParameters.put("username", username);
+        namedParameters.put("password", password);

Review Comment:
   tiny NIT:
   
   
   ```suggestion
           Map<String, String> namedParameters = Map.of("username", username,
                                                        "password", password);
   ```



##########
server/src/test/java/org/apache/cassandra/sidecar/cluster/auth/FileProviderTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class FileProviderTest
+{
+    @TempDir
+    Path tempDir;
+
+    @Test
+    void testInterfaceGetters() throws IOException
+    {
+        Path usernamePath = tempDir.resolve("username");
+        Path passwordPath = tempDir.resolve("password");
+        Files.writeString(usernamePath, "cassandra-user\n");
+        Files.writeString(passwordPath, "cassandra-pass\n");
+
+        CqlAuthProvider provider = new FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM,
+                                                                       usernamePath.toString(),
+                                                                       FileProvider.PASSWORD_PATH_PARAM,
+                                                                       passwordPath.toString()));
+        assertThat(provider.username()).isEqualTo("cassandra-user");
+        assertThat(provider.password()).isEqualTo("cassandra-pass");
+    }
+
+    @Test
+    void testMissingParameterThrows()
+    {
+        assertThatExceptionOfType(ConfigurationException.class)
+        .isThrownBy(() -> new FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM, "/tmp/username")))
+        .withMessageContaining("Missing required auth_provider parameter");
+    }
+
+    @Test
+    void testEmptySecretThrows() throws IOException
+    {
+        Path usernamePath = tempDir.resolve("username");
+        Path passwordPath = tempDir.resolve("password");
+        Files.writeString(usernamePath, " \n");
+        Files.writeString(passwordPath, "secret");
+
+        FileProvider provider = new FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM,
+                                                                       usernamePath.toString(),
+                                                                       FileProvider.PASSWORD_PATH_PARAM,
+                                                                       passwordPath.toString()));

Review Comment:
   minor NIT:
   ```suggestion
           FileProvider provider = new FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM, usernamePath.toString(),
                                                           FileProvider.PASSWORD_PATH_PARAM, passwordPath.toString()));
   ```



##########
server/src/test/java/org/apache/cassandra/sidecar/cluster/auth/FileProviderTest.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class FileProviderTest
+{
+    @TempDir
+    Path tempDir;
+
+    @Test
+    void testInterfaceGetters() throws IOException
+    {
+        Path usernamePath = tempDir.resolve("username");
+        Path passwordPath = tempDir.resolve("password");
+        Files.writeString(usernamePath, "cassandra-user\n");
+        Files.writeString(passwordPath, "cassandra-pass\n");
+
+        CqlAuthProvider provider = new FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM,
+                                                                       usernamePath.toString(),
+                                                                       FileProvider.PASSWORD_PATH_PARAM,
+                                                                       passwordPath.toString()));

Review Comment:
   minor NIT: formatting
   
   
   ```suggestion
           CqlAuthProvider provider = new FileProvider(Map.of(FileProvider.USERNAME_PATH_PARAM, usernamePath.toString(),
                                                              FileProvider.PASSWORD_PATH_PARAM, passwordPath.toString()));
   ```



##########
server/src/test/java/org/apache/cassandra/sidecar/cluster/auth/ConfigProviderTest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.auth;
+
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+class ConfigProviderTest
+{
+    @Test
+    void testInterfaceGetters()
+    {
+        CqlAuthProvider provider = new ConfigProvider(Map.of(ConfigProvider.USERNAME_PARAM, "cassandra",
+                                                            ConfigProvider.PASSWORD_PARAM, "cassandra"));

Review Comment:
   tiny NIT: formatting 
   ```suggestion
           CqlAuthProvider provider = new ConfigProvider(Map.of(ConfigProvider.USERNAME_PARAM, "cassandra",
                                                                ConfigProvider.PASSWORD_PARAM, "cassandra"));
   ```



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "yifan-c (via GitHub)" <gi...@apache.org>.
yifan-c commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2886424983


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/auth/FileProvider.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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.auth;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.Objects;
+
+import org.apache.cassandra.sidecar.exceptions.ConfigurationException;
+
+/**
+ * Loads CQL username/password from files.
+ */
+public class FileProvider implements CqlAuthProvider
+{
+    static final String USERNAME_PATH_PARAM = "username_path";
+    static final String PASSWORD_PATH_PARAM = "password_path";
+
+    private final Path usernamePath;
+    private final Path passwordPath;
+
+    public FileProvider(Map<String, String> parameters)
+    {
+        Objects.requireNonNull(parameters, "parameters must not be null");
+        this.usernamePath = resolvePath(parameters, USERNAME_PATH_PARAM);
+        this.passwordPath = resolvePath(parameters, PASSWORD_PATH_PARAM);
+    }
+
+    private static Path resolvePath(Map<String, String> parameters, String key)
+    {
+        if (!parameters.containsKey(key))
+        {
+            throw new ConfigurationException("Missing required auth_provider parameter \"" + key + "\"");
+        }
+
+        try
+        {
+            return Paths.get(parameters.get(key));
+        }
+        catch (InvalidPathException e)
+        {
+            throw new ConfigurationException("Invalid path in auth_provider parameter \"" + key + "\"", e);
+        }
+    }
+
+    private static String readSecret(Path path, String key)
+    {
+        try
+        {
+            String secret = Files.readString(path).trim();
+            if (secret.isEmpty())
+            {
+                throw new ConfigurationException("Empty content in auth_provider file for parameter \"" + key + "\"");
+            }
+            return secret;
+        }
+        catch (IOException e)
+        {
+            throw new ConfigurationException("Unable to read auth_provider file for parameter \"" + key + "\"", e);
+        }
+    }
+
+  @Override
+  public String username()
+  {
+      return readSecret(usernamePath, USERNAME_PATH_PARAM);
+  }
+
+  @Override
+  public String password()
+  {
+      return readSecret(passwordPath, PASSWORD_PATH_PARAM);
+  }

Review Comment:
   > I'd expect the password/username to be modifiable, yes. Same as with TLS secrets.
   
   ok. I guess it is for the scenarios such as password rotation. 



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r3002710616


##########
server/src/main/java/org/apache/cassandra/sidecar/cluster/CQLSessionProviderImpl.java:
##########
@@ -119,8 +122,10 @@ public CQLSessionProviderImpl(List<InetSocketAddress> contactPoints,
         this.localInstances = localInstances;
         this.localDc = localDc;
         this.numAdditionalConnections = numAdditionalConnections;
-        this.username = username;
-        this.password = password;
+        Map<String, String> namedParameters = new HashMap<>();
+        namedParameters.put("username", username);
+        namedParameters.put("password", password);

Review Comment:
   good catch!



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-407 Pluggable withCredentials provider for file access [cassandra-sidecar]

Posted by "burmanm (via GitHub)" <gi...@apache.org>.
burmanm commented on code in PR #318:
URL: https://github.com/apache/cassandra-sidecar/pull/318#discussion_r2840042954


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/ConfigurationModule.java:
##########
@@ -121,11 +128,45 @@ CQLSessionProvider cqlSessionProvider(Vertx vertx,
     {
         CQLSessionProviderImpl cqlSessionProvider = new CQLSessionProviderImpl(sidecarConfiguration,
                                                                                NettyOptions.DEFAULT_INSTANCE,
+                                                                               cqlAuthProvider(sidecarConfiguration),
                                                                                driverUtils);
         vertx.eventBus().localConsumer(ON_SERVER_STOP.address(), message -> cqlSessionProvider.close());
         return cqlSessionProvider;
     }
 
+    CqlAuthProvider cqlAuthProvider(SidecarConfiguration sidecarConfiguration)
+    {
+        DriverConfiguration driverConfiguration = sidecarConfiguration.driverConfiguration();
+
+        ParameterizedClassConfiguration config = driverConfiguration.authProvider();
+        if (config == null)
+        {
+          // Fallback to the old one
+          String username = driverConfiguration.username() != null ? driverConfiguration.username() : "";
+          String password = driverConfiguration.password() != null ? driverConfiguration.password() : "";
+
+          return new ConfigProvider(
+                Map.of("username", username, "password", password));
+        }
+
+        if (config.namedParameters() == null)
+        {
+            throw new ConfigurationException("Missing parameters for auth_provider");
+        }
+
+        Map<String, String> namedParameters = config.namedParameters();
+
+        if (config.className().equalsIgnoreCase(ConfigProvider.class.getName()))
+        {
+            return new ConfigProvider(namedParameters);
+        }
+        if (config.className().equalsIgnoreCase(FileProvider.class.getName()))
+        {
+            return new FileProvider(namedParameters);
+        }
+        throw new ConfigurationException("Unrecognized cql auth_provider " + config.className() + " set");

Review Comment:
   I was aware of that (mentioned in the JIRA ticket), but this is not how the rest of the project has done it so I modified this one to be the same. 
   
   https://github.com/apache/cassandra-sidecar/blob/trunk/server/src/main/java/org/apache/cassandra/sidecar/modules/LifecycleModule.java#L79
   
   https://github.com/apache/cassandra-sidecar/blob/trunk/server/src/main/java/org/apache/cassandra/sidecar/modules/UtilitiesModule.java#L110
   
   Should all these cases also use ClassLoader? It feels a bit out of context for this PR.



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org