-
-
Notifications
You must be signed in to change notification settings - Fork 187
fix: update pgbouncer.get_auth (INFRA-1530) #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4be80b
fix: update pgbouncer.get_auth
kangmingtay 25d23b7
chore: add tests for pgbouncer
kangmingtay e564965
chore: add pgbouncer test for role privileges
kangmingtay 6b7c966
chore: fix pgbouncer tests
kangmingtay 62d92a0
chore: include test for pgbouncer schema
kangmingtay 81a7483
chore: remove unnecessary comment
kangmingtay 507f13a
test: update schema files used for testing (#1559)
samrose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
migrations/db/migrations/20250417190610_update_pgbouncer_get_auth.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- migrate:up | ||
|
||
create or replace function pgbouncer.get_auth(p_usename text) returns table (username text, password text) | ||
language plpgsql security definer | ||
as $$ | ||
begin | ||
raise debug 'PgBouncer auth request: %', p_usename; | ||
|
||
return query | ||
select | ||
rolname::text, | ||
case when rolvaliduntil < now() | ||
then null | ||
else rolpassword::text | ||
end | ||
from pg_authid | ||
where rolname=$1 and rolcanlogin; | ||
end; | ||
$$; | ||
|
||
-- from migrations/db/migrations/20250312095419_pgbouncer_ownership.sql | ||
grant execute on function pgbouncer.get_auth(p_usename text) to postgres; | ||
|
||
-- migrate:down |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-- pgbouncer schema owner | ||
select | ||
n.nspname as schema_name, | ||
r.rolname as owner | ||
from | ||
pg_namespace n | ||
join | ||
pg_roles r on n.nspowner = r.oid | ||
where | ||
n.nspname = 'pgbouncer'; | ||
schema_name | owner | ||
-------------+----------- | ||
pgbouncer | pgbouncer | ||
(1 row) | ||
|
||
-- pgbouncer schema functions with owners | ||
select | ||
n.nspname as schema_name, | ||
p.proname as function_name, | ||
r.rolname as owner | ||
from | ||
pg_proc p | ||
join | ||
pg_namespace n on p.pronamespace = n.oid | ||
join | ||
pg_roles r on p.proowner = r.oid | ||
where | ||
n.nspname = 'pgbouncer' | ||
order by | ||
p.proname; | ||
schema_name | function_name | owner | ||
-------------+---------------+---------------- | ||
pgbouncer | get_auth | supabase_admin | ||
(1 row) | ||
|
||
-- Tests role privileges on the pgbouncer objects | ||
WITH schema_obj AS ( | ||
SELECT oid, nspname | ||
FROM pg_namespace | ||
WHERE nspname = 'pgbouncer' | ||
) | ||
SELECT | ||
s.nspname AS schema, | ||
c.relname AS object_name, | ||
acl.grantee::regrole::text AS grantee, | ||
acl.privilege_type | ||
FROM pg_class c | ||
JOIN schema_obj s ON s.oid = c.relnamespace | ||
CROSS JOIN LATERAL aclexplode(c.relacl) AS acl | ||
WHERE c.relkind IN ('r', 'v', 'm', 'f', 'p') | ||
AND acl.privilege_type <> 'MAINTAIN' | ||
UNION ALL | ||
SELECT | ||
s.nspname AS schema, | ||
p.proname AS object_name, | ||
acl.grantee::regrole::text AS grantee, | ||
acl.privilege_type | ||
FROM pg_proc p | ||
JOIN schema_obj s ON s.oid = p.pronamespace | ||
CROSS JOIN LATERAL aclexplode(p.proacl) AS acl | ||
ORDER BY object_name, grantee, privilege_type; | ||
schema | object_name | grantee | privilege_type | ||
-----------+-------------+----------------+---------------- | ||
pgbouncer | get_auth | pgbouncer | EXECUTE | ||
pgbouncer | get_auth | postgres | EXECUTE | ||
pgbouncer | get_auth | supabase_admin | EXECUTE | ||
(3 rows) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
-- pgbouncer schema owner | ||
select | ||
n.nspname as schema_name, | ||
r.rolname as owner | ||
from | ||
pg_namespace n | ||
join | ||
pg_roles r on n.nspowner = r.oid | ||
where | ||
n.nspname = 'pgbouncer'; | ||
|
||
-- pgbouncer schema functions with owners | ||
select | ||
n.nspname as schema_name, | ||
p.proname as function_name, | ||
r.rolname as owner | ||
from | ||
pg_proc p | ||
join | ||
pg_namespace n on p.pronamespace = n.oid | ||
join | ||
pg_roles r on p.proowner = r.oid | ||
where | ||
n.nspname = 'pgbouncer' | ||
order by | ||
p.proname; | ||
|
||
-- Tests role privileges on the pgbouncer objects | ||
WITH schema_obj AS ( | ||
SELECT oid, nspname | ||
FROM pg_namespace | ||
WHERE nspname = 'pgbouncer' | ||
) | ||
SELECT | ||
s.nspname AS schema, | ||
c.relname AS object_name, | ||
acl.grantee::regrole::text AS grantee, | ||
acl.privilege_type | ||
FROM pg_class c | ||
JOIN schema_obj s ON s.oid = c.relnamespace | ||
CROSS JOIN LATERAL aclexplode(c.relacl) AS acl | ||
WHERE c.relkind IN ('r', 'v', 'm', 'f', 'p') | ||
AND acl.privilege_type <> 'MAINTAIN' | ||
UNION ALL | ||
SELECT | ||
s.nspname AS schema, | ||
p.proname AS object_name, | ||
acl.grantee::regrole::text AS grantee, | ||
acl.privilege_type | ||
FROM pg_proc p | ||
JOIN schema_obj s ON s.oid = p.pronamespace | ||
CROSS JOIN LATERAL aclexplode(p.proacl) AS acl | ||
ORDER BY object_name, grantee, privilege_type; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.