首批通过分布式安全可靠测评,为关键业务系统打造
OBServer 传输加密
更新时间:2026-06-09 16:38:12
可以通过以下方法设置 OBServer 的传输加密。
创建 CA 证书
请登录可以执行 OpenSSL 命令的 OBServer 服务器或者客户端机器,进行以下操作。
创建目录存放证书文件。
说明
证书文件的 Common Name( CN ) 不能相同。
$ mkdir ~/tls $ chmod 700 ~/tls $ cd ~/tls创建 RSA 私钥。
$ openssl genrsa 2048 > cakey.pem Generating RSA private key, 2048 bit long modulus ....................................................................+++ ..............+++ e is 65537 (0x10001)生成 CA 证书。
$ openssl req -new -x509 -nodes -days 3600 -key cakey.pem -out ca.pem You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:ZJ Locality Name (eg, city) [Default City]:HZ Organization Name (eg, company) [Default Company Ltd]:OceanBase Organizational Unit Name (eg, section) []:PD Common Name (eg, your name or your server's hostname) []:ob Email Address []:
生成服务器证书
请登录可以执行 OpenSSL 命令的 OBServer 服务器端机器,进行以下操作。
生成服务器私钥。
$ openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem Generating a 2048 bit RSA private key ............................+++ ................................+++ writing new private key to 'server-key.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:ZJ Locality Name (eg, city) [Default City]:HZ Organization Name (eg, company) [Default Company Ltd]:OceanBase Organizational Unit Name (eg, section) []:PD Common Name (eg, your name or your server's hostname) []:observer Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:************ An optional company name []:生成服务器证书。
openssl x509 -req -in server-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out server-cert.pem
生成客户端证书
请登录可以执行 OpenSSL 命令的客户端机器,进行以下操作。
生成客户端私钥。
$ openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem -out client-req.pem Generating a 2048 bit RSA private key ........................................+++ ...........................................+++ writing new private key to 'client-key.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:ZJ Locality Name (eg, city) [Default City]:HZ Organization Name (eg, company) [Default Company Ltd]:OceanBase Organizational Unit Name (eg, section) []:PD Common Name (eg, your name or your server's hostname) []:obclient Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:************ An optional company name []:生成客户端证书。
$ openssl x509 -req -in client-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out client-cert.pem Signature ok subject=/C=CN/ST=ZJ/L=HZ/O=OceanBase/OU=PD/CN=obclient Getting CA Private Key
验证证书文件
请登录可以执行 OpenSSL 命令的 OBServer 服务器或者客户端机器,进行以下操作。
$ openssl verify -CAfile ca.pem server-cert.pem client-cert.pem
server-cert.pem: OK
client-cert.pem: OK
在服务端开启 SSL
请登录可以执行 OpenSSL 命令的 OBServer 服务器或者客户端机器,进行以下操作。
在服务端的 OceanBase 数据库的安装目录下创建子目录
wallet/,默认在/home/admin/oceanbase/wallet/。$ mkdir /home/admin/oceanbase/wallet/复制服务端相关的 3 个文件
ca.pem、server-key.pem和server-cert.pem至 安装目录wallet/下。$ cp ca.pem server-key.pem server-cert.pem /home/admin/oceanbase/wallet/ $ chmod 700 /home/admin/oceanbase/wallet/*.pem $ ls -l /home/admin/oceanbase/wallet/ total 12 -rwx------ 1 admin admin 1269 Oct 27 20:05 ca.pem -rwx------ 1 admin admin 1151 Oct 27 20:05 server-cert.pem -rwx------ 1 admin admin 1675 Oct 27 20:05 server-key.pem
在客户端配置 SSL 相关参数
请登录系统租户进行以下操作。
设置 ssl_client_authentication 为 TRUE,即可开启 SSL/TLS 加密认证。
obclient> ALTER SYSTEM SET ssl_client_authentication=TRUE;
obclient> SHOW PARAMETERS LIKE 'ssl_client_authentication';
修改参数后,重启数据库。
创建使用 SSL 连接的数据库用户
请登录可以执行 OpenSSL 命令的 OBServer 服务器或者客户端机器,进行以下操作。
为了增加灵活性,OceanBase 数据库可以为每个数据库用户指定不同的 SSL 认证机制。具体操作如下:
SSL 单向认证。
服务器端需要 CA 证书,客户端无需提供 CA 证书。客户端单向校验服务器端证书的有效性。
示例如下:
obclient> CREATE USER **user1** IDENTIFIED BY ****** REQUIRE SSL;X509 双向认证。
服务器端和客户端都需要 CA 证书,服务器端和客户端双向校验证书的有效性。
示例如下:
obclient> CREATE USER **user2** IDENTIFIED BY ****** REQUIRE X509;特殊双向认证(可组合)
指定加密算法认证:基于 X509 双向认证,同时限定 SSL 加密算法。
指定发行方认证:基于 X509 双向认证,同时限定客户端 CA 证书发行方。
指定 SSL 主体认证:基于 X509 双向认证,同时限定客户端 CA 证书主体。
限定加密算法为 DHE-RSA-AES128-GCM-SHA256,并指定 SSL 主体。示例如下:
obclient> CREATE USER **user3** IDENTIFIED BY ****** REQUIRE CIPHER 'DHE-RSA-AES128-GCM-SHA256' SUBJECT '/C=CN/ST=ZJ/L=HZ/O=OceanBase/OU=PD/CN=obclient';
授予用户数据库访问权限
请登录可以执行 OpenSSL 命令的 OBServer 服务器或者客户端机器,进行以下操作。
授予用户访问权限并查看用户属性的具体操作如下:
授予用户访问权限。
obclient> GRANT all privileges on *.* to **user1**; obclient> GRANT all privileges on *.* to **user2**; obclient> GRANT all privileges on *.* to **user3**;验证用户属性。
MySQL 租户
obclient> SELECT user_name, ssl_type,ssl_cipher, x509_issuer, x509_subject, length(ssl_cipher), length(x509_issuer), length(x509_subject) FROM oceanbase.__all_user WHERE user_name LIKE 'SSLTEST%';Oracle 租户
obclient> SELECT user_name, ssl_type,ssl_cipher, x509_issuer, x509_subject, length(ssl_cipher), length(x509_issuer), length(x509_subject) FROM SYS.ALL_VIRTUAL_USER_AGENT WHERE user_name LIKE 'SSLTEST%';
客户端配置和连接
请登录可以执行 OpenSSL 命令的 OBServer 服务器或者客户端机器,进行以下操作。 复制生成的客户端证书(ca.pem、client-cert.pem和client-key.pem)至客户端可以访问的目录。具体操作如下:
X509 双向认证
$ obclient -h <observer-ip> -P2881 -u **user2**@mytenant -p****** --ssl-ca=/path/to/ca.pem --ssl-cert=/p ath/to/client-cert.pem --ssl-key=/path/to/client-key.pem使用加密算法为 DHE-RSA-AES128-GCM-SHA256
$ obclient -h <observer-ip> -P2881 -u **user3**@mytenant -p****** --ssl-ca=/path/to/ca.pem --ssl-cert=/pat h/to/client-cert.pem --ssl-key=/path/to/client-key.pem --ssl-cipher=DHE-RSA-AES128-GCM-SHA256
说明
使用
require ssl和require none创建的用户,无需指定证书。