Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gf9wE-0000c1-CZ for pgsql-general@arkaria.postgresql.org; Thu, 03 Jan 2019 20:49:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gf9wD-0004oe-26 for pgsql-general@arkaria.postgresql.org; Thu, 03 Jan 2019 20:49:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gf9wC-0004oX-Mp for pgsql-general@lists.postgresql.org; Thu, 03 Jan 2019 20:49:56 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gf9wA-0002tE-9u for pgsql-general@lists.postgresql.org; Thu, 03 Jan 2019 20:49:55 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id B7A235F79E; Thu, 3 Jan 2019 15:49:53 -0500 (EST) Date: Thu, 3 Jan 2019 15:49:53 -0500 From: Stephen Frost To: Siegfried Bilstein Cc: pgsql-general@lists.postgresql.org Subject: Re: Thoughts on row-level security for webapps? Message-ID: <20190103204953.GW2528@tamriel.snowman.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Sl61CI1LVv3DiL8h" 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 --Sl61CI1LVv3DiL8h Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Siegfried Bilstein (sbilstein@gmail.com) wrote: > I'm evaluating using a tool called Postgraphile that generates a GraphSQL > server from a postgres setup. The recommended way of handling security is > to implement RLS within postgres and simply have the webserver take a > cookie or similar and define which user is querying data. >=20 > I've normally built webapps like this: pull out user id from a session > cookie -> the API endpoint verifies the user and whether or not it has > access to the given data -> app code mutates the data. >=20 > With Postgraphile the request specifies the mutation and the server > processes the request and relies on Postgres to determine if the user has > correct access rights. >=20 > It seems like I would need to create a ROLE for every single member that > signs up for my website which I'm a little concerned about. Is this a > common usage pattern for SQL security? Any gotchas relying on RLS? You don't have to create a role for every member, though depending on your expectation you might want to. You could just set a custom GUC which is used in the policy, but you then have to trust the web application code to always do that correctly and to always properly validate the client (without bugs, of course). RLS has been around for a while now and it works really rather well in most cases. There are some corner cases where you're doing some kind of filtering that might be able to use an index but the functions aren't leakproof and therefore can't be used, causing a performance regression, but that's not too hard to test for and only an issue if the policy itself isn't very selective. Thanks! Stephen --Sl61CI1LVv3DiL8h Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJcLnVxAAoJEO1sijiDR2RVmQ4P/3LORpVJZcdVGBrtC7PfOvEH q1sLLAOk50sxmBHhWSKETwJubUOIOB39tbDt9+CiYqmSaNUMerRN7zQqwJiC3mrM 5GUTmEFffWTNO+vz/Mp30832vSC6UbSW6w0JI2Jlwm/FaV1yZHgCJfDfip8V3rj0 dGs0eUwtCzzlRikgiVJWVW7a1Vqteh+WzSYahW7lTF+cAxup/+K+1ifSZ+rJJZlw o9PVNeWwBmPrlYYSvtVszcOlGWFcSd+foH5+9d7/FDycYUjP9BGQKHSWjnfmhtrl GaSR6ed2FJqh0vgJXPZyrusaE5NrZyU/487ejCZIviByxqH6VKQnPNtpcA0BZU8f tRI8GMp3nbcujzVevW74ar0PO47lqtQT6LWdmfis9s7JM5J8CXsfpXFCEOruDfcL B/maDyCyGnYxXQzV8kPkS8GMCep5MmOxXZHmzMVlGzDkunD6vRcitoG/JAo//vLg 4HlH3SeogUKHXqFnKTEGj4rDeWCC+gS71XL3EBKdGaJma0ja7b5FQg5b9WU9iUN+ f5oXFKNjn6AOk8UMjZ1aPIn2fFU1MOKmwHCKuTSS7H/XjbfjJ/KA+ugblnmNuGVW 54gMP9kAKFEMomR7wHw/eqeeLX79VaXLj57QOmDVDFEoLFWzu98y0VM1TXsxsDXk VgLK/JeucqFEf3dqrg6q =LkWp -----END PGP SIGNATURE----- --Sl61CI1LVv3DiL8h--