Skip to content

Commit a4be80b

Browse files
committed
fix: update pgbouncer.get_auth
1 parent a4828c2 commit a4be80b

File tree

4 files changed

+198
-27
lines changed

4 files changed

+198
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- migrate:up
2+
3+
create or replace function pgbouncer.get_auth(p_usename text) returns table (username text, password text)
4+
language plpgsql security definer
5+
as $$
6+
begin
7+
raise debug 'PgBouncer auth request: %', p_usename;
8+
9+
return query
10+
select
11+
rolname::text,
12+
case when rolvaliduntil < now()
13+
then null
14+
else rolpassword::text
15+
end
16+
from pg_authid
17+
where rolname=$1 and rolcanlogin;
18+
end;
19+
$$;
20+
21+
-- from migrations/db/migrations/20250312095419_pgbouncer_ownership.sql
22+
grant execute on function pgbouncer.get_auth(p_usename text) to postgres;
23+
24+
-- migrate:down

Diff for: migrations/schema-15.sql

+58-9
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,21 @@ COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeh
483483

484484
CREATE FUNCTION pgbouncer.get_auth(p_usename text) RETURNS TABLE(username text, password text)
485485
LANGUAGE plpgsql SECURITY DEFINER
486-
AS $$
487-
BEGIN
488-
RAISE WARNING 'PgBouncer auth request: %', p_usename;
489-
490-
RETURN QUERY
491-
SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
492-
WHERE usename = p_usename;
493-
END;
494-
$$;
486+
AS $_$
487+
begin
488+
raise debug 'PgBouncer auth request: %', p_usename;
489+
490+
return query
491+
select
492+
rolname::text,
493+
case when rolvaliduntil < now()
494+
then null
495+
else rolpassword::text
496+
end
497+
from pg_authid
498+
where rolname=$1 and rolcanlogin;
499+
end;
500+
$_$;
495501

496502

497503
--
@@ -1003,3 +1009,46 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
10031009
-- Dbmate schema migrations
10041010
--
10051011

1012+
INSERT INTO public.schema_migrations (version) VALUES
1013+
('00000000000000'),
1014+
('00000000000001'),
1015+
('00000000000002'),
1016+
('00000000000003'),
1017+
('10000000000000'),
1018+
('20211115181400'),
1019+
('20211118015519'),
1020+
('20211122051245'),
1021+
('20211124212715'),
1022+
('20211130151719'),
1023+
('20220118070449'),
1024+
('20220126121436'),
1025+
('20220224211803'),
1026+
('20220317095840'),
1027+
('20220321174452'),
1028+
('20220322085208'),
1029+
('20220404205710'),
1030+
('20220609081115'),
1031+
('20220613123923'),
1032+
('20220713082019'),
1033+
('20221028101028'),
1034+
('20221103090837'),
1035+
('20221207154255'),
1036+
('20230201083204'),
1037+
('20230224042246'),
1038+
('20230306081037'),
1039+
('20230327032006'),
1040+
('20230529180330'),
1041+
('20231013070755'),
1042+
('20231017062225'),
1043+
('20231020085357'),
1044+
('20231130133139'),
1045+
('20240124080435'),
1046+
('20240606060239'),
1047+
('20241031003909'),
1048+
('20241215003910'),
1049+
('20250205060043'),
1050+
('20250205144616'),
1051+
('20250218031949'),
1052+
('20250220051611'),
1053+
('20250312095419'),
1054+
('20250417190610');

Diff for: migrations/schema-17.sql

+58-9
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,21 @@ COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeh
470470

471471
CREATE FUNCTION pgbouncer.get_auth(p_usename text) RETURNS TABLE(username text, password text)
472472
LANGUAGE plpgsql SECURITY DEFINER
473-
AS $$
474-
BEGIN
475-
RAISE WARNING 'PgBouncer auth request: %', p_usename;
476-
477-
RETURN QUERY
478-
SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
479-
WHERE usename = p_usename;
480-
END;
481-
$$;
473+
AS $_$
474+
begin
475+
raise debug 'PgBouncer auth request: %', p_usename;
476+
477+
return query
478+
select
479+
rolname::text,
480+
case when rolvaliduntil < now()
481+
then null
482+
else rolpassword::text
483+
end
484+
from pg_authid
485+
where rolname=$1 and rolcanlogin;
486+
end;
487+
$_$;
482488

