首批通过分布式安全可靠测评,为关键业务系统打造
安全功能
更新时间:2026-04-13 12:00:53
导数工具默认在命令行中显式指定密码等敏感信息即可运行。为了加强信息的安全性,导数工具 4.2.0 及之后的版本支持对命令行中的敏感信息提供加密和解密的方法。
快速上手:使用 secure-gen 加密
安装 OpenSSL 并配置环境变量。
说明
使用 secure-gen 加密时,需要安装 OpenSSL 工具包。具体请参考本节的 查看 secure-gen 帮助 内容。
确认 OpenSSL 已安装成功。
$ which openssl /usr/bin/openssl加密本地路径下的敏感文件。
./secure-gen -n <file_path>说明
敏感文件的格式需要符合 Property File Format 规范 或者在交互界面中编辑待加密的敏感信息。
在
{ob-loader-dumper}/tools/目录下执行以下命令。./secure-gen -i在交互窗口中编辑需要加密的参数,完成后请输入
:wq保存并退出。# Input the sensitive fields below in plain-text respectively. # Note you can leave any of them as blank, ob-loader-dumper will parse from cli args first, and override any field if there is a conflict。 # # Database password. oceanbase.jdbc.password=****** # Database password for sys tenant. oceanbase.jdbc.sys.password=****** # Access key for cloud storages like OSS & S3. cloud.storage.access.key=****** # Secret key for cloud storages like OSS & S3. cloud.storage.secret.key=****** :wq目前导数工具支持加密的敏感参数包括:
参数 说明 oceanbase.jdbc.password 非必选项。OceanBase 业务租户的密码,即命令行选项 -p(--password)所指定的值。oceanbase.jdbc.sys.password 非必选项。OceanBase sys 租户下的账户密码,即命令行选项 --sys-password所指定的值。cloud.storage.access.key 非必选项。适用于云存储服务(S3/OSS),即命令行选项 -f所指定的访问账号access-key。cloud.storage.secret.key 非必选项。适用于云存储服务(S3/OSS),即命令行选项 -f所指定的访问密钥secret-key。
如果密钥已存在,可根据提示选择是否使用已存在的密钥。
$ ./secure-gen Detected that a key already exists, do you want to use it? If not, a new key will be generated and overwrite the existing key (y/n):输入
n表示通过 OpenSSL 重新生成密钥对,默认密钥对的存放路径为<用户根目录>/.loaddump/secure/。公钥文件默认是key.pem.pub,私钥文件默认是key.pem。Detected that a key already exists, do you want to use it? If not, a new key will be generated and overwrite the existing key (y/n): n Generating RSA private key, 4096 bit long modulus ............++ .......................................................++ e is 65537 (0x10001) writing RSA key The key pair has been generated under the directory /Users/chang/.loaddump, please keep it safe. The encrypted file /Users/chang/.loaddump/secure/secure.rsa has been generated for sensitive information. If you want to use it, please fill in the corresponding content in conf/decrypt.properties properly.输入
y表示使用已存在的密钥对,导数工具从<用户根目录>/.loaddump/secure/目录中加载密钥对并生成加密文件(secure.rsa)。Detected that a key already exists, do you want to use it? If not, a new key will be generated and overwrite the existing key (y/n): y The encrypted file /Users/chang/.loaddump/secure/secure.rsa has been generated for sensitive information. If you want to use it, please fill in the corresponding content in conf/decrypt.properties properly.
验证密钥对与加密文件是否生成成功。
$ ls ~/.loaddump/secure/ key.pem key.pem.pub secure.rsa在
{ob-loader-dumper}/conf/decrypt.properties中填写加密后的信息。# Absolute path of your secure file, whose name is secure.rsa by default. # secure.filePath= # Absolute path of your private key. whose name is key.pem by default. # privateKey.filePath= # Decrypt class name. Fill in this field only if you need a custom mechanism of decryption. # decrypt.className=
查看 secure-gen 帮助
secure-gen 为 Shell 可执行脚本,可以通过 RSA 算法加密敏感信息字段。运行导数工具时,会通过解析 {ob-loader-dumper}/conf/decrypt.properties 文件,安全地获取敏感信息。
secure-gen 在 {ob-loader-dumper}/tools/ 目录下,可执行 ./secure-gen -h 或直接输入 ./secure-gen 查看使用帮助。
$ ./secure-gen -h
Usage: ./secure-gen [-n <file>][-i][-h]
Description:
-n: Specify a to-be-encrypted file of sensitive contents in plain-text, use -i to check out the format.
-i: Input sensitive contents in interactive mode.
-h: Display this message.
高级用法:自定义加解密机制
如果未安装 openssl,可以通过此方法自定义加密和解密。
创建明文文件加密。
待加密的文件格式需符合 Property File Format 规范。具体请参考 Oracle 文件格式。
使用 Java 编写一个解密类的文件。类的定义如下:
必须定义无参构造函数。
拥有非静态方法:
public String decrypt(String encryptRaw)。形参encryptRaw为加密后的文本,返回值为解密后的文本。
将解密类打包成 JAR 包并放置在
{ob-loader-dumper}/lib/路径下。在
{ob-loader-dumper}/conf/decrypt.properties配置相应的内容。
操作示例
新建一个 Maven 项目并编写一个 CustomDecryptor 类,使用 Base64 算法进行编解码。
说明
在生产环境中,用户可以根据需求使用合适的加解密算法。
创建明文加密文件,通过 Base64 进行编码。
# 创建明文文件 $ vi password.txt # 输入以下内容并保存退出 oceanbase.jdbc.password=****** oceanbase.jdbc.sys.password=****** # 将编码后的文本保存至 custom.key 文件, 即加密文件。 $ echo $(base64 password.txt) > /user/loaddump/custom.key新建一个 Java 项目。项目结构中,
CustomDecryptor.java是需要编写的自定义解密类。
编写
CustomDecryptor类。package com.example.decrypt; import java.nio.charset.StandardCharsets; import sun.misc.BASE64Decoder; public class CustomDecryptor { public CustomDecryptor() {} /** * This method takes an encrypted string, decrypt it, and return it as a plain string. */ public String decrypt(String encryptedRaw) throws Exception { BASE64Decoder decoder = new BASE64Decoder(); return new String(decoder.decodeBuffer(encryptedRaw), StandardCharsets.UTF_8); } }将
CustomDecryptor类打包成 JAR 并放置在{ob-loader-dumper}/lib/路径下,完成设置解密器。mvn package && mv target/example-1.0-SNAPSHOT.jar path/to/ob-loader-dumper/lib/在
{ob-loader-dumper}/conf/decrypt.properties中填写相应的内容。# Absolute path of your secure file, whose name is secure.rsa by default. secure.filePath=~/tmp/custom.key # Absolute path of your private key. whose name is key.pem by default. # privateKey.filePath= # Decrypt class name. Fill in this field only if you need a custom mechanism of decryption. decrypt.className=com.example.decrypt.CustomDecryptor说明
使用自定义 SDK 加密和解密时,可以不填写
privateKey.filePath的参数值。安全地运行导数工具。
./obdumper -hxx.x.x.x -P2883 -t example -D example --csv --all说明
运行导数工具时,无需显式声明
-p/--password和--sys-password选项。
通过 SSL 协议连接数据库
导数工具 V4.3.1 及之后版本,支持通过 SSL 协议连接数据库。下文为您介绍通过 SSL 协议连接数据库的两种方案。
方案一:通过配置 SSL 相关参数来启用 SSL 连接
在 session.config.json 文件中配置 SSL 相关参数。session.config.json 文件的详情请参见 连接配置。
"useSSL": true,
"disableSslHostnameVerification": true,
"trustStore": "http://xxx.xxx.xxx.xxx:39411/rpcssl/truststore.jks",
"trustStorePassword": "123xxxx",
"//keyStore": "xxxxx",
"//keyStorePassword": ""
请根据实际情况配置 trustStore 和 trustStorePassword。
trustStore可以是 HTTP 指定的路径,也可以是本地路径。例如,"trustStore": "/home/admin/downloads/truststore.jks"。trustStorePassword配置的是明文密码,请注意此处并非数据库密码。
方案二:使用 secure-gen 加密
您也可以使用 secure-gen 加密方案连接数据库,以提升安全性,减少安全风险。示例如下:
安装 OpenSSL 并配置环境变量。
在
{ob-loader-dumper}/tools/目录下执行以下命令。./secure-gen -i在交互窗口中输入相关的密码参数,完成后请输入
:wq保存并退出。# Input the sensitive fields below in plain-text respectively. # Note ob-loader-dumper will parse from cli args first, and override any field in this file if there is a conflict. # # This password used for creating JDBC Connection. oceanbase.jdbc.password=******* # This password used for creating JDBC Connection of sys tenant. oceanbase.jdbc.sys.password=****** # Trust store password for creating JDBC Connection with useSSL=true. oceanbase.jdbc.trustStorePassword=****** # Key store password for creating JDBC Connection with useSSL=true (×509). # oceanbase.jdbc.keyStorePassword= # AccessKey for cloud storages like OSS, S3. # cloud.storage.access. key= # SecretKey for cloud storages like默认会使用 OpenSSL 在本地生成加密文件和秘钥,然后将加密文件(secure.rsa)和秘钥(key.pem)添加到
conf/security.properties。您也可以将加密文件和秘钥分别放在不同的 HTTP 服务器上,程序启动时自动加载加密文件和秘钥并解密信息。