Skip to content

Commit 8c6af02

Browse files
committed
add python ssl to data security
1 parent 3a3f4b5 commit 8c6af02

File tree

2 files changed

+76
-24
lines changed

2 files changed

+76
-24
lines changed

src/zh/UserGuide/latest-Table/User-Manual/Data-Security.md

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ encrypt_key_path=......
6464

6565
在某些客户的生产环境中,对于数据传输的安全性要求更高,希望有更安全的传输方式,因此扩展了 Datanode 的 Client RPC 以支持数据传输加密。以下是支持数据传输加密的方式:
6666

67-
1. Thrift 除了普通模式与压缩模式外,增加 SSL 模式
67+
1. Thrift 除了普通模式与压缩模式外,增加 SSL 模式
6868
2. SessionPool(java) 与 Session(java) 支持使用 SSL 模式连接
6969
3. JDBC 支持使用 SSL 模式连接
7070
4. CLI 支持使用 SSL 模式连接
@@ -160,15 +160,40 @@ session =
160160
.build();
161161
```
162162

163-
### 2.5 JDBC
163+
### 2.5 Python
164+
python 客户端配置 ssl 需要设置use_ssl、ca_certs。
165+
166+
- use_ssl :是否启用 SSL。
167+
- ca_certs : 指定客户端证书路径。
168+
169+
#### 2.5.1 代码示例
170+
171+
```python
172+
ip = "127.0.0.1"
173+
port_ = "6667"
174+
username_ = "root"
175+
password_ = "root"
176+
# Configure SSL enabled
177+
use_ssl = True
178+
# Configure certificate path
179+
ca_certs = "/path/server.crt"
180+
181+
182+
def get_data():
183+
session = Session(
184+
ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs
185+
)
186+
```
187+
188+
### 2.6 JDBC
164189

165190
jdbc 支持两种方式的ssl 配置,需要配置use_ssl、trust_store、trust_store_pwd。
166191

167192
- use_ssl:是否开启ssl 默认是false
168193
- trust_store:truststore的证书路径
169194
- trust_store_pwd:truststore证书的密码(秘钥库口令)
170195

171-
#### 2.5.1 代码示例:
196+
#### 2.6.1 代码示例:
172197

173198
**方式一、在jdbc 的url 中配置使用**
174199

@@ -204,15 +229,16 @@ try (Connection connection =
204229
}catch (IoTDBSQLException e) {
205230
logger.error("IoTDB Jdbc example error", e);
206231
}
207-
```
232+
```
233+
208234

209-
### 2.6 CLI
235+
### 2.7 CLI
210236

211237
```SQL
212238
./start-cli.sh -h 127.0.0.1 -p 6667 -u root -pw root -usessl true -ts /Users/keystore/.truststore -tpw 123456
213239
```
214240

215-
### 2.7 SSL证书生成方式
241+
### 2.8 SSL证书生成方式
216242

217243
需安装 JDK、测试jdk8和jdk11生成证书未发现问题
218244

@@ -246,9 +272,9 @@ keytool -export -alias mykey -keystore aa.keystore -rfc -file certificate.cer
246272
keytool -import -alias mykey -file certificate.cer -keystore aa.truststore
247273
```
248274

249-
### 2.8 性能测试
275+
### 2.9 性能测试
250276

251-
#### 2.8.1 插入测试
277+
#### 2.9.1 插入测试
252278

253279
使用session 的inserttablet方法,使用100 设备*100测点,每批 100 行 loop 100 次,测试3遍,三次插入使用不同的设备名字,测试环境:1c1d,mac 16G,Intel Core i5。
254280

@@ -301,21 +327,21 @@ private static void insertTablet(String d) throws IoTDBConnectionException, Stat
301327

302328
根据ssl 三次取平均值为13117ms、非ssl取平均值12666ms,综合测试结果可以看出非ssl 插入速度略快ssl(`3.5%`)
303329

304-
#### 2.8.2 查询测试
330+
#### 2.9.2 查询测试
305331

306332
使用session 的executeQueryStatement方法、循环100次查询不同设备的测点,测试3遍,查询完后修改ssl重启iotdb,三次查询使用不同的设备名字,测试环境:1c1d,mac 16G,Intel Core i5
307333

