From: Toomas <toomas.kristin@gmail.com>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Vijaykumar Jain <vijaykumarjain.github@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: Can db user change own password?
Date: Thu, 21 Oct 2021 20:32:18 +0300
Message-ID: <FECE58B3-40D1-4FBA-867C-869C18B35582@gmail.com> (raw)
In-Reply-To: <e2c57ee7-75d7-6a03-d9f2-052a8e880f9c@aklaver.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>
<e2c57ee7-75d7-6a03-d9f2-052a8e880f9c@aklaver.com>
Hi,
DB user has definition
GRANT db_owner TO db_user;
ALTER ROLE db_user IN DATABASE db SET role TO ‘db_owner’;
and user logs in with command
1) $ psql -U db_user -d db
2) db=> select current_user, session_user;
current_user | session_user
--------------+--------------
db_owner | db_user
(1 row)
3) db=> \du db_user
List of roles
Role name | Attributes | Member of
-----------+------------+-----------
db_user | | {db_owner}
4) db=> \password
Enter new password:
Enter it again:
ERROR: permission denied
5) db=> SET SESSION AUTHORIZATION db_user;
SET
6) db=> select current_user, session_user;
current_user | session_user
--------------+--------------
db_user | db_user
(1 row)
7) db=> \password
Enter new password:
Enter it again:
db=>
I hope this explains.
BR,
Toomas
> On 21. Oct 2021, at 19:13, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
> On 10/21/21 08:39, Toomas wrote:
>> 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.
>
> What I am looking for is a step by step outline that approximates:
>
> 1) psql -U <some_user>
>
> 2) The command(s) that set session_user as database owner.
>
> 3) The command(s) that make session_user != current_user.
>
> 4) Output of:
> select session_user, current_user;
>
> 5) The output of \du for the users involved
>
>> BR,
>> Toomas
>
>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
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, adrian.klaver@aklaver.com, vijaykumarjain.github@gmail.com
Subject: Re: Can db user change own password?
In-Reply-To: <FECE58B3-40D1-4FBA-867C-869C18B35582@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> <e2c57ee7-75d7-6a03-d9f2-052a8e880f9c@aklaver.com> <FECE58B3-40D1-4FBA-867C-869C18B35582@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