Restrict postgres_fdw/dblink passfile to user mappings

Started by Stepan Neretinabout 4 hours ago2 messageshackers
Jump to latest
#1Stepan Neretin
slpmcf@gmail.com

Hi,

password is a USER MAPPING option because libpq marks it with
dispchar '*'. passfile is not marked that way, so postgres_fdw and
dblink treat it as a FOREIGN SERVER option instead.

That puts the password file path into srvoptions, which are broadly
readable. Attached makes passfile user mapping only and
superuser only, and rejects a leftover server side passfile at
connect time. Same idea as keeping secrets out of srvoptions,
in the spirit of the servicefile revert, just for placement.

I left passfile in the libpqsrv proxy allowlist on purpose. That
safelist still blesses it (like sslcert), and Sehrope noted passfile
does not have the /dev/zero hang that servicefile did [1]/messages/by-id/CAH7T-aq+U6GDPO8mr3Gga3KzxGpAE=BSLb38x+R8fvWjzF-H8w@mail.gmail.com.
Docs deferred.

Regards,
Stepan Neretin

[1]: /messages/by-id/CAH7T-aq+U6GDPO8mr3Gga3KzxGpAE=BSLb38x+R8fvWjzF-H8w@mail.gmail.com
/messages/by-id/CAH7T-aq+U6GDPO8mr3Gga3KzxGpAE=BSLb38x+R8fvWjzF-H8w@mail.gmail.com

Attachments:

t259968_1
v1-0001-Make-postgres_fdw-dblink-passfile-a-user-mapping-option.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Make-postgres_fdw-dblink-passfile-a-user-mapping-option.patchDownload+106-16
#2Stepan Neretin
slpmcf@gmail.com
In reply to: Stepan Neretin (#1)
Re: Restrict postgres_fdw/dblink passfile to user mappings

On Sun, Nov 29, 2026 at 2:43 AM Stepan Neretin <slpmcf@gmail.com> wrote:

Hi,

password is a USER MAPPING option because libpq marks it with
dispchar '*'. passfile is not marked that way, so postgres_fdw and
dblink treat it as a FOREIGN SERVER option instead.

That puts the password file path into srvoptions, which are broadly
readable. Attached makes passfile user mapping only and
superuser only, and rejects a leftover server side passfile at
connect time. Same idea as keeping secrets out of srvoptions,
in the spirit of the servicefile revert, just for placement.

I left passfile in the libpqsrv proxy allowlist on purpose. That
safelist still blesses it (like sslcert), and Sehrope noted passfile
does not have the /dev/zero hang that servicefile did [1].
Docs deferred.

Regards,
Stepan Neretin

[1]
/messages/by-id/CAH7T-aq+U6GDPO8mr3Gga3KzxGpAE=BSLb38x+R8fvWjzF-H8w@mail.gmail.com

Hi,

CFBot failed on kerberos/001_auth because that test still put
passfile on the foreign server. Attached v1 moves it to the
user mapping. No other change.

Regards,
Stepan Neretin

Attachments:

t259968_2
v1-0001-Make-postgres_fdw-dblink-passfile-a-user-mapping-option.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Make-postgres_fdw-dblink-passfile-a-user-mapping-option.patchDownload+108-18