Skip to content

Commit 7643abb

Browse files
samrosesoedirgo
authored andcommitted
fix: incorporate v3.0.0 supautils (#1844)
* 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 * fix: add `grant usage` for postgres_fdw * test: postgres_fdw * fix: align expected output with test * chore: update versions --------- Co-authored-by: Bobbie Soedirgo <bobbie@soedirgo.dev>
1 parent b4a9631 commit 7643abb

File tree

5 files changed

+66
-26
lines changed

5 files changed

+66
-26
lines changed
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
do $$
2-
declare
3-
is_super boolean;
4-
begin
5-
is_super = (
6-
select usesuper
7-
from pg_user
8-
where usename = 'postgres'
9-
);
10-
11-
-- Need to be superuser to own FDWs, so we temporarily make postgres superuser.
12-
if not is_super then
13-
alter role postgres superuser;
14-
end if;
15-
16-
alter foreign data wrapper postgres_fdw owner to postgres;
17-
18-
if not is_super then
19-
alter role postgres nosuperuser;
20-
end if;
21-
end $$;
1+
grant usage on foreign data wrapper postgres_fdw to postgres with grant option;

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"
14+
postgres17: "17.6.1.023"
15+
postgres15: "15.14.1.023"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.24.1

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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
3+
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to use postgres_fdw.
4+
5+
This test ensures that the supautils extension properly handles FDW usage
6+
for the privileged postgres role without requiring temporary superuser privileges.
7+
8+
This verifies the fix that eliminated the need for:
9+
https://github.com/supabase/postgres/blob/a638c6fce0baf90b654e762eddcdac1bc8df01ee/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+
-- postgres_fdw should be owned by the superuser
16+
select fdwowner::regrole from pg_foreign_data_wrapper where fdwname = 'postgres_fdw';
17+
fdwowner
18+
----------------
19+
supabase_admin
20+
(1 row)
21+
22+
-- Verify that `postgres` can use the FDW despite not owning it
23+
create server s
24+
foreign data wrapper postgres_fdw
25+
options (
26+
host '127.0.0.1',
27+
port '5432',
28+
dbname 'postgres'
29+
);
30+
rollback;

nix/tests/sql/postgres_fdw.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
3+
Test to verify supautils (v3.0.0+) allows non-superuser postgres role to use postgres_fdw.
4+
5+
This test ensures that the supautils extension properly handles FDW usage
6+
for the privileged postgres role without requiring temporary superuser privileges.
7+
8+
This verifies the fix that eliminated the need for:
9+
https://github.com/supabase/postgres/blob/a638c6fce0baf90b654e762eddcdac1bc8df01ee/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+
-- postgres_fdw should be owned by the superuser
19+
select fdwowner::regrole from pg_foreign_data_wrapper where fdwname = 'postgres_fdw';
20+
21+
-- Verify that `postgres` can use the FDW despite not owning it
22+
create server s
23+
foreign data wrapper postgres_fdw
24+
options (
25+
host '127.0.0.1',
26+
port '5432',
27+
dbname 'postgres'
28+
);
29+
30+
rollback;

0 commit comments

Comments
 (0)