pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephen Frost <sfrost@snowman.net>
To: adudnik@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14060: row security policy does not work for updatable views
Date: Sat, 2 Apr 2016 21:40:06 -0400
Message-ID: <20160403014006.GK10850@tamriel.snowman.net> (raw)
In-Reply-To: <20160402200106.2623.11425@wrigleys.postgresql.org>
References: <20160402200106.2623.11425@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Artur,

* adudnik@gmail.com (adudnik@gmail.com) wrote:
> -- usage scenario:
> --   1. make a table
> --   2. enable row security for a role
> --   3. create view for restricted table
> --   4. grant to restricted role select and update for view and table
> 
> -- expected behavior - view and table could select/update same records
> -- bug behavior - view return/update all rows (policy ignored) and
> security_barrier too

The views you create here:

> set role postgres;
> 
> CREATE TABLE t AS SELECT n, 'secret'||n AS secret FROM generate_series(1,20)
> n;
> 
> create role test;
> 
> grant select, update on t to test;
> ALTER TABLE t ENABLE ROW LEVEL SECURITY;
> CREATE POLICY t_all ON t TO test USING (n % 2 = 1);
> CREATE VIEW t_odd WITH (security_barrier) AS SELECT * FROM t ;
> CREATE VIEW t2_odd AS SELECT * FROM t ;
> CREATE VIEW t3_odd WITH (security_barrier) AS SELECT * FROM t where n % 2 =
> 1;

Are all owned by the postgres user.

As such, the accesses to the table through the view are done with the
privileges of the postgres user.  The postgres user owns the table, is
the superuser, and has the BYPASSRLS role attribute, any of which are
sufficient to bypass the RLS policies on the table.

Try creating the view as the 'test' user and you'll see that then
accessing the table through the view will result in the RLS policy being
applied.

Note that this is consistent with regular privileges for views and
tables (a user accessing a view only needs access to the view, but the
view owner must have access to the table).

Thanks!

Stephen

Attachments:

  signature.asc (application/pgp-signature, 818B) download

view thread (4+ messages)  latest in thread

Message-ID: <20160403014006.GK10850@tamriel.snowman.net>
Permalink:  ../20160403014006.GK10850@tamriel.snowman.net/
Also on:    postgresql.org/message-id/20160403014006.GK10850@tamriel.snowman.net

 · 

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 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-bugs@postgresql.org
  Cc: sfrost@snowman.net, adudnik@gmail.com
  Subject: Re: BUG #14060: row security policy does not work for updatable views
  In-Reply-To: <20160403014006.GK10850@tamriel.snowman.net>
  References: <20160402200106.2623.11425@wrigleys.postgresql.org> <20160403014006.GK10850@tamriel.snowman.net>

* 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