Skip to content

Commit 45248f5

Browse files
authored
fix: pass through user-provided password in HiveServer2Hook for all auth modes (#62888)
* fix: pass through user-provided password in HiveServer2Hook regardless of auth mechanism Previously, HiveServer2Hook.get_conn() only set the password when auth_mechanism was LDAP, CUSTOM, or PLAIN. For all other auth modes (including the default NONE), user-provided passwords were silently dropped and pyhive would default to sending 'x' as the password. Now the password is passed through whenever the user has explicitly set one in the connection, regardless of the configured auth mechanism. Fixes #62338 * ci: retrigger CI
1 parent a998e28 commit 45248f5

File tree

2 files changed

+26
-2
lines changed
  • providers/apache/hive

2 files changed

+26
-2
lines changed

providers/apache/hive/src/airflow/providers/apache/hive/hooks/hive.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,11 @@ def get_conn(self, schema: str | None = None) -> Any:
885885
auth_mechanism = db.extra_dejson.get("auth_mechanism", "KERBEROS")
886886
kerberos_service_name = db.extra_dejson.get("kerberos_service_name", "hive")
887887

888-
# Password should be set if in LDAP, CUSTOM or PLAIN mode
889-
if auth_mechanism in ("LDAP", "CUSTOM", "PLAIN"):
888+
# Pass through the password whenever the user has explicitly set one.
889+
# Previously this was restricted to LDAP/CUSTOM/PLAIN, which caused
890+
# user-provided passwords to be silently dropped for other auth modes
891+
# (pyhive defaults to sending "x" when password is None).
892+
if db.password:
890893
password = db.password
891894

892895
from pyhive.hive import connect

providers/apache/hive/tests/unit/apache/hive/hooks/test_hive.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,27 @@ def test_get_conn_with_password_plain(self, mock_connect):
697697
database="default",
698698
)
699699

700+
@mock.patch("pyhive.hive.connect")
701+
def test_get_conn_with_password_none_auth(self, mock_connect):
702+
"""Test that password is passed through even when auth_mechanism is NONE."""
703+
conn_id = "conn_none_with_password"
704+
conn_env = CONN_ENV_PREFIX + conn_id.upper()
705+
706+
with mock.patch.dict(
707+
"os.environ",
708+
{conn_env: "jdbc+hive2://user:mypassword@localhost:10000/default"},
709+
):
710+
HiveServer2Hook(hiveserver2_conn_id=conn_id).get_conn()
711+
mock_connect.assert_called_once_with(
712+
host="localhost",
713+
port=10000,
714+
auth="NONE",
715+
kerberos_service_name=None,
716+
username="user",
717+
password="mypassword",
718+
database="default",
719+
)
720+
700721
@pytest.mark.parametrize(
701722
("host", "port", "schema", "message"),
702723
[

0 commit comments

Comments
 (0)