From 777b784439bd882dddeaca9215a8ee35335f96e3 Mon Sep 17 00:00:00 2001 From: senmiaoliu Date: Sun, 21 Jan 2024 14:26:12 +0800 Subject: [PATCH] [KYUUBI #5968] Support set authentication user for Trino engine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description ## Issue References ๐Ÿ”— This pull request fixes #5968 ## Describe Your Solution ๐Ÿ”ง Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. ## Types of changes :bookmark: - [ ] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐Ÿงช #### Behavior Without This Pull Request :coffin: #### Behavior With This Pull Request :tada: #### Related Unit Tests --- # Checklist ๐Ÿ“ - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #5970 from lsm1/branch-kyuubi-5968. Closes #5968 580eb45d2 [senmiaoliu] fix style a36380cde [senmiaoliu] add auth user conf for trino engine Authored-by: senmiaoliu Signed-off-by: Cheng Pan --- docs/configuration/settings.md | 1 + .../kyuubi/engine/trino/session/TrinoSessionImpl.scala | 8 +++++--- .../main/scala/org/apache/kyuubi/config/KyuubiConf.scala | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/configuration/settings.md b/docs/configuration/settings.md index fa329e6b48e..b203b0bdacb 100644 --- a/docs/configuration/settings.md +++ b/docs/configuration/settings.md @@ -194,6 +194,7 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co | kyuubi.engine.trino.connection.truststore.password | <undefined> | The truststore password used for connecting to trino cluster | string | 1.8.0 | | kyuubi.engine.trino.connection.truststore.path | <undefined> | The truststore path used for connecting to trino cluster | string | 1.8.0 | | kyuubi.engine.trino.connection.truststore.type | <undefined> | The truststore type used for connecting to trino cluster | string | 1.8.0 | +| kyuubi.engine.trino.connection.user | <undefined> | The user used for connecting to trino cluster | string | 1.9.0 | | kyuubi.engine.trino.event.loggers | JSON | A comma-separated list of engine history loggers, where engine/session/operation etc events go.
  • JSON: the events will be written to the location of kyuubi.engine.event.json.log.path
  • JDBC: to be done
  • CUSTOM: to be done.
| seq | 1.7.0 | | kyuubi.engine.trino.extra.classpath | <undefined> | The extra classpath for the Trino query engine, for configuring other libs which may need by the Trino engine | string | 1.6.0 | | kyuubi.engine.trino.java.options | <undefined> | The extra Java options for the Trino query engine | string | 1.6.0 | diff --git a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala index 21aa921b9f2..674a67d0e38 100644 --- a/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala +++ b/externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala @@ -54,7 +54,7 @@ class TrinoSessionImpl( override val handle: SessionHandle = conf.get(KYUUBI_SESSION_HANDLE_KEY).map(SessionHandle.fromUUID).getOrElse(SessionHandle()) - private val username: String = sessionConf + private val sessionUser: String = sessionConf .getOption(KyuubiReservedKeys.KYUUBI_SESSION_USER_KEY).getOrElse(currentUser) var trinoContext: TrinoContext = _ @@ -95,7 +95,7 @@ class TrinoSessionImpl( ClientSession.builder() .server(URI.create(connectionUrl)) - .principal(Optional.of(username)) + .principal(Optional.of(sessionUser)) .source("kyuubi") .catalog(catalogName) .schema(databaseName) @@ -133,7 +133,9 @@ class TrinoSessionImpl( require( serverScheme.equalsIgnoreCase("https"), "Trino engine using username/password requires HTTPS to be enabled") - builder.addInterceptor(OkHttpUtil.basicAuth(username, password)) + val user: String = sessionConf + .get(KyuubiConf.ENGINE_TRINO_CONNECTION_USER).getOrElse(sessionUser) + builder.addInterceptor(OkHttpUtil.basicAuth(user, password)) } builder.build() 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 9f075275472..3eedfdded91 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 @@ -1388,6 +1388,13 @@ object KyuubiConf { .stringConf .createOptional + val ENGINE_TRINO_CONNECTION_USER: OptionalConfigEntry[String] = + buildConf("kyuubi.engine.trino.connection.user") + .doc("The user used for connecting to trino cluster") + .version("1.9.0") + .stringConf + .createOptional + val ENGINE_TRINO_CONNECTION_PASSWORD: OptionalConfigEntry[String] = buildConf("kyuubi.engine.trino.connection.password") .doc("The password used for connecting to trino cluster")