Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gN1PQ-00043r-PJ for pgsql-general@arkaria.postgresql.org; Wed, 14 Nov 2018 20:05:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gN1PN-0003dm-PX for pgsql-general@arkaria.postgresql.org; Wed, 14 Nov 2018 20:05:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gN1PN-0003df-HC for pgsql-general@lists.postgresql.org; Wed, 14 Nov 2018 20:05:05 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gN1PH-0001Qi-IJ for pgsql-general@lists.postgresql.org; Wed, 14 Nov 2018 20:05:05 +0000 Received: from smtp2.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 172E5A1056; Wed, 14 Nov 2018 21:04:57 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id Ds0hSokvXezb; Wed, 14 Nov 2018 21:04:55 +0100 (CET) Message-ID: <306e4be880a264c701be5dfa667a1e95de76e175.camel@cybertec.at> Subject: Re: Default Privilege Table ANY ROLE From: Laurenz Albe To: Nicolas Paris , pgsql-general@lists.postgresql.org Date: Wed, 14 Nov 2018 21:04:44 +0100 In-Reply-To: <20181114141608.ryvolxl7v7z2grzi@riseup.net> References: <20181114141608.ryvolxl7v7z2grzi@riseup.net> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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