public inbox for [email protected]  
help / color / mirror / Atom feed
From: Mark Phillips <[email protected]>
To: [email protected]
Cc: David G. Johnston <[email protected]>
Subject: Re: Row level security policy
Date: Wed, 13 Nov 2024 21:05:34 -0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <CAKFQuwbJC2iLVj0-RCGhZ+DWPf3e8_n3krBpY6K5EuUyNghcsw@mail.gmail.com>
	<[email protected]>

Well, things did not work as I expected, which means there is more for me to learn. I am new to RLS usage. I want to implement this in a proper manner, so is the behavior described below correct? Are there other aspects of this I need to study?

Thanks, in advance. Advice and links to articles are greatly appreciated.

 - Mark

Here are two tests I ran using pg 12 (upgrade on the schedule). 

Given a table “customer” with a column “deadfiled” with a default of false. If deadfile is true, then exclude row from queries executed by role “staff”.

Test 1
CREATE POLICY filter_customer_deadfiled
    ON public.customer
    AS PERMISSIVE
    FOR SELECT
    TO staff
    USING ((deadfiled IS NOT TRUE));

Select queries by staff do not include row where deadfiled is true. Update and insert queries by staff on visible rows fail. 

Test 2
CREATE POLICY filter_customer_deadfiled
    ON public.customer
    AS PERMISSIVE
    FOR ALL
    TO prm_staff
    USING ((deadfiled IS NOT TRUE));

Select queries by staff do not include row where deadfiled is true. Update insert queries by staff on visible rows succeed. 

This indicates that policy using FOR ALL allows CRUD, but if the policy states FOR SELECT then additional policies are needed for insert, update and delete.



> On Nov 13, 2024, at 6:13 PM, Mark Phillips <[email protected]> wrote:
> 
> Thank you. I will revisit my test cases to be sure I have the use cases covered.
>  - Mark, out and about.
> 
>> On Nov 13, 2024, at 5:36 PM, David G. Johnston <[email protected]> wrote:
>> 
>> On Wednesday, November 13, 2024, Mark Phillips <[email protected] <mailto:[email protected]>> wrote:
>>> Given a database table with one policy statement FOR SELECT applied, it is necessary to apply additional policy statements for insert, update, and delete operations?
>> 
>> It isn’t necessary but most conventional use cases would involve establishing policies for writing as well as reading.  But it is use case dependent.
>> 
>> David J.
>> 



view thread (3+ messages)

reply

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 using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Row level security policy
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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