483489

484490
--
@@ -990,3 +996,46 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
990996
-- Dbmate schema migrations
991997
--
992998

999+
INSERT INTO public.schema_migrations (version) VALUES
1000+
('00000000000000'),
1001+
('00000000000001'),
1002+
('00000000000002'),
1003+
('00000000000003'),
1004+
('10000000000000'),
1005+
('20211115181400'),
1006+
('20211118015519'),
1007+
('20211122051245'),
1008+
('20211124212715'),
1009+
('20211130151719'),
1010+
('20220118070449'),
1011+
('20220126121436'),
1012+
('20220224211803'),
1013+
('20220317095840'),
1014+
('20220321174452'),
1015+
('20220322085208'),
1016+
('20220404205710'),
1017+
('20220609081115'),
1018+
('20220613123923'),
1019+
('20220713082019'),
1020+
('20221028101028'),
1021+
('20221103090837'),
1022+
('20221207154255'),
1023+
('20230201083204'),
1024+
('20230224042246'),
1025+
('20230306081037'),
1026+
('20230327032006'),
1027+
('20230529180330'),
1028+
('20231013070755'),
1029+
('20231017062225'),
1030+
('20231020085357'),
1031+
('20231130133139'),
1032+
('20240124080435'),
1033+
('20240606060239'),
1034+
('20241031003909'),
1035+
('20241215003910'),
1036+
('20250205060043'),
1037+
('20250205144616'),
1038+
('20250218031949'),
1039+
('20250220051611'),
1040+
('20250312095419'),
1041+
('20250417190610');

Diff for: migrations/schema-orioledb-17.sql

+58-9
Original file line numberDiff line numberDiff line change
@@ -484,15 +484,21 @@ COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeh
484484

485485
CREATE FUNCTION pgbouncer.get_auth(p_usename text) RETURNS TABLE(username text, password text)
486486
LANGUAGE plpgsql SECURITY DEFINER
487-
AS $$
488-
BEGIN
489-
RAISE WARNING 'PgBouncer auth request: %', p_usename;
490-
491-
RETURN QUERY
492-
SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
493-
WHERE usename = p_usename;
494-
END;
495-
$$;
487+
AS $_$
488+
begin
489+
raise debug 'PgBouncer auth request: %', p_usename;
490+
491+
return query
492+
select
493+
rolname::text,
494+
case when rolvaliduntil < now()
495+
then null
496+
else rolpassword::text
497+
end
498+
from pg_authid
499+
where rolname=$1 and rolcanlogin;
500+
end;
501+
$_$;
496502

497503

498504
--
@@ -1004,3 +1010,46 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
10041010
-- Dbmate schema migrations
10051011
--
10061012

1013+
INSERT INTO public.schema_migrations (version) VALUES
1014+
('00000000000000'),
1015+
('00000000000001'),
1016+
('00000000000002'),
1017+
('00000000000003'),
1018+
('10000000000000'),
1019+
('20211115181400'),
1020+
('20211118015519'),
1021+
('20211122051245'),
1022+
('20211124212715'),
1023+
('20211130151719'),
1024+
('20220118070449'),
1025+
('20220126121436'),
1026+
('20220224211803'),
1027+
('20220317095840'),
1028+
('20220321174452'),
1029+
('20220322085208'),
1030+
('20220404205710'),
1031+
('20220609081115'),
1032+
('20220613123923'),
1033+
('20220713082019'),
1034+
('20221028101028'),
1035+
('20221103090837'),
1036+
('20221207154255'),
1037+
('20230201083204'),
1038+
('20230224042246'),
1039+
('20230306081037'),
1040+
('20230327032006'),
1041+
('20230529180330'),
1042+
('20231013070755'),
1043+
('20231017062225'),
1044+
('20231020085357'),
1045+
('20231130133139'),
1046+
('20240124080435'),
1047+
('20240606060239'),
1048+
('20241031003909'),
1049+
('20241215003910'),
1050+
('20250205060043'),
1051+
('20250205144616'),
1052+
('20250218031949'),
1053+
('20250220051611'),
1054+
('20250312095419'),
1055+
('20250417190610');

0 commit comments

Comments
 (0)