Skip to content

Commit 9cffd3f

Browse files
committed
fix: incorporate v3.0.0 supautils
with change that checks that an event trigger function is owned by the same superuser negating the need for after-create for postgresql_fdw introduces a test in pg_regress that checks the outcome of this change
1 parent a638c6f commit 9cffd3f

File tree

5 files changed

+102
-26
lines changed

5 files changed

+102
-26
lines changed

ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql

Lines changed: 0 additions & 21 deletions
This file was deleted.

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ postgres_major:
1010

1111
# Full version strings for each major version
1212
postgres_release:
13-
postgresorioledb-17: "17.5.1.043-orioledb"
14-
postgres17: "17.6.1.022"
15-
postgres15: "15.14.1.022"
13+
postgresorioledb-17: "17.5.1.044-orioledb-supautils-1"
14+
postgres17: "17.6.1.023-supautils-1"
15+
postgres15: "15.14.1.023-supautils-1"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.19.0

nix/ext/supautils.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
stdenv.mkDerivation rec {
99
pname = "supautils";
10-
version = "2.9.4";
10+
version = "3.0.0";
1111

1212
buildInputs = [ postgresql ];
1313

1414
src = fetchFromGitHub {
1515
owner = "supabase";
1616
repo = pname;
1717
rev = "refs/tags/v${version}";
18-
hash = "sha256-qP9fOEWXw+wY49GopTizwxSBEGS0UoseJHVBtKS/BdI=";
18+
hash = "sha256-EKKjNZQf7HwP/MxpHoPtbEtwXk+wO241GoXVcXpDMFs=";
1919
};
2020

2121
installPhase = ''
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
3+
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to own FDWs.
4+
5+
This test ensures that the supautils extension properly handles FDW ownership
6+
for the privileged postgres role without requiring temporary superuser privileges.
7+
8+
This verifies the fix that eliminated the need for:
9+
ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed)
10+
11+
*/
12+
BEGIN;
13+
-- Switch to the postgres role (non-superuser) to test supautils behavior
14+
SET ROLE postgres;
15+
-- Test 1: Create a custom FDW directly (this is what supautils v3.0.0 fixes)
16+
-- Before v3.0.0, this would fail because only superusers can create FDWs
17+
-- With v3.0.0, supautils allows postgres (privileged role) to create and own FDWs
18+
CREATE FOREIGN DATA WRAPPER test_fdw_postgres_owned;
19+
-- Reset to original role for queries because the tests run under a superuser context
20+
RESET ROLE;
21+
-- Verify that the custom FDW is owned by postgres (non-superuser)
22+
SELECT
23+
fdw.fdwname as fdw_name,
24+
owner.rolname as owner_name,
25+
owner.rolsuper as owner_is_superuser
26+
FROM
27+
pg_foreign_data_wrapper fdw
28+
JOIN pg_roles owner ON fdw.fdwowner = owner.oid
29+
WHERE
30+
fdw.fdwname = 'test_fdw_postgres_owned';
31+
fdw_name | owner_name | owner_is_superuser
32+
-------------------------+------------+--------------------
33+
test_fdw_postgres_owned | postgres | f
34+
(1 row)
35+
36+
-- Verify the postgres role's superuser status
37+
-- The key test: postgres should NOT be a superuser, yet can own the FDW
38+
SELECT
39+
rolname,
40+
rolsuper as is_superuser
41+
FROM
42+
pg_roles
43+
WHERE
44+
rolname = 'postgres';
45+
rolname | is_superuser
46+
----------+--------------
47+
postgres | f
48+
(1 row)
49+
50+
ROLLBACK;

nix/tests/sql/postgres_fdw.sql

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
3+
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to own FDWs.
4+
5+
This test ensures that the supautils extension properly handles FDW ownership
6+
for the privileged postgres role without requiring temporary superuser privileges.
7+
8+
This verifies the fix that eliminated the need for:
9+
ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed)
10+
11+
*/
12+
13+
BEGIN;
14+
15+
-- Switch to the postgres role (non-superuser) to test supautils behavior
16+
SET ROLE postgres;
17+
18+
-- Test 1: Create a custom FDW directly (this is what supautils v3.0.0 fixes)
19+
-- Before v3.0.0, this would fail because only superusers can create FDWs
20+
-- With v3.0.0, supautils allows postgres (privileged role) to create and own FDWs
21+
CREATE FOREIGN DATA WRAPPER test_fdw_postgres_owned;
22+
23+
-- Reset to original role for queries because the tests run under a superuser context
24+
RESET ROLE;
25+
26+
-- Verify that the custom FDW is owned by postgres (non-superuser)
27+
SELECT
28+
fdw.fdwname as fdw_name,
29+
owner.rolname as owner_name,
30+
owner.rolsuper as owner_is_superuser
31+
FROM
32+
pg_foreign_data_wrapper fdw
33+
JOIN pg_roles owner ON fdw.fdwowner = owner.oid
34+
WHERE
35+
fdw.fdwname = 'test_fdw_postgres_owned';
36+
37+
-- Verify the postgres role's superuser status
38+
-- The key test: postgres should NOT be a superuser, yet can own the FDW
39+
SELECT
40+
rolname,
41+
rolsuper as is_superuser
42+
FROM
43+
pg_roles
44+
WHERE
45+
rolname = 'postgres';
46+
47+
ROLLBACK;

0 commit comments

Comments
 (0)