Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1emJkM-0006Im-Pb for pgsql-general@arkaria.postgresql.org; Thu, 15 Feb 2018 13:38:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emJkL-0004QD-SQ for pgsql-general@arkaria.postgresql.org; Thu, 15 Feb 2018 13:38:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1emJgd-0004ya-O5 for pgsql-general@lists.postgresql.org; Thu, 15 Feb 2018 13:34:56 +0000 Received: from aragorn.net-wizard.org ([138.201.127.29] helo=gandalf.net-wizard.org) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1emJS2-0007XW-4j for pgsql-general@postgresql.org; Thu, 15 Feb 2018 13:19:52 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id 05EC280480; Thu, 15 Feb 2018 14:19:45 +0100 (CET) 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 Qncx6eXPeXS5; Thu, 15 Feb 2018 14:19:37 +0100 (CET) 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 2DA478046D; Thu, 15 Feb 2018 14:19:33 +0100 (CET) From: "Charles Clavadetscher" To: "'Durumdara'" , "'Postgres General'" References: <09ca01d3a3e0$685ca460$3915ed20$@swisspug.org> In-Reply-To: Subject: RE: Remove default privilege from DB Date: Thu, 15 Feb 2018 14:19:27 +0100 Message-ID: <0f5a01d3a65f$a0a38010$e1ea8030$@swisspug.org> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0F5B_01D3A668.026A3200" X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHDGTavHGtULrHj3GkiY/OpfM1QIAIxvX6XAgByuFqjpOhNkA== 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_0F5B_01D3A668.026A3200 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi =20 From: Durumdara [mailto:durumdara@gmail.com]=20 Sent: Donnerstag, 15. Februar 2018 12:41 To: Charles Clavadetscher Cc: Postgres General Subject: Re: Remove default privilege from DB =20 Dear Charles! =20 2018-02-12 10:03 GMT+01:00 Charles Clavadetscher = >: Hi =20 From: Durumdara [mailto:durumdara@gmail.com = ]=20 Sent: Montag, 12. Februar 2018 09:32 To: Postgres General > Subject: Remove default privilege from DB =20 Hello! =20 I need to remove default privileges from a Database. After that some of them remains. =20 Default access privileges Owner | Schema | Type | Access privileges ------------+--------+----------+------------------- postgres | | function | =3DX/postgres postgres | | sequence | postgres | | table | postgres | | type | =3DU/postgres suser | | function | =3DX/suser suser | | sequence | suser | | table | suser | | type | =3DU/suser =20 How to completely remove the last items?=20 Could you send me one example? =20 I assume =20 ALTER DEFAULT PRIVILEGES FOR ROLE suser REVOKE EXECUTE ON FUNCTIONS FROM = PUBLIC; ALTER DEFAULT PRIVILEGES FOR ROLE suser REVOKE USAGE ON TYPE FROM = PUBLIC; =20 Bye Charles =20 =20 After that: =20 Default access privileges Owner | Schema | Type | Access privileges ------------+--------+----------+------------------- suser | | function | suser | | sequence | suser | | table | suser | | type | (4 rows) What are they? I am a bit puzzled. I checked the documentation and execute on function = is the hard wired default privilege. https://www.postgresql.org/docs/current/static/sql-grant.html PostgreSQL grants default privileges on some types of objects to PUBLIC. = No privileges are granted to PUBLIC by default on tables, table columns, = sequences, foreign data wrappers, foreign servers, large objects, = schemas, or tablespaces. For other types of objects, the default = privileges granted to PUBLIC are as follows: CONNECT and TEMPORARY = (create temporary tables) privileges for databases; EXECUTE privilege = for functions; and USAGE privilege for languages and data types = (including domains). The object owner can, of course, REVOKE both = default and expressly granted privileges. So after revoking it from public you should actually get an ACL like = {suser=3DX/suser} and the entry for the grants should make it disapper. Example: =20 charles@db.localhost=3D# \ddp Default access privileges Owner | Schema | Type | Access privileges -------+--------+------+------------------- (0 rows) =20 charles@db.localhost=3D# select * from pg_default_acl; defaclrole | defaclnamespace | defaclobjtype | defaclacl ------------+-----------------+---------------+----------- (0 rows) =20 charles@db.localhost=3D# ALTER DEFAULT PRIVILEGES FOR ROLE charlesc = REVOKE EXECUTE ON FUNCTIONS FROM public; ALTER DEFAULT PRIVILEGES charles@db.localhost=3D# \ddp Default access privileges Owner | Schema | Type | Access privileges ----------+--------+----------+--------------------- charlesc | | function | charlesc=3DX/charlesc (1 row) =20 Now only user charlesc can execute (new) functions created by himself. = This is the most typical use case when restricting access to self-made = functions. =20 charles@db.localhost=3D# select * from pg_default_acl; defaclrole | defaclnamespace | defaclobjtype | defaclacl ------------+-----------------+---------------+----------------------- 25269137 | 0 | f | {charlesc=3DX/charlesc} (1 row) =20 charles@db.localhost=3D# ALTER DEFAULT PRIVILEGES FOR ROLE charlesc = GRANT EXECUTE ON FUNCTIONS TO public; ALTER DEFAULT PRIVILEGES charles@db.localhost=3D# \ddp Default access privileges Owner | Schema | Type | Access privileges -------+--------+------+------------------- (0 rows) =20 charles@db.localhost=3D# select * from pg_default_acl; defaclrole | defaclnamespace | defaclobjtype | defaclacl ------------+-----------------+---------------+----------- (0 rows) =20 Now again. everybody can execute functions created by charlesc. What version of PostgreSQL are you using? And how did you get those first entries at all? What happens if you issue ALTER DEFAULT PRIVILEGES FOR ROLE suser GRANT EXECUTE ON FUNCTIONS TO = PUBLIC; again? Regards Charles select * from pg_default_acl 24629;0;"r";"{}" 24629;0;"S";"{}" 24629;0;"f";"{}" 24629;0;"T";"{}" =20 24629 =3D suser | namespace 0 =3D none in document Hmmm... It's very strange for me. I don't find any point which links = this user to this database. =20 Do you have any idea? =20 Thanks dd =20 =20 ------=_NextPart_000_0F5B_01D3A668.026A3200 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi

 