308334
**代码示例:**
309335

310336
```Properties
311337
private static void query(String d) throws IoTDBConnectionException, StatementExecutionException {
312-
try (SessionDataSet dataSet = session.executeQueryStatement("select * from root.sg1.d9"+d)) {
313-
System.out.println(dataSet.getColumnNames());
314-
dataSet.setFetchSize(1024); // default is 10000
315-
while (dataSet.hasNext()) {
316-
System.out.println(dataSet.next());
317-
}
318-
}
338+
try (SessionDataSet dataSet = session.executeQueryStatement("select * from root.sg1.d9"+d)) {
339+
System.out.println(dataSet.getColumnNames());
340+
dataSet.setFetchSize(1024); // default is 10000
341+
while (dataSet.hasNext()) {
342+
System.out.println(dataSet.next());
343+
}
344+
}
319345
}
320346
```
321347

src/zh/UserGuide/latest/User-Manual/Data-Security.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,40 @@ session =
160160
.build();
161161
```
162162

163-
### 2.5 JDBC
163+
### 2.5 Python
164+
python 客户端配置 ssl 需要设置use_ssl、ca_certs。
165+
166+
- use_ssl :是否启用 SSL。
167+
- ca_certs : 指定客户端证书路径。
168+
169+
#### 2.5.1 代码示例
170+
171+
```python
172+
ip = "127.0.0.1"
173+
port_ = "6667"
174+
username_ = "root"
175+
password_ = "root"
176+
# Configure SSL enabled
177+
use_ssl = True
178+
# Configure certificate path
179+
ca_certs = "/path/server.crt"
180+
181+
182+
def get_data():
183+
session = Session(
184+
ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs
185+
)
186+
```
187+
188+
### 2.6 JDBC
164189

165190
jdbc 支持两种方式的ssl 配置,需要配置use_ssl、trust_store、trust_store_pwd。
166191

167192
- use_ssl:是否开启ssl 默认是false
168193
- trust_store:truststore的证书路径
169194
- trust_store_pwd:truststore证书的密码(秘钥库口令)
170195

171-
#### 2.5.1 代码示例:
196+
#### 2.6.1 代码示例:
172197

173198
**方式一、在jdbc 的url 中配置使用**
174199

@@ -204,15 +229,16 @@ try (Connection connection =
204229
}catch (IoTDBSQLException e) {
205230
logger.error("IoTDB Jdbc example error", e);
206231
}
207-
```
232+
```
233+
208234

209-
### 2.6 CLI
235+
### 2.7 CLI
210236

211237
```SQL
212238
./start-cli.sh -h 127.0.0.1 -p 6667 -u root -pw root -usessl true -ts /Users/keystore/.truststore -tpw 123456
213239
```
214240

215-
### 2.7 SSL证书生成方式
241+
### 2.8 SSL证书生成方式
216242

217243
需安装 JDK、测试jdk8和jdk11生成证书未发现问题
218244

@@ -246,9 +272,9 @@ keytool -export -alias mykey -keystore aa.keystore -rfc -file certificate.cer
246272
keytool -import -alias mykey -file certificate.cer -keystore aa.truststore
247273
```
248274

249-
### 2.8 性能测试
275+
### 2.9 性能测试
250276

251-
#### 2.8.1 插入测试
277+
#### 2.9.1 插入测试
252278

253279
使用session 的inserttablet方法,使用100 设备*100测点,每批 100 行 loop 100 次,测试3遍,三次插入使用不同的设备名字,测试环境:1c1d,mac 16G,Intel Core i5。
254280

@@ -301,7 +327,7 @@ private static void insertTablet(String d) throws IoTDBConnectionException, Stat
301327

302328
根据ssl 三次取平均值为13117ms、非ssl取平均值12666ms,综合测试结果可以看出非ssl 插入速度略快ssl(`3.5%`)
303329

304-
#### 2.8.2 查询测试
330+
#### 2.9.2 查询测试
305331

306332
使用session 的executeQueryStatement方法、循环100次查询不同设备的测点,测试3遍,查询完后修改ssl重启iotdb,三次查询使用不同的设备名字,测试环境:1c1d,mac 16G,Intel Core i5
307333

0 commit comments

Comments
 (0)