pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Nicolas Paris <nicolas.paris@riseup.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Default Privilege Table ANY ROLE
Date: Wed, 14 Nov 2018 21:04:44 +0100
Message-ID: <306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at> (raw)
In-Reply-To: <20181114141608.ryvolxl7v7z2grzi@riseup.net>
References: <20181114141608.ryvolxl7v7z2grzi@riseup.net>

Nicolas Paris wrote:
> I d'like my user be able to select on any new table from other users.
> 
> > ALTER DEFAULT PRIVILEGES  FOR  ROLE "theowner1"  IN SCHEMA "myschema" GRANT  select ON TABLES TO "myuser"
> > ALTER DEFAULT PRIVILEGES  FOR  ROLE "theowner2"  IN SCHEMA "myschema" GRANT  select ON TABLES TO "myuser"
> > ...
> 
> 
> Do I really have to repeat the command for all users ?
> 
> The problem is I have many user able to create tables and all of them
> have to read each other. 

This is one setup that I can come up with:

CREATE ROLE tableowner NOINHERIT;
CREATE ROLE tablereader;
ALTER DEFAULT PRIVILEGES FOR ROLE tableowner IN SCHEMA myschema GRANT SELECT ON TABLES TO tablereader;

CREATE ROLE alice LOGIN IN ROLE tableowner, tablereader;
CREATE ROLE bob LOGIN IN ROLE tableowner, tablereader;

Now whenever "alice" has to create a table, she runs

SET ROLE tableowner;
CREATE TABLE myschema.newtable(x integer);
RESET ROLE;

Then all these tables belong to "tableowner", and each user in group "tablereader"
can SELECT from them:

\z myschema.newtable 
                                     Access privileges
  Schema  |   Name   | Type  |       Access privileges       | Column privileges | Policies 
----------+----------+-------+-------------------------------+-------------------+----------
 myschema | newtable | table | tableowner=arwdDxt/tableowner+|                   | 
          |          |       | tablereader=r/tableowner      |                   | 
(1 row)

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com





view thread (11+ messages)  latest in thread

Message-ID: <306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at>
Permalink:  ../306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at/
Also on:    postgresql.org/message-id/306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at

 · 

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: laurenz.albe@cybertec.at, nicolas.paris@riseup.net
  Subject: Re: Default Privilege Table ANY ROLE
  In-Reply-To: <306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at>
  References: <20181114141608.ryvolxl7v7z2grzi@riseup.net> <306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at>

* 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