KingbaseES的加密功能介绍
加密enc_show功能与数据脱敏anon功能是相冲突的,所以开启enc_show的时候,anon是不可用的
一、基础环境介绍
操作系统: CentOS Linux release 7.4.1708 (Core)
cpu架构: Architecture: x86_64
cpu型号名称: Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
数据库版本: 最新版本
二、加密前置条件
需要在kingbase.conf文件中加载sys_anon插件
shared_preload_libraries = '...,sys_anon'
注:需要重新启动数据库
三、测试加密
test=#
test=# \c - sso
用户 sso 的口令:
You are now connected to database "test" as userName "sso".
test=>
test=> select current_user;
current_user
--------------
sso
(1 行记录)
test=>
test=> alter system set anon.enable = on;
ALTER SYSTEM
test=>
test=> alter system set anon.anon_type = enc_show ;
ALTER SYSTEM
test=>
test=> alter system set anon.application_name = 'kingbase';
ALTER SYSTEM
test=>
test=> select sys_reload_conf();
sys_reload_conf
-----------------
t
(1 行记录)
test=>
test=>
test=> \dt
Did not find any relations.
test=>
test=>
test=> \c - system
You are now connected to database "test" as userName "system".
test=#
test=#
test=# select current_user;
current_user
------------------------------------
\x3a59bf9b601e361aaa186febeb687fd7
(1 行记录)
test=#
test=#
test=# create table t1 (a int);
CREATE TABLE
test=#
test=# \dt
关联列表
架构模式 | 名称 | 类型 | 拥有者
----------+------+--------+--------
public | t1 | 数据表 | system
(1 行记录)
test=#
test=# insert into t1 values (1);
INSERT 0 1
test=#
test=#
test=# select * from t1 ;
a
------------------------------------
\xe0c7d6a53f7614a3a0cf3e6dcfd2895a
(1 行记录)
test=#
test=#
test=# \c - sso
用户 sso 的口令:
You are now connected to database "test" as userName "sso".
test=>
test=> select anon.gen_enckey('123456');
gen_enckey
--------------------------
csAI2Ru4v8QUp07Lh1bfjw==
(1 行记录)
test=>
test=> alter system set anon.enc_key = 'csAI2Ru4v8QUp07Lh1bfjw==';
ALTER SYSTEM
test=>
test=>
test=> select sys_reload_conf();
sys_reload_conf
-----------------
t
(1 行记录)
test=>
test=>
四、客户端查看加密后的数据
如图所示
五、总结
1、KES数据库加密需要加载sys_anon插件,并重启数据库
2、设置加密需要使用sso用户打开加密开关