Skip to content

Commit 18718e5

Browse files
committed
test: fdws and publications in evtrigs
Ensure evtrigs don't fire for all the non-superuser fdws and publications.
1 parent 3ef5e76 commit 18718e5

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

test/expected/event_triggers.out.in

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ NOTICE: Skipping event trigger function "show_current_user" for user "postgres"
8787
DETAIL: "postgres" is a superuser and the function "show_current_user" is not superuser-owned, it's owned by "privileged_role"
8888
\echo
8989

90-
-- extensions won't execute the event trigger function (since they're executed by superuser under our implementation)
91-
set role rolecreator;
92-
\echo
93-
90+
-- creating extensions will not fire evtrigs
91+
set role privileged_role;
9492
create extension postgres_fdw;
9593
NOTICE: Skipping event trigger function "show_current_user" for user "postgres"
9694
DETAIL: "postgres" is a superuser and the function "show_current_user" is not superuser-owned, it's owned by "privileged_role"
@@ -99,6 +97,24 @@ NOTICE: Skipping event trigger function "show_current_user" for user "postgres"
9997
DETAIL: "postgres" is a superuser and the function "show_current_user" is not superuser-owned, it's owned by "privileged_role"
10098
\echo
10199

100+
-- creating fdws will not fire evtrigs
101+
create foreign data wrapper new_fdw;
102+
NOTICE: Skipping event trigger function "show_current_user" for user "postgres"
103+
DETAIL: "postgres" is a superuser and the function "show_current_user" is not superuser-owned, it's owned by "privileged_role"
104+
-- TODO: while correct, this is inconsistent as dropping the fdw does fire the evtrig for the privileged_role
105+
drop foreign data wrapper new_fdw;
106+
NOTICE: the event trigger is executed for privileged_role
107+
\echo
108+
109+
-- creating pubs will not fire evtrigs
110+
create publication p for all tables;
111+
NOTICE: Skipping event trigger function "show_current_user" for user "postgres"
112+
DETAIL: "postgres" is a superuser and the function "show_current_user" is not superuser-owned, it's owned by "privileged_role"
113+
-- TODO: while correct, this is inconsistent as dropping the publication does fire the evtrig for the privileged_role
114+
drop publication p;
115+
NOTICE: the event trigger is executed for privileged_role
116+
\echo
117+
102118
-- privesc shouldn't happen due to superuser tripping over a user-defined event trigger
103119
set role privileged_role;
104120
\echo

test/expected/event_triggers_super.out

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,26 @@ NOTICE: superuser mandated event trigger: current_user is supabase_storage_admi
5656

5757
-- creating extensions will fire superuser evtrigs
5858
set role privileged_role;
59-
\echo
60-
6159
create extension postgres_fdw;
6260
NOTICE: superuser mandated event trigger: current_user is postgres
6361
drop extension postgres_fdw;
6462
NOTICE: superuser mandated event trigger: current_user is postgres
6563
\echo
6664

65+
-- creating fdws will fire superuser evtrigs
66+
create foreign data wrapper new_fdw;
67+
NOTICE: superuser mandated event trigger: current_user is postgres
68+
drop foreign data wrapper new_fdw;
69+
NOTICE: superuser mandated event trigger: current_user is privileged_role
70+
\echo
71+
72+
-- creating publications will fire superuser evtrigs
73+
create publication p for all tables;
74+
NOTICE: superuser mandated event trigger: current_user is postgres
75+
drop publication p;
76+
NOTICE: superuser mandated event trigger: current_user is privileged_role
77+
\echo
78+
6779
-- a non-privileged role cannot alter a superuser owned evtrig
6880
set role rolecreator;
6981
\echo

test/sql/event_triggers.sql

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,24 @@ set role postgres;
7171
create table super_stuff();
7272
\echo
7373

74-
-- extensions won't execute the event trigger function (since they're executed by superuser under our implementation)
75-
set role rolecreator;
76-
\echo
77-
74+
-- creating extensions will not fire evtrigs
75+
set role privileged_role;
7876
create extension postgres_fdw;
7977
drop extension postgres_fdw;
8078
\echo
8179

80+
-- creating fdws will not fire evtrigs
81+
create foreign data wrapper new_fdw;
82+
-- TODO: while correct, this is inconsistent as dropping the fdw does fire the evtrig for the privileged_role
83+
drop foreign data wrapper new_fdw;
84+
\echo
85+
86+
-- creating pubs will not fire evtrigs
87+
create publication p for all tables;
88+
-- TODO: while correct, this is inconsistent as dropping the publication does fire the evtrig for the privileged_role
89+
drop publication p;
90+
\echo
91+
8292
-- privesc shouldn't happen due to superuser tripping over a user-defined event trigger
8393
set role privileged_role;
8494
\echo

test/sql/event_triggers_super.sql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ drop table storage_stuff;
4747

4848
-- creating extensions will fire superuser evtrigs
4949
set role privileged_role;
50-
\echo
51-
5250
create extension postgres_fdw;
5351
drop extension postgres_fdw;
5452
\echo
5553

54+
-- creating fdws will fire superuser evtrigs
55+
create foreign data wrapper new_fdw;
56+
drop foreign data wrapper new_fdw;
57+
\echo
58+
59+
-- creating publications will fire superuser evtrigs
60+
create publication p for all tables;
61+
drop publication p;
62+
\echo
63+
5664
-- a non-privileged role cannot alter a superuser owned evtrig
5765
set role rolecreator;
5866
\echo

0 commit comments

Comments
 (0)