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 1ooyse-0003xm-8V for pgsql-general@arkaria.postgresql.org; Sun, 30 Oct 2022 03:21:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ooysd-0007lO-5F for pgsql-general@arkaria.postgresql.org; Sun, 30 Oct 2022 03:20:59 +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 1ooysc-0007lF-Lo for pgsql-general@lists.postgresql.org; Sun, 30 Oct 2022 03:20:58 +0000 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ooysZ-0007ck-C1 for pgsql-general@lists.postgresql.org; Sun, 30 Oct 2022 03:20:58 +0000 Received: by mail-pg1-x536.google.com with SMTP id 20so8049805pgc.5 for ; Sat, 29 Oct 2022 20:20:54 -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=luVD4DZKLzm5/DbRLx9BBgnabFyqHr9Ph+cSnEOTrN8=; b=euQNT2QAPiSKvNXj/Ua/m7pV0gCJwkhT2vBJ12zBEc5Uc5zKAb2JLo6Zf85JpyO6Jn 9Y/TwHRRuAG2lW4sQpEKb1lG1o251PhuZabSCK79vE0rqFnYdq8MZ1m8yaGDRy5ErKLf oX3Eon1N7SCjVO5df7jTlLDaY81ZWsV+9slMk= 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=luVD4DZKLzm5/DbRLx9BBgnabFyqHr9Ph+cSnEOTrN8=; b=q3Sb9XKSTSRfjc/pWgTEcwAXmLOYD44wa6aP5xhe7Fyfob4LjGdiW8pkELYcen/f9X lJcoaIy8rSY2OOs6MGX7gpHJUTkB5DVgNeBMhKW54TH0G+jH6OsrG4/JnBNp0M/Yf7g9 E/t50/eSJ7RPtNn6EfncjzqWl0IYirPz4NzFNamtgi9b9Vae9tctQ/zeOXiOM04kOb6I /Fn7YDwyYN6yxIRrq046ns7d8HfpjfcdIbuIHhmo5oYCSkJjMMgtQrdoieRStblyl4AJ XKakXPvpLKjNq8hoC4yL5roF2u9ktOPPP9VM38GXsFO7zlRiX1APxrvcO/6MGXzFH6QW RiIA== X-Gm-Message-State: ACrzQf1Gj4dv9X9f9exXtSi0nG1pXGHBRmOBuojye8WVo231J4Weiu3/ lObVmOLeYNqTRy3XEgfOjVcvqQ== X-Google-Smtp-Source: AMsMyM6v8x25vNmL41YLVqdPs4DCdnfSQrbinws4wIIO5ajoqmUzVdhyrM/V7v2/Wwfz0Z0nFZNQWw== X-Received: by 2002:a63:88c8:0:b0:46f:1e8d:ece9 with SMTP id l191-20020a6388c8000000b0046f1e8dece9mr6464404pgd.249.1667100052691; Sat, 29 Oct 2022 20:20:52 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:6092:b354:42ed:abbd]) by smtp.gmail.com with ESMTPSA id 68-20020a17090a09ca00b0021134a19ae2sm1653053pjo.50.2022.10.29.20.20.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2022 20:20:52 -0700 (PDT) From: Bryn Llewellyn Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_3094B874-9395-4E68-AF37-CBCADEAEDB1D" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: "peer" authentication: cannot make "pg_ident.conf" work as I believe that the doc says that it should Date: Sat, 29 Oct 2022 20:20:50 -0700 In-Reply-To: Cc: "David G. Johnston" , pgsql-general list To: Adrian Klaver References: <9801E977-425C-41BF-B024-19BC875940C0@icloud.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=_3094B874-9395-4E68-AF37-CBCADEAEDB1D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > adrian.klaver@aklaver.com wrote: >=20 >> bryn@yugabyte.com wrote: >>=20 >> ...What am I doing wrong? >=20 > You skipped over this part of my post and the documentation (Section = 21.2): > https://www.postgresql.org/docs/current/auth-pg-hba-conf.html = >=20 > "The map-name is an arbitrary name that will be used to refer to this = mapping in pg_hba.conf." >=20 > This example below is for the ident auth method but the same syntax = applies to peer. >=20 > # TYPE DATABASE USER ADDRESS METHOD > host all all 192.168.0.0/16 ident = map=3Domicron >=20 > pg_ident.conf and pg_hba.conf are two separate files and the only way = information gets from the former to the latter is if you explicitly = include the map name under METHOD for the the auth line. Yes, Adrian, I see that I did slip up. Thanks, David, for pointing out = this same error in your separate reply. I=E2=80=99m advertising my = stupidity in this area rather effectively. My problem stems from the = fact that the goal statement that my inner voice expresses seems so = simple to state. This is what I want: 1. I want to do this at the O/S prompt on the machine where my PG = cluster has been started: "su mary". 2. Then I want to start a session (I use "psql" here an an example) like = this: "psql -d postgres". 3. Then, at the "psql" prompt, I want "select session_user" to show = "bob". It would have seemed to me, knowing just that the goal is achievable, = that I could express this declaratively in one place=E2=80=94without = needing to name the mapping between the system user's name and the = cluster role's name, thus: authentication type: local authentication method: peer system user: mary cluster role: bob I know that it isn't like this. But I have no intuition for why it could = not be like this=E2=80=94and so it's easy for me to get muddled. For the purpose of the tests that follow, I set up the O/S users "bob" = and "mary" so that "id bob mary postgres" shows this: id=3D1002(bob) gid=3D1001(postgres) groups=3D1001(postgres) uid=3D1003(mary) gid=3D1001(postgres) groups=3D1001(postgres) uid=3D1001(postgres) gid=3D1001(postgres) = groups=3D1001(postgres),27(sudo),114(ssl-cert) And I set up the cluster-roles "bob" and "mary" so that "\du" shows = this: bob | | = {} mary | | = {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | = {} Then I started with this in "pg_hba.conf": ... # TYPE DATABASE USER METHOD [auth-options] # ---- -------------- -------------- ------ = ---------------------------- local all bob peer local all mary peer ... together with en empty "pg_ident.conf". So far, after either "su bob" or = "su mary", i was able to confirm that the bare "psql -d postgres" worked = fine and that then "select session_user" showed, respectively, "bob" or = "mary", too. Then I changed "pg_hba.conf" to add a mapping for "mary" thus: # TYPE DATABASE USER METHOD [auth-options] # ---- -------------- -------------- ------ = ---------------------------- local all bob peer local all mary peer map=3Dbllewell But I left "pg_ident.conf" deliberately empty. I expected, now, that = "psql -d postgres" would still work fine for "bob" but that if would = fail for "mary". With this deliberate error in place, I found that after = "su bob", the bare "psql -d postgres" worked fine. But after "su mary", = the same command caused this error: Peer authentication failed for user "mary" I assume that the phrase =C2=AB user "mary" =C2=BB means the O/S user = "mary". It seems to me that the message =C2=AB no entry for the mapping = "bllewell" in "pg_ident.conf" =C2=BB would be more helpful. But maybe = that would need psychic powers. Next, I put an identity mapping in for "mary" in "pg_ident.conf" thus: # MAPNAME SYSTEM-USERNAME PG-USERNAME # ------- --------------- ----------- bllewell mary mary So, "bob" is the simple case. And "mary" is one step harder. Now, the = unqualified "psql -d postgres" works again for "mary" (and it still = works, of course, for "bob"). So far, so good. Now for the test, I mapped "mary" to "bob" in = "pg_ident.conf" thus: # MAPNAME SYSTEM-USERNAME PG-USERNAME # ------- --------------- ----------- bllewell mary bob As I'd expect, O/S "bob" still works fine and ends up as cluster-role = "bob". But now, the attempt by O/S "mary" to connect using "psql -d = postgres" fails, as it had ealier, with what boils sown to "computer = says No": Peer authentication failed for user "mary" I still don't have a mental model that can explain this. As I reason it, = the name "mary" is passed to the step that's informed by "pg_hba.conf" = because it's available from the facts about the O/S user that's running = the shell. Then, seeing "map=3Dbllewell", the name "mary" is looked up = in "pg_ident.conf" (just as it was in the previous test). Only now, = instead of mapping it to the cluster-role "mary", which had worked, it = now maps it to the role "bob". Why can it not connect, now, as "Bob"? Clutching at straws, I reversed the mutual order of "mary" and "bob" in = "pg_ident.conf"=E2=80=94even though that seemed wrong. It made no = difference to the spelling of the =C2=AB Peer authentication failed for = user "mary" =C2=BB error. I've read the two relevant doc sections as carefully as I can. I can't = see what I'm missing. I also confirmed with this query select name, setting from pg_settings where category =3D 'File Locations'; =20 that the files that I've been editing are indeed the files that the = server uses. Do I have to grant permission in some way to allow O/S "mary" to connect = as cluster-role "bob". I though that I had exactly done this by the = facts in "pg_hba.conf" and "pg_ident.conf". I'm still missing something. What is it? --Apple-Mail=_3094B874-9395-4E68-AF37-CBCADEAEDB1D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

...What am I = doing wrong?

You = skipped over this part of my post and the documentation (Section = 21.2):
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html





























= --Apple-Mail=_3094B874-9395-4E68-AF37-CBCADEAEDB1D--