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 1jg7at-0003Dx-LE for pgsql-general@arkaria.postgresql.org; Tue, 02 Jun 2020 14:08:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jg7ao-0002Xq-NO for pgsql-general@arkaria.postgresql.org; Tue, 02 Jun 2020 14:08:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jg7ao-0002Xj-B7 for pgsql-general@lists.postgresql.org; Tue, 02 Jun 2020 14:08:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jg7af-0000Eh-SU for pgsql-general@lists.postgresql.org; Tue, 02 Jun 2020 14:08:35 +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 052E8QXG539940; Tue, 2 Jun 2020 10:08:26 -0400 From: Tom Lane To: Paul Bonaud cc: pgsql-general@lists.postgresql.org Subject: Re: Fine grained permissions on User Mapping In-reply-to: References: Comments: In-reply-to Paul Bonaud message dated "Tue, 02 Jun 2020 12:01:36 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <539938.1591106906.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 02 Jun 2020 10:08:26 -0400 Message-ID: <539939.1591106906@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Paul Bonaud writes: > Imagine you have a destination database which you have no control over. > Let's call it =E2=80=9Cexternal-db=E2=80=9D. This database has a unique = pg user (no > specific pg permission attributes) with read-write access to the whole > database let's call it =E2=80=9Cexternal-user=E2=80=9D. > ... > Now over to our own database which we have control over. Imagine we want= to > use a pg foreign data wrapper to access tables from the =E2=80=9Cexterna= l-db=E2=80=9D from > a basic (non superuser) user, let's call it =E2=80=9Cbasic-user=E2=80=9D= . > ... > *However*, we would like to avoid our =E2=80=9Cbasic-user=E2=80=9D to ha= ve full control > over the external-db. We would like this basic user to only be able to > *read* the external database. > With this current setup the user can very simply list the user mappings > with details (\deu+ in psql) to collect the username/password combinatio= n > and thus directly connect to the initial =E2=80=9Cexternal-db=E2=80=9D w= ith full access. So you're doing it wrong at at least two levels here: 1. The remote user you're mapping to ought to have just the privileges you want the local user to have w.r.t. that database. User IDs are cheap in Postgres; don't be so miserly as not to create a separate one for each privilege level you need. If you did that, you wouldn't really care whether the user could also connect directly to the remote DB. 2. You don't want to grant USAGE on the foreign server to the local user, either. It's possibly an error in the design of SQL/MED that foreign server USAGE grants both the ability to create/delete foreign tables and the ability to create/delete/inspect user mappings. But that's how the committee did it, so we're stuck. If it's really too painful to not let the local user create/delete his own foreign tables, then what you could do is make sure the remote user ID's password is useless for any purpose except connecting from the source database. One way to do that is to adjust the remote DB's pg_hba.conf to disallow the remote user ID from connecting from anyplace except the local database server. regards, tom lane