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 1ns3wy-0003tp-8z for pgsql-bugs@arkaria.postgresql.org; Fri, 20 May 2022 14:49:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ns3wv-0006Jz-QQ for pgsql-bugs@arkaria.postgresql.org; Fri, 20 May 2022 14:49:53 +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 1ns3wv-0006Jq-I1 for pgsql-bugs@lists.postgresql.org; Fri, 20 May 2022 14:49:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ns3wt-0006Ht-Fg for pgsql-bugs@lists.postgresql.org; Fri, 20 May 2022 14:49:53 +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 24KEnkFA335501; Fri, 20 May 2022 10:49:46 -0400 From: Tom Lane To: "Suralkar, Yogendra (Yogendra)" cc: "pgsql-bugs@lists.postgresql.org" , David Steele , "Porob, Dattaram (Datta)" , "Oswal, Prashant (Prashant) **CTR**" , "Patil, Parag (Parag)" , "Devaraj, Sankar (Sankar)" , "Singh, Payal (Payal) **CTR**" Subject: Re: Unable to connect to PostgreSQL DB as root user when private key is owned by root with permission 640 In-reply-to: References: Comments: In-reply-to "Suralkar, Yogendra (Yogendra)" message dated "Fri, 20 May 2022 05:53:11 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <335499.1653058186.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 20 May 2022 10:49:46 -0400 Message-ID: <335500.1653058186@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Suralkar, Yogendra (Yogendra)" writes: > Recently we updated to PostgreSQL 13.7 (Please see list of rpms used bel= ow). > After update we have noticed an issue when connecting to Database as 'ro= ot' 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 =3D=3D geteuid() && buf.st_mode & (S_IRWXG | S_IRW= XO)) || (buf.st_uid =3D=3D 0 && buf.st_mode & (S_IWGRP | S_IXGRP | S_I= RWXO))) which was copied verbatim from the equivalent test in the backend. However, in the backend it's safe to assume that geteuid() !=3D 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 !=3D 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