6

We are using a foreign data wrapper to query across databases on a single PostgreSQL RDS. The foreign data wrapper server needs a user mapping for each user who will query against the remote server. However, adding the user mapping for each user may prove to be error prone.

All of our users who need to query against the foreign data server have a shared role, e.g. role_name, on our PostgreSQL server.

How can we share the foreign data wrapper server user mapping between users?

2 Answers 2

6

The only way to share a user mapping is if you define it for PUBLIC, but then it applies to all users. Groups don't work in that context, probably because it would cause ambiguity if several user mappings apply to a single user through inheritance.

If you don't want to go with a user mapping per user, you could opt to create one for PUBLIC but limit access to the foreign tables to role_name through permissions.

I know that this is not a great solution either, because it will allow all users to see the user mapping and the password in there (if there is one). But at least it is easy to GRANT SELECT ON ALL TABLES IN SCHEMA ... TO role_name.

1
  • Thanks Laurenz. I appreciate your quick and considered response. Commented Dec 18, 2020 at 9:39
5

My prefered solution here is to create the foreign table, then create a view on that foreign table, and grant select rights on the view to whoever needs them. Only the owner of the table needs a mapping, the view users will inherit the usage of the mapping (without being able to see the details of the mapping, in case you want that to be secret, although in the past there were bugs which exposed this, so don't use ancient minor releases).

1
  • I've been having all sorts of problems with permissions on foreign tables; and this idea to set up the foreign table for a single user with a view on top of it seems to be working for me. Commented Aug 15, 2022 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.