Skip to content

Commit c17829b

Browse files
hddongpan3793
authored andcommitted
[KYUUBI #3104] Support SSL for Etcd
### _Why are the changes needed?_ Support SSL for Etcd ### _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 #3105 from hddong/support-etcd-ssl. Closes #3104 49aadb9 [hongdongdong] change enable to enabled 87fa626 [hongdongdong] [KYUUBI #3104] Support SSL for Etcd Authored-by: hongdongdong <hongdongdong@cmss.chinamobile.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent 65ccf78 commit c17829b

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

docs/deployment/settings.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ Key | Default | Meaning | Type | Since
312312
kyuubi.ha.addresses||The connection string for the discovery ensemble|string|1.6.0
313313
kyuubi.ha.client.class|org.apache.kyuubi.ha.client.zookeeper.ZookeeperDiscoveryClient|Class name for service discovery client.<ul> <li>Zookeeper: org.apache.kyuubi.ha.client.zookeeper.ZookeeperDiscoveryClient</li> <li>Etcd: org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient</li></ul>|string|1.6.0
314314
kyuubi.ha.etcd.lease.timeout|PT10S|Timeout for etcd keep alive lease. The kyuubi server will known unexpected loss of engine after up to this seconds.|duration|1.6.0
315+
kyuubi.ha.etcd.ssl.ca.path|&lt;undefined&gt;|Where the etcd CA certificate file is stored.|string|1.6.0
316+
kyuubi.ha.etcd.ssl.client.certificate.path|&lt;undefined&gt;|Where the etcd SSL certificate file is stored.|string|1.6.0
317+
kyuubi.ha.etcd.ssl.client.key.path|&lt;undefined&gt;|Where the etcd SSL key file is stored.|string|1.6.0
318+
kyuubi.ha.etcd.ssl.enabled|false|When set to true, will build a ssl secured etcd client.|boolean|1.6.0
315319
kyuubi.ha.namespace|kyuubi|The root directory for the service to deploy its instance uri|string|1.6.0
316320
kyuubi.ha.zookeeper.acl.enabled|false|Set to true if the zookeeper ensemble is kerberized|boolean|1.0.0
317321
kyuubi.ha.zookeeper.auth.digest|&lt;undefined&gt;|The digest auth string is used for zookeeper authentication, like: username:password.|string|1.3.2

kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/HighAvailabilityConf.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,32 @@ object HighAvailabilityConf {
191191
.timeConf
192192
.checkValue(_ > 0, "Must be positive")
193193
.createWithDefault(Duration.ofSeconds(10).toMillis)
194+
195+
val HA_ETCD_SSL_ENABLED: ConfigEntry[Boolean] =
196+
buildConf("kyuubi.ha.etcd.ssl.enabled")
197+
.doc("When set to true, will build a ssl secured etcd client.")
198+
.version("1.6.0")
199+
.booleanConf
200+
.createWithDefault(false)
201+
202+
val HA_ETCD_SSL_CA_PATH: OptionalConfigEntry[String] =
203+
buildConf("kyuubi.ha.etcd.ssl.ca.path")
204+
.doc("Where the etcd CA certificate file is stored.")
205+
.version("1.6.0")
206+
.stringConf
207+
.createOptional
208+
209+
val HA_ETCD_SSL_CLINET_CRT_PATH: OptionalConfigEntry[String] =
210+
buildConf("kyuubi.ha.etcd.ssl.client.certificate.path")
211+
.doc("Where the etcd SSL certificate file is stored.")
212+
.version("1.6.0")
213+
.stringConf
214+
.createOptional
215+
216+
val HA_ETCD_SSL_CLINET_KEY_PATH: OptionalConfigEntry[String] =
217+
buildConf("kyuubi.ha.etcd.ssl.client.key.path")
218+
.doc("Where the etcd SSL key file is stored.")
219+
.version("1.6.0")
220+
.stringConf
221+
.createOptional
194222
}

kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala

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

1818
package org.apache.kyuubi.ha.client.etcd
1919

20+
import java.io.File
2021
import java.nio.charset.StandardCharsets.UTF_8
2122
import java.util.concurrent.TimeUnit
2223

@@ -36,6 +37,7 @@ import io.etcd.jetcd.options.GetOption
3637
import io.etcd.jetcd.options.PutOption
3738
import io.etcd.jetcd.watch.WatchEvent
3839
import io.etcd.jetcd.watch.WatchResponse
40+
import io.grpc.netty.GrpcSslContexts
3941
import io.grpc.stub.StreamObserver
4042

4143
import org.apache.kyuubi.KYUUBI_VERSION
@@ -44,7 +46,7 @@ import org.apache.kyuubi.KyuubiSQLException
4446
import org.apache.kyuubi.config.KyuubiConf
4547
import org.apache.kyuubi.config.KyuubiConf.ENGINE_INIT_TIMEOUT
4648
import org.apache.kyuubi.ha.HighAvailabilityConf
47-
import org.apache.kyuubi.ha.HighAvailabilityConf.HA_ENGINE_REF_ID
49+
import org.apache.kyuubi.ha.HighAvailabilityConf._
4850
import org.apache.kyuubi.ha.client.DiscoveryClient
4951
import org.apache.kyuubi.ha.client.DiscoveryPaths
5052
import org.apache.kyuubi.ha.client.ServiceDiscovery
@@ -63,9 +65,32 @@ class EtcdDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient {
6365

6466
var leaseTTL: Long = _
6567

68+
private def buildClient(): Client = {
69+
val endpoints = conf.get(HA_ADDRESSES).split(",")
70+
val sslEnabled = conf.get(HA_ETCD_SSL_ENABLED)
71+
if (!sslEnabled) {
72+
Client.builder.endpoints(endpoints: _*).build
73+
} else {
74+
val caPath = conf.getOption(HA_ETCD_SSL_CA_PATH.key).getOrElse(
75+
throw new IllegalArgumentException(s"${HA_ETCD_SSL_CA_PATH.key} is not defined"))
76+
val crtPath = conf.getOption(HA_ETCD_SSL_CLINET_CRT_PATH.key).getOrElse(
77+
throw new IllegalArgumentException(s"${HA_ETCD_SSL_CLINET_CRT_PATH.key} is not defined"))
78+
val keyPath = conf.getOption(HA_ETCD_SSL_CLINET_KEY_PATH.key).getOrElse(
79+
throw new IllegalArgumentException(s"${HA_ETCD_SSL_CLINET_KEY_PATH.key} is not defined"))
80+
81+
val context = GrpcSslContexts.forClient()
82+
.trustManager(new File(caPath))
83+
.keyManager(new File(crtPath), new File(keyPath))
84+
.build()
85+
Client.builder()
86+
.endpoints(endpoints: _*)
87+
.sslContext(context)
88+
.build()
89+
}
90+
}
91+
6692
def createClient(): Unit = {
67-
val endpoints = conf.get(HighAvailabilityConf.HA_ADDRESSES).split(",")
68-
client = Client.builder.endpoints(endpoints: _*).build
93+
client = buildClient()
6994
kvClient = client.getKVClient()
7095
lockClient = client.getLockClient()
7196
leaseClient = client.getLeaseClient()

0 commit comments

Comments
 (0)