mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
Only superuser can set sslcert/sslkey in postgres_fdw user mappings
Othrwise there is a security risk. Discussion: https://postgr.es/m/20200109103014.GA4192@msg.df7cb.de
This commit is contained in:
parent
4e514c6180
commit
cebf9d6e6e
@ -8898,6 +8898,15 @@ SELECT * FROM ft1_nopw LIMIT 1;
|
|||||||
1111 | 2 | | | | | ft1 |
|
1111 | 2 | | | | | ft1 |
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
-- unpriv user also cannot set sslcert / sslkey on the user mapping
|
||||||
|
-- first set password_required so we see the right error messages
|
||||||
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (SET password_required 'true');
|
||||||
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (ADD sslcert 'foo.crt');
|
||||||
|
ERROR: sslcert and sslkey are superuser-only
|
||||||
|
HINT: User mappings with the sslcert or sslkey options set may only be created or modified by the superuser
|
||||||
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (ADD sslkey 'foo.key');
|
||||||
|
ERROR: sslcert and sslkey are superuser-only
|
||||||
|
HINT: User mappings with the sslcert or sslkey options set may only be created or modified by the superuser
|
||||||
-- We're done with the role named after a specific user and need to check the
|
-- We're done with the role named after a specific user and need to check the
|
||||||
-- changes to the public mapping.
|
-- changes to the public mapping.
|
||||||
DROP USER MAPPING FOR CURRENT_USER SERVER loopback_nopw;
|
DROP USER MAPPING FOR CURRENT_USER SERVER loopback_nopw;
|
||||||
|
@ -159,6 +159,16 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
|
|||||||
errmsg("password_required=false is superuser-only"),
|
errmsg("password_required=false is superuser-only"),
|
||||||
errhint("User mappings with the password_required option set to false may only be created or modified by the superuser")));
|
errhint("User mappings with the password_required option set to false may only be created or modified by the superuser")));
|
||||||
}
|
}
|
||||||
|
else if (strcmp(def->defname, "sslcert") == 0 ||
|
||||||
|
strcmp(def->defname, "sslkey") == 0)
|
||||||
|
{
|
||||||
|
/* similarly for sslcert / sslkey on user mapping */
|
||||||
|
if (catalog == UserMappingRelationId && !superuser())
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||||
|
errmsg("sslcert and sslkey are superuser-only"),
|
||||||
|
errhint("User mappings with the sslcert or sslkey options set may only be created or modified by the superuser")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PG_RETURN_VOID();
|
PG_RETURN_VOID();
|
||||||
|
@ -2567,6 +2567,7 @@ SELECT * FROM ft1_nopw LIMIT 1;
|
|||||||
-- Unpriv user cannot make the mapping passwordless
|
-- Unpriv user cannot make the mapping passwordless
|
||||||
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (ADD password_required 'false');
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (ADD password_required 'false');
|
||||||
|
|
||||||
|
|
||||||
SELECT * FROM ft1_nopw LIMIT 1;
|
SELECT * FROM ft1_nopw LIMIT 1;
|
||||||
|
|
||||||
RESET ROLE;
|
RESET ROLE;
|
||||||
@ -2579,6 +2580,12 @@ SET ROLE regress_nosuper;
|
|||||||
-- Should finally work now
|
-- Should finally work now
|
||||||
SELECT * FROM ft1_nopw LIMIT 1;
|
SELECT * FROM ft1_nopw LIMIT 1;
|
||||||
|
|
||||||
|
-- unpriv user also cannot set sslcert / sslkey on the user mapping
|
||||||
|
-- first set password_required so we see the right error messages
|
||||||
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (SET password_required 'true');
|
||||||
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (ADD sslcert 'foo.crt');
|
||||||
|
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback_nopw OPTIONS (ADD sslkey 'foo.key');
|
||||||
|
|
||||||
-- We're done with the role named after a specific user and need to check the
|
-- We're done with the role named after a specific user and need to check the
|
||||||
-- changes to the public mapping.
|
-- changes to the public mapping.
|
||||||
DROP USER MAPPING FOR CURRENT_USER SERVER loopback_nopw;
|
DROP USER MAPPING FOR CURRENT_USER SERVER loopback_nopw;
|
||||||
|
@ -130,7 +130,7 @@
|
|||||||
</listitem>
|
</listitem>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<literal>sslkey</literal> and <literal>sslpassword</literal> - these may
|
<literal>sslkey</literal> and <literal>sslcert</literal> - these may
|
||||||
appear in <emphasis>either or both</emphasis> a connection and a user
|
appear in <emphasis>either or both</emphasis> a connection and a user
|
||||||
mapping. If both are present, the user mapping setting overrides the
|
mapping. If both are present, the user mapping setting overrides the
|
||||||
connection setting.
|
connection setting.
|
||||||
@ -139,6 +139,10 @@
|
|||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
Only superusers may create or modify user mappings with the
|
||||||
|
<literal>sslcert</literal> or <literal>sslkey</literal> settings.
|
||||||
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Only superusers may connect to foreign servers without password
|
Only superusers may connect to foreign servers without password
|
||||||
authentication, so always specify the <literal>password</literal> option
|
authentication, so always specify the <literal>password</literal> option
|
||||||
|
Loading…
x
Reference in New Issue
Block a user