From: Charles Clavadetscher (SwissPUG) <clavadetscher@swisspug.org>
To: Carl Sverre <sverre.carl@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Postgres trigger side-effect is occurring out of order with row-level security select policy
Date: Mon, 01 Oct 2018 05:53:58 +0200
Message-ID: <92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com> (raw)
In-Reply-To: <a78c224d-cc9c-4904-bdb0-c05f7c702eda@getmailbird.com>
References: <CADUo9RHPvJhKXs33t-39KqZ831JhQs=P_Ckoeg7C5OHvNLP0TQ@mail.gmail.com>
<7e9e8e8b-c368-8007-4a1d-b67308d26dd6@aklaver.com>
<1155c242-cac9-4bac-b73e-6f55a2327c27@getmailbird.com>
<CADUo9REJUb5OT_169ZG=k=_f14X=J+ON8Vb31FSaA+JGqGnWiw@mail.gmail.com>
<26b52a79-cef2-903c-3696-fc3b6d6cbcb4@aklaver.com>
<af2735ba-656d-44bf-904f-95bccdf9f418@getmailbird.com>
<CADUo9RG=hHSigumPOv8jVHDjBL2jg=Z_suSKcpAePYSEL+S23A@mail.gmail.com>
<a78c224d-cc9c-4904-bdb0-c05f7c702eda@getmailbird.com>
An addition
On 01.10.2018 05:18:15, Charles Clavadetscher (SwissPUG) <clavadetscher@swisspug.org> wrote:
Hello
On 01.10.2018 05:00:02, Carl Sverre <sverre.carl@gmail.com> wrote:
Thank you for the detailed report Charles. I think you may be missing the “returning id” clause in the insert. Can you verify it works when you use “returning id”? Thanks!
[Charles] : You are right:
testuser@charles.localhost=> INSERT INTO a VALUES ('fails2') RETURNING id;
NOTICE: inside trigger handler
ERROR: new 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] : In 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 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: clavadetscher@swisspug.org, sverre.carl@gmail.com, adrian.klaver@aklaver.com
Subject: Re: Postgres trigger side-effect is occurring out of order with row-level security select policy
In-Reply-To: <92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com>
References: <CADUo9RHPvJhKXs33t-39KqZ831JhQs=P_Ckoeg7C5OHvNLP0TQ@mail.gmail.com> <7e9e8e8b-c368-8007-4a1d-b67308d26dd6@aklaver.com> <1155c242-cac9-4bac-b73e-6f55a2327c27@getmailbird.com> <CADUo9REJUb5OT_169ZG=k=_f14X=J+ON8Vb31FSaA+JGqGnWiw@mail.gmail.com> <26b52a79-cef2-903c-3696-fc3b6d6cbcb4@aklaver.com> <af2735ba-656d-44bf-904f-95bccdf9f418@getmailbird.com> <CADUo9RG=hHSigumPOv8jVHDjBL2jg=Z_suSKcpAePYSEL+S23A@mail.gmail.com> <a78c224d-cc9c-4904-bdb0-c05f7c702eda@getmailbird.com> <92b59fb7-98a1-4937-bafa-4eb812bb2b02@getmailbird.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox