Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g6pK9-0000jG-8r for pgsql-general@arkaria.postgresql.org; Mon, 01 Oct 2018 03:56:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g6pK7-0004BJ-7J for pgsql-general@arkaria.postgresql.org; Mon, 01 Oct 2018 03:56:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g6pK6-0004BC-S8 for pgsql-general@lists.postgresql.org; Mon, 01 Oct 2018 03:56:43 +0000 Received: from aragorn.net-wizard.org ([138.201.127.29] helo=gandalf.net-wizard.org) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g6pJy-0008FB-1S for pgsql-general@lists.postgresql.org; Mon, 01 Oct 2018 03:56:40 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id 75DCB80229; Mon, 1 Oct 2018 05:56:31 +0200 (CEST) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v2oZQhBYSX65; Mon, 1 Oct 2018 05:56:24 +0200 (CEST) Received: from [82.130.89.233] (mtec-lee-dock-3-233.ethz.ch [82.130.89.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: clavadetscher@swisspug.org) by gandalf.net-wizard.org (Postfix) with ESMTPSA id 9C4E1801A4; Mon, 1 Oct 2018 05:56:18 +0200 (CEST) Content-Type: multipart/alternative; boundary="----=_NextPart_26900901.494501881394" MIME-Version: 1.0 Date: Mon, 01 Oct 2018 05:53:58 +0200 Message-ID: <92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com> Subject: Re: Postgres trigger side-effect is occurring out of order with row-level security select policy From: "Charles Clavadetscher (SwissPUG)" To: "Carl Sverre" Cc: "Adrian Klaver" , "" In-Reply-To: References: <7e9e8e8b-c368-8007-4a1d-b67308d26dd6@aklaver.com> <1155c242-cac9-4bac-b73e-6f55a2327c27@getmailbird.com> <26b52a79-cef2-903c-3696-fc3b6d6cbcb4@aklaver.com> User-Agent: Mailbird/2.5.14.0 X-Mailbird-ID: 92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_NextPart_26900901.494501881394 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable An addition On 01.10.2018 05:18:15, Charles Clavadetscher (SwissPUG) wrote: Hello On 01.10.2018 05:00:02, Carl Sverre wrote: Thank you for the detailed report Charles. I think you may be missing the = =E2=80=9Creturning id=E2=80=9D clause in the insert. Can you verify it work= s when you use =E2=80=9Creturning id=E2=80=9D? Thanks! [Charles] :=C2=A0You are right: testuser@charles.localhost=3D> INSERT INTO a VALUES ('fails2') RETURNING id; NOTICE: =C2=A0inside trigger handler ERROR: =C2=A0new row violates row-level security policy for table "a" This implies that the returning_id is evaluated before the trigger executes= , i.e. Adrian's assumption is probably correct. Regards Charles [Charles] :=C2=A0In the RLS documentation (https://www.postgresql.org/docs/= current/static/ddl-rowsecurity.html): "To specify which rows are visible or modifiable according to a policy, an = expression is required that returns a Boolean result. This expression will = be evaluated for each row prior to any conditions or functions coming from = the user's query." I assume that the returning clause is essentially a condition or function f= rom the user query or it is implemented as such. Therefore the policy is ap= plied prior to it. The most knowlegdable person on this list on the RLS topic is Stephen Frost= . He may shed light on the matter. Regards Charles ------=_NextPart_26900901.494501881394 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
=0A =0A = =0A = =0A =0A = =0A An addition<= br>


On 01.10.2018= 05:18:15, Charles Clavadetscher (SwissPUG) <clavadetscher@swisspug.org&= gt; wrote:

=0A = =0A =0A = =0A =0A = =0A = Hello


On 0= 1.10.2018 05:00:02, Carl Sverre <sverre.carl@gmail.com> wrote:

Tha= nk you for the detailed report Charles. I think you may be missing the =E2= =80=9Creturning id=E2=80=9D clause in the insert. Can you verify it works w= hen you use =E2=80=9Creturning id=E2=80=9D? Thanks!
= = [Charles] : You are right:

tes= tuser@charles.localhost=3D> INSERT INTO a VALUES ('fails2') RETURNING id= ;
NOTICE:  inside trig= ger handler
ERRO= R:  new row violates row-level security policy for table "a"

This implies that the returning_id i= s evaluated before the trigger executes, i.e. Adrian's assumption is probab= ly correct.

=
Regards<= /div>
Charles
[Charles] : In the= RLS documentation (https://www.postgresql.org/docs/current/static/d= dl-rowsecurity.html):

"To specify which rows are v= isible or modifiable according to a=0Apolicy, an expression is required tha= t returns a Boolean result.=0AThis expression will be evaluated for each ro= w prior to any=0Aconditions or functions coming from the user's query."

I assume that the returning clause is essentially a condit= ion or function from the user query or it is implemented as such. Therefore= the policy is applied prior to it.
The most knowlegdable = person on this list on the RLS topic is Stephen Frost. He may shed light on= the matter.

Regards
Charles

=
=0A =0A =
------=_NextPart_26900901.494501881394--