|
1 | 1 | /* |
2 | 2 |
|
3 | | -Test to verify supautils (v3.0.0+) allows non-superuser postgres role to own FDWs. |
| 3 | +Test to verify supautils (v3.0.0+) allows non-superuser postgres role to use postgres_fdw. |
4 | 4 |
|
5 | | -This test ensures that the supautils extension properly handles FDW ownership |
| 5 | +This test ensures that the supautils extension properly handles FDW usage |
6 | 6 | for the privileged postgres role without requiring temporary superuser privileges. |
7 | 7 |
|
8 | 8 | This verifies the fix that eliminated the need for: |
9 | | -ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed) |
| 9 | +https://github.com/supabase/postgres/blob/a638c6fce0baf90b654e762eddcdac1bc8df01ee/ansible/files/postgresql_extension_custom_scripts/postgres_fdw/after-create.sql (removed) |
10 | 10 |
|
11 | 11 | */ |
12 | | -BEGIN; |
| 12 | +begin; |
13 | 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) |
| 14 | +set role postgres; |
35 | 15 |
|
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 |
| 16 | +-- postgres_fdw should be owned by the superuser |
| 17 | +select fdwowner::regrole from pg_foreign_data_wrapper where fdwname = 'postgres_fdw'; |
| 18 | + fdwowner |
| 19 | +---------------- |
| 20 | + supabase_admin |
48 | 21 | (1 row) |
49 | 22 |
|
50 | | -ROLLBACK; |
| 23 | +-- Verify that `postgres` can use the FDW despite not owning it |
| 24 | +create server s |
| 25 | + foreign data wrapper postgres_fdw |
| 26 | + options ( |
| 27 | + host '127.0.0.1', |
| 28 | + port '5432', |
| 29 | + dbname 'postgres' |
| 30 | + ); |
| 31 | +CREATE SERVER |
| 32 | + |
| 33 | +rollback; |
0 commit comments