diff options
author | Noah Misch <noah@leadboat.com> | 2024-11-15 20:39:56 -0800 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2024-11-15 20:39:59 -0800 |
commit | edf80895f6bda824403f843df91cbc83890e4b6c (patch) | |
tree | 5b8cb9163ead548f55f2e20c6945c8e4db47fadf /src/test | |
parent | 91771b3fbbc33e066e9a28a7d85bde87f5a0c900 (diff) |
Fix per-session activation of ALTER {ROLE|DATABASE} SET role.
After commit 5a2fed911a85ed6d8a015a6bafe3a0d9a69334ae, the catalog state
resulting from these commands ceased to affect sessions. Restore the
longstanding behavior, which is like beginning the session with a SET
ROLE command. If cherry-picking the CVE-2024-10978 fixes, default to
including this, too. (This fixes an unintended side effect of fixing
CVE-2024-10978.) Back-patch to v12, like that commit. The release team
decided to include v12, despite the original intent to halt v12 commits
earlier this week.
Tom Lane and Noah Misch. Reported by Etienne LAFARGE.
Discussion: https://postgr.es/m/CADOZwSb0UsEr4_UTFXC5k7=fyyK8uKXekucd+-uuGjJsGBfxgw@mail.gmail.com
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/modules/unsafe_tests/Makefile | 5 | ||||
-rw-r--r-- | src/test/modules/unsafe_tests/expected/setconfig.out | 31 | ||||
-rw-r--r-- | src/test/modules/unsafe_tests/sql/setconfig.sql | 24 |
3 files changed, 59 insertions, 1 deletions
diff --git a/src/test/modules/unsafe_tests/Makefile b/src/test/modules/unsafe_tests/Makefile index 90d19791871..d4ff227ef07 100644 --- a/src/test/modules/unsafe_tests/Makefile +++ b/src/test/modules/unsafe_tests/Makefile @@ -1,6 +1,9 @@ # src/test/modules/unsafe_tests/Makefile -REGRESS = rolenames alter_system_table guc_privs +REGRESS = rolenames setconfig alter_system_table guc_privs +REGRESS_OPTS = \ + --create-role=regress_authenticated_user_sr \ + --create-role=regress_authenticated_user_ssa # the whole point of these tests is to not run installcheck NO_INSTALLCHECK = 1 diff --git a/src/test/modules/unsafe_tests/expected/setconfig.out b/src/test/modules/unsafe_tests/expected/setconfig.out new file mode 100644 index 00000000000..6a021d9ad03 --- /dev/null +++ b/src/test/modules/unsafe_tests/expected/setconfig.out @@ -0,0 +1,31 @@ +-- This is borderline unsafe in that an additional login-capable user exists +-- during the test run. Under installcheck, a too-permissive pg_hba.conf +-- might allow unwanted logins as regress_authenticated_user_ssa. +ALTER USER regress_authenticated_user_ssa superuser; +CREATE ROLE regress_session_user; +CREATE ROLE regress_current_user; +GRANT regress_current_user TO regress_authenticated_user_sr; +GRANT regress_session_user TO regress_authenticated_user_ssa; +ALTER ROLE regress_authenticated_user_ssa + SET session_authorization = regress_session_user; +ALTER ROLE regress_authenticated_user_sr SET ROLE = regress_current_user; +\c - regress_authenticated_user_sr +SELECT current_user, session_user; + current_user | session_user +----------------------+------------------------------- + regress_current_user | regress_authenticated_user_sr +(1 row) + +-- The longstanding historical behavior is that session_authorization in +-- setconfig has no effect. Hence, session_user remains +-- regress_authenticated_user_ssa. See comment in InitializeSessionUserId(). +\c - regress_authenticated_user_ssa +SELECT current_user, session_user; + current_user | session_user +--------------------------------+-------------------------------- + regress_authenticated_user_ssa | regress_authenticated_user_ssa +(1 row) + +RESET SESSION AUTHORIZATION; +DROP USER regress_session_user; +DROP USER regress_current_user; diff --git a/src/test/modules/unsafe_tests/sql/setconfig.sql b/src/test/modules/unsafe_tests/sql/setconfig.sql new file mode 100644 index 00000000000..8817a7c7636 --- /dev/null +++ b/src/test/modules/unsafe_tests/sql/setconfig.sql @@ -0,0 +1,24 @@ +-- This is borderline unsafe in that an additional login-capable user exists +-- during the test run. Under installcheck, a too-permissive pg_hba.conf +-- might allow unwanted logins as regress_authenticated_user_ssa. + +ALTER USER regress_authenticated_user_ssa superuser; +CREATE ROLE regress_session_user; +CREATE ROLE regress_current_user; +GRANT regress_current_user TO regress_authenticated_user_sr; +GRANT regress_session_user TO regress_authenticated_user_ssa; +ALTER ROLE regress_authenticated_user_ssa + SET session_authorization = regress_session_user; +ALTER ROLE regress_authenticated_user_sr SET ROLE = regress_current_user; + +\c - regress_authenticated_user_sr +SELECT current_user, session_user; + +-- The longstanding historical behavior is that session_authorization in +-- setconfig has no effect. Hence, session_user remains +-- regress_authenticated_user_ssa. See comment in InitializeSessionUserId(). +\c - regress_authenticated_user_ssa +SELECT current_user, session_user; +RESET SESSION AUTHORIZATION; +DROP USER regress_session_user; +DROP USER regress_current_user; |