Skip to content

Commit

Permalink
[KYUUBI #3355] Backport HIVE-20583 - Use canonical hostname only for …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
pan3793 committed Aug 26, 2022
1 parent 593696d commit 340893f
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ public KyuubiConnection(String uri, Properties info) throws SQLException {
throw new KyuubiSQLException(e);
}
jdbcUriString = connParams.getJdbcUriString();
sessConfMap = connParams.getSessionVars();
// JDBC URL: jdbc:hive2://<host>:<port>/dbName;sess_var_list?hive_conf_list#hive_var_list
// each list: <key1>=<val1>;<key2>=<val2> and so on
// sess_var_list -> sessConfMap
// hive_conf_list -> hiveConfMap
// hive_var_list -> hiveVarMap
host = Utils.getCanonicalHostName(connParams.getHost());
if (isKerberosAuthMode()) {
host = Utils.getCanonicalHostName(connParams.getHost());
} else {
host = connParams.getHost();
}
port = connParams.getPort();
sessConfMap = connParams.getSessionVars();

setupTimeout();

Expand Down Expand Up @@ -200,7 +204,11 @@ public KyuubiConnection(String uri, Properties info) throws SQLException {
}
// Update with new values
jdbcUriString = connParams.getJdbcUriString();
host = Utils.getCanonicalHostName(connParams.getHost());
if (isKerberosAuthMode()) {
host = Utils.getCanonicalHostName(connParams.getHost());
} else {
host = connParams.getHost();
}
port = connParams.getPort();
} else {
errMsg = warnMsg;
Expand Down Expand Up @@ -816,6 +824,10 @@ private boolean isPlainSaslAuthMode() {
return isSaslAuthMode() && !hasSessionValue(AUTH_PRINCIPAL);
}

private boolean isKerberosAuthMode() {
return isSaslAuthMode() && hasSessionValue(AUTH_PRINCIPAL);
}

private Subject createSubject() {
if (isFromSubjectAuthMode()) {
AccessControlContext context = AccessController.getContext();
Expand Down

0 comments on commit 340893f

Please sign in to comment.