数据安全
更新时间:2020-01-17
概述
数据交换和数据联合查询是大数据分析中比较常见的使用场景,跨产品、跨部门、跨公司的数据联合查询可以弥补彼此数据使用的缺少。但是联合查询也引来一个很关键的问题:数据安全问题。以往的数据安全是通过账号控制(包括权限账号和权限授权等),但这都存在安全泄露的风险,且权限一旦授予后,用户就可以直接获得明文数据,能够对数据做任意拷贝。
数据安全为用户提供了更可靠的数据环境,当用户查询的表或者数据是安全数据时,用户将只能通过Pingo的SQL查询少量数据或写出到其他路径,输出格式必须是安全数据格式。
基础概念
- 安全的数据模式
安全的数据模式分为两类,一类是数据通道安全,即用户对数据存储路径无权限,只能读取数据表;一类是安全数据格式,用户可访问并随意迁移数据,但数据本身是加密的,只能读取数据表。 - 安全表
对于数据通道安全(用户无法通过location的方式直接读数据)的表,通过在table的properties内定义securityTable=true即可完成安全表的配置。安全表支持所有已有文件格式,只需要在表的properties内增加配置即可生效。 - 安全数据格式
SecurityParquetFileFormat,基于最新parquet打造,通过白盒加密技术加密数据。用户在创建表时,必须使用create table using securityParquet的语法来创建。安全数据格式允许用户通过写表方式写出,也可以自由移动文件,在新的位置创建表读取,但要想看到内容,只能通过select查询少量内容。 - 明文条数限制
安全数据默认允许用户查询所有明文数据,因此需要数据产出方在table的properties中添加maxResult来指定数据需求方通过select查询获得的最大明文条数。而且,明文条数限制是自动继承的,无论用户如何输出、拷贝、倒库,都会自动继承,保证安全可靠。
使用说明
使用场景
存在数据联合查询需求,且对数据安全有较高需求的大数据分析场景
使用流程
- 数据提供方将数据上传到BOS;
- 数据提供方创建安全表(非加密数据)或SecurityParquet表(加密数据),并授权给数据使用方读权限;
- 数据使用方在查询数据时,只要数据存在于安全表或为安全数据格式,就处于安全数据模式,只能通过Pingo的SQL模式查询数据,目前支持的SQL前端只有批量作业的SQL模式,其他方式访问安全数据都会抛异常。
- 数据提供方可以直接通过select查询明文数据(条数由产出方在表中指定)或写出到自定义的SecurityParquet表。
使用样例
安全表
- 创建安全表
create table table_security(name string) tblproperties(securityTable=true,maxResult=10);
- 写入安全表
insert into table_security values("test0"),("test1"),("test2"),("test3"),("test4"),("test5"),("test6"),("test7"),("test8"),("test9"),("test10"),("test11"),("test12"),("test13"),("test14"),("test15"),("test16"),("test17"),("test18"),("test19"),("test20");
- 查询安全表
select * from table_security;
安全数据格式
- 创建安全数据格式表
create table parquet_table_security(name string, age int)
using securityParquet
partitioned by (event_day)
tblproperties(maxResult=1000)
options(
path="/tmp/parquet_table_security");
- 写入安全数据格式表
insert into parquet_table_security values("test", 1, "20190603"),("test", 2, "20190605"),("test", 3, "20190605"),("test", 4, "20190605"),("test", 5, "20190605"),("test", 6, "20190605"),("test", 7, "20190605"),("test", 8, "20190605"),("test", 9, "20190605"),("test", 10, "20190605"),("test", 11, "20190605"),("test", 12, "20190605"),("test", 13, "20190605"),("test", 14, "20190605"),("test", 15, "20190605"),("test", 16, "20190605"),("test", 17, "20190605"),("test", 18, "20190605"),("test", 19, "20190605"),("test", 20, "20190605");
- 查询安全数据格式表
select * from parquet_table_security where event_day="20190605";
用户操作审计
- 用户可以对Pingo4中的system.auditor.{tablename}等5张表的用户操作审计数据进行查询计算,审计数据表每小时整点进行更新。
- 审计日志数据表共5张,分别为pingo_session_info、pingo_job_info、pingo_session_state、pingo_query_info、pingo_query_state。其中审计表pingo_query_info为常用数据表,可满足大部分需求。
常用审计查询demo
- 统计某人总共查询数量
select count(*) from system.auditor.pingo_session_info where user = "zhangsan";
- 统计每个用户查询创建session数量
select user,count(*) from system.auditor.pingo_session_info group by user;
- 统计每日查询总数
select count(*) from system.auditor.pingo_query_info where starttime>'2019-12-22 00:00:00' and starttime < '2019-12-23 00:00:00';
- 统计某个sessionid对应的查询语句
select cast(unbase64(queryCode) as string) from system.auditor.pingo_query_info where sessiontype='interactive' and sessionid = 458770;
注意事项
- 只要同一个Job的查询中存在安全数据,就会进行安全模式检查,此时只能用Pingo的SQL(目前可提供的是批量计算Spark组件的SQL模式)来查询数据;
- 如果一个Job位于安全模式,是无法使用UDF的,且无法使用远程调试;
- 安全数据格式明文查询条数限制是自动继承的,如果数据源本身是安全加密数据,则能查看的明文数据量取table定义的maxResult和数据本身记录的maxResult的最小值;