pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
connect permission based on database name
6+ messages / 3 participants
[nested] [flat]

* connect permission based on database name
@ 2022-05-25 14:09  Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Rob Sargent @ 2022-05-25 14:09 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Just wondering if I've bumped into some security issue.

I'm somewhat surprised that "grant connect to database <dbname>  to 
<role>" appears to be stored "by name"?

I have the luxury of dropping/recreate databases at will (within 
limits).  My script for creating a new db also creates a role and grants 
that role access to that database.  Of course on re-running the script a 
second time (with same names for db, role) the portion of the script 
dealing with the role, in its own transaction, fails after the "create 
role" line.  All that is clearly understood. (And I realize I could 
clean up the role per drop db.)
However, I can still connect to the new database (of same name) using 
the previously connected role using psql --user role --dbname db.  For 
the original "grant connect" to still be in play, wouldn't it have to be 
store using dbname as opposed to an id?  In a different environment, I 
can see it might be surprising that an "old" role could connect to a 
"new" database.

    begin;
    create schema if not exists study\p\g
    create role role with login encrypted password 'password'\p\g
    alter role role set search_path=study,base,public\p\g
    grant connect on database dbname to role\p\g
    -- 
    -- Allow this role to diddle with base, bulk and project tables
    -- 
    grant all on schema base, bulk, study to role\p\g
    grant all on all tables in schema base, bulk, study to role\p\g
    commit;

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: connect permission based on database name
@ 2022-05-25 14:20  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Tom Lane @ 2022-05-25 14:20 UTC (permalink / raw)
  To: Rob Sargent <robjsargent@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

Rob Sargent <robjsargent@gmail.com> writes:
> Just wondering if I've bumped into some security issue.
> I'm somewhat surprised that "grant connect to database <dbname>  to 
> <role>" appears to be stored "by name"?

I think you are forgetting that databases have a default GRANT CONNECT
TO PUBLIC.  You need to revoke that before other grants/revokes will
have any functional effect.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: connect permission based on database name
@ 2022-05-25 14:27  Rob Sargent <robjsargent@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 6+ messages in thread

From: Rob Sargent @ 2022-05-25 14:27 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On 5/25/22 08:20, Tom Lane wrote:
> Rob Sargent<robjsargent@gmail.com>  writes:
>> Just wondering if I've bumped into some security issue.
>> I'm somewhat surprised that "grant connect to database <dbname>  to
>> <role>" appears to be stored "by name"?
> I think you are forgetting that databases have a default GRANT CONNECT
> TO PUBLIC.  You need to revoke that before other grants/revokes will
> have any functional effect.
>
> 			regards, tom lane
Yes, of course.  Thanks

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: connect permission based on database name
@ 2022-05-25 14:38  Rob Sargent <robjsargent@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 6+ messages in thread

From: Rob Sargent @ 2022-05-25 14:38 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On 5/25/22 08:20, Tom Lane wrote:
> Rob Sargent<robjsargent@gmail.com>  writes:
>> Just wondering if I've bumped into some security issue.
>> I'm somewhat surprised that "grant connect to database <dbname>  to
>> <role>" appears to be stored "by name"?
> I think you are forgetting that databases have a default GRANT CONNECT
> TO PUBLIC.  You need to revoke that before other grants/revokes will
> have any functional effect.
>
> 			regards, tom lane
And then the search path is "just a string"?

    psql --user oldrole --dbname newdb --host $DBHOST
    psql (12.11, server 12.7)
    SSL connection (protocol: TLSv1.2, cipher:
    ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
    Type "help" for help.

    newdb=> show search_path;
         search_path
    --------------------
      study, base, public
    (1 row)

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: connect permission based on database name
@ 2022-05-25 14:44  David G. Johnston <david.g.johnston@gmail.com>
  parent: Rob Sargent <robjsargent@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread

From: David G. Johnston @ 2022-05-25 14:44 UTC (permalink / raw)
  To: Rob Sargent <robjsargent@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Wednesday, May 25, 2022, Rob Sargent <robjsargent@gmail.com> wrote:

> On 5/25/22 08:20, Tom Lane wrote:
>
> Rob Sargent <robjsargent@gmail.com> <robjsargent@gmail.com> writes:
>
> Just wondering if I've bumped into some security issue.
> I'm somewhat surprised that "grant connect to database <dbname>  to
> <role>" appears to be stored "by name"?
>
> I think you are forgetting that databases have a default GRANT CONNECT
> TO PUBLIC.  You need to revoke that before other grants/revokes will
> have any functional effect.
>
> 			regards, tom lane
>
> And then the search path is "just a string"?
>
>
>
Search_path isn’t a security component and accepts, but ignores, unknown
names.  So yes, it is just a string.

David J.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: connect permission based on database name
@ 2022-05-25 14:45  Rob Sargent <robjsargent@gmail.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Rob Sargent @ 2022-05-25 14:45 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On 5/25/22 08:44, David G. Johnston wrote:
> On Wednesday, May 25, 2022, Rob Sargent <robjsargent@gmail.com> wrote:
>
>     On 5/25/22 08:20, Tom Lane wrote:
>>     Rob Sargent<robjsargent@gmail.com>  <mailto:robjsargent@gmail.com>  writes:
>>>     Just wondering if I've bumped into some security issue.
>>>     I'm somewhat surprised that "grant connect to database <dbname>  to
>>>     <role>" appears to be stored "by name"?
>>     I think you are forgetting that databases have a default GRANT CONNECT
>>     TO PUBLIC.  You need to revoke that before other grants/revokes will
>>     have any functional effect.
>>
>>     			regards, tom lane
>     And then the search path is "just a string"?
>
>
>
> Search_path isn’t a security component and accepts, but ignores, 
> unknown names.  So yes, it is just a string.
>
> David J.
>
Roger that, thanks.

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2022-05-25 14:45 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 14:09 connect permission based on database name Rob Sargent <robjsargent@gmail.com>
2022-05-25 14:20 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-05-25 14:27   ` Rob Sargent <robjsargent@gmail.com>
2022-05-25 14:38   ` Rob Sargent <robjsargent@gmail.com>
2022-05-25 14:44     ` David G. Johnston <david.g.johnston@gmail.com>
2022-05-25 14:45       ` Rob Sargent <robjsargent@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox