pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bryn Llewellyn <bryn@yugabyte.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Neeraj M R <neerajmr12219@gmail.com>
Cc: Tom Lane PostgreSQL <tgl@sss.pgh.pa.us>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Restricting user to see schema structure
Date: Tue, 17 May 2022 13:21:05 -0700
Message-ID: <099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.com> (raw)
In-Reply-To: <CAKFQuwZrgdPeoneH8j1oHOBDpbWJwz_iB=HeBGXU6M1rcOgnPQ@mail.gmail.com>
References: <CANV4nBEqKefjxaBJkYrucGDLM41Tr0QehG2WBmoM_D2BXTUrfg@mail.gmail.com>
	<e3b4ecf7-cda2-d47b-cc0e-2b91c3b1c127@aklaver.com>
	<E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com>
	<048ab2c5-ddf6-d039-3c2a-1828d8c9137b@aklaver.com>
	<CAKFQuwYmBFKrfTstgQPSRG-gAt-2Ne=vdQOfmEUL2Sy8x5S6Cg@mail.gmail.com>
	<A0348203-9026-46A0-B53E-3720EA0401F6@yugabyte.com>
	<569304.1652411286@sss.pgh.pa.us>
	<228E8A44-A504-4E0D-99BD-71B41812FFE2@yugabyte.com>
	<CANV4nBFEVNgXy9nTwXuuRRKAY_t-LMdXFeCKVTCnXx9Z6p+P4g@mail.gmail.com>
	<E92A52A6-ACA5-4CDD-B65A-624A2B335E65@yugabyte.com>
	<557fd2b6-dd2e-66ad-4920-25d173eaf10e@aklaver.com>
	<84B060E2-4393-4D49-AB4C-BAFCA94620F1@yugabyte.com>
	<bb217064-ac5f-fa7e-1e66-553373f05d76@aklaver.com>
	<766C91F2-6FF8-4D4B-94BB-39B3BAD2AFE8@yugabyte.com>
	<CAKFQuwZrgdPeoneH8j1oHOBDpbWJwz_iB=HeBGXU6M1rcOgnPQ@mail.gmail.com>

> david.g.johnston@gmail.com wrote:
> 
>> bryn@yugabyte.com wrote:
>> 
>> Right, I see the importance of this now. I now realize that when a database is created, CONNECT on it is automatically granted to PUBLIC. But there's no mention of this (or what to read to learn that this is the case) in the "pg_hba.conf" chapter. Nor does the section on the CREATE DATABASE statement mention this. How is the neophyte supposed to know about this behavior?
> 
> By reading the documentation, specifically the chapter linked before, where this is discussed.
> 
> https://www.postgresql.org/docs/current/ddl-priv.html
> 
> Not saying there isn't room for improvement here, I tend to agree that the SQL Command Reference section should be considered a primary jumping off point.  But the chapter on Data Definition is basically mandatory reading once a DBA wants to do any non-trivial modifications to their cluster.

Thanks again, David. Yes... the section "5.7. Privileges" is essential reading. And I do see what I'd missed now. I broke it into bullets to make it (very much) easier for me at least to parse.

«
PostgreSQL grants privileges on some types of objects to PUBLIC by default when the objects are created.

* 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 procedures;

* USAGE privilege for languages and data types (including domains).

The object owner can, of course, REVOKE both default and expressly granted privileges. (For maximum security, issue the REVOKE in the same transaction that creates the object; then there is no window in which another user can use the object.) Also, these default privilege settings can be overridden using the ALTER DEFAULT PRIVILEGES command.
»

(I'd already been burned by the fact that EXECUTE is granted to PUBLIC on newly-created functions and procedures.)

The paragraph describes very surprising behavior in the present era of "secure by default". The sentence "For maximum security..." at the end emphasizes this and has you go to some effort (CREATE and REVOKE in the same txn) to undo the "insecurity by default" paradigm. I s'pose that compatibility on upgrade means that nothing can change here.

Might it be possible to give the paragraph more prominence (like make it a note and start it with "WARNING" in large letters). And to x-ref it from the CREATE DATABASE section? And from the "pg_hba.conf" section? And correspondingly from the CREATE accounts for the objects of the other types?

view thread (31+ messages)  latest in thread

Message-ID: <099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.com>
Permalink:  ../099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.com/
Also on:    postgresql.org/message-id/099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.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: bryn@yugabyte.com, david.g.johnston@gmail.com, adrian.klaver@aklaver.com, neerajmr12219@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Restricting user to see schema structure
  In-Reply-To: <099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.com>
  References: <CANV4nBEqKefjxaBJkYrucGDLM41Tr0QehG2WBmoM_D2BXTUrfg@mail.gmail.com> <e3b4ecf7-cda2-d47b-cc0e-2b91c3b1c127@aklaver.com> <E9B37863-A142-4898-8BD6-85D46CF2CC29@yugabyte.com> <048ab2c5-ddf6-d039-3c2a-1828d8c9137b@aklaver.com> <CAKFQuwYmBFKrfTstgQPSRG-gAt-2Ne=vdQOfmEUL2Sy8x5S6Cg@mail.gmail.com> <A0348203-9026-46A0-B53E-3720EA0401F6@yugabyte.com> <569304.1652411286@sss.pgh.pa.us> <228E8A44-A504-4E0D-99BD-71B41812FFE2@yugabyte.com> <CANV4nBFEVNgXy9nTwXuuRRKAY_t-LMdXFeCKVTCnXx9Z6p+P4g@mail.gmail.com> <E92A52A6-ACA5-4CDD-B65A-624A2B335E65@yugabyte.com> <557fd2b6-dd2e-66ad-4920-25d173eaf10e@aklaver.com> <84B060E2-4393-4D49-AB4C-BAFCA94620F1@yugabyte.com> <bb217064-ac5f-fa7e-1e66-553373f05d76@aklaver.com> <766C91F2-6FF8-4D4B-94BB-39B3BAD2AFE8@yugabyte.com> <CAKFQuwZrgdPeoneH8j1oHOBDpbWJwz_iB=HeBGXU6M1rcOgnPQ@mail.gmail.com> <099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.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