Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1amX24-0002Dc-UT for pgsql-bugs@arkaria.postgresql.org; Sun, 03 Apr 2016 01:40:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1amX24-0008Ml-7S for pgsql-bugs@arkaria.postgresql.org; Sun, 03 Apr 2016 01:40:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1amX1Q-0007dE-Cn for pgsql-bugs@postgresql.org; Sun, 03 Apr 2016 01:40:12 +0000 Received: from tamriel.snowman.net ([2001:4830:167b::11]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1amX1N-0003GY-5U for pgsql-bugs@postgresql.org; Sun, 03 Apr 2016 01:40:11 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id B94745F795; Sat, 2 Apr 2016 21:40:06 -0400 (EDT) Date: Sat, 2 Apr 2016 21:40:06 -0400 From: Stephen Frost To: adudnik@gmail.com Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14060: row security policy does not work for updatable views Message-ID: <20160403014006.GK10850@tamriel.snowman.net> References: <20160402200106.2623.11425@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Xsbw7+pkldUUnFG3" Content-Disposition: inline In-Reply-To: <20160402200106.2623.11425@wrigleys.postgresql.org> X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-77-generic (x86_64) X-Uptime: 21:32:19 up 39 days, 22:25, 10 users, load average: 0.04, 0.09, 0.06 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -2.9 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --Xsbw7+pkldUUnFG3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 >=20 > -- 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; >=20 > CREATE TABLE t AS SELECT n, 'secret'||n AS secret FROM generate_series(1,= 20) > n; >=20 > create role test; >=20 > 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 =3D 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= =3D > 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 --Xsbw7+pkldUUnFG3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJXAHR2AAoJEO1sijiDR2RVA4IP/3ppbUnvZxfNNJNbeCf7+xCy vC9hgoeTwr+UwE5MG45dXPmm/9heXsEL4Z/SHLAKTdA11fEcYM6c8NnmoN5nXaHx vy3VyZfokk9y45AnYGqwkAVgNfuGMur5oSNhDuXxlcjHjgMtiqx96ILSYXLfzae9 oqMYdNTPAJISQGeFSYQHidcP8wpj0XYoW4+JA7DMvlWecNtk0aCURerQr6Wi3922 GedALvXh/KjZcqv0w2hgmsNWOCKAATqHhgwmDOakMGpRYfhljh40AgzPwgMISzJx RXuRDcqZMYalW62WsljUiJz9FxiDEXay0GgeCsmdmYl2EYjNOctD8hlo01KOY0dg rVIQnYzjtKdQF9F2DD2Upv5o3hJlDXW5InrLqJv6RA/er3OSd2155LXdTr+LHtbn Tz0qmp56v9YAttEiSbFYuAYuL1nmtChWmxPNSeAoJmMIG/zzxmXOclUiNiKtfPV3 5tjZHsnzoqxh8a5UN3MO8/Ky5UsOYmPL9UbnZbQU/IXNuzNeYYkQZFfMv8y415eq cxe2naDchSHTZ6AQPV349kj1jNtRpscxL43NWSdZP2iANSbqBTTgA/9xRgyPGc42 eIbpCTXujx3cXatQpU2rL+8ZdAlUaf6G+poo7/XKhyAVv+NUep7lHEvpEIj3epjb k8BfxZ3vEknTBwWNTDkw =xZs0 -----END PGP SIGNATURE----- --Xsbw7+pkldUUnFG3--