This is an automated email from the ASF dual-hosted git repository.
bowenliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 9a001c8d7 [KYUUBI #5120] [JDBC] Allow using session's user and
password for connecting database in JDBC engine
9a001c8d7 is described below
commit 9a001c8d7cb50c0c68884c7c6f7ab0b12bb6c657
Author: liangbowen <[email protected]>
AuthorDate: Mon Aug 7 13:33:50 2023 +0800
[KYUUBI #5120] [JDBC] Allow using session's user and password for
connecting database in JDBC engine
### _Why are the changes needed?_
- allow using the session's user/password to connect database in the JDBC
engine
- it is allowed to be applied on any share level of engines, since every
kyuubi session maintains a dedicated JDBC connection in the current
implementation
### _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.readthedocs.io/en/master/contributing/code/testing.html#running-tests)
locally before make a pull request
Closes #5120 from bowenliang123/jdbc-user.
Closes #5120
7b8ebd137 [liangbowen] Use session's user and password to connect to
database in JDBC engine
Authored-by: liangbowen <[email protected]>
Signed-off-by: liangbowen <[email protected]>
---
docs/deployment/settings.md | 1 +
.../kyuubi/engine/jdbc/session/JdbcSessionImpl.scala | 14 ++++++++++++--
.../main/scala/org/apache/kyuubi/config/KyuubiConf.scala | 7 +++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/docs/deployment/settings.md b/docs/deployment/settings.md
index a2750fc7c..7ce3c2d4b 100644
--- a/docs/deployment/settings.md
+++ b/docs/deployment/settings.md
@@ -148,6 +148,7 @@ You can configure the Kyuubi properties in
`$KYUUBI_HOME/conf/kyuubi-defaults.co
| kyuubi.engine.hive.memory | 1g
| The heap memory for the Hive query engine
[...]
| kyuubi.engine.initialize.sql | SHOW DATABASES
| SemiColon-separated list of SQL statements to be initialized in the
newly created engine before queries. i.e. use `SHOW DATABASES` to eagerly
active HiveClient. This configuration can not be used in JDBC url due to the
limitation of Beeline/JDBC driver.
[...]
| kyuubi.engine.jdbc.connection.password | <undefined>
| The password is used for connecting to server
[...]
+| kyuubi.engine.jdbc.connection.propagateCredential | false
| Whether to use the session's user and password to connect to database
[...]
| kyuubi.engine.jdbc.connection.properties
|| The additional properties are used for connecting to server
[...]
| kyuubi.engine.jdbc.connection.provider | <undefined>
| The connection provider is used for getting a connection from the
server
[...]
| kyuubi.engine.jdbc.connection.url | <undefined>
| The server url that engine will connect to
[...]
diff --git
a/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
b/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
index 5acae8f24..8b36e5a56 100644
---
a/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
+++
b/externals/kyuubi-jdbc-engine/src/main/scala/org/apache/kyuubi/engine/jdbc/session/JdbcSessionImpl.scala
@@ -23,7 +23,8 @@ import scala.util.{Failure, Success, Try}
import org.apache.hive.service.rpc.thrift.{TGetInfoType, TGetInfoValue,
TProtocolVersion}
import org.apache.kyuubi.KyuubiSQLException
-import org.apache.kyuubi.config.KyuubiConf.ENGINE_JDBC_SESSION_INITIALIZE_SQL
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf._
import org.apache.kyuubi.config.KyuubiReservedKeys.KYUUBI_SESSION_HANDLE_KEY
import org.apache.kyuubi.engine.jdbc.connection.ConnectionProvider
import org.apache.kyuubi.engine.jdbc.util.KyuubiJdbcUtils
@@ -45,7 +46,16 @@ class JdbcSessionImpl(
private var databaseMetaData: DatabaseMetaData = _
- private val kyuubiConf = sessionManager.getConf
+ private val kyuubiConf: KyuubiConf = normalizeConf
+
+ private def normalizeConf: KyuubiConf = {
+ val kyuubiConf = sessionManager.getConf.clone
+ if (kyuubiConf.get(ENGINE_JDBC_CONNECTION_PROPAGATECREDENTIAL)) {
+ kyuubiConf.set(ENGINE_JDBC_CONNECTION_USER, user)
+ kyuubiConf.set(ENGINE_JDBC_CONNECTION_PASSWORD, password)
+ }
+ kyuubiConf
+ }
override def open(): Unit = {
info(s"Starting to open jdbc session.")
diff --git
a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
index 2de7abf89..b4102d267 100644
--- a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
+++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala
@@ -2706,6 +2706,13 @@ object KyuubiConf {
.stringConf
.createOptional
+ val ENGINE_JDBC_CONNECTION_PROPAGATECREDENTIAL: ConfigEntry[Boolean] =
+ buildConf("kyuubi.engine.jdbc.connection.propagateCredential")
+ .doc("Whether to use the session's user and password to connect to
database")
+ .version("1.8.0")
+ .booleanConf
+ .createWithDefault(false)
+
val ENGINE_JDBC_CONNECTION_USER: OptionalConfigEntry[String] =
buildConf("kyuubi.engine.jdbc.connection.user")
.doc("The user is used for connecting to server")