Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyHzP-0008DI-LB for pgsql-admin@arkaria.postgresql.org; Tue, 20 Mar 2018 14:11:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eyHzO-0006fd-4N for pgsql-admin@arkaria.postgresql.org; Tue, 20 Mar 2018 14:11:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyHzN-0006fL-TC for pgsql-admin@lists.postgresql.org; Tue, 20 Mar 2018 14:11:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eyHzL-0007Tk-AK for pgsql-admin@lists.postgresql.org; Tue, 20 Mar 2018 14:11:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w2KEBfwa010824; Tue, 20 Mar 2018 10:11:41 -0400 From: Tom Lane To: Michael.Dietrich@swisscom.com cc: sfrost@snowman.net, pgsql-admin@lists.postgresql.org Subject: Re: AW: Connect to db denied for superuser inherited by group In-reply-to: <214530c2d4cb438ca204bd2a3b5b4747@swisscom.com> References: <9cd041b2b19143758e4f4d8a752421c5@swisscom.com> <20180316134234.GE2416@tamriel.snowman.net> <214530c2d4cb438ca204bd2a3b5b4747@swisscom.com> Comments: In-reply-to message dated "Tue, 20 Mar 2018 08:29:43 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <10822.1521555101.1@sss.pgh.pa.us> Date: Tue, 20 Mar 2018 10:11:41 -0400 Message-ID: <10823.1521555101@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk writes: > What I've done > CREATE ROLE superrole WITH NOLOGIN SUPERUSER ..; > CREATE USER nosuperuser WITH LOGIN NOSUPERUSER INHERIT ..; > GRANT superrole TO nosuperuser WITH ADMIN OPTION; > REVOKE CONNECT ON DATABASE nonpublicdb FROM public ; > psql -d postgres -U nosupuser > postgres=# set role superrole; > postgres=# \c nonpublicdb > FATAL: permission denied for database " nonpublicdb " > DETAIL: User does not have CONNECT privilege. > I expect that the connection to the database is allowed since a role > with superuser is used. You're misunderstanding what psql's \c command does. In this form, it attempts a connection with the new database name, but the same username as the previous connection, ie nosupuser. It doesn't know anything about SET ROLE commands you may have issued to the server while connected. regards, tom lane