You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@amoro.apache.org by "davedwwang (via GitHub)" <gi...@apache.org> on 2025/12/11 00:53:18 UTC

[PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

davedwwang opened a new pull request, #4009:
URL: https://github.com/apache/amoro/pull/4009

   ## Why are the changes needed?
   The current Dashboard login uses an admin-user with a plaintext password, which is highly insecure. To enhance security, centralize user management, and align with industry standard practices, we need to switch to LDAP authentication.
   
   Close #4008.
   
   ## Brief change log
   - Introduced three new login-related configurations in AmoroManagementConf.
   - Added LdapPasswdAuthenticationProvider to support LDAP integration (implements PasswdAuthenticationProvider).
   - Updated LoginController to use PasswdAuthenticationProvider for user login validation.
   
   
   ## How was this patch tested?
   
   - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
   
   - [ ] Run test locally before making a pull request
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes / no) yes
   - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented) not documented
   


-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "davedwwang (via GitHub)" <gi...@apache.org>.
davedwwang commented on code in PR #4009:
URL: https://github.com/apache/amoro/pull/4009#discussion_r2659567780


##########
amoro-ams/src/main/java/org/apache/amoro/server/AmoroManagementConf.java:
##########
@@ -328,6 +328,29 @@ public class AmoroManagementConf {
               "User-defined password authentication implementation of"
                   + " org.apache.amoro.authentication.PasswdAuthenticationProvider");
 
+  public static final ConfigOption<String> HTTP_SERVER_LOGIN_AUTH_PROVIDER =
+      ConfigOptions.key("http-server.login-auth-provider")
+          .stringType()
+          .defaultValue(DefaultPasswdAuthenticationProvider.class.getName())
+          .withDescription(
+              "User-defined login authentication implementation of"
+                  + " org.apache.amoro.authentication.PasswdAuthenticationProvider");
+
+  public static final ConfigOption<String> HTTP_SERVER_LOGIN_AUTH_LDAP_USERPARTTERN =