From:<= /b> Durumdara = [mailto:durumdara@gmail.com]
Sent: Donnerstag, 15. Februar = 2018 12:41
To: Charles Clavadetscher = <clavadetscher@swisspug.org>
Cc: Postgres General = <pgsql-general@postgresql.org>
Subject: Re: Remove = default privilege from DB

 

Dear = Charles!

 

2018-02-12 10:03 GMT+01:00 Charles Clavadetscher = <clavadetscher@swisspug.org>:

Hi

 

From:<= /b> Durumdara = [mailto:durumdara@gmail.com]
Sent: Montag, 12. = Februar 2018 09:32
To: Postgres General <pgsql-general@postgresql.org>
Subject:= Remove default privilege from DB

 <= /o:p>

Hello!<= /o:p>

 <= /o:p>

I need to remove default = privileges from a Database.

After that some of them = remains.

 <= /o:p>

        =      Default access = privileges

   Owner  =   | Schema |   Type   | Access = privileges

------------+--------+--------= --+-------------------

 postgres  =  |        | function | = =3DX/postgres

 postgres  =  |        | sequence = |

 postgres  =  |        | table    = |

 postgres  =  |        | type     | = =3DU/postgres

 suser    =     |        | function | = =3DX/suser

 suser    =     |        | sequence = |

 suser    =     |        | table    = |

 suser    =     |        | type     | = =3DU/suser

 

How to completely remove the = last items? 

Could you send me one = example?

 

I = assume

 

ALTER DEFAULT PRIVILEGES FOR ROLE suser REVOKE = EXECUTE ON FUNCTIONS FROM PUBLIC;

