From: Tom Lane <tgl@sss.pgh.pa.us>
To: Suralkar, Yogendra (Yogendra) <suralkary@avaya.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Cc: David Steele <david@pgmasters.net>
Cc: Porob, Dattaram (Datta) <porobd@avaya.com>
Cc: Oswal, Prashant (Prashant) **CTR** <poswal@avaya.com>
Cc: Patil, Parag (Parag) <paragp@avaya.com>
Cc: Devaraj, Sankar (Sankar) <devarajs@avaya.com>
Cc: Singh, Payal (Payal) **CTR** <payals@avaya.com>
Subject: Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640
Date: Fri, 20 May 2022 10:49:46 -0400
Message-ID: <335500.1653058186@sss.pgh.pa.us> (raw)
In-Reply-To: <MW3PR15MB3931DF96896DC36D21AFD47CA3D39@MW3PR15MB3931.namprd15.prod.outlook.com>
References: <MW3PR15MB3931DF96896DC36D21AFD47CA3D39@MW3PR15MB3931.namprd15.prod.outlook.com>
"Suralkar, Yogendra (Yogendra)" <suralkary@avaya.com> writes:
> Recently we updated to PostgreSQL 13.7 (Please see list of rpms used below).
> After update we have noticed an issue when connecting to Database as 'root' user when private key file is owned by root and has permission 640.
TBH, my immediate reaction is "what are you doing running database
accesses as root?". But given that you are, I see the problem: the test
is coded like
if ((buf.st_uid == geteuid() && buf.st_mode & (S_IRWXG | S_IRWXO)) ||
(buf.st_uid == 0 && buf.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)))
which was copied verbatim from the equivalent test in the backend.
However, in the backend it's safe to assume that geteuid() != 0.
libpq apparently shouldn't assume that, meaning that the two arms
of the if aren't disjoint cases anymore, and it matters which one
we check first.
The repeat call of geteuid() is a waste of cycles anyway, so maybe better
like
if (buf.st_uid != 0 ?
buf.st_mode & (S_IRWXG | S_IRWXO) :
buf.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO))
This feels kind of wrong, in that root's privacy check is now strictly
weaker than anyone else's, but root ought to know what she's doing anyway.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, suralkary@avaya.com, pgsql-bugs@lists.postgresql.org, david@pgmasters.net, porobd@avaya.com, poswal@avaya.com, paragp@avaya.com, devarajs@avaya.com, payals@avaya.com
Subject: Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640
In-Reply-To: <335500.1653058186@sss.pgh.pa.us>
* 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