Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdqVC-0002Z3-NB for pgsql-general@arkaria.postgresql.org; Fri, 13 Jul 2018 05:20:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdqVA-0001yj-3V for pgsql-general@arkaria.postgresql.org; Fri, 13 Jul 2018 05:20:20 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdqV9-0001xi-Nc for pgsql-general@lists.postgresql.org; Fri, 13 Jul 2018 05:20:19 +0000 Received: from aragorn.net-wizard.org ([138.201.127.29] helo=gandalf.net-wizard.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdqV5-0003xI-Db for pgsql-general@postgresql.org; Fri, 13 Jul 2018 05:20:19 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id D883180AD0; Fri, 13 Jul 2018 07:20:11 +0200 (CEST) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lwKNubB2RNWv; Fri, 13 Jul 2018 07:20:08 +0200 (CEST) Received: from MTEC0211 (mtec-lee-dock-2-133.ethz.ch [129.132.6.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: clavadetscher@swisspug.org) by gandalf.net-wizard.org (Postfix) with ESMTPSA id 9AAC080AAA; Fri, 13 Jul 2018 07:20:04 +0200 (CEST) From: "Charles Clavadetscher" To: =?utf-8?Q?'=C5=81ukasz_Jarych'?= , References: In-Reply-To: Subject: RE: Read only to schema Date: Fri, 13 Jul 2018 07:19:57 +0200 Message-ID: <017e01d41a69$2a5fd9c0$7f1f8d40$@swisspug.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_017F_01D41A79.EDEB1AC0" X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHznPPGGnJz+lyr/RH7IZtKJgF+kaRNlTbw Content-Language: de-ch List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multipart message in MIME format. ------=_NextPart_000_017F_01D41A79.EDEB1AC0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hello =20 From: =C5=81ukasz Jarych [mailto:jaryszek@gmail.com]=20 Sent: Freitag, 13. Juli 2018 07:00 To: pgsql-general@postgresql.org >> PG-General Mailing List = Subject: Read only to schema =20 Hi Guys, =20 Yesterday i tried all day to figure out system to read only schemas.=20 =20 I want to : =20 Here is a try. I did not test it all, but it should go in this = direction. =20 1. Create user who can login (user: jaryszek) =20 CREATE ROLE jaryszek LOGIN; \password jaryszek =20 2. Create role who can read only data (only watching tables) (role: = readonly) =20 Suppose you have a schema xyz =20 GRANT USAGE ON SCHEMA xyz; GRANT SELECT ON ALL TABLES IN SCHEMA xyz TO jaryzsek; =20 3, Create role who can read all data (inserting, deleting, altering, = dropping) (role: readall) =20 CREATE ROLE candoall LOGIN; \password candoall =20 GRANT USAGE, CREATE ON SCHEMA xyz; GRANT SELECT, INSERT, UPDATE DELETE ON ALL TABLES IN SCHEMA xyz TO = candoall; =20 For schema: USAGE: allows users to see or modify contents of tables in the schema CREATE: allows users to create new objects in the schema =20 For tables: SELECT without other privileges: user can only read from tables INSERT, UPDATE, DELETE: Well, that shoud be obvious =20 If you have other objects (sequences, functions, etc) you may need to = add other privileges. =20 What sqls should i use for this?=20 What grants should i add? =20 And now i am logged as jaryszek =20 I want to grant myself role read only to schema public (when owner is = postgres).=20 =20 Schema public has a default privilege setting that grants basically = everything to everybody (public). So you must first revoke all those = privileges from publc. =20 REVOKE ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC; GRANT SELECT ON ALL TABLES IN SCHEMA public TO jaryszek; =20 You may want to change the default privilege settings for schema public. = It would help you to read about which default privileges are set and how = to change them: =20 https://www.postgresql.org/docs/current/static/sql-alterdefaultprivileges= .html =20 Regards Charles =20 I want to review tables as views only, After work i want to grant myself role readall to schema public.=20 =20 It is possible?=20 Or possible workaround ?=20 =20 Best, Jacek ------=_NextPart_000_017F_01D41A79.EDEB1AC0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

Hello

 

From:<= /b> =C5=81ukasz = Jarych [mailto:jaryszek@gmail.com]
Sent: Freitag, 13. Juli = 2018 07:00
To: pgsql-general@postgresql.org >> = PG-General Mailing List = <pgsql-general@postgresql.org>
Subject: Read only to = schema

 

Hi = Guys,

 

Yesterday i tried all day to figure out system to read = only schemas. 

 

I = want to :

 

Here = is a try. I did not test it all, but it should go in this = direction.

 

1.      = Create user who can = login (user: jaryszek)

 

CREATE = ROLE jaryszek LOGIN;

\password jaryszek

 

2.      = Create role who can = read only data (only watching tables) (role: = readonly)

 

Suppose you have a schema = xyz

 

GRANT = USAGE ON SCHEMA xyz;

GRANT SELECT ON ALL TABLES IN SCHEMA xyz TO = jaryzsek;

 

3, Create role who can read all = data (inserting, deleting, altering, dropping) (role: = readall)

 

CREATE = ROLE candoall LOGIN;

\password candoall

 

GRANT = USAGE, CREATE ON SCHEMA xyz;

GRANT = SELECT, INSERT, UPDATE DELETE ON ALL TABLES IN SCHEMA xyz TO = candoall;

 

For = schema:

USAGE: = allows users to see or modify contents of tables in the = schema

CREATE: allows users to create new objects in the = schema

 

For = tables:

SELECT = without other privileges: user can only read from = tables

INSERT, UPDATE, DELETE: Well, that shoud be = obvious

 

If you = have other objects (sequences, functions, etc) you may need to add other = privileges.

 

What sqls should i use for = this? 

What = grants should i add?

 

And now i am logged as = jaryszek

 

I = want to grant myself role read only to schema public (when owner is = postgres). 

 

Schema = public has a default privilege setting that grants basically everything = to everybody (public). So you must first revoke all those privileges = from publc.

 

REVOKE = ALL ON ALL TABLES IN SCHEMA public FROM PUBLIC;

GRANT = SELECT ON ALL TABLES IN SCHEMA public TO = jaryszek;

 

You = may want to change the default privilege settings for schema public. It = would help you to read about which default privileges are set and how to = change them:

 

https://www.postgresql.org/docs/current/static/sql-alterde= faultprivileges.html

 

Regards

Charles

 

I want to review tables as views = only,

After work i = want to grant myself role readall to schema = public. 

 

It is possible? 

Or possible workaround = ? 

 

Best,

Jacek

------=_NextPart_000_017F_01D41A79.EDEB1AC0--