Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
67 changes: 58 additions & 9 deletions migrations/schema-15.sql
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,21 @@ COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeh

CREATE FUNCTION pgbouncer.get_auth(p_usename text) RETURNS TABLE(username text, password text)
LANGUAGE plpgsql SECURITY DEFINER
AS $$
BEGIN
RAISE WARNING 'PgBouncer auth request: %', p_usename;

RETURN QUERY
SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
WHERE usename = p_usename;
END;
$$;
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;
$_$;


--
Expand Down Expand Up @@ -1003,3 +1009,46 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
-- Dbmate schema migrations
--

INSERT INTO public.schema_migrations (version) VALUES
('00000000000000'),
('00000000000001'),
('00000000000002'),
('00000000000003'),
('10000000000000'),
('20211115181400'),
('20211118015519'),
('20211122051245'),
('20211124212715'),
('20211130151719'),
('20220118070449'),
('20220126121436'),
('20220224211803'),
('20220317095840'),
('20220321174452'),
('20220322085208'),
('20220404205710'),
('20220609081115'),
('20220613123923'),
('20220713082019'),
('20221028101028'),
('20221103090837'),
('20221207154255'),
('20230201083204'),
('20230224042246'),
('20230306081037'),
('20230327032006'),
('20230529180330'),
('20231013070755'),
('20231017062225'),
('20231020085357'),
('20231130133139'),
('20240124080435'),
('20240606060239'),
('20241031003909'),
('20241215003910'),
('20250205060043'),
('20250205144616'),
('20250218031949'),
('20250220051611'),
('20250312095419'),
('20250417190610');
67 changes: 58 additions & 9 deletions migrations/schema-17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,21 @@ COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeh

CREATE FUNCTION pgbouncer.get_auth(p_usename text) RETURNS TABLE(username text, password text)
LANGUAGE plpgsql SECURITY DEFINER
AS $$
BEGIN
RAISE WARNING 'PgBouncer auth request: %', p_usename;

RETURN QUERY
SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
WHERE usename = p_usename;
END;
$$;
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;
$_$;


--
Expand Down Expand Up @@ -990,3 +996,46 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
-- Dbmate schema migrations
--

INSERT INTO public.schema_migrations (version) VALUES
('00000000000000'),
('00000000000001'),
('00000000000002'),
('00000000000003'),
('10000000000000'),
('20211115181400'),
('20211118015519'),
('20211122051245'),
('20211124212715'),
('20211130151719'),
('20220118070449'),
('20220126121436'),
('20220224211803'),
('20220317095840'),
('20220321174452'),
('20220322085208'),
('20220404205710'),
('20220609081115'),
('20220613123923'),
('20220713082019'),
('20221028101028'),
('20221103090837'),
('20221207154255'),
('20230201083204'),
('20230224042246'),
('20230306081037'),
('20230327032006'),
('20230529180330'),
('20231013070755'),
('20231017062225'),
('20231020085357'),
('20231130133139'),
('20240124080435'),
('20240606060239'),
('20241031003909'),
('20241215003910'),
('20250205060043'),
('20250205144616'),
('20250218031949'),
('20250220051611'),
('20250312095419'),
('20250417190610');
67 changes: 58 additions & 9 deletions migrations/schema-orioledb-17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,21 @@ COMMENT ON FUNCTION extensions.set_graphql_placeholder() IS 'Reintroduces placeh

CREATE FUNCTION pgbouncer.get_auth(p_usename text) RETURNS TABLE(username text, password text)
LANGUAGE plpgsql SECURITY DEFINER
AS $$
BEGIN
RAISE WARNING 'PgBouncer auth request: %', p_usename;

RETURN QUERY
SELECT usename::TEXT, passwd::TEXT FROM pg_catalog.pg_shadow
WHERE usename = p_usename;
END;
$$;
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;
$_$;


--
Expand Down Expand Up @@ -1004,3 +1010,46 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop
-- Dbmate schema migrations
--

INSERT INTO public.schema_migrations (version) VALUES
('00000000000000'),
('00000000000001'),
('00000000000002'),
('00000000000003'),
('10000000000000'),
('20211115181400'),
('20211118015519'),
('20211122051245'),
('20211124212715'),
('20211130151719'),
('20220118070449'),
('20220126121436'),
('20220224211803'),
('20220317095840'),
('20220321174452'),
('20220322085208'),
('20220404205710'),
('20220609081115'),
('20220613123923'),
('20220713082019'),
('20221028101028'),
('20221103090837'),
('20221207154255'),
('20230201083204'),
('20230224042246'),
('20230306081037'),
('20230327032006'),
('20230529180330'),
('20231013070755'),
('20231017062225'),
('20231020085357'),
('20231130133139'),
('20240124080435'),
('20240606060239'),
('20241031003909'),
('20241215003910'),
('20250205060043'),
('20250205144616'),
('20250218031949'),
('20250220051611'),
('20250312095419'),
('20250417190610');