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 1mdbKS-0002WL-KH for pgsql-general@arkaria.postgresql.org; Thu, 21 Oct 2021 16:54:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdbKR-0006Dp-8F for pgsql-general@arkaria.postgresql.org; Thu, 21 Oct 2021 16:54:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdbKQ-0006Dg-Tz for pgsql-general@lists.postgresql.org; Thu, 21 Oct 2021 16:54:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdbKM-0008Ka-Nf for pgsql-general@lists.postgresql.org; Thu, 21 Oct 2021 16:54:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 19LGrvK62424681; Thu, 21 Oct 2021 12:53:58 -0400 From: Tom Lane To: Adrian Klaver cc: Toomas , Vijaykumar Jain , pgsql-general Subject: Re: Can db user change own password? In-reply-to: References: <62f56a19-0504-4d7b-5f73-b10e8206642a@aklaver.com> <7FC82398-5C8C-4F2D-9620-D16E54E77091@gmail.com> Comments: In-reply-to Adrian Klaver message dated "Thu, 21 Oct 2021 09:13:47 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2424679.1634835237.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 21 Oct 2021 12:53:57 -0400 Message-ID: <2424680.1634835237@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver writes: > On 10/21/21 08:39, Toomas wrote: >> Basically the case was, when *session_user !=3D current_user* then comm= and = >> \password failed with error message =E2=80=9CERROR: =C2=A0permission de= nied=E2=80=9D. All was = >> good when session_user =3D=3D current_user. >> = >> In terms of statement =E2=80=9Csession_user user was set as the owner o= f the = >> database automatically=E2=80=9D - I have a setup where session_user is = changed = >> automatically as database owner when user logs into database. > What I am looking for is a step by step outline that approximates: It's fairly obvious what's happening here: psql sends ALTER USER xxx PASSWORD ..., where it gets xxx from PQuser(), so that is the role name that was logged in with. There are any number of reasons why that might not be the currently active role. The psql man page says \password [ username ] Changes the password of the specified user (by default, the current user). So I'd say this is not doing what the documentation says. With server versions >=3D 9.5 we could dodge the issue by sending ALTER USER CURRENT_USER PASSWORD .... For older servers, I suppose we could do "SELECT CURRENT_USER" first. I'm not sure if we want to change a security-relevant behavior in released branches. But if we don't, we probably need to change the docs to something like "(by default, the logged-in user)". regards, tom lane