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 1mdaA1-0007uB-7t for pgsql-general@arkaria.postgresql.org; Thu, 21 Oct 2021 15:39:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdaA0-0001IJ-18 for pgsql-general@arkaria.postgresql.org; Thu, 21 Oct 2021 15:39:16 +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 1mda9z-0001IA-JX for pgsql-general@lists.postgresql.org; Thu, 21 Oct 2021 15:39:15 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mda9w-0005fb-W7 for pgsql-general@lists.postgresql.org; Thu, 21 Oct 2021 15:39:15 +0000 Received: by mail-lj1-x234.google.com with SMTP id g8so549536ljn.4 for ; Thu, 21 Oct 2021 08:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=GXHEeKHB1Y9XzClKpqvCw/ytSMtcjpdDG3hlEfeaa7Y=; b=bN5aMTCBWFr0Inr3DzvHFURU0L16YH+DIyTSB97ah7Fk4AMQu1hA1Z8w+Jdr/9u9MX bEU12mU6nDS2VVL/GfU+cqqSib/SNrQsVSRT0PnPIjgJD96nFhCqwSIlHsczewEpc9q8 TPTp3Fed8Uwsc8WSfKPDRrHQUtG8LgdnCxNfB897/MJiLRpnKfC0FylxmR/39Oc5tkCt 65Wa3YuCD9i4bbCuUDTdy1TwleWUbRJSuGa1FJtUxP8Q6M2/AIirtRqWwSCg2W2M7uvc L4Lyb78H8VyHQWbyRaBiDdg7HVkvO8BM5YT3XUxAP538MIZxRZm2MhL+LqCAbC9iVYrx VFAQ== 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=GXHEeKHB1Y9XzClKpqvCw/ytSMtcjpdDG3hlEfeaa7Y=; b=2Hs0Qvu61Q8WkbmYKS7/t31EOfoENF/+2Ul8uLCGAT/kyF6KAI6A1RATUUB14fjzDd fa3ZoRTQBDdWYk0UtmqIkVzLra7Rl+0Fq45ibmpjZ19lNes3smgpGZkuXUoZ3hgGbJex Map5+Vc9FX7xpOUtIxaxzZ59Lt5u/9xvFWtbdi49FPkHgiz+ANVY0OFG8DpbhI9gwi8a duqVgdT9+8Ond5WiARvasBYdUN2UZDT+fcfrbCjCkUM+1nEmRammrFGWmNUM9mPxq4h+ ARkK9UXBwyFeyM74WHIxRQhCq0N8hmNZxF8FLXzLc7Y2fo5emcIFP11PZTrCXov+ydq0 ST2A== X-Gm-Message-State: AOAM533+KklfqswP6U9P/z1TrVFt2WjFMFY7/zNK1nToexzFkG9rHCiP uVt5cLBDb9q/glpH4IkJKDtpHa1aOKM= X-Google-Smtp-Source: ABdhPJwqa93u+POpnqB0w+gAvKyu2/RgU4y40O5WSaIumtBJ7FJd+JcPbWawymGXFBaeloHzAB7/7g== X-Received: by 2002:a2e:3e16:: with SMTP id l22mr6865066lja.210.1634830751757; Thu, 21 Oct 2021 08:39:11 -0700 (PDT) Received: from smtpclient.apple (94-93-157-37.dyn.estpak.ee. [37.157.93.94]) by smtp.gmail.com with ESMTPSA id l26sm489753lfh.247.2021.10.21.08.39.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 08:39:09 -0700 (PDT) From: Toomas Message-Id: <7FC82398-5C8C-4F2D-9620-D16E54E77091@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_E3DD7E3D-A7BA-4E1C-BC80-8C349C6DEE15" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Can db user change own password? Date: Thu, 21 Oct 2021 18:39:08 +0300 In-Reply-To: Cc: Adrian Klaver , pgsql-general To: Vijaykumar Jain References: <62f56a19-0504-4d7b-5f73-b10e8206642a@aklaver.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=_E3DD7E3D-A7BA-4E1C-BC80-8C349C6DEE15 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, Basically the case was, when session_user !=3D current_user then command = \password failed with error message =E2=80=9CERROR: permission = denied=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 of = the database automatically=E2=80=9D - I have a setup where session_user = is changed automatically as database owner when user logs into database. BR, Toomas > On 20. Oct 2021, at 18:43, Vijaykumar Jain = wrote: >=20 >=20 >=20 > On Wed, 20 Oct 2021 at 20:52, Adrian Klaver > wrote: > On 10/20/21 08:07, Toomas wrote: > > Hi Adrian, > >=20 > > Thank you for your help. The issue was that when user logged into = database his session_user user was set as owner of database = automatically. User had success to change password when session_user =3D = current_user was set before. >=20 > I'm not understanding. You will need to sketch this out: >=20 > 1) Connection parameters for log in with . >=20 > 2) On log in the output from: select session_user, current_user; >=20 > 3) Define '...set as owner of database automatically'. >=20 >=20 > Toomas,=20 > things work for me as expected.=20 >=20 > I guess as asked, you may want to show an example for your below = statement to help understand better. > "The issue was that when a user logged into the database his = session_user user was set as the owner of the database automatically." >=20 >=20 > postgres@u1:~$ psql > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > Type "help" for help. >=20 > postgres=3D# \du > List of roles > Role name | Attributes = | Member of > = -----------+------------------------------------------------------------+-= ---------- > postgres | Superuser, Create role, Create DB, Replication, Bypass = RLS | {} >=20 > postgres=3D# create role vijay login nosuperuser password '1234'; > CREATE ROLE > postgres=3D# grant CONNECT on database postgres to vijay; > GRANT > postgres=3D# \q > postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h 127.0.0.1 > Password for user vijay: > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, = bits: 256, compression: off) > Type "help" for help. >=20 > postgres=3D> \password > Enter new password: > Enter it again: > postgres=3D> \q > postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h 127.0.0.1 # old = password > Password for user vijay: > psql: error: FATAL: password authentication failed for user "vijay" > FATAL: password authentication failed for user "vijay" > postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h 127.0.0.1 # new = password > Password for user vijay: > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, = bits: 256, compression: off) > Type "help" for help. >=20 > postgres=3D> \q > =20 > postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h 127.0.0.1 > Password for user vijay: > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, = bits: 256, compression: off) > Type "help" for help. >=20 > postgres=3D> select session_user, current_user; > session_user | current_user > --------------+-------------- > vijay | vijay > (1 row) >=20 > postgres=3D> \password > Enter new password: > Enter it again: > postgres=3D> alter role vijay password '666'; -- trying both ways, = works > ALTER ROLE > postgres=3D> \q > postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h 127.0.0.1 > Password for user vijay: > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, = bits: 256, compression: off) > Type "help" for help. >=20 > postgres=3D> select session_user, current_user; > session_user | current_user > --------------+-------------- > vijay | vijay > (1 row) >=20 >=20 > postgres@u1:~$ psql > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > Type "help" for help. >=20 > postgres=3D# create database vijay owner vijay; > CREATE DATABASE > postgres=3D# \q > postgres@u1:~$ psql -U vijay -p 5432 -d vijay -h 127.0.0.1 > Password for user vijay: > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, = bits: 256, compression: off) > Type "help" for help. >=20 > vijay=3D> select session_user, current_user; > session_user | current_user > --------------+-------------- > vijay | vijay > (1 row) >=20 > vijay=3D> alter role vijay password '999'; -- trying both ways, works > ALTER ROLE > vijay=3D> \q > postgres@u1:~$ psql -U vijay -p 5432 -d vijay -h 127.0.0.1 > Password for user vijay: > psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1)) > SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, = bits: 256, compression: off) > Type "help" for help. >=20 > vijay=3D> \q --Apple-Mail=_E3DD7E3D-A7BA-4E1C-BC80-8C349C6DEE15 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi,

