Re: RLS makes COPY TO process child tables

From: Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Antonin Houska <ah(at)cybertec(dot)at>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: RLS makes COPY TO process child tables
Date: 2023-02-02 07:00:31
Message-ID: 20230202160031.defd38f35433c7677b48a8ec@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 01 Feb 2023 11:47:23 -0500
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp> writes:
> > Antonin Houska <ah(at)cybertec(dot)at> wrote:
> >> While working on [1] I noticed that if RLS gets enabled, the COPY TO command
> >> includes the contents of child table into the result, although the
> >> documentation says it should not:
>
> > I think this is a bug because the current behaviour is different from
> > the documentation.
>
> I agree, it shouldn't do that.
>
> > When RLS is enabled on a table in `COPY ... TO ...`, the query is converted
> > to `COPY (SELECT * FROM ...) TO ...` to allow the rewriter to add in RLS
> > clauses. This causes to dump the rows of child tables.
>
> Do we actually say that in so many words, either in the code or docs?
> If so, it ought to read `COPY (SELECT * FROM ONLY ...) TO ...`
> instead. (If we say that in the docs, then arguably the code *does*
> conform to the docs. But I don't see it in the COPY ref page at least.)

The documentation do not say that, but the current code actually do that.
Also, there is the following comment in BeginCopyTo().

* With row-level security and a user using "COPY relation TO", we
* have to convert the "COPY relation TO" to a query-based COPY (eg:
* "COPY (SELECT * FROM relation) TO"), to allow the rewriter to add
* in any RLS clauses.

Maybe, it is be better to change the description in the comment to
"COPY (SELECT * FROM ONLY relation) TO" when fixing the bug.

Regards,
Yugo Nagata

--
Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Antonin Houska 2023-02-02 07:01:54 Re: RLS makes COPY TO process child tables
Previous Message Tom Lane 2023-02-02 06:40:29 Re: run pgindent on a regular basis / scripted manner