ALTER DEFAULT PRIVILEGES FOR ROLE suser REVOKE USAGE = ON TYPE FROM PUBLIC;

 

Bye

Charles

 

 

After that:

 

            =  Default access privileges

   Owner    | Schema |  =  Type   | Access privileges

------------+--------+----------+-------------------

 suser |    =     | function |

 suser |        | sequence = |

 suser |  =       | table    |

 suser |        | type  =    |

(4 = rows)


What are they?

I am a = bit puzzled. I checked the documentation and execute on function is the = hard wired default privilege.

https://www.postgresql.org/docs/current/static/sql-gr= ant.html

PostgreSQL grants default privileges on some types = of objects to PUBLIC. No privileges are granted to PUBLIC by default on = tables, table columns, sequences, foreign data wrappers, foreign = servers, large objects, schemas, or tablespaces. For other types of = objects, the default privileges granted to PUBLIC are as follows: = CONNECT and TEMPORARY (create temporary tables) privileges for = databases; EXECUTE privilege for functions; and USAGE privilege for = languages and data types (including domains). The object owner can, of = course, REVOKE both default and expressly granted = privileges.

So = after revoking it from public you should actually get an ACL like = {suser=3DX/suser} and the entry for the grants should make it = disapper.

Example:

 

charles@db.localhost=3D# \ddp
Default access = privileges

Owner = | Schema | Type | Access privileges

-------+--------+------+-------------------

(0 rows)

 

charles@db.localhost=3D# select * from = pg_default_acl;

= defaclrole | defaclnamespace | defaclobjtype | = defaclacl

------------+-----------------+---------------+------= -----

(0 = rows)

 

charles@db.localhost=3D# ALTER DEFAULT PRIVILEGES = FOR ROLE charlesc REVOKE EXECUTE ON FUNCTIONS FROM = public;

ALTER = DEFAULT PRIVILEGES

charles@db.localhost=3D# = \ddp

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Default access privileges

=C2=A0 = Owner=C2=A0=C2=A0 | Schema |=C2=A0=C2=A0 = Type=C2=A0=C2=A0 |=C2=A0 Access privileges

----------+--------+----------+---------------------<= o:p>

= charlesc |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | function | = charlesc=3DX/charlesc

(1 = row)

 

Now = only user charlesc can execute (new) functions created by himself. This = is the most typical use case when restricting access to self-made = functions.

 

charles@db.localhost=3D# select * from = pg_default_acl;

= defaclrole | defaclnamespace | defaclobjtype = |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 defaclacl

------------+-----------------+---------------+------= -----------------

=C2=A0=C2=A0 25269137 = |=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 0 | = f=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= | {charlesc=3DX/charlesc}

(1 = row)

 

charles@db.localhost=3D# ALTER DEFAULT PRIVILEGES = FOR ROLE charlesc GRANT EXECUTE ON FUNCTIONS TO = public;

ALTER = DEFAULT PRIVILEGES

charles@db.localhost=3D# = \ddp

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = Default access privileges

Owner = | Schema | Type | Access privileges

-------+--------+------+-------------------

(0 rows)

 

charles@db.localhost=3D# select * from = pg_default_acl;

= defaclrole | defaclnamespace | defaclobjtype | = defaclacl

------------+-----------------+---------------+------= -----

(0 = rows)

 

Now = again. everybody can execute functions created by = charlesc.

What = version of PostgreSQL are you using?
And how did you get those first = entries at all?

What = happens if you issue

ALTER = DEFAULT PRIVILEGES FOR ROLE suser GRANT EXECUTE ON FUNCTIONS TO = PUBLIC;

again?

Regards
Charles

select * from pg_default_acl

24629;0;"r";"{}"

24629;0;"S";"{}"

24629;0;"f";"{}"

24629;0;"T";"{}"

 

24629 =3D suser | namespace 0 =3D none in = document

Hmmm... It's very = strange for me. I don't find any point which links this user to this = database.

 

Do you have any idea?

 

Thanks

  dd

 

 

------=_NextPart_000_0F5B_01D3A668.026A3200--