Basically the case was, when session_user !=3D = current_user then command \password failed with error message = =E2=80=9CERROR:  permission denied=E2=80=9D. All was good when = session_user =3D=3D current_user.

In terms of statement =E2=80=9Csession_us= er user was set as the owner of the database automatically=E2=80=9D - I = have a setup where session_user is changed automatically as database = owner when user logs into database.

BR,
Toomas

On 20. Oct 2021, at 18:43, Vijaykumar Jain <vijaykumarjain.github@gmail.com> wrote:



On Wed, 20 Oct 2021 at = 20:52, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 10/20/21 = 08:07, Toomas wrote:
> Hi Adrian,
> 
> Thank = you for your help. The issue was that when user logged into database his = session_user user was set as owner of database automatically. User had = success to change password when session_user =3D current_user was set = before.

I'm not understanding. You will = need to sketch this out:

1) Connection = parameters for log in with <user_name>.

2) On log in the output from: select session_user, = current_user;

3) Define '...set as owner of = database automatically'.


Toomas, 
things work for me as expected. 

I guess as asked, you = may want to show an example for your below statement to help = understand better.
"The issue was = that when a user logged into the database his session_user user was set = as the owner of the database automatically."


postgres@u1:~$ psql
psql (12.8 (Ubuntu = 12.8-0ubuntu0.20.04.1))
Type "help" for = help.

