pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Niels Jespersen <NJN@dst.dk>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Foreign tables, user mappings and privilege setup
Date: Mon, 21 Sep 2020 08:21:12 +0000
Message-ID: <d0306b1670674d70ab923c42d4340db3@dst.dk> (raw)

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', password 'remotepassword');
create foreign table t....   ( a int) server s... options (table_name 't_remote');

This works fine. Except only the 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 solution 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 mapping 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 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

view thread (2+ messages)  latest in thread

Message-ID: <d0306b1670674d70ab923c42d4340db3@dst.dk>
Permalink:  ../d0306b1670674d70ab923c42d4340db3@dst.dk/
Also on:    postgresql.org/message-id/d0306b1670674d70ab923c42d4340db3@dst.dk

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: NJN@dst.dk
  Subject: Re: Foreign tables, user mappings and privilege setup
  In-Reply-To: <d0306b1670674d70ab923c42d4340db3@dst.dk>
  References: <d0306b1670674d70ab923c42d4340db3@dst.dk>

* 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