Row level security does not work for table owner

2019-03-06 06:33发布

问题:

I have a table, customer on which I did the following:

ALTER TABLE customer FORCE ROW LEVEL SECURITY;
CREATE POLICY customer_rls ON  customer USING (false);

However, doing SELECT * FROM customer still returns all the rows.

The current role is myrole

\dg myrole
           List of roles
 Role name | Attributes | Member of
-----------+------------+-----------
 my_role   |            | {}

As you can see it's not a superuser and it RLS isn't disabled on it.

What am I doing wrong?

回答1:

You forgot to enable row level security for the table.

ALTER TABLE customer enable ROW LEVEL SECURITY;

force only makes sure that RLS is applied if enabled, it does not enable RLS on the table.

Online example: https://rextester.com/TCLZ82421