Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJe09-0004LL-GF for pgsql-general@arkaria.postgresql.org; Wed, 01 Apr 2020 14:05:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJe08-0007SE-FM for pgsql-general@arkaria.postgresql.org; Wed, 01 Apr 2020 14:05:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJe08-0007Rk-7C for pgsql-general@lists.postgresql.org; Wed, 01 Apr 2020 14:05:52 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJe01-000893-9V for pgsql-general@lists.postgresql.org; Wed, 01 Apr 2020 14:05:51 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 9FF735F7A0; Wed, 1 Apr 2020 10:05:46 -0400 (EDT) Date: Wed, 1 Apr 2020 10:05:46 -0400 From: Stephen Frost To: Alastair McKinley Cc: Tom Lane , "pgsql-general@lists.postgresql.org" Subject: Re: Index selection issues with RLS using expressions Message-ID: <20200401140546.GW13712@tamriel.snowman.net> References: <23829.1585682302@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="PeEtTtIyPIoxp38l" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --PeEtTtIyPIoxp38l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, We prefer to use in-line responses, please don't top-post on these lists. * Alastair McKinley (a.mckinley@analyticsengines.com) wrote: > Thanks for looking at this! It seems like there are quite a few performa= nce gotchas around leaky operators and RLS, this is my second encounter wit= h this issue in the last few weeks. It ends up being a choice between being correct (as in, implementing the security that RLS is intended to provide) vs. being fast (better performance). If you aren't concerned with the security risk posed by leaky functions, you can use regular views, but you need to realize that users who can execute arbitrary SQL on the database system would very likely be able to then circumvent your views and get access to all of the data in the table. > What would you recommend as a reasonable workaround? The right solution is really to hack on PG to make it support having the && operator (and equality ones, as needed, though many already are) be marked leakproof, with enough intelligence to also pass that information through to the parts that need to know, as Tom mentions. That's not going to happen for v13 at this point as I don't think anyone's actively working on that, but it could possibly be worked on for v14. > I have a large table with a gin index that I would like to use RLS on and= use the @@ text search operator. My initial thought is to use a security = definer set-returning function that implements the RLS policy explicitly. = Would a security barrier view also potentially work? A security barrier view is also going to prevent non-leakproof functions =66rom being pushed down (that's what being a security barrier view more-or-less exactly means). Using a security-definer function could possible work, but you can't just mark a function as leakproof that actually isn't leakproof or, as Tom said before, you're creating a security hole. Thanks, Stephen --PeEtTtIyPIoxp38l Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJehJ+6AAoJEO1sijiDR2RVAJAQALh+XRru9i0nvVqsWGSFqh2H H9qFCY95Nln+6WIf5nvthk2EljGCd5tPEZ34wO6De6qqZ/OxMvyIbZJu1LCfeLjq YH9UbjZwPUHOhln+ju863e3Di+Bovp75tcoRNZEuQ0APW7ia5oQAvfQVqXjzZegF EqxD64w01xSH7CsTgPhUoYYNacfQQuaBSb3vzMf3pa+lxwhuHb4nQf7LmWLdlLtN AJdmYuoPGcTpMxpBuZPi3JX++GR9nXxT+CHEMEdUv+/7F7EaFCt4TBVHURq2DHXj hvPoENdk4uRwJmVF0bCY1b0k0hcEm7EIic+qvqy4STHeByfDw9JgBKGOz+WNVpJS J9uid3M8py5hXYPULoEgaqOQtzk3OLlZZwVlMi/iY05zdE7KFdzPdfyFCbA3JO4Y IVVDsd4KbjQOc7bBZ1Q75uhR/Hof00iIlVhlkb+0xQ48AuWIgpwVpIN1TtzyRQE+ w1rWK//JbINjcVr/2Tvep+NiOolHTou4CGmPILG7/bWVRkljhbki4aR3LW/p+QaD VxscRDby/w5SICmPWwfitf3pRuR78JAgXcZ6xaF2CLXX/GwAzWrgZV7awV/gZDDM u+FzQu0P364/8lM5+WvG36Rf4MKIwdAAKLxyYZcRXv33hdBGInoCzxpgUwHQ3dNn pq1SMopKpIATJeu65ML6 =D/DU -----END PGP SIGNATURE----- --PeEtTtIyPIoxp38l--