行级策略不适用于我的 table
Row level policy doesn't work on my table
我有一个 table,我正尝试对其应用策略,设置如下所示:
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
和 select 来自 mytable
的所有记录时:
set role anonymous;
select * from api.mytable;
我预计不会返回任何行,因为我在策略的 using
子句中的表达式是 null
,但我得到了所有内容。
我尝试了不同的 postgresql
版本(9.5、9.6、10.3),但它们都有相同的行为,我在这里做错了吗?
更新
RLS 不适用于这样的视图。您可以将 RLS 用于视图,但它是有限的。
你能做的是
alter view api.mytable owner to anonymous ;
我有一个 table,我正尝试对其应用策略,设置如下所示:
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
和 select 来自 mytable
的所有记录时:
set role anonymous;
select * from api.mytable;
我预计不会返回任何行,因为我在策略的 using
子句中的表达式是 null
,但我得到了所有内容。
我尝试了不同的 postgresql
版本(9.5、9.6、10.3),但它们都有相同的行为,我在这里做错了吗?
更新
RLS 不适用于这样的视图。您可以将 RLS 用于视图,但它是有限的。
你能做的是
alter view api.mytable owner to anonymous ;