vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| * Tom Lane (tgl@sss.pgh.pa.us) wrote: > Stephen Frost <sfrost@snowman.net> writes: > > Attached please find files and patches associated with moving from the > > User/Group system currently in place to Roles, as discussed > > previously. > > I have cleaned this up a bit and committed it. I normally wouldn't > commit an incomplete patch, but this change is blocking Alvaro's work > on dependencies for shared objects, so I felt it was best to get the > catalog changes in now. That will let Alvaro work on dependencies > while I sort out the unfinished bits of roles, which I intend to do > over the next day or so. Great, glad to hear it. I hope you got a chance to look over the open items in the 'milestones' file. I'd really like to see the grammar be fixed to match SQL spec for GRANT ROLE/REVOKE ROLE. I think an approach to take there might be to try and get GrantRoleStmt and GrantStmt to use the same productions at the end of the line if possible or something along those lines. Also, I've been looking through the diff between my tree and what you committed to CVS and had a couple comments (just my 2c: I think it would have been alot easier using SVN to see exaclty what was different from my patch vs. other changes since my last CVS up): First, sorry about the gratuitous name changes, it helped me find every place I needed to look at the code and think about if it needed to be changed in some way (ie: Int32GetDatum -> ObjectIdGetDatum, etc). I had planned on changing some of them back to minimize the patch but kind of ran out of time. Second, looks like I missed fixing an owner check in pg_proc.c Current CVS has, line 269: if (GetUserId() != oldproc->proowner && !superuser()) Which is not a sufficient owner check. This should by fixed by doing a proper pg_proc_ownercheck, ie: if (!pg_proc_ownercheck(HeapTupleGetOid(oldtup), GetUserId())) Third, I feel it's incorrect to only allow superuser() to change ownership of objects under a role-based system. Users must be able to create objects owned by a role they're in (as opposed to owned only by themselves). Without this there is no way for a given role to allow other roles to perform owner-level actions on objects which they create. The point of adding roles was to allow owner-level actions on objects to more than a single user or the superuser. Requiring the superuser to get involved with every table creation defeats much of the point. This should really be possible either by explicitly changing the ownership of an object using ALTER ... OWNER, or by a SET ROLE followed by CREATE TABLE, etc. SET ROLE is defined by the SQL specification, though we don't support it specifically yet (shouldn't be too difficult to add now though). Certainly if we accept that SET ROLE should be supported and that objects then created should be owned by the role set in SET ROLE we should be willing to support non-superusers doing ALTER ... OWNER given that they could effectively do the same thing via SET ROLE (though with much more difficulty, which has no appreciable gain). Fourth, not that I use it, but, it looks like my changes to src/interfaces/ecpg/preproc/preproc.y were lost. Not sure if that was intentional or not (I wouldn't think so... I do wish ecpg could just be the differences necessary for ecpg and be based off the main parser somehow, but that'd be a rather large change). Oh, and in that same boat, src/tools/pgindent/pgindent also appears to not have gotten the changes that I made. > Many thanks for your work on this! Happy to have helped though frustrated that you seem to have removed the part that I was originally looking for. I don't feel that's justification for having it (I feel I've addressed that above) but it certainly would have been nice to be aware of that earlier and perhaps to have discussed the issues around it a bit more before being so close to the feature freeze (I know, alot my fault, but there it is). Thanks, Stephen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCwXT9rzgMPqB3kigRAi3NAJ94+rBKka+xJ2tIzJkvBf 1Uq4faUgCeLTn6 RNzKj8Hb6lorWTFjemFzWlg= =PJ/z -----END PGP SIGNATURE----- |
| |||
| Stephen Frost <sfrost@snowman.net> writes: > Also, I've been looking through the diff between my tree and what you > committed to CVS and had a couple comments > First, sorry about the gratuitous name changes, it helped me find > every place I needed to look at the code and think about if it needed > to be changed in some way (ie: Int32GetDatum -> ObjectIdGetDatum, > etc). I had planned on changing some of them back to minimize the > patch but kind of ran out of time. No problem, I figured that was why you'd done it, but changing them back helped me to understand the patch also ;-) > Second, looks like I missed fixing an owner check in pg_proc.c Got it. I was wondering if there were more --- might be worth checking all the superuser() calls. > Third, I feel it's incorrect to only allow superuser() to change > ownership of objects under a role-based system. I took that out because it struck me as a likely security hole; we don't allow non-superuser users to give away objects now, and we shouldn't allow non-superuser roles to do so either. Moreover the tests you had were inconsistent (not same test everyplace). > Users must be able to > create objects owned by a role they're in (as opposed to owned only > by themselves). This is what SET SESSION AUTHORIZATION/SET ROLE is for, no? You set the auth to a role you are allowed to be in, then create the object. I do notice that we don't have this yet, but it's surely a required piece of the puzzle. > Fourth, not that I use it, but, it looks like my changes to > src/interfaces/ecpg/preproc/preproc.y were lost. Not sure if that was > intentional or not Yeah, it was. I leave it to Michael Meskes to sync ecpg with the main parser; on the occasions where I've tried to do it for him, things didn't work out well. > I do wish ecpg could just > be the differences necessary for ecpg and be based off the main parser > somehow, Me too, but I haven't seen a way yet. > src/tools/pgindent/pgindent also appears to not have gotten the > changes that I made. That's an automatically generated list; there's no need to edit it. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend |
| |||
| Stephen Frost <sfrost@snowman.net> writes: > The code I had for this was: > if (!pg_class_ownercheck(tuple,GetUserId()) || > !is_role_member(newowner,GetUserId())) > That needs a check for superuser though because while the test will pass > on the 'pg_class_ownercheck' side, it won't on the 'is_role_member' side Um, right, that was another problem I had with it --- at one point the regression tests were failing because the superuser wasn't allowed to reassign object ownership ... I'm still fairly concerned about the security implications of letting ordinary users reassign object ownership. The fact that SET ROLE would let you *create* an object with ownership X is a long way away from saying that you should be allowed to change an *existing* object to have ownership X. This is particularly so if you are a member of a couple of different roles with different memberships: you will be able to cause objects to become effectively owned by certain other people, or make them stop being effectively owned by those people. I don't have a clear trouble case in mind at the moment, but this sure sounds like the stuff of routine security-hole reports. (Altering the ownership of a SECURITY DEFINER function, in particular, sounds like a great path for a cracker to pursue.) > One place I recall seeing one and not being sure if it should be a new > *_ownercheck() function or not was in the 2PC patch- twophase.c, line > 380: This one I think we can leave... regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match |
| |||
| * Tom Lane (tgl@sss.pgh.pa.us) wrote: > Stephen Frost <sfrost@snowman.net> writes: > > Second, looks like I missed fixing an owner check in pg_proc.c > > Got it. I was wondering if there were more --- might be worth checking > all the superuser() calls. Yeah, let's come up with a decision about what exactly we should allow and then perhaps I can go through all of the superuser() calls and see what needs fixing up. > > Third, I feel it's incorrect to only allow superuser() to change > > ownership of objects under a role-based system. > > I took that out because it struck me as a likely security hole; we don't > allow non-superuser users to give away objects now, and we shouldn't > allow non-superuser roles to do so either. Moreover the tests you had > were inconsistent (not same test everyplace). Sorry about them being inconsistent, I didn't intend for them to be. I went through a couple of iterations of them trying to do the check the 'right' way. Thinking back on it, even the checks I ended up with were wrong (in the superuser case), though I think they were closer. Basically my thought was to allow the same thing you could do w/ SET ROLE, etc: If you are the owner of the object to be changed (following the normal owner checking rules) AND would still be considered the owner of the object *after* the change, then you can change the ownership. The code I had for this was: if (!pg_class_ownercheck(tuple,GetUserId()) || !is_role_member(newowner,GetUserId())) That needs a check for superuser though because while the test will pass on the 'pg_class_ownercheck' side, it won't on the 'is_role_member' side (currently anyway, I suppose a superuser could be considered to be in any role, so we could change is_role_member to always return true for superusers, that'd probably make pg_group look ugly though, either way): if (!superuser() && !(pg_class_ownercheck(tupe,GetUserId()) && is_role_member(newowner,GetUserId()))) I think that's the correct check and can be done the same way for pretty much all of the objects. Were there other security concerns you had? I'd be happy to look through the superuser() checks in commands/ and develop a patch following what I described above, as well as looking for other cases where we should be using the *_ownercheck() functions. One place I recall seeing one and not being sure if it should be a new *_ownercheck() function or not was in the 2PC patch- twophase.c, line 380: if (user != gxact->owner && !superuser_arg(user)) Wasn't sure if that made sense to have *_ownercheck, or, even if we added one for it, if it made sense to check is_member_of_role() for prepared transactions. I don't think SQL has anything to say about it, anyone know what other DBs do here? > > Users must be able to > > create objects owned by a role they're in (as opposed to owned only > > by themselves). > > This is what SET SESSION AUTHORIZATION/SET ROLE is for, no? You set the > auth to a role you are allowed to be in, then create the object. I do > notice that we don't have this yet, but it's surely a required piece of > the puzzle. (Technically I think SET SESSION AUTHORIZATION is different from SET ROLE, but anyway) Right, that's another way to do it (as I mentioned), and that lets you do ownership changes, but they're much more painful: CONNECT AS joe; CREATE TABLE abc as SELECT name,avg(a),sum(b) FROM reallybigtable; -- Whoops, I meant for abc to be owned by role C so sally can add her -- column to it later, or vacuum/analyze it, whatever GRANT SELECT ON abc TO C; -- Might not be necessary ALTER TABLE abc RENAME TO abc_temp; SET ROLE C; CREATE TABLE abc AS SELECT * FROM abc_temp; -- Could be big SET ROLE NONE; -- Might be just 'SET ROLE;'? Gotta check the spec DROP TABLE abc_temp; I don't really see the point in making users go through all of these hoops to do an ownership change. In the end, it's the same result near as I can tell... > Yeah, it was. I leave it to Michael Meskes to sync ecpg with the main > parser; on the occasions where I've tried to do it for him, things > didn't work out well. Ah, ok. > > src/tools/pgindent/pgindent also appears to not have gotten the > > changes that I made. > > That's an automatically generated list; there's no need to edit it. Hah, silly me. Thanks, Stephen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCwZqyrzgMPqB3kigRAhv+AJ9UaV8yFd77mHS0IZiUL8 U0CU8YcwCcCkZw yId/JlCsmiGJcNeZhiTahyg= =abH9 -----END PGP SIGNATURE----- |
| |||
| * Tom Lane (tgl@sss.pgh.pa.us) wrote: > Stephen Frost <sfrost@snowman.net> writes: > > That needs a check for superuser though because while the test will pass > > on the 'pg_class_ownercheck' side, it won't on the 'is_role_member' side > > Um, right, that was another problem I had with it --- at one point the > regression tests were failing because the superuser wasn't allowed to > reassign object ownership ... Yeah, sorry about that. > I'm still fairly concerned about the security implications of letting > ordinary users reassign object ownership. The fact that SET ROLE would > let you *create* an object with ownership X is a long way away from > saying that you should be allowed to change an *existing* object to have > ownership X. This is particularly so if you are a member of a couple of > different roles with different memberships: you will be able to cause > objects to become effectively owned by certain other people, or make > them stop being effectively owned by those people. I don't have a clear > trouble case in mind at the moment, but this sure sounds like the stuff > of routine security-hole reports. (Altering the ownership of a SECURITY > DEFINER function, in particular, sounds like a great path for a cracker > to pursue.) SET ROLE also lets you *drop* an object owned by that role. Or alter it. Or CREATE OR REPLACE FUNCTION ... I can understand your concern. The specific use case I'm thinking about is where a user creates an object, does some work on it, and then wants to change its ownership to be owned by a role which that user is in. I find myself doing that a fair bit (as superuser atm). One thing I don't like about limiting it to that is that you then can't go back without the whole drop/create business or getting an admin. This also isn't stuff that couldn't be done through other means, even in the SECURITY DEFINER function case, you just need to drop, set role, create. Having a role with members be able to own objects isn't meant to replace the privileges system and I don't expect people to try to use it to. I can perhaps see a special case for SECURITY DEFINER functions but if we're going to special case them I'd think we'd need to make them only be creatable/modifiable at all by superusers or add another flag to the role to allow that. Thanks, Stephen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCwadvrzgMPqB3kigRAvZxAJkBPzHBoPBhhCmrxfwmy6 zzUM3fpQCfVIqZ p0Usb6l6MVAugBrXNfCARSY= =zCNc -----END PGP SIGNATURE----- |
| |||
| On Tue, Jun 28, 2005 at 14:45:06 -0400, Stephen Frost <sfrost@snowman.net> wrote: > > If you are the owner of the object to be changed (following the normal > owner checking rules) AND would still be considered the owner of the > object *after* the change, then you can change the ownership. That still isn't a good idea, because the new owner may not have had access to create the object you just gave to them. Or you may not have had access to drop the object you just gave away. That is going to be a security hole. ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly |
| |||
| On Tue, Jun 28, 2005 at 14:52:07 -0500, Bruno Wolff III <bruno@wolff.to> wrote: > On Tue, Jun 28, 2005 at 14:45:06 -0400, > Stephen Frost <sfrost@snowman.net> wrote: > > > > If you are the owner of the object to be changed (following the normal > > owner checking rules) AND would still be considered the owner of the > > object *after* the change, then you can change the ownership. > > That still isn't a good idea, because the new owner may not have had > access to create the object you just gave to them. Or you may not have > had access to drop the object you just gave away. That is going to > be a security hole. Thinking about it some more, drops wouldn't be an issue since the owner can always drop objects. Creating objects in particular schemas or databases is not something that all roles may be able to do. ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly |
| |||
| * Bruno Wolff III (bruno@wolff.to) wrote: > On Tue, Jun 28, 2005 at 14:45:06 -0400, > Stephen Frost <sfrost@snowman.net> wrote: > > > > If you are the owner of the object to be changed (following the normal > > owner checking rules) AND would still be considered the owner of the > > object *after* the change, then you can change the ownership. > > That still isn't a good idea, because the new owner may not have had > access to create the object you just gave to them. Or you may not have > had access to drop the object you just gave away. That is going to > be a security hole. If you're considered the owner of an object then you have access to drop it already. You have to be a member of the role to which you're changing the ownership. That role not having permission to create the object in place is an interesting question. That's an issue for SET ROLE too, to some extent I think, do you still have your role's permissions after you've SET ROLE to another role? If not then you'd have to grant CREATE on the schema to the role in order to create objects owned by that role, and I don't think that's necessairly something you'd want to do. Thanks, Stephen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCwa18rzgMPqB3kigRAnzvAJ4pYH0oim+OFVhziQFH24 B77PfksACfZXQ9 KOKpSdf2FyPtd9RwT+86+5I= =VEJ5 -----END PGP SIGNATURE----- |
| |||
| Stephen Frost wrote: > I can perhaps see a special case for SECURITY DEFINER functions but if > we're going to special case them I'd think we'd need to make them only > be creatable/modifiable at all by superusers or add another flag to the > role to allow that. I agree that owner changes of SECURITY DEFINER functions seem dangerous. I would follow Stephen's idea that SECURITY DEFINER functions should only be creatable/modifiable by superusers. This would be similar to unix, where setting the suid/sgid bits is usually only allowed to root. Best Regards, Michael Paesold ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings |
| ||||
| Stephen Frost wrote: > If you're considered the owner of an object then you have access to drop > it already. You have to be a member of the role to which you're > changing the ownership. That role not having permission to create the > object in place is an interesting question. That's an issue for SET > ROLE too, to some extent I think, do you still have your role's > permissions after you've SET ROLE to another role? For me this would be the "natural" way how SET ROLE would behave. This is unix'ism again, but using setuid to become another user, you loose the privileges of the old user context. Therefore SET ROLE should not inherit privileges from the other role. This seems to be the safes approach. Nevertheless, what does the standard say? > If not then you'd > have to grant CREATE on the schema to the role in order to create > objects owned by that role, and I don't think that's necessairly > something you'd want to do. Right, that's an issue. But since the new role will be the *owner* of the object, it *should* really have create-privileges in that schema. So the above way seems to be correct anyway. Best Regards, Michael Paesold ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org |