From: Toomas <toomas.kristin@gmail.com>
To: Vijaykumar Jain <vijaykumarjain.github@gmail.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Can db user change own password?
Date: Thu, 21 Oct 2021 18:39:08 +0300
Message-ID: <7FC82398-5C8C-4F2D-9620-D16E54E77091@gmail.com> (raw)
In-Reply-To: <CAM+6J96rw6_PA7vxbogGgnhPmha2A9Ux33sodmYwC6S404g42w@mail.gmail.com>
References: <B340250F-A0E3-43BF-A1FB-2AE36003F68D@gmail.com>
<62f56a19-0504-4d7b-5f73-b10e8206642a@aklaver.com>
<EA29ACFC-830F-49D0-9DFD-8E1974DD791B@gmail.com>
<e1647dd4-3801-1ccd-f452-910aec961060@aklaver.com>
<CAM+6J96rw6_PA7vxbogGgnhPmha2A9Ux33sodmYwC6S404g42w@mail.gmail.com>
Hi,
Basically the case was, when session_user != current_user then command \password failed with error message “ERROR: permission denied”. All was good when session_user == current_user.
In terms of statement “session_user user was set as the owner of the database automatically” - 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 <mailto: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 = 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=# \du
> List of roles
> Role name | Attributes | Member of
> -----------+------------------------------------------------------------+-----------
> postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
>
> postgres=# create role vijay login nosuperuser password '1234';
> CREATE ROLE
> postgres=# grant CONNECT on database postgres to vijay;
> GRANT
> postgres=# \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=> \password
> Enter new password:
> Enter it again:
> postgres=> \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=> \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=> select session_user, current_user;
> session_user | current_user
> --------------+--------------
> vijay | vijay
> (1 row)
>
> postgres=> \password
> Enter new password:
> Enter it again:
> postgres=> alter role vijay password '666'; -- trying both ways, works
> ALTER ROLE
> postgres=> \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=> 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=# create database vijay owner vijay;
> CREATE DATABASE
> postgres=# \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=> select session_user, current_user;
> session_user | current_user
> --------------+--------------
> vijay | vijay
> (1 row)
>
> vijay=> alter role vijay password '999'; -- trying both ways, works
> ALTER ROLE
> vijay=> \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=> \q
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: toomas.kristin@gmail.com, vijaykumarjain.github@gmail.com, adrian.klaver@aklaver.com
Subject: Re: Can db user change own password?
In-Reply-To: <7FC82398-5C8C-4F2D-9620-D16E54E77091@gmail.com>
References: <B340250F-A0E3-43BF-A1FB-2AE36003F68D@gmail.com> <62f56a19-0504-4d7b-5f73-b10e8206642a@aklaver.com> <EA29ACFC-830F-49D0-9DFD-8E1974DD791B@gmail.com> <e1647dd4-3801-1ccd-f452-910aec961060@aklaver.com> <CAM+6J96rw6_PA7vxbogGgnhPmha2A9Ux33sodmYwC6S404g42w@mail.gmail.com> <7FC82398-5C8C-4F2D-9620-D16E54E77091@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox