You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "valepakh (via GitHub)" <gi...@apache.org> on 2023/04/19 09:36:44 UTC

[GitHub] [ignite-3] valepakh opened a new pull request, #1956: IGNITE-19194 Support basic auth and SSL for CLI SQL command

valepakh opened a new pull request, #1956:
URL: https://github.com/apache/ignite-3/pull/1956

   https://issues.apache.org/jira/browse/IGNITE-19194


-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite-3] ptupitsyn commented on a diff in pull request #1956: IGNITE-19194 Support basic auth and SSL for CLI SQL command

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #1956:
URL: https://github.com/apache/ignite-3/pull/1956#discussion_r1172368057


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/rest/ApiClientSettings.java:
##########
@@ -72,8 +72,8 @@ public String trustStorePassword() {
         return trustStorePassword;
     }
 
-    public String basicAuthLogin() {
-        return basicAuthLogin;
+    public String basicAuthUsername() {

Review Comment:
   `auth` is ambiguous: authentication or authorization? Let's rename `basicAuthUsername` and `basicAuthPassword` everywhere to `basicAuthenticationUsername` and `basicAuthenticationPassword`.



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite-3] PakhomovAlexander commented on a diff in pull request #1956: IGNITE-19194 Support basic auth and SSL for CLI SQL command

Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #1956:
URL: https://github.com/apache/ignite-3/pull/1956#discussion_r1172216352


##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlConnectBasicTest.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.ignite.internal.cli.commands.sql;
+
+import static org.apache.ignite.internal.cli.commands.cliconfig.TestConfigManagerHelper.createIntegrationTests;
+import static org.apache.ignite.internal.cli.commands.cliconfig.TestConfigManagerHelper.createJdbcTestsBasicSecret;
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import java.util.List;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.security.AuthenticationConfig;
+import org.apache.ignite.security.BasicAuthenticationProviderConfig;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+class ItSqlConnectBasicTest extends CliSqlConnectCommandTestBase {
+
+    @Override
+    protected void configureInitParameters(InitParametersBuilder builder) {
+        builder.authenticationConfig(new AuthenticationConfig(
+                true,
+                List.of(new BasicAuthenticationProviderConfig("basic", "usr", "pwd")))
+        );
+    }
+
+    @Test
+    @DisplayName("Should succeed after connect with basic auth configured")
+    void jdbcOkWithBasicConfiguredAfterConnect() {
+        // Given basic auth is configured in config file
+        configManagerProvider.setConfigFile(createIntegrationTests(), createJdbcTestsBasicSecret());

Review Comment:
   `createIntegrationTests` sound confusing in this context. Why do we create "integration tests"? Maybe we can use better naming that will describe what the method really does?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/JdbcUrlFactory.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.core;
+
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.BASIC_AUTHENTICATION_PASSWORD;
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.BASIC_AUTHENTICATION_USERNAME;
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.JDBC_CLIENT_AUTH;
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.JDBC_KEY_STORE_PASSWORD;
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.JDBC_KEY_STORE_PATH;
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.JDBC_TRUST_STORE_PASSWORD;
+import static org.apache.ignite.internal.cli.config.CliConfigKeys.JDBC_TRUST_STORE_PATH;
+
+import com.google.gson.Gson;
+import jakarta.inject.Singleton;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.cli.config.CliConfigKeys;
+import org.apache.ignite.internal.cli.config.ConfigManager;
+import org.apache.ignite.internal.cli.config.ConfigManagerProvider;
+import org.apache.ignite.internal.cli.core.repl.config.RootConfig;
+import org.apache.ignite.internal.util.StringUtils;
+import org.jetbrains.annotations.Nullable;
+
+/** Ignite JDBC URL factory. */
+@Singleton
+public class JdbcUrlFactory {
+    private final ConfigManagerProvider configManagerProvider;
+
+    /** Constructor. */
+    public JdbcUrlFactory(ConfigManagerProvider configManagerProvider) {
+        this.configManagerProvider = configManagerProvider;
+    }
+
+    /**
+     * Constructs JDBC URL from node URL, port taken from the node configuration, SSL and basic auth properties from the config.
+     *
+     * @param configuration Node configuration in HOCON format.
+     * @param nodeUrl Node URL.
+     * @return JDBC URL.
+     */
+    @Nullable
+    public String constructJdbcUrl(String configuration, String nodeUrl) {
+        try {
+            int port = new Gson().fromJson(configuration, RootConfig.class).clientConnector.port;
+            String host = new URL(nodeUrl).getHost();
+            return applyConfig("jdbc:ignite:thin://" + host + ":" + port);
+        } catch (MalformedURLException ignored) {
+            return null;
+        }
+    }
+
+    private String applyConfig(String jdbcUrl) {
+        List<String> queryParams = new ArrayList<>();
+        append(queryParams, JDBC_TRUST_STORE_PATH, "trustStorePath");
+        append(queryParams, JDBC_TRUST_STORE_PASSWORD, "trustStorePassword");
+        append(queryParams, JDBC_KEY_STORE_PATH, "keyStorePath");
+        append(queryParams, JDBC_KEY_STORE_PASSWORD, "keyStorePassword");
+        append(queryParams, JDBC_CLIENT_AUTH, "clientAuth");
+        if (!queryParams.isEmpty()) {

Review Comment:
   After the sequence of `append` methods `if (!queryParams.isEmpty())` statement looks strange. Could you rename `append` to `appendIfSet` or something like that?



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite-3] PakhomovAlexander merged pull request #1956: IGNITE-19194 Support basic auth and SSL for CLI SQL command

Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander merged PR #1956:
URL: https://github.com/apache/ignite-3/pull/1956


-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite-3] valepakh commented on a diff in pull request #1956: IGNITE-19194 Support basic auth and SSL for CLI SQL command

Posted by "valepakh (via GitHub)" <gi...@apache.org>.
valepakh commented on code in PR #1956:
URL: https://github.com/apache/ignite-3/pull/1956#discussion_r1172373387


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/rest/ApiClientSettings.java:
##########
@@ -72,8 +72,8 @@ public String trustStorePassword() {
         return trustStorePassword;
     }
 
-    public String basicAuthLogin() {
-        return basicAuthLogin;
+    public String basicAuthUsername() {

Review Comment:
   I think "basic auth" is pretty commonly understood as a "basic authentication"?



-- 
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: notifications-unsubscribe@ignite.apache.org

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


[GitHub] [ignite-3] valepakh commented on a diff in pull request #1956: IGNITE-19194 Support basic auth and SSL for CLI SQL command

Posted by "valepakh (via GitHub)" <gi...@apache.org>.
valepakh commented on code in PR #1956:
URL: https://github.com/apache/ignite-3/pull/1956#discussion_r1172373387


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/rest/ApiClientSettings.java:
##########
@@ -72,8 +72,8 @@ public String trustStorePassword() {
         return trustStorePassword;
     }
 
-    public String basicAuthLogin() {
-        return basicAuthLogin;
+    public String basicAuthUsername() {

Review Comment:
   I think "basic auth" is pretty commonly understood as a "basic authentication"?



-- 
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: notifications-unsubscribe@ignite.apache.org

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