VastbaseG100

基于openGauss内核开发的企业级关系型数据库。

Menu

透明数据加密功能

功能描述

Vastbase支持透明数据加密功能,用于为了防止数据文件被窃取后泄露用户数据。数据将在写入磁盘时被自动加密,从磁盘中读取时被自动解密,整个过程对用户以及上层应用是透明的。

透明数据加密,即TDE(Transeparent Data Encryption),是一种数据库加密技术,设计用于在存储层对数据库中的数据进行透明的数据加密。它提供了保护敏感数据的安全性和机密性,同时对应用程序保持透明,无需更改代码和查询。

  • 单机模式下,Vastbase支持对数据使用KMS加密(包括三未信安、江南天安、光电安辰、格尔算法)和软件加密。

  • 高可用流复制的架构下,主库和备库均支持对数据使用江南天安加密算法加密。在开启TDE的高可用架构中,备库在数据页置换时进行数据加密,在数据页加载时进行数据解密。

注意事项

  • 由于数据读写时需要进行额外的加解密操作,故会对数据库性能造成一定影响。加密表的查询性能比不加密时会有劣化,在对性能有较高要求的情况下需要谨慎开启加密功能。

  • 不支持列存表、物化视图、Ustore存储引擎、索引、Sequence、XLOG日志、MOT内存表、系统表的加密。

  • 若在创建表时未开启TDE功能,则后续无法再切换成加密表。

  • 只有在开启表加密功能时才支持数据密钥轮转。

  • 仅Vastbase G100 V2.2 Build 10(Patch No.12)及以后补丁版本支持此功能。

操作步骤

前置条件

用户已配置好适配江南天安加密机的集群环境,可参见KMS加密的示例

步骤1 在开启TDE透明数据加密功能开关。

vi $PGDATA/postgresql.conf
enable_tde=on

步骤2创建开启TDE功能的表,更多可参见CREATE TABLE

  • 若在创建表时未开启TDE功能,则后续无法再切换成加密表。

  • 当未指定密钥索引dek_info时,dek_info为加密卡内部生成数据。

CREATE TABLE table_name(col_name type) WITH (enable_tde=on,dek_info=1);

步骤3 数据库的数据均进行存储加密,但不影响用户在应用层的正常查询。

示例

如下示例以主备架构为例,即使用江南天安算法,实现主备架构的透明数据存储加密。单机模式的数据存储加密可参考KMS加密的示例4

前提条件

1、已配置好加密机的集群环境。

2、主库开启TDE透明数据加密功能开关。

vi $PGDATA/postgresql.conf
enable_tde=on

示例1 表级存储加密。

1、在主库创建测试表并插入数据,并确保数据已持久化。

当未指定密钥索引dek_info时,dek_info为江南天安加密卡内部生成数据。

create table test(id int unique,name text default 'testkoalkms',c3 text not null) with (enable_tde=on,dek_info=1);
create table test1(id int unique,name text default 'testkoalkms',c3 text not null);
insert into test values(1,'asdfghjkl','a'),(2,null,'b'),(null,'','c');
insert into test1 values(1,'qazwsxedc','a');
checkpoint;

2、查询主库数据文件中是否包含明文信息。若返回结果为空,则表示存储数据已被加密。且正确结果应为空。

cd $PGDATA/base
grep -iR 'asdfghjkl'

3、在主库对加密表进行DML操作,确保数据已持久化。

delete from test where id=2;
update test set name='qazwsxedc' where id=1;
select * from test;
--insert 触发约束
insert into test values(1);
insert into test(id,c3) values(4,'d');
select * from test order by id;
--upsert
insert into test values(4,'zxcvbnm','e') on duplicate key update name='qwerty123';
--merge into
merge into test p using test1 np on(p.id=np.id)
when matched then update set p.name='qwerty1234' when not matched then insert values(np.id,to_char('azsxdcfvgb'),'aaa');
select * from test order by id;
select * from test1;
checkpoint;

返回结果为如下:

DELETE 1

UPDATE 1

 id |   name    | c3
----+-----------+----
    |           | c
  1 | qazwsxedc | a
(2 rows)

--触发约束则出现如下报错
ERROR:  null value in column "c3" violates not-null constraint
DETAIL:  Failing row contains (1, testkoalkms, null).

INSERT 0 1

 id |    name     | c3
----+-------------+----
  1 | qazwsxedc   | a
  4 | testkoalkms | d
    |             | c
(3 rows)

INSERT 0 1

MERGE 1

 id |    name    | c3
----+------------+----
  1 | qwerty1234 | a
  4 | qwerty123  | d
    |            | c
(3 rows)

 id |   name    | c3
----+-----------+----
  1 | qazwsxedc | a
(1 row)

CHECKPOINT

4、查询备库数据文件中是否包含明文信息。若返回结果为空,则表示存储数据已被加密。且正确结果应为空。

cd $PGDATA/base
grep -iR 'qwerty123'

5、在备库查看表数据。

select * from test order by id;

返回结果为如下:

 id |    name    | c3
----+------------+----
  1 | qwerty1234 | a
  4 | qwerty123  | d
    |            | c
(3 rows)

相关链接

安全配置CREATE TABLEKMS加密