Skip to content

Commit 340893f

Browse files
committed
[KYUUBI #3355] Backport HIVE-20583 - Use canonical hostname only for kerberos auth in HiveConnection
### _Why are the changes needed?_ Fix #3352 [HIVE-17218](https://issues.apache.org/jira/browse/HIVE-17218): Canonical-ize hostnames for Hive metastore, and HS2 servers This may have the problem mentioned by JIRA [HIVE-20583](https://issues.apache.org/jira/browse/HIVE-20583): Use canonical hostname only for kerberos auth in HiveConnection ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #3355 from pan3793/HIVE-20583. Closes #3355 6e2ffa4 [Cheng Pan] Fix NPE f09b8e6 [Cheng Pan] Backport HIVE-20583 Authored-by: Cheng Pan <chengpan@apache.org> Signed-off-by: Cheng Pan <chengpan@apache.org> (cherry picked from commit 1163a76) Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 593696d commit 340893f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,18 @@ public KyuubiConnection(String uri, Properties info) throws SQLException {
130130
throw new KyuubiSQLException(e);
131131
}
132132
jdbcUriString = connParams.getJdbcUriString();
133+
sessConfMap = connParams.getSessionVars();
133134
// JDBC URL: jdbc:hive2://<host>:<port>/dbName;sess_var_list?hive_conf_list#hive_var_list
134135
// each list: <key1>=<val1>;<key2>=<val2> and so on
135136
// sess_var_list -> sessConfMap
136137
// hive_conf_list -> hiveConfMap
137138
// hive_var_list -> hiveVarMap
138-
host = Utils.getCanonicalHostName(connParams.getHost());
139+
if (isKerberosAuthMode()) {
140+
host = Utils.getCanonicalHostName(connParams.getHost());
141+
} else {
142+
host = connParams.getHost();
143+
}
139144
port = connParams.getPort();
140-
sessConfMap = connParams.getSessionVars();
141145

142146
setupTimeout();
143147

@@ -200,7 +204,11 @@ public KyuubiConnection(String uri, Properties info) throws SQLException {
200204
}
201205
// Update with new values
202206
jdbcUriString = connParams.getJdbcUriString();
203-
host = Utils.getCanonicalHostName(connParams.getHost());
207+
if (isKerberosAuthMode()) {
208+
host = Utils.getCanonicalHostName(connParams.getHost());
209+
} else {
210+
host = connParams.getHost();
211+
}
204212
port = connParams.getPort();
205213
} else {
206214
errMsg = warnMsg;
@@ -816,6 +824,10 @@ private boolean isPlainSaslAuthMode() {
816824
return isSaslAuthMode() && !hasSessionValue(AUTH_PRINCIPAL);
817825
}
818826

827+
private boolean isKerberosAuthMode() {
828+
return isSaslAuthMode() && hasSessionValue(AUTH_PRINCIPAL);
829+
}
830+
819831
private Subject createSubject() {
820832
if (isFromSubjectAuthMode()) {
821833
AccessControlContext context = AccessController.getContext();

0 commit comments

Comments
 (0)