DBLINK_CONNECT_U(3)

πŸ“¦ version 13.23, in opensuse-leap 16.0

πŸŽ€ NAME πŸŽ€

okay so dblink_connect_u is the function that opens a persistent connection to a remote database, insecurely β€” yes bestie, β€œinsecurely” is literally in the name, I am not being dramatic πŸ’€. This is the DBLINK_CONNECT_U(3) page from the PostgreSQL 13.23 docs, and we are gonna get into it.

✨ SYNOPSIS ✨

dblink_connect_u(text connstr) returns text
dblink_connect_u(text connname, text connstr) returns text

πŸ’– DESCRIPTION πŸ’–

So dblink_connect_u() is literally identical to dblink_connect(), except that it will allow non-superusers to connect using any authentication method. That is the whole vibe, and also the whole risk 🫢.

If the remote server selects an authentication method that does not involve a password, then impersonation and subsequent escalation of privileges can occur, because the session will appear to have originated from the user as which the local PostgreSQL server runs. Not me explaining the danger like it’s a group-chat warning 😭.

Also, even if the remote server does demand a password, it is possible for the password to be supplied from the server environment, such as a ~/.pgpass file belonging to the server's user. This opens not only a risk of impersonation, but the possibility of exposing a password to an untrustworthy remote server. This is the part where you take it seriously, bestie.

Therefore, dblink_connect_u() is initially installed with all privileges revoked from PUBLIC, making it un-callable except by superusers. In some situations it may be appropriate to grant EXECUTE permission for dblink_connect_u() to specific users who are considered trustworthy, but this should be done with care. It is also recommended that any ~/.pgpass file belonging to the server's user not contain any records specifying a wildcard host name. I said what I said πŸ’….

For further details see dblink_connect().


xoxo, your Unix bestie signing off with the deets: PostgreSQL 13.23 docs, 2025, manual page DBLINK_CONNECT_U(3) πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from