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 1kKH4d-0001UB-09 for pgsql-general@arkaria.postgresql.org; Mon, 21 Sep 2020 08:21:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kKH4b-0003XJ-UN for pgsql-general@arkaria.postgresql.org; Mon, 21 Sep 2020 08:21:21 +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 1kKH4b-0003X4-6Q for pgsql-general@lists.postgresql.org; Mon, 21 Sep 2020 08:21:21 +0000 Received: from srvimsva2.dst.dk ([91.208.143.64]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kKH4Y-0005yc-8l for pgsql-general@lists.postgresql.org; Mon, 21 Sep 2020 08:21:20 +0000 Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F30B1104074 for ; Mon, 21 Sep 2020 10:21:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dst.dk; s=dmz20180119; t=1600676475; bh=mMabKP9Wuj+ikP9pap2mSCP+3IcRW64H8XMhfahFAek=; h=From:To:Date; b=AEnCcS4xB9PRv1H3NR2zPZjb38zQIrNcCKZ1FO4NU5NSYD89vPNsOj1wS0otsxY9h O2dqa6C/dktJ7hoAC2qwCAm2bVd/4VYixLt88TOoJ3LFPyyRQxJySH1sQ3GnmfA47S geY4PwrzeJgiLzzirv6TqdLsTGj9NLbhNom9ceAk= Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD194104072 for ; Mon, 21 Sep 2020 10:21:14 +0200 (CEST) Received: from Sepo.dst.dk (unknown [192.168.64.11]) by srvimsva2.dst.dk (Postfix) with ESMTP for ; Mon, 21 Sep 2020 10:21:14 +0200 (CEST) Received: from srvexc9.dst.local ([172.30.32.49]) by Sepo.dst.dk (JAMES SMTP Server 2.3.2-1) with SMTP ID 321 for ; Mon, 21 Sep 2020 10:21:12 +0200 (CEST) Received: from srvexc8.dst.local (172.30.32.48) by srvexc9.dst.local (172.30.32.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2044.4; Mon, 21 Sep 2020 10:21:12 +0200 Received: from srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b]) by srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b%4]) with mapi id 15.01.2044.004; Mon, 21 Sep 2020 10:21:12 +0200 From: Niels Jespersen To: "pgsql-general@lists.postgresql.org" Subject: Foreign tables, user mappings and privilege setup Thread-Topic: Foreign tables, user mappings and privilege setup Thread-Index: AdaP8CnDY0sPwz7kSTG7en4cbPygtA== Date: Mon, 21 Sep 2020 08:21:12 +0000 Message-ID: Accept-Language: da-DK, en-US Content-Language: da-DK X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.30.33.38] Content-Type: multipart/alternative; boundary="_000_d0306b1670674d70ab923c42d4340db3dstdk_" MIME-Version: 1.0 X-TM-AS-GCONF: 00 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --_000_d0306b1670674d70ab923c42d4340db3dstdk_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello all I am a bit confused about how to design privileges properly around foreign = tables. Here's the setup. -- As superuser create server s.... foreign data wrapper postgres_fdw options (host 'hhh.d'= , dbname 'db1', port '5432'); grant usage on foreign server s... to public; -- This does not give access = to anything beyond allowing user created foreign tables and user mappings. -- As user with create privileges in schema create user mapping for current_user server s... (user 'remoteuser', passwo= rd 'remotepassword'); create foreign table t.... ( a int) server s... options (table_name 't_re= mote'); This works fine. Except only the user who created the user mapping can sele= ct from foreign table, even if other users have select privilege on the tab= le. They will get a "user mapping not found for...". Now, I could, as superuser: create user mapping for public server s.... -- But that would give anyone a= ccess the whatever thre remote user has access to. Not good. I am unsure of the best solution to this. I can see a few, but I have not t= ested them. There may be other solutions that are much better. One way is a public user mapping on top of a server, and only give a specif= ic role usage privileges. Another way is to create a view on top of the foreign table and give select= privileges on that. I'm not sure that would work, actually. Yet another is a set returning function on top of the foreign table defined= as 'security definer'. That's basically it. Shoot. Regards Niels Jespersen --_000_d0306b1670674d70ab923c42d4340db3dstdk_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello all

 

I am a bit confused about how t= o design privileges properly around foreign tables.

 

Here's the setup.

 

-- As superuser

create server s.... foreign dat= a wrapper postgres_fdw options (host 'hhh.d', dbname 'db1', port '5432');

grant usage on foreign server s= ... to public; -- This does not give access to anything beyond allowing use= r created foreign tables and user mappings.

-- As user with create privileg= es in schema

create user mapping for current= _user server s... (user 'remoteuser', password 'remotepassword');

create foreign table t.... = ;  ( a int) server s... options (table_name 't_remote');

 

This works fine. Except only th= e user who created the user mapping can select from foreign table, even if = other users have select privilege on the table. They will get a "user = mapping not found for...".

 

Now, I could, as superuser:

 

create user mapping for public = server s.... -- But that would give anyone access the whatever thre remote = user has access to. Not good.

 

I am unsure of the best solutio= n to this. I can see a few, but I have not tested them. There may be other = solutions that are much better.

 

One way is a public user mappin= g on top of a server, and only give a specific role usage privileges.

Another way is to create a view= on top of the foreign table and give select privileges on that. I'm not su= re that would work, actually.

Yet another is a set returning = function on top of the foreign table defined as 'security definer'.

 

That's basically it. Shoot.

 

Regards Niels Jespersen

 

 

--_000_d0306b1670674d70ab923c42d4340db3dstdk_--