pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedForeign tables, user mappings and privilege setup
2+ messages / 2 participants
[nested] [flat]
* Foreign tables, user mappings and privilege setup
@ 2020-09-21 08:21 Niels Jespersen <NJN@dst.dk>
2020-09-21 14:10 ` Re: Foreign tables, user mappings and privilege setup Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 2+ messages in thread
From: Niels Jespersen @ 2020-09-21 08:21 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Foreign tables, user mappings and privilege setup
2020-09-21 08:21 Foreign tables, user mappings and privilege setup Niels Jespersen <NJN@dst.dk>
@ 2020-09-21 14:10 ` Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 0 replies; 2+ messages in thread
From: Laurenz Albe @ 2020-09-21 14:10 UTC (permalink / raw)
To: Niels Jespersen <NJN@dst.dk>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
On Mon, 2020-09-21 at 08:21 +0000, Niels Jespersen wrote:
> 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...".
You have to create a user mapping for every user that is to access the foreign table.
If several users should have the same credentials, use a group.
Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2020-09-21 14:10 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 08:21 Foreign tables, user mappings and privilege setup Niels Jespersen <NJN@dst.dk>
2020-09-21 14:10 ` Laurenz Albe <laurenz.albe@cybertec.at>
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