Skip to content

Commit c8363a0

Browse files
authored
client java/rust/go should support TLS (#352)
* client java/rust/go should support TLS Signed-off-by: iosmanthus <[email protected]> * add code snippets for tls config Signed-off-by: iosmanthus <[email protected]> --------- Signed-off-by: iosmanthus <[email protected]>
1 parent c061417 commit c8363a0

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

content/docs/7.1/deploy/configure/security.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ For the information about all TLS configuration parameters of PD, see [PD securi
124124

125125
## Step 3. Configure the TiKV client
126126

127-
You need to set TLS options for the TiKV client to connect to TiKV. Taking [Rust Client](https://github.com/tikv/client-rust) as an example, the TLS options are set as follows:
127+
You need to set TLS options for the TiKV client to connect to TiKV.
128+
129+
### [Rust Client](https://github.com/tikv/client-rust)
128130

129131
```rust
130132
let config = Config::new(/* ... */).with_security(
@@ -137,11 +139,32 @@ let config = Config::new(/* ... */).with_security(
137139
);
138140
```
139141

140-
Besides, the **connection URL should be changed to `https://`** instead of a plain `ip:port`.
142+
### [Java Client](https://github.com/tikv/client-java)
143+
144+
```java
145+
TiConfiguration conf = TiConfiguration.createRawDefault("127.0.0.1:2379");
146+
conf.setTlsEnable(true);
147+
conf.setTrustCertCollectionFile("/path/to/ca.pem");
148+
conf.setKeyCertChainFile("/path/to/cert.pem");
149+
conf.setKeyFile("/path/to/key.pem");
150+
```
151+
152+
For more information about the TLS config of Java client, check the [Java client documentation](https://tikv.github.io/client-java/administration/configuration.html#tikvtls_enable)
153+
154+
### [Go Client](https://github.com/tikv/client-go)
155+
156+
```go
157+
cli, err := rawkv.NewClient(context.TODO(), []string{"127.0.0.1:2379"}, config.Security{
158+
ClusterSSLCA: "/path/to/ca.pem",
159+
ClusterSSLCert: "/path/to/cert.pem",
160+
ClusterSSLKey: "/path/to/key.pem",
161+
})
162+
if err != nil {
163+
panic(err)
164+
}
165+
```
141166

142-
{{< warning >}}
143-
Currently, TiKV Java Client does not support TLS.
144-
{{< /warning >}}
167+
For more information about the TLS config of Go client, check the [Go client documentation](https://pkg.go.dev/github.com/tikv/client-go/[email protected]/config#Security)
145168

146169
## Step 4. Connect TiKV using `tikv-ctl` and `pd-ctl`
147170

content/docs/dev/deploy/configure/security.md

+28-5
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ For the information about all TLS configuration parameters of PD, see [PD securi
124124

125125
## Step 3. Configure the TiKV client
126126

127-
You need to set TLS options for the TiKV client to connect to TiKV. Taking [Rust Client](https://github.com/tikv/client-rust) as an example, the TLS options are set as follows:
127+
You need to set TLS options for the TiKV client to connect to TiKV.
128+
129+
### [Rust Client](https://github.com/tikv/client-rust)
128130

129131
```rust
130132
let config = Config::new(/* ... */).with_security(
@@ -137,11 +139,32 @@ let config = Config::new(/* ... */).with_security(
137139
);
138140
```
139141

140-
Besides, the **connection URL should be changed to `https://`** instead of a plain `ip:port`.
142+
### [Java Client](https://github.com/tikv/client-java)
143+
144+
```java
145+
TiConfiguration conf = TiConfiguration.createRawDefault("127.0.0.1:2379");
146+
conf.setTlsEnable(true);
147+
conf.setTrustCertCollectionFile("/path/to/ca.pem");
148+
conf.setKeyCertChainFile("/path/to/cert.pem");
149+
conf.setKeyFile("/path/to/key.pem");
150+
```
151+
152+
For more information about the TLS config of Java client, check the [Java client documentation](https://tikv.github.io/client-java/administration/configuration.html#tikvtls_enable)
153+
154+
### [Go Client](https://github.com/tikv/client-go)
155+
156+
```go
157+
cli, err := rawkv.NewClient(context.TODO(), []string{"127.0.0.1:2379"}, config.Security{
158+
ClusterSSLCA: "/path/to/ca.pem",
159+
ClusterSSLCert: "/path/to/cert.pem",
160+
ClusterSSLKey: "/path/to/key.pem",
161+
})
162+
if err != nil {
163+
panic(err)
164+
}
165+
```
141166

142-
{{< warning >}}
143-
Currently, TiKV Java Client does not support TLS.
144-
{{< /warning >}}
167+
For more information about the TLS config of Go client, check the [Go client documentation](https://pkg.go.dev/github.com/tikv/client-go/[email protected]/config#Security)
145168

146169
## Step 4. Connect TiKV using `tikv-ctl` and `pd-ctl`
147170

0 commit comments

Comments
 (0)