Skip to content

Commit 7b5704f

Browse files
authored
Merge pull request #9 from arenadata/feature/trino-kerberos-support
fix(trino): add Kerberos authentication support
2 parents 55c0d7f + 516982a commit 7b5704f

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

externals/kyuubi-trino-engine/src/main/scala/org/apache/kyuubi/engine/trino/session/TrinoSessionImpl.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.kyuubi.engine.trino.session
1919

20+
import java.io.File
2021
import java.net.URI
2122
import java.time.ZoneId
2223
import java.util.{Locale, Optional}
@@ -136,6 +137,43 @@ class TrinoSessionImpl(
136137
Optional.ofNullable(truststoreType.orNull),
137138
true)
138139
}
140+
141+
val kerberosEnabled = sessionConf.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_ENABLED)
142+
143+
if (kerberosEnabled) {
144+
val servicePrincipalPattern = sessionConf
145+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_SERVICE_PRINCIPAL_PATTERN)
146+
val remoteServiceName = sessionConf
147+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_REMOTE_SERVICE_NAME)
148+
val useCanonicalHostname = sessionConf
149+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_USE_CANONICAL_HOSTNAME)
150+
val principal = sessionConf
151+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_PRINCIPAL)
152+
val kerberosConfig = sessionConf
153+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_CONFIG)
154+
val keytab = sessionConf
155+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_KEYTAB)
156+
val credentialCache = sessionConf
157+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_CREDENTIAL_CACHE)
158+
val delegatedKerberos = sessionConf
159+
.get(KyuubiConf.ENGINE_TRINO_CONNECTION_KERBEROS_DELEGATED_KERBEROS)
160+
161+
val configFile = kerberosConfig.map(new File(_))
162+
val keytabFile = keytab.map(new File(_))
163+
val credCacheFile = credentialCache.map(new File(_))
164+
165+
OkHttpUtil.setupKerberos(
166+
builder,
167+
servicePrincipalPattern,
168+
remoteServiceName,
169+
useCanonicalHostname,
170+
Optional.ofNullable(principal.orNull),
171+
Optional.ofNullable(configFile.orNull),
172+
Optional.ofNullable(keytabFile.orNull),
173+
Optional.ofNullable(credCacheFile.orNull),
174+
delegatedKerberos)
175+
}
176+
139177
sessionConf.get(KyuubiConf.ENGINE_TRINO_CONNECTION_PASSWORD).foreach { password =>
140178
require(
141179
serverScheme.equalsIgnoreCase("https"),

kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,70 @@ object KyuubiConf {
15761576
.checkValue(_ >= 200, "Minimum 200 milliseconds")
15771577
.createWithDefault(1000)
15781578

1579+
val ENGINE_TRINO_CONNECTION_KERBEROS_ENABLED: ConfigEntry[Boolean] =
1580+
buildConf("kyuubi.engine.trino.connection.kerberos.enabled")
1581+
.doc("Enable Kerberos authentication when connecting to Trino")
1582+
.version("1.10.1")
1583+
.booleanConf
1584+
.createWithDefault(false)
1585+
1586+
val ENGINE_TRINO_CONNECTION_KERBEROS_SERVICE_PRINCIPAL_PATTERN: ConfigEntry[String] =
1587+
buildConf("kyuubi.engine.trino.connection.kerberos.servicePrincipalPattern")
1588+
.doc("Pattern for constructing the Kerberos service principal," +
1589+
" using variables ${SERVICE} and ${HOST}")
1590+
.version("1.10.1")
1591+
.stringConf
1592+
.createWithDefault("${SERVICE}@${HOST}")
1593+
1594+
val ENGINE_TRINO_CONNECTION_KERBEROS_REMOTE_SERVICE_NAME: ConfigEntry[String] =
1595+
buildConf("kyuubi.engine.trino.connection.kerberos.remoteServiceName")
1596+
.doc("Remote service name for Kerberos (typically 'HTTP')")
1597+
.version("1.10.1")
1598+
.stringConf
1599+
.createWithDefault("HTTP")
1600+
1601+
val ENGINE_TRINO_CONNECTION_KERBEROS_USE_CANONICAL_HOSTNAME: ConfigEntry[Boolean] =
1602+
buildConf("kyuubi.engine.trino.connection.kerberos.useCanonicalHostname")
1603+
.doc("Use the canonical hostname when acquiring the Kerberos ticket")
1604+
.version("1.10.1")
1605+
.booleanConf
1606+
.createWithDefault(true)
1607+
1608+
val ENGINE_TRINO_CONNECTION_KERBEROS_PRINCIPAL: OptionalConfigEntry[String] =
1609+
buildConf("kyuubi.engine.trino.connection.kerberos.principal")
1610+
.doc("Kerberos principal for authentication (format: primary/instance@REALM)")
1611+
.version("1.10.1")
1612+
.stringConf
1613+
.createOptional
1614+
1615+
val ENGINE_TRINO_CONNECTION_KERBEROS_CONFIG: OptionalConfigEntry[String] =
1616+
buildConf("kyuubi.engine.trino.connection.kerberos.config")
1617+
.doc("Path to the Kerberos configuration file (krb5.conf)")
1618+
.version("1.10.1")
1619+
.stringConf
1620+
.createOptional
1621+
1622+
val ENGINE_TRINO_CONNECTION_KERBEROS_KEYTAB: OptionalConfigEntry[String] =
1623+
buildConf("kyuubi.engine.trino.connection.kerberos.keytab")
1624+
.doc("Path to the keytab file containing the Kerberos principal credentials")
1625+
.version("1.10.1")
1626+
.stringConf
1627+
.createOptional
1628+
1629+
val ENGINE_TRINO_CONNECTION_KERBEROS_CREDENTIAL_CACHE: OptionalConfigEntry[String] =
1630+
buildConf("kyuubi.engine.trino.connection.kerberos.credentialCache")
1631+
.doc("Path to the Kerberos credential cache file")
1632+
.version("1.10.1")
1633+
.stringConf
1634+
.createOptional
1635+
1636+
val ENGINE_TRINO_CONNECTION_KERBEROS_DELEGATED_KERBEROS: ConfigEntry[Boolean] =
1637+
buildConf("kyuubi.engine.trino.connection.kerberos.delegatedKerberos")
1638+
.doc("Enable Kerberos credential delegation to the Trino server")
1639+
.version("1.10.1")
1640+
.booleanConf
1641+
.createWithDefault(false)
1642+
15791643
val ENGINE_HIVE_MAIN_RESOURCE: OptionalConfigEntry[String] =
15801644
buildConf("kyuubi.session.engine.hive.main.resource")
15811645
.doc("The package used to create Hive engine remote job. If it is undefined," +

0 commit comments

Comments
 (0)