agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Fix RLS checks for FOR PORTION OF leftover rows
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix RLS checks for FOR PORTION OF leftover rows
@ 2026-07-20 06:50 Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2026-07-20 06:50 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix RLS checks for FOR PORTION OF leftover rows

UPDATE/DELETE FOR PORTION OF may insert leftover rows to preserve the
parts of the old row that are outside the target range.  Those inserts
go through ExecInsert(), which checks RLS policies using
WCO_RLS_INSERT_CHECK.

However, the rewriter only added RLS WITH CHECK options for the
original statement command.  For UPDATE, that meant only
WCO_RLS_UPDATE_CHECK options were available, so ExecInsert() skipped
them.  For DELETE, no RLS WITH CHECK options were added at all.  As a
result, leftover rows could be inserted even when they violated INSERT
RLS policies.

Fix this by adding INSERT RLS WITH CHECK options for UPDATE/DELETE FOR
PORTION OF target relations.  Also add regression coverage for both
UPDATE and DELETE, including cases where allowed leftovers still
succeed and disallowed leftovers are rejected.

Author: Chao Li <lic@highgo.com>
Co-authored-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/6C34A987-AC50-4477-BD71-2D4AFEE1A589%40gmail.com
Discussion: https://www.postgresql.org/message-id/flat/CAJTYsWWdeBkoH5g8D-k9LDw9ciqsMxb21EJSiFXAzP4J%3DXyxOQ%40m...

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/20fe90bbb93df755e00dc88ace5988fda0b1d7d3

Modified Files
--------------
doc/src/sgml/ref/create_policy.sgml          | 32 ++++++++++++
doc/src/sgml/ref/delete.sgml                 |  3 +-
doc/src/sgml/ref/update.sgml                 |  3 +-
src/backend/rewrite/rowsecurity.c            | 25 ++++++++++
src/test/regress/expected/for_portion_of.out | 75 ++++++++++++++++++++++++++++
src/test/regress/expected/rowsecurity.out    | 39 ++++++++++++++-
src/test/regress/sql/for_portion_of.sql      | 58 +++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql         | 33 +++++++++++-
8 files changed, 264 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix RLS checks for FOR PORTION OF leftover rows
@ 2026-07-20 06:50 Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2026-07-20 06:50 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix RLS checks for FOR PORTION OF leftover rows

UPDATE/DELETE FOR PORTION OF may insert leftover rows to preserve the
parts of the old row that are outside the target range.  Those inserts
go through ExecInsert(), which checks RLS policies using
WCO_RLS_INSERT_CHECK.

However, the rewriter only added RLS WITH CHECK options for the
original statement command.  For UPDATE, that meant only
WCO_RLS_UPDATE_CHECK options were available, so ExecInsert() skipped
them.  For DELETE, no RLS WITH CHECK options were added at all.  As a
result, leftover rows could be inserted even when they violated INSERT
RLS policies.

Fix this by adding INSERT RLS WITH CHECK options for UPDATE/DELETE FOR
PORTION OF target relations.  Also add regression coverage for both
UPDATE and DELETE, including cases where allowed leftovers still
succeed and disallowed leftovers are rejected.

Author: Chao Li <lic@highgo.com>
Co-authored-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Paul A Jungwirth <pj@illuminatedcomputing.com>
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/6C34A987-AC50-4477-BD71-2D4AFEE1A589%40gmail.com
Discussion: https://www.postgresql.org/message-id/flat/CAJTYsWWdeBkoH5g8D-k9LDw9ciqsMxb21EJSiFXAzP4J%3DXyxOQ%40m...

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c58c83ce50cf65ee45bd60910f710a2bd251cc36

Modified Files
--------------
doc/src/sgml/ref/create_policy.sgml          | 32 ++++++++++++
doc/src/sgml/ref/delete.sgml                 |  3 +-
doc/src/sgml/ref/update.sgml                 |  3 +-
src/backend/rewrite/rowsecurity.c            | 25 ++++++++++
src/test/regress/expected/for_portion_of.out | 75 ++++++++++++++++++++++++++++
src/test/regress/expected/rowsecurity.out    | 39 ++++++++++++++-
src/test/regress/sql/for_portion_of.sql      | 58 +++++++++++++++++++++
src/test/regress/sql/rowsecurity.sql         | 33 +++++++++++-
8 files changed, 264 insertions(+), 4 deletions(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-07-20 06:50 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-20 06:50 pgsql: Fix RLS checks for FOR PORTION OF leftover rows Peter Eisentraut <peter@eisentraut.org>
2026-07-20 06:50 pgsql: Fix RLS checks for FOR PORTION OF leftover rows Peter Eisentraut <peter@eisentraut.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox