This is an automated email from the ASF dual-hosted git repository.
stigahuang pushed a commit to branch branch-4.5.1
in repository https://gitbox.apache.org/repos/asf/impala.git
The following commit(s) were added to refs/heads/branch-4.5.1 by this push:
new 40b459280 IMPALA-13746: Fix long ldap password handling in
impala-shell+hs2-http
40b459280 is described below
commit 40b459280a83ddbd6eeb816927d0c59a5aa54979
Author: Csaba Ringhofer <[email protected]>
AuthorDate: Mon Apr 14 15:58:20 2025 +0200
IMPALA-13746: Fix long ldap password handling in impala-shell+hs2-http
Before this patch impala-shell inserted a \n char after every 76 bytes.
The fix is to switch to a different function for encoding. The exact
semantics of base64 functions is described in
https://docs.python.org/3/library/base64.html
Based on impyla fix https://github.com/cloudera/impyla/pull/562 by
https://github.com/paulmayer (released in Impyla 0.21a3)
Change-Id: I4d73d682cf2d1843d9801ef71b99d551b79deb19
Reviewed-on: http://gerrit.cloudera.org:8080/22780
Reviewed-by: Csaba Ringhofer <[email protected]>
Tested-by: Csaba Ringhofer <[email protected]>
Reviewed-on: http://gerrit.cloudera.org:8080/22812
Reviewed-by: Michael Smith <[email protected]>
Tested-by: Impala Public Jenkins <[email protected]>
---
.../org/apache/impala/customcluster/LdapImpalaShellTest.java | 11 +++++++++++
fe/src/test/java/org/apache/impala/testutil/LdapUtil.java | 4 ++++
fe/src/test/resources/users.ldif | 12 +++++++++++-
shell/impala_client.py | 10 +++++-----
4 files changed, 31 insertions(+), 6 deletions(-)
diff --git
a/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
b/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
index c950d4519..bc301010d 100644
--- a/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
+++ b/fe/src/test/java/org/apache/impala/customcluster/LdapImpalaShellTest.java
@@ -171,6 +171,12 @@ public class LdapImpalaShellTest {
// 6. Without username and password. Should fail.
String[] commandWithoutAuth = {
"impala-shell.sh", "", String.format("--query=%s", query)};
+ // 7. Valid username with long password to trigger IMPALA-13746. Should
succeed.
+ String[] validCommandLongPsw = {"impala-shell.sh", "", "--ldap",
+ "--auth_creds_ok_in_clear", "--verbose",
+ String.format("--user=%s", TEST_USER_LONG_PSW),
+ String.format("--ldap_password_cmd=printf %s", TEST_PASSWORD_LONG),
+ String.format("--query=%s", query)};
String protocolTemplate = "--protocol=%s";
// Sorted list of cookies for validCommand, where all cookies are
preserved.
@@ -228,6 +234,11 @@ public class LdapImpalaShellTest {
commandWithoutAuth[1] = protocol;
RunShellCommand.Run(
commandWithoutAuth, /*shouldSucceed*/ false, "", "Not connected to
Impala");
+
+ validCommandLongPsw[1] = protocol;
+ RunShellCommand.Run(validCommandLongPsw,
+ /*shouldSucceed*/ true, TEST_USER_LONG_PSW,
+ "Starting Impala Shell with LDAP-based authentication");
}
}
diff --git a/fe/src/test/java/org/apache/impala/testutil/LdapUtil.java
b/fe/src/test/java/org/apache/impala/testutil/LdapUtil.java
index 1df057957..170fe238d 100644
--- a/fe/src/test/java/org/apache/impala/testutil/LdapUtil.java
+++ b/fe/src/test/java/org/apache/impala/testutil/LdapUtil.java
@@ -40,6 +40,10 @@ public class LdapUtil {
public static final String TEST_USER_7 = "Test7Ldap";
+ public static final String TEST_USER_LONG_PSW = "TestLdapLongPsw";
+ public static final String TEST_PASSWORD_LONG =
+ "verylongpasswordthatcreatesalongbasic64encoding";
+
// TEST_USER_1 and TEST_USER_2 are members of this group.
public static final String TEST_USER_GROUP = "group1";
diff --git a/fe/src/test/resources/users.ldif b/fe/src/test/resources/users.ldif
index c1787ef1b..dfb2195ea 100644
--- a/fe/src/test/resources/users.ldif
+++ b/fe/src/test/resources/users.ldif
@@ -102,4 +102,14 @@ dn: cn=group2,ou=Groups,dc=myorg,dc=com
objectClass: top
objectClass: groupOfUniqueNames
cn: group2
-uniqueMember: cn=Test1Ldap,ou=Users,dc=myorg,dc=com
\ No newline at end of file
+uniqueMember: cn=Test1Ldap,ou=Users,dc=myorg,dc=com
+
+dn: cn=TestLdapLongPsw,ou=Users,dc=myorg,dc=com
+objectClass: inetOrgPerson
+objectClass: organizationalPerson
+objectClass: person
+objectClass: top
+cn: TestLdapLongPsw
+sn: Ldap
+uid: estldaplongpsw
+userPassword: verylongpasswordthatcreatesalongbasic64encoding
diff --git a/shell/impala_client.py b/shell/impala_client.py
index 6ed2f5f87..a2392e032 100755
--- a/shell/impala_client.py
+++ b/shell/impala_client.py
@@ -585,11 +585,11 @@ class ImpalaClient(object):
if self.use_ldap:
# Set the BASIC authorization
user_passwd = "{0}:{1}".format(self.user, self.ldap_password)
- if sys.version_info.major < 3 or \
- sys.version_info.major == 3 and sys.version_info.minor == 0:
- auth = base64.encodestring(user_passwd.encode()).decode().strip('\n')
- else:
- auth = base64.encodebytes(user_passwd.encode()).decode().strip('\n')
+ # Produce RFC 2617-compliant basic credentials:
+ # - RFC 2045 encoding of username:password without limitations to 76
chars
+ # per line (and without trailing newline)
+ # - No translation of characters (+,/) for URL-safety
+ auth = base64.b64encode(user_passwd.encode()).decode()
transport.setLdapAuth(auth)
elif self.jwt is not None:
transport.setJwtAuth(self.jwt)