Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gatekeeper: disallow reading rolpassword in elevated contexts
It is possible to write a function that might extract password hashes (or plaintext passwords, if enabled) from `pg_authid` that could be executed in an elevated context. For the sake of example: ``` mblewitt=# \df+ steal_yer_passwords List of functions -[ RECORD 1 ]-------+------------------------------------------------------------------------------------------------------------------------------------------- Schema | public Name | steal_yer_passwords Result data type | void Argument data types | Type | func Volatility | volatile Parallel | unsafe Owner | mblewitt Security | definer Access privileges | Language | plpgsql Source code | BEGIN CREATE TABLE IF NOT EXISTS yer_passwords AS SELECT rolname, rolpassword FROM pg_authid; GRANT ALL ON yer_passwords TO foobar; END; Description | ``` Without this patch, it is possible to execute this func as an unprivileged user and extract the information: ``` mblewitt=> select current_user; current_user -------------- foobar (1 row) ``` ``` mblewitt=> select * from pg_authid; ERROR: permission denied for table pg_authid ``` ``` mblewitt=> select steal_yer_passwords(); steal_yer_passwords --------------------- (1 row) ``` ``` mblewitt=> select * from yer_passwords where rolname = 'victim'; rolname | rolpassword ---------+------------------------------------- victim | md5710772761ee5086c0a06cfef4cb4256d (1 row) ``` With this patch, we prevent such access in an elevated context: ``` mblewitt=> select steal_yer_passwords(); ERROR: Reading pg_authid sensitive columns is not allowed in elevated context CONTEXT: SQL statement "CREATE TABLE IF NOT EXISTS yer_passwords AS SELECT rolname, rolpassword FROM pg_authid" PL/pgSQL function steal_yer_passwords() line 1 at SQL statement ``` This guards only against reading `rolpassword`, so other operations are fine in an elevated context: ``` mblewitt=> \df+ baz_the_qux; List of functions -[ RECORD 1 ]-------+-------------------------------- Schema | public Name | baz_the_qux Result data type | void Argument data types | Type | func Volatility | volatile Parallel | unsafe Owner | mblewitt Security | definer Access privileges | Language | sql Source code | SELECT rolname FROM pg_authid Description | ``` ``` mblewitt=> select baz_the_qux(); -[ RECORD 1 ]- baz_the_qux | ```
- Loading branch information