Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nr3h1-0002NS-BV for pgsql-general@arkaria.postgresql.org; Tue, 17 May 2022 20:21:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nr3gz-0005P9-U5 for pgsql-general@arkaria.postgresql.org; Tue, 17 May 2022 20:21:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nr3gz-0005Oy-Gb for pgsql-general@lists.postgresql.org; Tue, 17 May 2022 20:21:17 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nr3gs-0003Aq-A3 for pgsql-general@lists.postgresql.org; Tue, 17 May 2022 20:21:16 +0000 Received: by mail-pg1-x52c.google.com with SMTP id h186so242355pgc.3 for ; Tue, 17 May 2022 13:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=XSsxctN05mD2g9yf00r8NdZu7CGdov8Mx4xU9J+wtpE=; b=d2X0IHU3kQPTfNbQDWMTYdzaMN/x7iMTx7HlyPx/aYbN+dYBzxHazC50H1XszbOWTv byPTIcmk0tlot549p8m93sFcobtWvpzqFvUVytPs1sYjF3oPbAVkk/3KWN4eKp8fSatj 7pxlL0zXNX+kBgK4aV6Fsr4KRi2pe6hQro0Jw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=XSsxctN05mD2g9yf00r8NdZu7CGdov8Mx4xU9J+wtpE=; b=yrrX+vQAGQM/06zOGuoIGrEvGY43kp0Y2S730SYq41kk1o9zsylQLGAiYky1OVnT4H QB3PQDIR2fMXN2FU0Zx/Morpq3mimWshSDo53HnILZZj0lh/KROQjBOh+hoUitogJPcu x8VxpVfI2XNSritit0Hx/Q8URgaJtzKnZkxkyTRsbbt04jOzBL90y0aqJmoKlMBapOQE AG9kBhqriF6/NBgC0lOuEjg8xeeTSlm7ikeIKSCvj2ypRx6SEzsBFFsjz86EMg9ateRv qpvdvOn5yjF13Jr+wBC5F5gtoxd/Ap3vMsiBmVGaXptS4D8sP8f2a3HkW4yGd4NRcxtC u+tg== X-Gm-Message-State: AOAM532Ka1vSnu72ckr628dZD3p13VZenYk7+W8BpeGnPcdcvMStty/X Y1+2GNHaz6DFvUf030zYzWNd2Q== X-Google-Smtp-Source: ABdhPJw7YTrlQgZvT3Z4CbJjnMaNdzWGv4i/ERAXfwU5ljeTt1mnqK8T/NeoO8s1k/fEwn9WYTwfgA== X-Received: by 2002:a05:6a00:885:b0:510:950f:f787 with SMTP id q5-20020a056a00088500b00510950ff787mr23747874pfj.83.1652818867845; Tue, 17 May 2022 13:21:07 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:c1a5:6d20:fbe4:b33b]) by smtp.gmail.com with ESMTPSA id x13-20020a170902a38d00b0015e8d4eb1d1sm45109pla.27.2022.05.17.13.21.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 May 2022 13:21:06 -0700 (PDT) From: Bryn Llewellyn Message-Id: <099E4479-6ADE-45E6-AA98-27BDD949EE20@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_029A993C-E7EB-4F53-A5AF-C74E9AEB8EBC" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Restricting user to see schema structure Date: Tue, 17 May 2022 13:21:05 -0700 In-Reply-To: Cc: Adrian Klaver , Neeraj M R , Tom Lane PostgreSQL , pgsql-general list To: "David G. Johnston" References: <048ab2c5-ddf6-d039-3c2a-1828d8c9137b@aklaver.com> <569304.1652411286@sss.pgh.pa.us> <228E8A44-A504-4E0D-99BD-71B41812FFE2@yugabyte.com> <557fd2b6-dd2e-66ad-4920-25d173eaf10e@aklaver.com> <84B060E2-4393-4D49-AB4C-BAFCA94620F1@yugabyte.com> <766C91F2-6FF8-4D4B-94BB-39B3BAD2AFE8@yugabyte.com> X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_029A993C-E7EB-4F53-A5AF-C74E9AEB8EBC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > david.g.johnston@gmail.com wrote: >=20 >> bryn@yugabyte.com wrote: >>=20 >> 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? >=20 > By reading the documentation, specifically the chapter linked before, = where this is discussed. >=20 > https://www.postgresql.org/docs/current/ddl-priv.html >=20 > 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. =C2=AB 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. =C2=BB (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? --Apple-Mail=_029A993C-E7EB-4F53-A5AF-C74E9AEB8EBC Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
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.

=C2=AB
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.
=C2=BB

(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?

= --Apple-Mail=_029A993C-E7EB-4F53-A5AF-C74E9AEB8EBC--