]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Ensure COPY TO on an RLS-enabled table copies no more than it should.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Mar 2023 18:52:28 +0000 (13:52 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 10 Mar 2023 18:52:28 +0000 (13:52 -0500)
commit59947bac7384ac56b5c95c69dee7655e2ed810df
treee8afc44257ec19f4b5c616faea4c207ad6dbae3c
parentaf397c6c27b70b422f81151452640ae8e1261e54
Ensure COPY TO on an RLS-enabled table copies no more than it should.

The COPY documentation is quite clear that "COPY relation TO" copies
rows from only the named table, not any inheritance children it may
have.  However, if you enabled row-level security on the table then
this stopped being true, because the code forgot to apply the ONLY
modifier in the "SELECT ... FROM relation" query that it constructs
in order to allow RLS predicates to be attached.  Fix that.

Report and patch by Antonin Houska (comment adjustments and test case
by me).  Back-patch to all supported branches.

Discussion: https://postgr.es/m/3472.1675251957@antos
src/backend/commands/copy.c
src/backend/commands/copyto.c
src/test/regress/expected/rowsecurity.out
src/test/regress/sql/rowsecurity.sql