×
技术社区 >  技术博客 >  OceanBase 全链路 SSL 加密访问配置指南

OceanBase 全链路 SSL 加密访问配置指南

一、功能介绍

SSL(Secure Socket Layer)是基于 TCP/IP 传输通信协议实现的安全协议,采用公开密钥技术,广泛支持各类网络,提供三种基础安全服务。

为全面提升数据安全,OceanBase 全数据链路(Observer、Obproxy、JDBC 驱动层)均已全面支持 SSL 加密访问。

二、相关参数

参数名称 默认值 描述
disableSslHostnameVerification false 使用 SSL 时,驱动会校验服务器证书中的主机名(备用名称/证书 CN),防范中间人攻击;该参数可关闭校验,需配合 trustServerCertificate=true 使用
useSSL false 强制启用 SSL 连接
trustStore null 信任库文件路径,等价于 Java 属性 javax.net.ssl.trustStore
trustStorePassword 信任库密码,等价于 Java 属性 javax.net.ssl.trustStorePassword

三、配置开启 SSL

使用 SSL 功能需完成全链路 SSL 开启 + 证书生成 两步核心操作。

(一)证书生成

1. CA 证书生成

  1. # 1. 生成 RSA 私钥
  2. openssl genrsa 2048 > cakey.pem
  3. # 2. 创建 CA 证书
  4. openssl req -new -x509 -nodes -days 3600 -key cakey.pem -out ca.pem

2. 服务端证书生成

  1. # 1. 生成私钥与证书请求文件
  2. openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem
  3. # 2. 写入 RSA
  4. openssl rsa -in server-key.pem -out server-key.pem
  5. # 3. CA 签名(必须填写 common name:observer)
  6. openssl x509 -req -in server-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out server-cert.pem

3. 客户端证书生成

  1. # 1. 生成私钥与证书请求文件
  2. openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem -out client-req.pem
  3. # 2. 写入 RSA
  4. openssl rsa -in client-key.pem -out client-key.pem
  5. # 3. CA 签名(必须填写 common name:obclient)
  6. openssl x509 -req -in client-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out client-cert.pem

4. Proxy 证书生成

  1. # 1. 生成私钥与证书请求文件
  2. openssl req -newkey rsa:2048 -days 3600 -nodes -keyout proxy-key.pem -out proxy-req.pem
  3. # 2. 写入 RSA
  4. openssl rsa -in proxy-key.pem -out proxy-key.pem
  5. # 3. CA 签名
  6. openssl x509 -req -in proxy-req.pem -days 3600 -CA ca.pem -CAkey cakey.pem -set_serial 01 -out proxy-cert.pem

(二)Observer 开启 SSL 并验证

1. Observer 配置

  1. # 1. 创建证书存放目录
  2. mkdir /home/admin/oceanbase/wallet
  3. # 2. 拷贝证书文件至目录
  4. cp ca.pem server-cert.pem server-key.pem /home/admin/oceanbase/wallet/
-- 3. 关闭 SSL(初始状态)
alter system set ssl_client_authentication=FALSE;

-- 4. 设置 kms_info 为 file
alter system set ssl_external_kms_info = '{"ssl_mode":"file"}';

-- 5. 开启客户端 SSL 认证
alter system set ssl_client_authentication=TRUE;

-- 6. 设置 SSL 白名单(允许 obclient、obproxy 连接)
alter system set ob_ssl_invited_common_names='obclient,obproxy' tenant=all;

2. 验证

  1. 使用 obclient 连接 Observer
  2. 执行 SQL 查看 SSL 连接:
select * from oceanbase.__all_virtual_processlist where ssl_cipher is not null;

(三)Obproxy 开启 SSL 并验证

1. Obproxy 配置

  1. # 1. 放置证书至 wallet 目录
  2. cp ca.pem proxy-cert.pem proxy-key.pem /home/xuping.lz/ob9.proxy0/wallet/
-- 2. 连接 Obproxy(使用 proxysys 账户)
mysql -h 192.168.0.XX -P 1XX3 -u root@proxysys -paaAA11__

-- 3. 配置证书路径
update proxyconfig.security_config set CONFIG_VAL= '{"sourceType" : "FILE", "CA" : "/home/xuping.lz/ob9.proxy0/wallet/ca.pem", "publicKey" : "/home/xuping.lz/ob9.proxy0/wallet/proxy-cert.pem", "privateKey" : "/home/xuping.lz/ob9.proxy0/wallet/proxy-key.pem"}' where APP_NAME = 'obprox ' and VERSION = '1';

-- 4. 开启客户端/服务端 SSL
alter proxyconfig set enable_client_ssl=true;
alter proxyconfig set enable_server_ssl=true;

2. 验证

-- 查看证书配置
select CONFIG_VAL from proxyconfig.security_config where APP_NAME = 'obproxy';

-- 查看 SSL 相关配置
show proxyconfig like '%ssl%';

(四)创建 SSL 专用用户

-- 创建必须使用 SSL 连接的用户
create user testssl identified by '123456' require ssl;

-- 授权
grant all on *.* to testssl@'%';

四、JDBC SSL 配置

(一)证书库转换

1. 导入服务器 CA 证书到信任库

  1. sudo /opt/taobao/java/jre/bin/keytool -import -alias mysqlServerCACert -file /home/xuping.lz/wallet/ca.pem -keystore test.jks
  2. # 输入密码:123456

2. 客户端证书捆绑为 PKCS12 文件

  1. openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem -out client.p12 -name clientalias -CAfile ca-cert.pem
  2. # 输入密码:123456

3. PKCS12 导入密钥库

  1. keytool -importkeystore -deststorepass 123456 -destkeystore test.jks -srckeystore client.p12 -srcstoretype PKCS12 -srcstorepass 123456 -alias clientalias

(二)JDBC 连接使用 SSL

1. HTTP 服务器远程加载 JKS 文件

  1. String url = "jdbc:oceanbase://192.168.0.XX:1xxx1/sys?user=testssl&password=123456&pool=false&useSSL=true&disableSslHostnameVerification=true&trustStore=http://100.81.152.xx:7xx7/wallet/truststore.jks&trustStorePassword=123456";

2. 本地使用 JKS 文件

  1. // 方式1:连接串配置
  2. String url = "jdbc:oceanbase://192.168.0.XX:1xxx1/sys?user=testssl&password=123456&pool=false&useSSL=true&disableSslHostnameVerification=true";
  3. // 方式2:系统属性配置
  4. System.setProperty("javax.net.ssl.trustStore", "/Users/lize/Downloads/test.jks");
  5. System.setProperty("javax.net.ssl.trustStorePassword", "123456");
  6. Class.forName("com.oceanbase.jdbc.Driver");
  7. Connection connection = DriverManager.getConnection(url);

总结

  1. 全链路 SSL 需先生成 CA、服务端、客户端、Proxy 四类证书,且证书签名时需严格指定对应 common name
  2. Observer 和 Obproxy 需分别配置证书路径并开启 SSL 开关,配置白名单限制连接来源;
  3. JDBC 需完成证书格式转换,支持远程 HTTP本地文件两种方式加载信任库,实现 SSL 加密连接。

精选推荐