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 1opxlf-0001OV-Ch for pgsql-general@arkaria.postgresql.org; Tue, 01 Nov 2022 20:21:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1opxkf-0007Be-RB for pgsql-general@arkaria.postgresql.org; Tue, 01 Nov 2022 20:20:49 +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 1opxkf-0007BV-BE for pgsql-general@lists.postgresql.org; Tue, 01 Nov 2022 20:20:49 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1opxkc-0000VI-FV for pgsql-general@lists.postgresql.org; Tue, 01 Nov 2022 20:20:48 +0000 Received: by mail-pj1-x102c.google.com with SMTP id b11so14287493pjp.2 for ; Tue, 01 Nov 2022 13:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=3tq/w1HcKVB/qUvvUSZsGZhw2oSDia7WFOdu0eNm4Aw=; b=bL41VnAc2FfIkJqBZQh3E076MmWPUz+P6Vb8GT6mQnyclLhL9p4mZqCYTWCo5m9Et4 A7ipip/SS6hcxkVQswxdnKuVhmiYf07sjEHC0nzhRyQgyr/CtxGolXbYLX7dSKTRx9DU vOohSDV2BlKzBQD0g+ivIIfZiTG3Vfmk7LZM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3tq/w1HcKVB/qUvvUSZsGZhw2oSDia7WFOdu0eNm4Aw=; b=C69bWX1zQfq8soVr1Ei23gkkvQtjKd5NKh8YXTOmvkyvGe8SSAWpzfwy1oUxDVklar vQ8B3bwjiy+JaqLTf0mdyHvvQ5Sh7KgrnZ0n93dAOYeTypWwv4V7EvebeYIAs2C6qLQ/ AwarLp1Q1Hqc2N4NZQS5A/rO7uXb5HKoKJCT72b9R3q48W5xJmmIvWzpkwEXCShKFuvC QVAaBxYhwjliMeDglQmZGIT4LxLcFOvgFKYCvUq2vAF5PGlO9KxILwW219k+Lm+3k7WQ Q8/krtzAAwCg/Iu9crzQ5g52z2/FEMf0aQtDL1VmsqMqoWp51sFepukg+r1EzNHuLLwD g8zA== X-Gm-Message-State: ACrzQf3cZUBUe+v6pdK1Ss3T6pfBbFHPlSde9/8da50mK/UP9I27JAqw UKdwKb3/PG9brs7EDOTcXqfwLg== X-Google-Smtp-Source: AMsMyM4n+iCJ5NF95CeYmPWKUP++0VPaE337vZeeOAXrk0tgVH8O/t1oBXUbJPhEE1vQnL/WL5hKUQ== X-Received: by 2002:a17:902:8343:b0:187:31da:6195 with SMTP id z3-20020a170902834300b0018731da6195mr7111391pln.62.1667334044431; Tue, 01 Nov 2022 13:20:44 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:61dd:7e0a:2be3:8618]) by smtp.gmail.com with ESMTPSA id s26-20020aa78bda000000b005623f96c24bsm6933598pfd.89.2022.11.01.13.20.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Nov 2022 13:20:43 -0700 (PDT) From: Bryn Llewellyn Message-Id: <4B667995-647F-48BB-94CC-22ADE19F0BFB@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_BD5F80F7-3274-4BBA-B554-6CC9496C5BF2" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Putting the O/S user for "local" "peer" authentication in the "postgres" group vs chmod'ing the "pg*.conf" files to be readable by "all" Date: Tue, 1 Nov 2022 13:20:42 -0700 In-Reply-To: Cc: pgsql-general list , "Peter J. Holzer" , Adrian Klaver , laurenz.albe@cybertec.at, Karsten Hilbert To: "David G. Johnston" References: <5EDD4790-7982-4610-8371-9E7F9C7F960B@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=_BD5F80F7-3274-4BBA-B554-6CC9496C5BF2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > david.g.johnston@gmail.com wrote: >=20 >> bryn@yugabyte.com wrote: >>=20 >> It would seem proper to put any user who you want to set up for = "local", "peer" authentication into the "postgres" group >=20 > Did you really mean to write that? >=20 > The postgres o/s user should be able to login using peer. It is a = one-way idea though. Wanting to login using peer says nothing about = whether the user getting that capability should be allowed to mess with = the running server in the operating system. >=20 > As for the rest, all I see is that you are using an opinionated = package manager to install software whose opinions you don't agree with. = Maybe there is some buggy behavior with respect to shared o/s db = administration among users in a common group...you haven't demonstrated = that one way or the other here. I think it is pointless to have the o/s = admin and postgres bootstrap user be anything but postgres and this = whole thing is counter-productive. But if you are going down to first = principles maybe you should install from source and build your own = "package" from that. I meant only to ask a question=E2=80=94and not to pre-judge anything. I = should have thought more carefully about its wording. (I'm thinking = specifically of a PG installation on Linux=E2=80=94and only that.) About "opinionated package manager", I created my installation by = following the steps described here: https://wiki.postgresql.org/wiki/Apt My aim is simply to conform to recommended practice. When I've said = (like I believe that I have) that I didn't get a chance, during the = flow, to specify , my intention was only to note this fact = and to imply that what I got without any intervention coincided with the = recommended practice. This suits me. I'm going to need to use a term to denote the O/S user that very often = ends up with the name "postgres". I don't know what the official term = is. I'll simply say "postgres" here. I haven't yet found an overview of = the set of files that jointly implement a freshly installed PG system. = But, of course, I've noticed where critical directories are. For = example: /usr/lib/postgresql/11/bin Lots of familiar names, like "initdb" are found there. They all have = owner/group "root". And they're all executable by "all". The point has = been made that its not who owns them that matters but, rather, what the = effective user ID is at execution time. I can therefore ignore these for = the purpose of my present question. In contrast, on (my) "data_directory" (I have just one) here: /var/lib/postgresql/11/main I see that every file has owner/group "postgres/postgres". The "owner" = has all privileges. And each of "group" and "all" have no privileges. = This doesn't seem at all surprising. But it does indicate that whatever = privileges some critical file has (anywhere), the set has been = determined by design. There are several "*.conf" files on the same directory as the = "config_file ". For me, it's this: /etc/postgresql/11/main These, too, all have owner/group "postgres/postgres" =E2=80=94 and = "postgres" has all meaningful privileges (presumably "execute" means = nothing for a text config file). But "group=E2=80=9D has only "read" on = them all and "all" has no privileges except (I believe) for = =E2=80=9Cpostgresql.conf"=E2=80=94which is readable by all.=20 I mentioned that I'll presently re-do my PG installation from scratch. = Then I'll record the permissions that all the config files are set up = with and know for sure. I looked in this section: 20.2. File Locations = https://www.postgresql.org/docs/current/runtime-config-file-locations.html= = But "permission" isn't found on the page. Anyway, it's only natural to assume that privileges on all of the = "postgres/postgres" files have been determined in accordance with a = deliberate design. The docs tell me to edit certain of these files to = achieve certain intended effects. I've done this=E2=80=94by authorizing = as the "postgres" O/S user. So there's an inevitable risk (at least for = me) that I might have changed some permissions accidentally. I've observed that, for my present use case (enable "local", "peer" = authentication for an O/S user other than "postgres), the authorization = attempt fails unless that user can read one critical config file. I just = did a careful test with the brand-new O/S user "bob". Here's what "id" = shows: id=3D1003(bob) gid=3D1003(bob) groups=3D1003(bob) uid=3D1001(postgres) gid=3D1001(postgres) = groups=3D1001(postgres),27(sudo),114(ssl-cert) Here's what my "pg_hba.conf" has: local all bob peer My experiment shows that my attempt to authorize as "bob" using = "local", "peer" authorization fails when every config file is readable = only by "owner" and "group". And it shows that a sufficient fix is to = make just "postgresql.conf" readable by "all" (as I believe is the = intention). Of course, an alternative fix (in the sesne that it would = work) would be to have "postgresql.conf" not readable by all but to put = "bob" in the "postgres" group. All this leads to an obvious question: =C2=AB Given that all of the config files have been made readable by "group" = (in contrast to the regime for the data files), what is the intention of = this design? In other words, when is it proper to put an O/S user in the = "postgres" group? After all, if the answer is "never" than no privileges = on "postgres/postgres" files would ever have been granted to "group". =C2=BB --Apple-Mail=_BD5F80F7-3274-4BBA-B554-6CC9496C5BF2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
david.g.johnston@gmail.com wrote:

