pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: connect permission based on database name
Date: Wed, 25 May 2022 08:09:50 -0600
Message-ID: <3659d499-9a98-6362-7c33-d8f2947474b4@gmail.com> (raw)

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;

view thread (6+ messages)  latest in thread

Message-ID: <3659d499-9a98-6362-7c33-d8f2947474b4@gmail.com>
Permalink:  ../3659d499-9a98-6362-7c33-d8f2947474b4@gmail.com/
Also on:    postgresql.org/message-id/3659d499-9a98-6362-7c33-d8f2947474b4@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: robjsargent@gmail.com
  Subject: Re: connect permission based on database name
  In-Reply-To: <3659d499-9a98-6362-7c33-d8f2947474b4@gmail.com>
  References: <3659d499-9a98-6362-7c33-d8f2947474b4@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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