Unix Technical Forum

Re: [PATCHES] Users/Groups -> Roles

This is a discussion on Re: [PATCHES] Users/Groups -> Roles within the pgsql Hackers forums, part of the PostgreSQL category; --> Hi Fabien, * Fabien COELHO (fabien.coelho@ensmp.fr) wrote: > I've looked very quickly at the patch. ISTM that the proposed ...


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

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

Hi Fabien,

* Fabien COELHO (fabien.coelho@ensmp.fr) wrote:
> I've looked very quickly at the patch. ISTM that the proposed patch is a
> reworking of the user/group stuff, which are both unified for a new "role"
> concept where a user is a kind of role and a role can be a member of
> another role. Well, why not.


Right, it's a beginning to proper 'Role' support as defined by the SQL
specification.

> Some added files seems not to be provided in the patch :


pg_authid.h and pg_auth_members.h were attached to the email. They're
also available at http://kenobi.snowman.net/~sfrost/pg_role/ ; but the
patch has already been applied by Tom to CVS HEAD (well, with lots of
modifications and whatnot), so you probably should just take a look at
that.

> Anyway, from what I can see in the patch it seems that the roles are per
> cluster, and not per catalog. So this is not so conceptually different
> from user/group as already provided in pg.


It's conceptually different from users/groups in that it's roles, which
aren't the same thing. You're right, it's still per-cluster though.

> What would have been much more interesting for me would be a per catalog
> role, so that rights could be administrated locally in each database. I'm
> not sure how to provide such a feature, AFAICS the current version does
> not give me new abilities wrt right management.


I understand your concerns here and while I agree with the basic idea
that per-catalog role sets would be nice it wasn't what I had set out to
do with this patch. Perhaps what you're asking for will be added later
on. Some things this patch does do though are:

Allow role ownership. This role can also have members, and doesn't
necessairly have to be allowed to log in. Members of a role which owns
an object have owner-level rights on that object (so, fe: roles user1,
user2 and group1 where user1 and user2 are members of group1, a table
owned by group1 can be vacuumed, have columns added/removed, have
indexes create on it, etc, by user1 or user2).

Allow granting roles to other roles based on the 'with admin option'.
This means you don't have to be a superuser to add a member to a role
which you have the 'admin option' on.

There's other things (startup may be a bit faster since the pg_auth file
is sorted by the backend instead of during each startup, etc) but the
above were the types of things that I was looking to do mainly.

I'd like to see it possible to distinguish between 'superuser' and
'createrole' permissions, but I didn't get to that point with the roles
support (it's really a seperate issue anyway).

Thanks,

Stephen


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCwXdGrzgMPqB3kigRAv80AKCTm/iiuk/PnkGeWmZZ7ow/J5GZPACfQKs9
Afdm3dBvH+J5P3IU0SXiqf4=
=EZrg
-----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, 05:40 AM
Stephen Frost
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

Fabien,

* Fabien COELHO (fabien@coelho.net) wrote:
> This is a very useful feature, and a key idea of the specs IMVVHO. ISTM
> that the way "fuse" user and role misses that important point, as I have
> not seen a "set role" in the grammar file.


'set role' is coming, sorry it wasn't in my initial patch. We are
looking to support pretty much all of the SQL features 'Basic roles' and
'Extended roles'. I think 'set role' and maybe some cleanup of
information_schema is all we need to claim 'Basic roles' support. For
'Extended roles' I think we need revoke role cascade support.
Interestingly, the SQL2003 draft I'm looking at doesn't list 'drop role
<role name> cascade' as being valid, yet other places in the spec
specify 'drop role <role name> cascade' usage, so I think we should
support that.

> Although in the spec role rights are transitive in the role realm, it
> should *stop* at the user. If you drop the user concept, you just have a
> group with automatically provided rights.


I'm not quite sure what you mean here. Role right resolution starts
from the user and then works backwards up the tree, with multi-level
resolution. It wouldn't go past the logged in user since that's really
where it starts.

> The fact that the spec does not specify the USER stuff and specifies the
> ROLE stuff does not mean that having only roles is the good way to go.


I'm pretty sure we'll be able to match the SQL spec and support at least
everything we did before with users/groups...

> So for me we should have per-cluser users as they where up to now,
> per-catalog roles with the properties I described, and possibly
> per-cluster group just for the sake of compatibility/simplicity of the
> access control and managing group of users as a whole. ROLE should not
> replace USER/GROUP. It should be added next to it.


I don't see much point in having USER or GROUP when we have roles. Is
there something specific that you feel can't be done with roles that
could be done w/ USER/GROUP? Per-catalog roles is an interesting idea,
but I'd tend to think that if you want per-catalog roles, you'd want
per-catalog users too. I don't have any problem with that, but I don't
see how not being per-catalog indicates we should have USER/GROUP
instead of roles.

> Maybe I'm wrong at my reading of the spec and its intent, and at my quick
> check through the status of the cvs head, but that's my current
> understanding, and I think it should be checked seriously.


I just went through the spec yesterday, check -hackers for my email
about what CVS head supports vs. what's in the SQL spec. I don't see
any particular reason why we wouldn't be able to fully support 'Basic
roles' and 'Extended roles' in 8.1, I think we're quite close now...

Thanks,

Stephen

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCw+4QrzgMPqB3kigRAj66AJ4paQkn2cEern1sisOQCX 7RJA+/RwCfULX6
iMmIRucuqzkpjzWf5u2hTPA=
=8+UY
-----END PGP SIGNATURE-----

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


Dear Stephen,

> Right, it's a beginning to proper 'Role' support as defined by the SQL
> specification.


Ok. AFAIC remember, the specification is pretty subtle and fuzzy enough so
that there is room for little design options.

> I understand your concerns here and while I agree with the basic idea
> that per-catalog role sets would be nice it wasn't what I had set out to
> do with this patch. Perhaps what you're asking for will be added later
> on.
>
> Some things this patch does do though are:
> [...]


Ok. I think I understand but I'm not sure it is done the right way.
Let me explain my (possibly wrong) point of view:

The standard talks about 2 distinct concepts: USER and ROLE (4.34). I'm
not sure it is a good idea to drop the user concept to replace it by role.
If you do so, you may miss something about what roles are about.

The SESSION_USER/CURRENT_USER has a CURRENT_ROLE which defines the rights
at a given time. This role can be changed by the user, based on user/role
membership, so the user can change its 'effective' rights. Roles are
potential privileges that a user can set himself in if he/she desires so.
example:

sh> psql -u calvin mydb
calvin@mydb>
-- I'm user calvin with no role or a default role on mydb.
-- I can do all which is allowed to 'calvin' as a user.

calvin@mydb> SET ROLE admin;
calvin/admin@mydb> ...
-- I'm allowed to do that if the role 'admin' is granted to 'calvin'
-- now I can do whatever is allowed to role 'admin'.

calvin/admin@mydb> SET ROLE basic;
calvin/basic@mydb> ...
-- now I can do what is allowed to role 'basic' and the roles 'basic' are in.
-- things that where allowed to admin may *not* be accessible now.

This is a very useful feature, and a key idea of the specs IMVVHO. ISTM
that the way "fuse" user and role misses that important point, as I have
not seen a "set role" in the grammar file.

Although in the spec role rights are transitive in the role realm, it
should *stop* at the user. If you drop the user concept, you just have a
group with automatically provided rights.

The fact that the spec does not specify the USER stuff and specifies the
ROLE stuff does not mean that having only roles is the good way to go.


So for me we should have per-cluser users as they where up to now,
per-catalog roles with the properties I described, and possibly
per-cluster group just for the sake of compatibility/simplicity of the
access control and managing group of users as a whole. ROLE should not
replace USER/GROUP. It should be added next to it.


Maybe I'm wrong at my reading of the spec and its intent, and at my quick
check through the status of the cvs head, but that's my current
understanding, and I think it should be checked seriously.

Have a nice day,

--
Fabien

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

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


Dear Stephen,

Thanks again on working on this feature.

> Role right resolution starts from the user and then works backwards up
> the tree, with multi-level resolution. It wouldn't go past the logged
> in user since that's really where it starts.


ISTM that the starting point should *not* be the user, but the
CURRENT_ROLE, which must be something distinct: Even if I'm root, if a
'SET ROLE very_limited_privileges' is performed, then the privileges in
effect are those of the chosen role. That is what is told by section
4.34.1.1 "SQL-session authorization identifiers" of the SQL 2003 specs as
I understand it.

If the user is kind of a role, then I'm afraid the whole point may be
missed. But maybe not, it would depend on the implementation details.

>> So for me we should have per-cluser users as they where up to now,
>> per-catalog roles with the properties I described, and possibly
>> per-cluster group just for the sake of compatibility/simplicity of the
>> access control and managing group of users as a whole. ROLE should not
>> replace USER/GROUP. It should be added next to it.

>
> I don't see much point in having USER or GROUP when we have roles.


Indeed, if you have per-cluster ROLE, you don't need GROUP anymore.

If USER is per-cluster for connection management and ROLE per-catalog for
database access management, then you will need a per-cluster grouping
(say for pg_hba.conf...) which is just the current GROUP.

> Is there something specific that you feel can't be done with roles that
> could be done w/ USER/GROUP?


No, it is the reverse: I'm afraid that the way it seems to be heading, no
more will be done with role than with group before.


> Per-catalog roles is an interesting idea, but I'd tend to think that if
> you want per-catalog roles, you'd want per-catalog users too.


I'm fine with per-cluster users.


> I just went through the spec yesterday, check -hackers for my email


Ok, I'm going to look into that.


> about what CVS head supports vs. what's in the SQL spec. I don't see
> any particular reason why we wouldn't be able to fully support 'Basic
> roles' and 'Extended roles' in 8.1, I think we're quite close now...


I'm looking forward to the 'SET ROLE' implementation. If the
interpretation of the privileges is restricted to the current role, then
I'll be happy.

I still think that removing groups and having per-cluster roles is not a
good idea. The better way would be to keep user/group and add per-catalog
roles. There is an opportunity which is being missed, and that won't show
up later. Well, I can see that I'm pretty alone to think that;-)

Thanks for your answer, have a nice day,

--
Fabien.

---------------------------(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
  #5 (permalink)  
Old 04-11-2008, 05:40 AM
Stephen Frost
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

Fabien & Tom (if you're watching),

* Fabien COELHO (coelho@cri.ensmp.fr) wrote:
> >Role right resolution starts from the user and then works backwards up
> >the tree, with multi-level resolution. It wouldn't go past the logged
> >in user since that's really where it starts.

>
> ISTM that the starting point should *not* be the user, but the
> CURRENT_ROLE, which must be something distinct: Even if I'm root, if a


Err, yes, from the CURRENT_ROLE, which is what we get back from
'GetUserId()', technically I think. I'm not sure the stack has really
been implemented yet (I'd expect it to be done correctly w/ the SET ROLE
things).

> 'SET ROLE very_limited_privileges' is performed, then the privileges in
> effect are those of the chosen role. That is what is told by section
> 4.34.1.1 "SQL-session authorization identifiers" of the SQL 2003 specs as
> I understand it.


Right, that's what the behavior should be.

> If the user is kind of a role, then I'm afraid the whole point may be
> missed. But maybe not, it would depend on the implementation details.


No, I don't think the point will be missed at all. I certainly
understand that privileges are dropped when doing SET ROLE. Really, I
think SET ROLE and the associated SESSION_USER/CURRENT_USER/CURRENT_ROLE
need to be implemented/looked at carefully to make sure the right things
happen.

Tom, if you're watching, are you working on this? I can probably spend
some time today on it, if that'd be helpful.

> >>So for me we should have per-cluser users as they where up to now,
> >>per-catalog roles with the properties I described, and possibly
> >>per-cluster group just for the sake of compatibility/simplicity of the
> >>access control and managing group of users as a whole. ROLE should not
> >>replace USER/GROUP. It should be added next to it.

> >
> >I don't see much point in having USER or GROUP when we have roles.

>
> Indeed, if you have per-cluster ROLE, you don't need GROUP anymore.
>
> If USER is per-cluster for connection management and ROLE per-catalog for
> database access management, then you will need a per-cluster grouping
> (say for pg_hba.conf...) which is just the current GROUP.
>
> >Is there something specific that you feel can't be done with roles that
> >could be done w/ USER/GROUP?

>
> No, it is the reverse: I'm afraid that the way it seems to be heading, no
> more will be done with role than with group before.


Already at least some of the things I was looking for with Roles can be
done, such as a role with members having ownership of an object- this
allows me to create 'admin' roles for a given area without having to
give them superuser(). It's not perfect yet, but it's getting closer.

> >Per-catalog roles is an interesting idea, but I'd tend to think that if
> >you want per-catalog roles, you'd want per-catalog users too.

>
> I'm fine with per-cluster users.


I'm pretty sure others have been asking about per-catalog users and if
we're going to accept that per-catalog roles makes sense I'd really
think per-catalog users would too.

> >about what CVS head supports vs. what's in the SQL spec. I don't see
> >any particular reason why we wouldn't be able to fully support 'Basic
> >roles' and 'Extended roles' in 8.1, I think we're quite close now...

>
> I'm looking forward to the 'SET ROLE' implementation. If the
> interpretation of the privileges is restricted to the current role, then
> I'll be happy.


Right, according to the SQL spec it's a 'stack', where generally the
only thing visible, and what's used for permissions checking, etc, is
whatever is on the top of the stack, so after a 'SET ROLE' you only have
the permissions of that 'SET ROLE'. The only concern I can see here is
that I'm pretty sure the SQL spec allows you to go back (Using 'SET
ROLE' with no argument, or maybe 'SET ROLE NONE', I'd have to
double-check). That makes sense in some instances, but not in others.
There might be room to consider something like 'SET ROLE <role> FINAL'
or some such which disallows going back, though that'd be a PG extension
beyond the SQL spec I'm pretty sure.

> I still think that removing groups and having per-cluster roles is not a
> good idea. The better way would be to keep user/group and add per-catalog
> roles. There is an opportunity which is being missed, and that won't show
> up later. Well, I can see that I'm pretty alone to think that;-)


I really disagree with you here. I feel it makes much more sense to do
this in stages, first user/group -> roles, then roles-per-catalog, which
means you can then have both per-catalog 'users' and per-catalog
'groups', if you want to limit your view to that.

> Thanks for your answer, have a nice day,


Thanks,

Stephen

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCxAURrzgMPqB3kigRAjMDAJ45kMYkz+9gZHHbjGdC4B kzszYMvgCfdhPz
UzvVJshSp66UPf2WmYhM/uM=
=3jS+
-----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, 05:40 AM
Tom Lane
 
Posts: n/a
Default Re: [PATCHES] Users/Groups -> Roles

Stephen Frost <sfrost@snowman.net> writes:
> Tom, if you're watching, are you working on this? I can probably spend
> some time today on it, if that'd be helpful.


I am not; I was hoping you'd deal with SET ROLE. Is it really much
different from SET SESSION AUTHORIZATION?

> I'm pretty sure others have been asking about per-catalog users and if
> we're going to accept that per-catalog roles makes sense I'd really
> think per-catalog users would too.


We really can't do this. Especially not 3 days before feature freeze.

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
  #7 (permalink)  
Old 04-11-2008, 05:40 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:
> > Tom, if you're watching, are you working on this? I can probably spend
> > some time today on it, if that'd be helpful.

>
> I am not; I was hoping you'd deal with SET ROLE. Is it really much
> different from SET SESSION AUTHORIZATION?


No, it's not, but it's going to need to be done carefully to make sure
GetUserId() returns the correct thing at the correct time and that the
other GetSessionUserId() calls are only used where they should be and
that they return the correct information too.

I'll work on SET ROLE and the associated CURRENT_* functions and
information_schema today and tommorow.

> > I'm pretty sure others have been asking about per-catalog users and if
> > we're going to accept that per-catalog roles makes sense I'd really
> > think per-catalog users would too.

>
> We really can't do this. Especially not 3 days before feature freeze.


Right, I wasn't expecting that to be done in this round. It's something
people have asked for though and so might be something to consider for
8.2. I'm hoping your work on CREATEROLE will stem some of that demand
for per-catalog users/roles actually. I've been trying to think what
else per-catalog users/roles would get us besides a segmented namespace.
I think one big issue is that we don't have a 'usage' database check
beyond pg_hba and so any user could get the schema definitions for any
database, which kind of sucks. Is that maybe something we could try to
address for 8.1?

Thanks,

Stephen

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCxAy7rzgMPqB3kigRAsAKAJ9cGszm1HGswDWnQyMwMM PntwaAggCeOO32
S2FExGl+wzRRQMecrktr30A=
=p+Zm
-----END PGP SIGNATURE-----

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

Stephen Frost <sfrost@snowman.net> writes:
> I think one big issue is that we don't have a 'usage' database check
> beyond pg_hba and so any user could get the schema definitions for any
> database, which kind of sucks.


Not unless he can connect to it.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-11-2008, 05:41 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:
> > I think one big issue is that we don't have a 'usage' database check
> > beyond pg_hba and so any user could get the schema definitions for any
> > database, which kind of sucks.

>
> Not unless he can connect to it.


That's controlled by pg_hba.conf though, isn't it? The idea being that
you'd like to give some people the ability to create users/roles, but to
limit the databases those created users/roles could connect to by, say,
requiring they have 'usage' or 'connect' permissions to that database,
which could be set by the database owner; without the database owner
having write permissions to the pg_hba.conf.

The scenario is one of an ISP who wants to give people Postgres access
but doesn't want to have to manage all the users. So, the ISP creates
a database, an 'admin' role for a given customer and gives 'createrole'
permissions to that admin role. The admin role can then create new
roles but can only give them access to connect to their database (since
that's the only one the admin either 'owns' or has 'create', etc,
privileges on). I *think* (perhaps I'm wrong..) that the only thing we
lack to make this work is a permissions check on the connect to a given
database which can be managed by a user of the database (ie: not
pg_hba.conf).

Thinking about this a bit more I guess this would probably involve
basically moving pg_hba.conf into the database catalogs and then having
pg_hba.conf generated similar to how pg_authid is generated. That's
probably too much to do for 8.1 then, I had been hoping there was a way
to do it which would be a smaller change than that.

Thanks,

Stephen

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCxBNsrzgMPqB3kigRAl/vAJ9mTIVoQPtuY9scqS82pW/KDUlf/gCeK9IO
kmKnszrD/No+L5BHTOiQEBA=
=scVP
-----END PGP SIGNATURE-----

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

Stephen Frost <sfrost@snowman.net> writes:
> That's controlled by pg_hba.conf though, isn't it? The idea being that
> you'd like to give some people the ability to create users/roles, but to
> limit the databases those created users/roles could connect to by, say,
> requiring they have 'usage' or 'connect' permissions to that database,
> which could be set by the database owner; without the database owner
> having write permissions to the pg_hba.conf.


You can do that today by putting a group name in pg_hba.conf. Roles
will make it more flexible; I don't see that we need anything more.

For instance, if pg_hba.conf says "samegroup" then you could manage
everything by associating a group with each database.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@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 08:15 PM.


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