创建列访问策略
CREATE ACCESS POLICY 可以在各个表列上创建访问策略,每列一个策略。每个列访问策略都允许您为不同的用户和角色指定对该列数据的不同访问级别。列访问表达式还可以指定如何为用户和角色呈现列数据。
以下示例在 client_dimension
表中的 customer_address
列上创建访问策略。此访问策略为具有 administrator
角色的非超级用户提供对该列中所有数据的完全访问权限,但会屏蔽所有其他用户的客户地址数据:
=> CREATE ACCESS POLICY ON public.customer_dimension FOR COLUMN customer_address
-> CASE
-> WHEN ENABLED_ROLE('administrator') THEN customer_address
-> ELSE '**************'
-> END ENABLE;
CREATE ACCESS POLICY
Vertica 使用此策略来确定它授予用户 MaxineT 和 MikeL 的访问权限,对于这两个用户分别分配了 employee
和 administrator
角色。当这些用户查询 customer_dimension
表时,Vertica 会应用列访问策略表达式,如下所示:
=> \c - MaxineT;
You are now connected as user "MaxineT".
=> SET ROLE employee;
SET
=> SELECT customer_type, customer_name, customer_gender, customer_address, customer_city FROM customer_dimension;
customer_type | customer_name | customer_gender | customer_address | customer_city
---------------+-------------------------+-----------------+------------------+------------------
Individual | Craig S. Robinson | Male | ************** | Fayetteville
Individual | Mark M. Kramer | Male | ************** | Joliet
Individual | Barbara S. Farmer | Female | ************** | Alexandria
Individual | Julie S. McNulty | Female | ************** | Grand Prairie
...
=> \c - MikeL
You are now connected as user "MikeL".
=> SET ROLE administrator;
SET
=> SELECT customer_type, customer_name, customer_gender, customer_address, customer_city FROM customer_dimension;
customer_type | customer_name | customer_gender | customer_address | customer_city
---------------+-------------------------+-----------------+------------------+------------------
Individual | Craig S. Robinson | Male | 138 Alden Ave | Fayetteville
Individual | Mark M. Kramer | Male | 311 Green St | Joliet
Individual | Barbara S. Farmer | Female | 256 Cherry St | Alexandria
Individual | Julie S. McNulty | Female | 459 Essex St | Grand Prairie
...
限制
访问策略具有以下限制:
-
一列只能有一个访问策略。
-
不能为除原生数组以外的复杂类型列设置列访问策略。
-
不能为 Flex 表中的实体化列设置列访问策略。可以为
__raw__
列设置访问策略,但此举将限制对整个表的访问。 -
行访问策略对临时表和具有聚合投影的表无效。
-
访问策略表达式不能包含:
-
子查询
-
聚合函数
-
分析函数
-
用户定义的转换函数 (UDTF)
-
-
如果查询优化器无法使用计算值替换仅涉及常量的确定性表达式,则会阻止所有 DML 操作,例如 INSERT。