pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14600: Passwords in user mappings leaked by psql \deu+ command
4+ messages / 3 participants
[nested] [flat]

* BUG #14600: Passwords in user mappings leaked by psql \deu+ command
@ 2017-03-28 05:38 andrew.wheelwright@familysearch.org
  2017-03-29 14:54 ` Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command Feike Steenbergen <feikesteenbergen@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: andrew.wheelwright@familysearch.org @ 2017-03-28 05:38 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14600
Logged by:          Andrew Wheelwright
Email address:      andrew.wheelwright@familysearch.org
PostgreSQL version: 9.5.3
Operating system:   CentOS 6.7
Description:        

Scenario:

I'm working with a multi-server scenario where we have several classes of
user.  For the sake of simplicity I'll call one class power_user and the
other standard_user.  Also for the sake of simplicity, imagine the multiple
servers are called Alice, Bob, and Chuck.

The typical daily use case involve our standard users creating a foreign
table on Alice which references another table on Bob, copying said table
(e.g. create table as ...), dropping the foreign table to Bob, manipulating
data in the table on Alice (i.e. modifying millions of records), creating
another foreign table to Chuck, and copying the data from the table on Alice
to the table on Chuck before dropping both the foreign table and the local
table on Alice.

For our standard users to do their work, they must be able to create these
foreign tables (and no, they're not connecting to the same tables on Bob or
Chuck).

Now, the power_user role has more privileges than the standard_user role. 
Specifically, the power_user has grants to other schemas on Alice and Chuck.

 Both the power_user and the standard_user have usage granted on the foreign
servers Bob and Chuck.

The Problem:

If a standard user logs into Alice using command line client, psql, and runs
the command \deu+, the password for both the standard_user and the
power_user will be visible in the displayed user mapping.  The user could
then log out of Alice and log back in as a power_user.  As far as I can
determine, anyone with usage granted on the foreign server can see ALL
passwords for that foreign server's user mappings.

Note: querying the information schema for user mappings does not display
this same security vulnerability.  It seems psql is getting the information
through some other means.




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command
  2017-03-28 05:38 BUG #14600: Passwords in user mappings leaked by psql \deu+ command andrew.wheelwright@familysearch.org
@ 2017-03-29 14:54 ` Feike Steenbergen <feikesteenbergen@gmail.com>
  2017-03-29 17:53   ` Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command Feike Steenbergen <feikesteenbergen@gmail.com>
  2017-04-08 19:34   ` Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command Noah Misch <noah@leadboat.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Feike Steenbergen @ 2017-03-29 14:54 UTC (permalink / raw)
  To: andrew.wheelwright@familysearch.org; +Cc: pgsql-bugs

> If a standard user logs into Alice using command line client, psql, and
runs
> the command \deu+, the password for both the standard_user and the
> power_user will be visible in the displayed user mapping.

\deu+ queries pg_catalog.pg_user_mappings, which itself is a view on top of
pg_user_mapping.

The permissions on pg_user_mapping (the table) seem sane, they do not allow
you
to see the values. The permissions on pg_user_mappings (the view) are too
wide
it seems.

you could - for your current environment - use the following workaround on
all
your databases:

REVOKE SELECT ON pg_user_mappings FROM public;

I do think this needs a fix however, these credentials should not be
visible to
public.

regards,

Feike

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command
  2017-03-28 05:38 BUG #14600: Passwords in user mappings leaked by psql \deu+ command andrew.wheelwright@familysearch.org
  2017-03-29 14:54 ` Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command Feike Steenbergen <feikesteenbergen@gmail.com>
@ 2017-03-29 17:53   ` Feike Steenbergen <feikesteenbergen@gmail.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Feike Steenbergen @ 2017-03-29 17:53 UTC (permalink / raw)
  To: andrew.wheelwright@familysearch.org; +Cc: pgsql-bugs

Attached a patch which copies the logic from commit
93a6be63a55a8cd0d73b3fa81eb6a46013a3a974.

In the current implementation we only consider privileges of the foreign
server
in determining whether or not to show the user mapping details. This patch
copies the same logic (and documentation) used in commit
93a6be63a55a8cd0d73b3fa81eb6a46013a3a974 to not always show the user mapping
options.

regards,

Feike

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

user_mappings_leak.patch (application/octet-stream, 1.7K) download diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index ac39c639ed..f75f69e86f 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -11042,8 +11042,12 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx <entry></entry> <entry> User mapping specific options, as <quote>keyword=value</> - strings, if the current user is the owner of the foreign - server, else null + strings. This column will show as null + unless the current user is the user being mapped, or the mapping + is for <literal>PUBLIC</literal> and the current user is the + server owner, or the current user is a superuser. The intent is + to protect password information stored as user mapping + option. </entry> </row> </tbody> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index d357c8b8fd..43fe44fbe9 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -920,10 +920,11 @@ CREATE VIEW pg_user_mappings AS ELSE A.rolname END AS usename, - CASE WHEN pg_has_role(S.srvowner, 'USAGE') OR has_server_privilege(S.oid, 'USAGE') THEN - U.umoptions - ELSE - NULL + CASE + WHEN U.umuser <> 0::oid AND A.rolname = "current_user"() OR U.umuser = 0::oid AND pg_has_role(S.srvowner::name, 'USAGE'::text) OR ( SELECT pg_authid.rolsuper + FROM pg_authid + WHERE pg_authid.rolname = "current_user"()) THEN U.umoptions + ELSE NULL::text[] END AS umoptions FROM pg_user_mapping U JOIN pg_foreign_server S ON (U.umserver = S.oid)
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command
  2017-03-28 05:38 BUG #14600: Passwords in user mappings leaked by psql \deu+ command andrew.wheelwright@familysearch.org
  2017-03-29 14:54 ` Re: BUG #14600: Passwords in user mappings leaked by psql \deu+ command Feike Steenbergen <feikesteenbergen@gmail.com>
@ 2017-04-08 19:34   ` Noah Misch <noah@leadboat.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Noah Misch @ 2017-04-08 19:34 UTC (permalink / raw)
  To: Feike Steenbergen <feikesteenbergen@gmail.com>; +Cc: pgsql-bugs

On Wed, Mar 29, 2017 at 04:54:03PM +0200, Feike Steenbergen wrote:
> > If a standard user logs into Alice using command line client, psql, and
> runs
> > the command \deu+, the password for both the standard_user and the
> > power_user will be visible in the displayed user mapping.
> 
> \deu+ queries pg_catalog.pg_user_mappings, which itself is a view on top of
> pg_user_mapping.

Thanks for the report; the next back-branch releases will contain a fix.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2017-04-08 19:34 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-03-28 05:38 BUG #14600: Passwords in user mappings leaked by psql \deu+ command andrew.wheelwright@familysearch.org
2017-03-29 14:54 ` Feike Steenbergen <feikesteenbergen@gmail.com>
2017-03-29 17:53   ` Feike Steenbergen <feikesteenbergen@gmail.com>
2017-04-08 19:34   ` Noah Misch <noah@leadboat.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox