Extensible user mapping handler for FDW
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t51349psql -h localhost -U postgresBuilt from patchset v1 (message #1), July 27, 2026 at 09:35 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t51349_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t51349_1 && git checkout t51349_1Patchset v1 (message #1) is on t51349_1
Hi hackers,
I'm working on a patch that makes FDW user mapping extensible.
Main motivation for this is to avoid plain text password or other
sensitive secret being stored in catalog table, and let an external
source to handle this.
In our use case, the foreign tables are created by an admin user
and granted to normal user for read/write access. We don't want
the user to recover the original password.
Proposal:
CREATE FUNCTION user_mapping_handler
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT;
CREATE USER MAPPING FOR user_name SERVER server_name
[ USING user_mapping_handler ] [ OPTIONS ( ... ) ]
Add column "umhandler" to pg_user_mapping catalog table.
Design considerations:
1. Existing FDW code base should just work fine without
modifications. The user mapping handler is just a plugin.
2. User mapping handler should detect the FDW type itself and
provide necessary option list accordingly.
3. User mapping handler may have reserved options. These options
must not be exposed to individual FDWs, and they should be
meaningless to the user.
Patch for proof of concept is attached.
A major downside is the need to modify catalog table
pg_user_mapping. So we can't apply this change to existing
installation of prior stable versions.
Another competing proposal we have internally is to introduce a
new FDW API: ForeignUserMapping() and let individual FDW to
handle for themselves. This approach won't introduce change to
catalog table, but requires modification to every FDW we want to
support, the benefit is that it works also for prior stable versions.
Well it's arguable that if we can modify the FDW code then this
is probably not even needed, the idea is to draw a clear line
between the user mapping logic and original code base. This will
make it easy to maintain.
Any thought on these approaches?
Thanks in advance.
--
Best wishes,
Peifeng Qiu
On 2 Apr 2025, at 03:36, Peifeng Qiu <peifeng.qiu@openpie.com> wrote:
A major downside is the need to modify catalog table
pg_user_mapping. So we can't apply this change to existing
installation of prior stable versions.
A feature like this would never be considered for backpatching anyways so
that's not really a concern.
--
Daniel Gustafsson