Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 04:37 AM
Stephen Frost
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

* 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-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 04:38 AM
Tom Lane
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 04:38 AM
Tom Lane
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 04:38 AM
Stephen Frost
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

* 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-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 04:38 AM
Stephen Frost
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

* 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-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-11-2008, 04:38 AM
Bruno Wolff III
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-11-2008, 04:38 AM
Bruno Wolff III
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-11-2008, 04:38 AM
Stephen Frost
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

* 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-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-11-2008, 04:38 AM
Michael Paesold
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-11-2008, 04:38 AM
Michael Paesold
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:00 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447