bryn@yugabyte.com wrote:

It would seem proper to put any user who you want to set up = for "local", "peer" authentication into the "postgres" group

Did you = really mean to write that?

The postgres o/s = user should be able to login using peer.  It is a one-way idea = though.  Wanting to login using peer says nothing about = whether the user getting that capability should be allowed to mess with = the running server in the operating system.

As for the rest, all I see is that you are using an = opinionated package manager to install software whose opinions you = don't agree with.  Maybe there is some buggy behavior with respect = to shared o/s db administration among users in a common group...you = haven't demonstrated that one way or the other here.  I think it is = pointless to have the o/s admin and postgres bootstrap user be = anything but postgres and this whole thing is = counter-productive.  But if you are going down to first = principles maybe you should install from source and build your own = "package" from that.

I meant only to ask a = question=E2=80=94and not to pre-judge anything. I should have thought = more carefully about its wording. (I'm thinking specifically of a PG = installation on Linux=E2=80=94and only that.)

About "opinionated package manager", I = created my installation by following the steps described here:


My aim is simply to = conform to recommended practice. When I've said (like I believe that I = have) that I didn't get a chance, during the flow, to specify <this = or that>, my intention was only to note this fact and to imply that = what I got without any intervention coincided with the recommended = practice. This suits me.

I'm going to need to use a term to denote the O/S user that = very often ends up with the name "postgres". I don't know what the = official term is. I'll simply say "postgres" here. I haven't yet found = an overview of the set of files that jointly implement a freshly = installed PG system. But, of course, I've noticed where critical = directories are. For example:

/usr/lib/postgresql/11/bin

Lots of familiar names, = like "initdb" are found there. They all have owner/group "root". And = they're all executable by "all". The point has been made that its not = who owns them that matters but, rather, what the effective user ID is at = execution time. I can therefore ignore these for the purpose of my = present question.

In contrast, on (my) "data_directory" (I have just one) = here:

/var/lib/postgresql/11/main

I see that every file has owner/group = "postgres/postgres". The "owner" has all privileges. And each of "group" = and "all" have no privileges. This doesn't seem at all surprising. But = it does indicate that whatever privileges some critical file has = (anywhere), the set has been determined by design.

There are several = "*.conf" files on the same directory as the "config_file ". For me, it's = this:

/etc/postgresql/11/main

These, too, all have owner/group "postgres/postgres" =E2=80= =94 and "postgres" has all meaningful privileges (presumably "execute" = means nothing for a text config file). But "group=E2=80=9D has only = "read" on them all and "all" has no privileges except (I believe) for = =E2=80=9Cpostgresql.conf"=E2=80=94which is readable by = all. 

I = mentioned that I'll presently re-do my PG installation from scratch. = Then I'll record the permissions that all the config files are set up = with and know for sure. I looked in this section:
20.2. File Locations

But "permission" isn't found on the page.

Anyway, it's only = natural to assume that privileges on all of the "postgres/postgres" = files have been determined in accordance with a deliberate design. The = docs tell me to edit certain of these files to achieve certain intended = effects. I've done this=E2=80=94by authorizing as the "postgres" O/S = user. So there's an inevitable risk (at least for me) that I might have = changed some permissions accidentally.

I've observed that, for my present use = case (enable "local", "peer" authentication for an O/S user other than = "postgres), the authorization attempt fails unless that user can read = one critical config file. I just did a careful test with the brand-new = O/S user "bob". Here's what "id" shows:

id=3D1003(bob) gid=3D1003(bob) = groups=3D1003(bob)
uid=3D1001(postgres) gid=3D1001(postgres)= groups=3D1001(postgres),27(sudo),114(ssl-cert)

<aside>
I know that I've been told = off for allowing "sudo" for "postgres". I'm only experimenting on my = laptop. But I want to be able to stop the server, delete the datafiles, = create a new cluster, and then start that using a single script. I can't = use "pg_ctl stop/start" because it expects to find its config files on = the data directory. (That's a different story. And I'm not ready to ask = about that yet.) So I use "sudo systemctl stop/start postgresql" because = this method looks in the right place for the config files.
</aside>

Here's what my "pg_hba.conf" has:

  local   all   bob   = peer

My experiment = shows that my attempt to authorize  as "bob" using "local", "peer" = authorization fails when every config file is readable only by "owner" = and "group". And it shows that a sufficient fix is to make just = "postgresql.conf" readable by "all" (as I believe is the intention). Of = course, an alternative fix (in the sesne that it would work) would be to = have "postgresql.conf" not readable by all but to put "bob" in the = "postgres" group.

All this leads to an obvious question:
=C2=AB
Given that all of the config files have been = made readable by "group" (in contrast to the regime for the data files), = what is the intention of this design? In other words, when is it proper = to put an O/S user in the "postgres" group? After all, if the answer is = "never" than no privileges on "postgres/postgres" files would ever have = been granted to "group".
=C2=BB







= --Apple-Mail=_BD5F80F7-3274-4BBA-B554-6CC9496C5BF2--