pgsql: Include policies based on ACLs needed - Mailing list pgsql-committers

From Stephen Frost
Subject pgsql: Include policies based on ACLs needed
Date
Msg-id E1ZhFjX-00082G-1n@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Include policies based on ACLs needed

When considering which policies should be included, rather than look at
individual bits of the query (eg: if a RETURNING clause exists, or if a
WHERE clause exists which is referencing the table, or if it's a
FOR SHARE/UPDATE query), consider any case where we've determined
the user needs SELECT rights on the relation while doing an UPDATE or
DELETE to be a case where we apply SELECT policies, and any case where
we've deteremind that the user needs UPDATE rights on the relation while
doing a SELECT to be a case where we apply UPDATE policies.

This simplifies the logic and addresses concerns that a user could use
UPDATE or DELETE with a WHERE clauses to determine if rows exist, or
they could use SELECT .. FOR UPDATE to lock rows which they are not
actually allowed to modify through UPDATE policies.

Use list_append_unique() to avoid adding the same quals multiple times,
as, on balance, the cost of checking when adding the quals will almost
always be cheaper than keeping them and doing busywork for each tuple
during execution.

Back-patch to 9.5 where RLS was added.

Branch
------
REL9_5_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/75096c458aa8e27160112cc20a18fec3a111e4b0

Modified Files
--------------
src/backend/rewrite/rowsecurity.c         |  108 ++++++++++++++++++++---------
src/test/regress/expected/rowsecurity.out |   60 ++++++++--------
2 files changed, 101 insertions(+), 67 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Small improvements in comments in async.c.
Next
From: Stephen Frost
Date:
Subject: pgsql: Include policies based on ACLs needed