Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ab3f008

Browse files
committed
postgres_fdw: Judge password use by run-as user, not session user.
This is a backward incompatibility which should be noted in the release notes for PostgreSQL 11. For security reasons, we require that a postgres_fdw foreign table use password authentication when accessing a remote server, so that an unprivileged user cannot usurp the server's credentials. Superusers are exempt from this requirement, because we assume they are entitled to usurp the server's credentials or, at least, can find some other way to do it. But what should happen when the foreign table is accessed by a view owned by a user different from the session user? Is it the view owner that must be a superuser in order to avoid the requirement of using a password, or the session user? Historically it was the latter, but this requirement makes it the former instead. This allows superusers to delegate to other users the right to select from a foreign table that doesn't use password authentication by creating a view over the foreign table and handing out rights to the view. It is also more consistent with the idea that access to a view should use the view owner's privileges rather than the session user's privileges. The upshot of this change is that a superuser selecting from a view created by a non-superuser may now get an error complaining that no password was used, while a non-superuser selecting from a view created by a superuser will no longer receive such an error. No documentation changes are present in this patch because the wording of the documentation already suggests that it works this way. We should perhaps adjust the documentation in the back-branches, but that's a task for another patch. Originally proposed by Jeff Janes, but with different semantics; adjusted to work like this by me per discussion. Discussion: http://postgr.es/m/CA+TgmoaY4HsVZJv5SqEjCKLDwtCTSwXzKpRftgj50wmMMBwciA@mail.gmail.com
1 parent c572599 commit ab3f008

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

contrib/postgres_fdw/connection.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static bool xact_got_connection = false;
7575
/* prototypes of private functions */
7676
static PGconn *connect_pg_server(ForeignServer *server, UserMapping *user);
7777
static void disconnect_pg_server(ConnCacheEntry *entry);
78-
static void check_conn_params(const char **keywords, const char **values);
78+
static void check_conn_params(const char **keywords, const char **values, UserMapping *user);
7979
static void configure_remote_session(PGconn *conn);
8080
static void do_sql_command(PGconn *conn, const char *sql);
8181
static void begin_remote_xact(ConnCacheEntry *entry);
@@ -261,7 +261,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
261261
keywords[n] = values[n] = NULL;
262262

263263
/* verify connection parameters and make connection */
264-
check_conn_params(keywords, values);
264+
check_conn_params(keywords, values, user);
265265

266266
conn = PQconnectdbParams(keywords, values, false);
267267
if (!conn || PQstatus(conn) != CONNECTION_OK)
@@ -276,7 +276,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
276276
* otherwise, he's piggybacking on the postgres server's user
277277
* identity. See also dblink_security_check() in contrib/dblink.
278278
*/
279-
if (!superuser() && !PQconnectionUsedPassword(conn))
279+
if (!superuser_arg(user->userid) && !PQconnectionUsedPassword(conn))
280280
ereport(ERROR,
281281
(errcode(ERRCODE_S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED),
282282
errmsg("password is required"),
@@ -322,12 +322,12 @@ disconnect_pg_server(ConnCacheEntry *entry)
322322
* contrib/dblink.)
323323
*/
324324
static void
325-
check_conn_params(const char **keywords, const char **values)
325+
check_conn_params(const char **keywords, const char **values, UserMapping *user)
326326
{
327327
int i;
328328

329329
/* no check required if superuser */
330-
if (superuser())
330+
if (superuser_arg(user->userid))
331331
return;
332332

333333
/* ok if params contain a non-empty password */

0 commit comments

Comments
 (0)