Review Comment:
   done



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java:
##########
@@ -92,6 +92,7 @@ public class DashboardServer {
 
   private final PasswdAuthenticationProvider basicAuthProvider;
   private final TokenAuthenticationProvider jwtAuthProvider;
+

Review Comment:
   done



-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "zhoujinsong (via GitHub)" <gi...@apache.org>.
zhoujinsong commented on PR #4009:
URL: https://github.com/apache/amoro/pull/4009#issuecomment-3723555603

   Thanks for the contribution! @davedwwang 
   Thanks for the review! @turboFei 


-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #4009:
URL: https://github.com/apache/amoro/pull/4009#issuecomment-3644638764

   ## [Codecov](https://app.codecov.io/gh/apache/amoro/pull/4009?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 4.78%. Comparing base ([`cbdc517`](https://app.codecov.io/gh/apache/amoro/commit/cbdc5176b760b2ab46daa5051f29b72f1fee7175?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`3c9c606`](https://app.codecov.io/gh/apache/amoro/commit/3c9c606faac3899b7eb52b421118f7d040850c31?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 12 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #4009       +/-   ##
   ============================================
   - Coverage     22.12%   4.78%   -17.35%     
   + Complexity     2461     471     -1990     
   ============================================
     Files           445     446        +1     
     Lines         40897   40951       +54     
     Branches       5767    5767               
   ============================================
   - Hits           9050    1958     -7092     
   - Misses        31089   38799     +7710     
   + Partials        758     194      -564     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/amoro/pull/4009/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [trino](https://app.codecov.io/gh/apache/amoro/pull/4009/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.78% <ø> (-17.35%)` | :arrow_down: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/amoro/pull/4009?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #4009:
URL: https://github.com/apache/amoro/pull/4009#discussion_r2659315692


##########
amoro-ams/src/main/java/org/apache/amoro/server/AmoroManagementConf.java:
##########
@@ -328,6 +328,29 @@ public class AmoroManagementConf {
               "User-defined password authentication implementation of"
                   + " org.apache.amoro.authentication.PasswdAuthenticationProvider");
 
+  public static final ConfigOption<String> HTTP_SERVER_LOGIN_AUTH_PROVIDER =
+      ConfigOptions.key("http-server.login-auth-provider")
+          .stringType()
+          .defaultValue(DefaultPasswdAuthenticationProvider.class.getName())
+          .withDescription(
+              "User-defined login authentication implementation of"
+                  + " org.apache.amoro.authentication.PasswdAuthenticationProvider");
+
+  public static final ConfigOption<String> HTTP_SERVER_LOGIN_AUTH_LDAP_USERPARTTERN =

Review Comment:
   typo:   `PARTTERN` -> `PATTERN`
   



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java:
##########
@@ -92,6 +92,7 @@ public class DashboardServer {
 
   private final PasswdAuthenticationProvider basicAuthProvider;
   private final TokenAuthenticationProvider jwtAuthProvider;
+

Review Comment:
   nit: unnecessary change



##########
amoro-ams/src/main/java/org/apache/amoro/server/AmoroManagementConf.java:
##########
@@ -328,6 +328,29 @@ public class AmoroManagementConf {
               "User-defined password authentication implementation of"
                   + " org.apache.amoro.authentication.PasswdAuthenticationProvider");
 
+  public static final ConfigOption<String> HTTP_SERVER_LOGIN_AUTH_PROVIDER =
+      ConfigOptions.key("http-server.login-auth-provider")
+          .stringType()
+          .defaultValue(DefaultPasswdAuthenticationProvider.class.getName())
+          .withDescription(
+              "User-defined login authentication implementation of"
+                  + " org.apache.amoro.authentication.PasswdAuthenticationProvider");
+
+  public static final ConfigOption<String> HTTP_SERVER_LOGIN_AUTH_LDAP_USERPARTTERN =

Review Comment:
   recommend: `USER_PATTERN`.



-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "turboFei (via GitHub)" <gi...@apache.org>.
turboFei commented on code in PR #4009:
URL: https://github.com/apache/amoro/pull/4009#discussion_r2653749828


##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/LoginController.java:
##########
@@ -49,10 +50,11 @@ public void login(Context ctx) {
     Map<String, String> bodyParams = ctx.bodyAsClass(Map.class);
     String user = bodyParams.get("user");
     String pwd = bodyParams.get("password");
-    if (adminUser.equals(user) && (adminPassword.equals(pwd))) {
-      ctx.sessionAttribute("user", new SessionInfo(adminUser, System.currentTimeMillis() + ""));
-      ctx.json(OkResponse.of("success"));

Review Comment:
   Seems this part of logic is missed after `dashboardServer.getLoginAuthProvider().authenticate(credential);`



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/LoginController.java:
##########
@@ -49,10 +50,11 @@ public void login(Context ctx) {
     Map<String, String> bodyParams = ctx.bodyAsClass(Map.class);
     String user = bodyParams.get("user");
     String pwd = bodyParams.get("password");

Review Comment:
   check the user and pwd non empty 



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/LoginController.java:
##########
@@ -49,10 +50,11 @@ public void login(Context ctx) {
     Map<String, String> bodyParams = ctx.bodyAsClass(Map.class);
     String user = bodyParams.get("user");
     String pwd = bodyParams.get("password");
-    if (adminUser.equals(user) && (adminPassword.equals(pwd))) {
-      ctx.sessionAttribute("user", new SessionInfo(adminUser, System.currentTimeMillis() + ""));
-      ctx.json(OkResponse.of("success"));
-    } else {
+    DefaultPasswordCredential credential = new DefaultPasswordCredential(user, pwd);
+    try {
+      dashboardServer.getLoginAuthProvider().authenticate(credential);
+    } catch (Exception e) {
+      LOG.error("authenticate user {} failed", user, e);
       throw new RuntimeException("invalid user " + user + " or password!");

Review Comment:
   return the cause message as well



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/DashboardServer.java:
##########
@@ -92,6 +92,8 @@ public class DashboardServer {
 
   private final PasswdAuthenticationProvider basicAuthProvider;
   private final TokenAuthenticationProvider jwtAuthProvider;
+
+  private final PasswdAuthenticationProvider loginAuthProvider;

Review Comment:
   how about moving the loginAuthProvider into LoginController?



##########
amoro-ams/src/main/java/org/apache/amoro/server/authentication/LdapPasswdAuthenticationProvider.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.amoro.server.authentication;
+
+import org.apache.amoro.authentication.BasicPrincipal;
+import org.apache.amoro.authentication.PasswdAuthenticationProvider;
+import org.apache.amoro.authentication.PasswordCredential;
+import org.apache.amoro.config.Configurations;
+import org.apache.amoro.exception.SignatureCheckException;
+import org.apache.amoro.server.AmoroManagementConf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.InitialDirContext;
+
+import java.text.MessageFormat;
+import java.util.Hashtable;
+
+public class LdapPasswdAuthenticationProvider implements PasswdAuthenticationProvider {
+  public static final Logger LOG = LoggerFactory.getLogger(LdapPasswdAuthenticationProvider.class);
+
+  private String ldapUrl;
+  private String ldapUserParttern;
+  private MessageFormat formatter;
+
+  public LdapPasswdAuthenticationProvider(Configurations conf) {
+    this.ldapUrl = conf.get(AmoroManagementConf.HTTP_SERVER_LOGIN_AUTH_LDAP_URL);
+    this.ldapUserParttern = conf.get(AmoroManagementConf.HTTP_SERVER_LOGIN_AUTH_LDAP_USERPARTTERN);

Review Comment:
   check the ldapUrl and ldapUserParttern non empty 



##########
amoro-ams/src/test/resources/ldap/users.ldif:
##########
@@ -0,0 +1,37 @@
+################################################################################
+#  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.
+################################################################################
+version: 1
+dn: dc=test,dc=com
+objectClass: domain
+objectClass: top
+dc: test
+
+dn: ou=Users,dc=test,dc=com
+objectClass: organizationalUnit
+objectClass: top
+ou: Users
+
+dn: cn=user1,ou=Users,dc=test,dc=com
+objectClass: inetOrgPerson
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: user1
+sn: Ldap
+uid: ldaptest1
+userPassword: 12345

Review Comment:
   new line at the end



-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "davedwwang (via GitHub)" <gi...@apache.org>.
davedwwang commented on PR #4009:
URL: https://github.com/apache/amoro/pull/4009#issuecomment-3692021427

   hi @turboFei Would you mind reviewing this? I’d really appreciate it. Thanks!


-- 
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: commits-unsubscribe@amoro.apache.org

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


Re: [PR] [Feature]: Support LDAP Authentication for Dashboard Login [amoro]

Posted by "zhoujinsong (via GitHub)" <gi...@apache.org>.
zhoujinsong merged PR #4009:
URL: https://github.com/apache/amoro/pull/4009


-- 
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: commits-unsubscribe@amoro.apache.org

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