sql - 行级策略不适用于我的表
问题描述
我有一个表,我正在尝试对其应用策略,设置如下所示:
create role anonymous nologin;
create schema api;
create schema private;
create table private.mytable(
id serial primary key,
description text default ''
);
create view api.mytable as select * from private.mytable;
insert into api.mytable (description) values ('row 1'), ('row 2');
grant usage on schema api to anonymous;
grant select on api.mytable to anonymous;
alter table private.mytable enable row level security;
create policy mytable_policy on private.mytable
for select
using (null);
当我将角色设置为anonymous
并从中选择所有记录时mytable
:
set role anonymous;
select * from api.mytable;
我预计不会返回任何行,因为我在using
策略中的子句中的表达式是,null
但我得到了一切。
我尝试了不同的postgresql
版本(9.5、9.6、10.3),但它们都有相同的行为,我在这里做错了吗?
解决方案
更新
https://stackoverflow.com/a/33863371/5315974
RLS 不适用于这样的视图。您可以将 RLS 用于视图,尽管它是有限的。
你能做的是
alter view api.mytable owner to anonymous ;
推荐阅读
- css - 如何动态生成 CSS 类和/或设置其属性
- python - 如何在 Numba Vectorize 签名中指定元组?
- java - 查找当前位置
- ruby-on-rails - nil:NilClass 的未定义方法“railties_load_path”
- vim - 将文本颜色设置为状态行中的字符串
- php - Get data on daily basis in laravel
- javascript - setInterval 函数中的计数器变量不起作用
- javascript - print local image to pdf using jsPDF
- php - Laravel 5.7. Route model binding validation
- groovy - 如何使用不同的键按值分组?