Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yxsaw-0006d2-JT for pgsql-hackers@arkaria.postgresql.org; Thu, 28 May 2015 07:51:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yxsaw-0002LU-3z for pgsql-hackers@arkaria.postgresql.org; Thu, 28 May 2015 07:51:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yxsau-0002LO-PB for pgsql-hackers@postgresql.org; Thu, 28 May 2015 07:51:12 +0000 Received: from tamriel.snowman.net ([2001:4830:167b::11]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Yxsaq-0004Gl-Iu for pgsql-hackers@postgresql.org; Thu, 28 May 2015 07:51:11 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id AEBCF5F7A0; Thu, 28 May 2015 03:51:07 -0400 (EDT) Date: Thu, 28 May 2015 03:51:07 -0400 From: Stephen Frost To: Dean Rasheed Cc: Alvaro Herrera , PostgreSQL Hackers Subject: Re: [COMMITTERS] pgsql: Row-Level Security Policies (RLS) Message-ID: <20150528075107.GS26667@tamriel.snowman.net> References: <20150522180807.GB5885@postgresql.org> <20150526130800.GA26667@tamriel.snowman.net> <20150526144406.GU5885@postgresql.org> <20150527014206.GF26667@tamriel.snowman.net> <20150527135154.GI26667@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="cCQRCm2DpEj+xiEj" Content-Disposition: inline In-Reply-To: X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-46-generic (x86_64) X-Uptime: 03:45:39 up 69 days, 13:34, 22 users, load average: 0.01, 0.04, 0.07 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --cCQRCm2DpEj+xiEj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Dean, * Dean Rasheed (dean.a.rasheed@gmail.com) wrote: > On 27 May 2015 at 14:51, Stephen Frost wrote: > >> On 27 May 2015 at 02:42, Stephen Frost wrote: > >> > Now, looking at the code, I'm actually failing to see a case where we > >> > use the RowSecurityPolicy->policy_name.. Perhaps *that's* what we > >> > should be looking to remove? > >> > >> If we add support for restrictive policies, it would be possible, and > >> I think desirable, to report on which policy was violated. For that, > >> having the policy name would be handy. We might also arguably decide > >> to enforce restrictive RLS policies in name order, like check > >> constraints. Of course none of that means it must be kept now, but it > >> feels like a useful field to keep nonetheless. > > > > I agree that it could be useful, but we really shouldn't have fields in > > the current code base which are "just in case".. The one exception > > which comes to mind is if we should keep it for use by extensions. > > Those operate on an independent cycle from our major releases and would > > likely find having the name field useful. >=20 > Hmm, when I wrote that I had forgotten that we already allow > extensions to add restrictive policies. I think it would be good to > allow those policies to have names, and if they do, to copy those > names to any WCOs created. Then, if a WCO is violated, and it has a > non-NULL policy name associated with it, we should include that in the > error report. I'm certainly not against that and I agree that it'd be nicer than simply reporting that there was a violation, but we combine all of the various pieces together, no? Are we really going to be able to confidently say which policy was violated? Even if we are able to say the first which was violated, more than one might be. Is that an issue we need to address? Perhaps not, but it's something to consider. > > One thing which now occurs to me, however, is that, while the current > > coding is fine, using InvalidOid as an indicator for the default-deny > > policy, in general, does fall over when we consider policies added by > > extensions. Those policies are necessairly going to need to put > > InvalidOid into that field, unless they acquire an OID somehow > > themselves (it doesn't seem reasonable to make that a requirement, > > though I suppose we could..), and, therefore, perhaps we should add a > > boolean field which indicates which is the defaultDeny policy anyway and > > not use that field for that purpose. >=20 > Actually I think a new boolean field is unnecessary, and probably the > policy_id field is too. Re-reading the code in rowsecurity.c, I think > it could use a bit of refactoring. Essentially what it needs to do > (for permissive policies at least) is just >=20 > * fetch a list of internal policies > * fetch a list of external policies > * concatenate them > * if the resulting list is empty, add a default-deny qual and/or WCO >=20 > By only building the default-deny qual/WCO at the end, rather than > half-way through and pretending that it's a fully-fledged policy, the > code ought to be simpler. I tend to agree. > I might get some time at the weekend, so I can take a look and see if > refactoring it this way works out in practice. That would certainly be fantastic and most appreciated. Beyond that, we have the add-a-default-deny-policy logic in multiple places, as I recall, and I wonder if that's overkill and done out of paranoia rather than sound judgement. I'm certainly not suggesting that we take unnecessary risks, and so perhaps we should keep it, but I do think it's something which should be reviewed and considered (I've been planning to do so for a while, in fact). > BTW, I just spotted another problem with the current code, which is > that policies from extensions aren't being checked against the current > role (policy->roles is just being ignored). I think it would be neater > and safer to move the check_role_for_policy() check up and apply it to > the entire concatenated list of policies, rather than having the lower > level code have to worry about that. Excellent point... We should address that and your proposed approach sounds reasonable to me. If you're able to work on that this weekend, I'd be happy to review next week. Thanks! Stephen --cCQRCm2DpEj+xiEj Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJVZsjrAAoJEO1sijiDR2RVN+cP/jWZ6+Gnl3zJYjn4f5tXFBTd NjzUN7ZTJkpCgRPwQjhyIhGKRO4vyblQqEkXz563v3bCRR0IZKaMsEC94AtPXJ8g 4cpRUnkAmG7dIbaSvhA3UxIg/Vzq1BWSSzZEBvV1d9LULdlCynQxWbLRudxI0XWK undLemj9motQcrlsdPmpM1L+GO6cOLhdFBDHBYRqQv/tmveL0nXsksvcqk3FeU/4 woNCC8MwnMgIL5v7Qyt30kxNEN0k91bgh6zrKZ4QtweJblKyjiJ56DNAZ3aqlUjE GrmlWEiAcrHjbEJuLnIsmovmVbrIm8waIt29aqtKXhUujUZ91NESdAPJZZFsr5tn vqgKl0LOXMTaecmMoMneiqiTX34RRKok3iDlTGnK95fB6OSNtrSCrOEA18GPizON Jp0TM9v9/3UqqL3qWeYsbGXBbdr6jxwZkQ8vtA0+zxf0SxdFEPYt6LB5TionDfJW 8rUWkMjuAlEnJz4upPsQB3IhLUNQE9bjJCBmlWNXUg9cKz3PpP5AFsscbXKUbU+n F7/gRX8oRGe5e8Fw4xTp3gox5GAnHcGunaKyjaxdrgtnJRcP1XvHqCh7YAbLBqoo 07UPGOVVmJwx/H2XVWQYOpXevasL19XnOf5pDMvt3n+uEGiD4B23UIsSHcNopDVz y13MGiXk0qWsXx9yWQMO =SdL6 -----END PGP SIGNATURE----- --cCQRCm2DpEj+xiEj--