postgres=3D= # \du
            =                     =    List of roles
 Role name |  =                     =    Attributes              =            | Member of
-----------+---------------------------------------------------= ---------+-----------
 postgres  | = Superuser, Create role, Create DB, Replication, Bypass RLS | = {}

postgres=3D# = create role vijay login nosuperuser password '1234';
CREATE ROLE
postgres=3D# grant CONNECT = on database postgres to vijay;
GRANT
postgres=3D# \q
postgres@u1:~$ psql -U = vijay -p 5432 -d postgres -h 127.0.0.1
Password for = user vijay:
psql (12.8 (Ubuntu = 12.8-0ubuntu0.20.04.1))
SSL connection (protocol: = TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: = off)
Type "help" for help.

postgres=3D> \password
Enter new password:
Enter it = again:
postgres=3D> \q
postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h = 127.0.0.1  # old password
Password for user = vijay:
psql: error: FATAL:  password = authentication failed for user "vijay"
FATAL:  = password authentication failed for user "vijay"
postgres@u1:~$ psql -U vijay -p 5432 -d postgres -h 127.0.0.1 = # new password
Password for user vijay:
psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
SSL connection (protocol: TLSv1.3, cipher: = TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=3D> \q
 
postgres@u1:~$ = psql -U vijay -p 5432 -d postgres -h 127.0.0.1
Password for user vijay:
psql (12.8 = (Ubuntu 12.8-0ubuntu0.20.04.1))
SSL connection = (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, = compression: off)
Type "help" for help.

postgres=3D> select = session_user, current_user;
 session_user | = current_user
--------------+--------------
 vijay        | vijay
(1 row)

postgres=3D> \password
Enter new = password:
Enter it again:
postgres=3D> alter role vijay password '666'; -- trying = both ways, works
ALTER ROLE
postgres=3D> \q
postgres@u1:~$ psql = -U vijay -p 5432 -d postgres -h 127.0.0.1
Password = for user vijay:
psql (12.8 (Ubuntu = 12.8-0ubuntu0.20.04.1))
SSL connection (protocol: = TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: = off)
Type "help" for help.

postgres=3D> select session_user, = current_user;
 session_user | = current_user
--------------+--------------
 vijay        | vijay
(1 row)


postgres@u1:~$ psql
psql (12.8 (Ubuntu = 12.8-0ubuntu0.20.04.1))
Type "help" for = help.

postgres=3D= # create database vijay owner vijay;
CREATE = DATABASE
postgres=3D# \q
postgres@u1:~$ psql -U vijay -p 5432 -d vijay -h = 127.0.0.1
Password for user vijay:
psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
SSL connection (protocol: TLSv1.3, cipher: = TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

vijay=3D> select session_user, = current_user;
 session_user | = current_user
--------------+--------------
 vijay        | vijay
(1 row)

vijay=3D> alter role vijay password '999'; -- trying both = ways, works
ALTER ROLE
vijay=3D> \q
postgres@u1:~$ psql -U = vijay -p 5432 -d vijay -h 127.0.0.1
Password for = user vijay:
psql (12.8 (Ubuntu = 12.8-0ubuntu0.20.04.1))
SSL connection (protocol: = TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: = off)
Type "help" for help.

vijay=3D> = \q

= --Apple-Mail=_E3DD7E3D-A7BA-4E1C-BC80-8C349C6DEE15--