Skip to content

Commit 32e93b5

Browse files
committed
fix: pg_cron perms
1 parent de19ac2 commit 32e93b5

File tree

4 files changed

+70
-13
lines changed

4 files changed

+70
-13
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
grant usage on schema cron to postgres with grant option;
2+
grant all on all functions in schema cron to postgres with grant option;
3+
4+
alter default privileges for user supabase_admin in schema cron grant all
5+
on sequences to postgres with grant option;
6+
alter default privileges for user supabase_admin in schema cron grant all
7+
on tables to postgres with grant option;
8+
alter default privileges for user supabase_admin in schema cron grant all
9+
on functions to postgres with grant option;
10+
11+
grant all privileges on all tables in schema cron to postgres with grant option;
12+
revoke all on table cron.job from postgres;
13+
grant select on table cron.job to postgres with grant option;

common.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.131"
1+
postgres-version = "15.1.0.132"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- migrate:up
2+
do $$
3+
begin
4+
if exists (select from pg_extension where extname = 'pg_cron') then
5+
revoke all on table cron.job from postgres;
6+
grant select on table cron.job to postgres with grant option;
7+
end if;
8+
end $$;
9+
10+
CREATE OR REPLACE FUNCTION extensions.grant_pg_cron_access() RETURNS event_trigger
11+
LANGUAGE plpgsql
12+
AS $$
13+
BEGIN
14+
IF EXISTS (
15+
SELECT
16+
FROM pg_event_trigger_ddl_commands() AS ev
17+
JOIN pg_extension AS ext
18+
ON ev.objid = ext.oid
19+
WHERE ext.extname = 'pg_cron'
20+
)
21+
THEN
22+
grant usage on schema cron to postgres with grant option;
23+
24+
alter default privileges in schema cron grant all on tables to postgres with grant option;
25+
alter default privileges in schema cron grant all on functions to postgres with grant option;
26+
alter default privileges in schema cron grant all on sequences to postgres with grant option;
27+
28+
alter default privileges for user supabase_admin in schema cron grant all
29+
on sequences to postgres with grant option;
30+
alter default privileges for user supabase_admin in schema cron grant all
31+
on tables to postgres with grant option;
32+
alter default privileges for user supabase_admin in schema cron grant all
33+
on functions to postgres with grant option;
34+
35+
grant all privileges on all tables in schema cron to postgres with grant option;
36+
revoke all on table cron.job from postgres;
37+
grant select on table cron.job to postgres with grant option;
38+
END IF;
39+
END;
40+
$$;
41+
42+
drop event trigger if exists issue_pg_cron_access;
43+
CREATE EVENT TRIGGER issue_pg_cron_access ON ddl_command_end
44+
WHEN TAG IN ('CREATE EXTENSION')
45+
EXECUTE FUNCTION extensions.grant_pg_cron_access();
46+
47+
-- migrate:down

migrations/schema.sql

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,14 @@ $$;
210210
CREATE FUNCTION extensions.grant_pg_cron_access() RETURNS event_trigger
211211
LANGUAGE plpgsql
212212
AS $$
213-
DECLARE
214-
schema_is_cron bool;
215213
BEGIN
216-
schema_is_cron = (
217-
SELECT n.nspname = 'cron'
214+
IF EXISTS (
215+
SELECT
218216
FROM pg_event_trigger_ddl_commands() AS ev
219-
LEFT JOIN pg_catalog.pg_namespace AS n
220-
ON ev.objid = n.oid
221-
);
222-
223-
IF schema_is_cron
217+
JOIN pg_extension AS ext
218+
ON ev.objid = ext.oid
219+
WHERE ext.extname = 'pg_cron'
220+
)
224221
THEN
225222
grant usage on schema cron to postgres with grant option;
226223

@@ -236,9 +233,9 @@ BEGIN
236233
on functions to postgres with grant option;
237234

238235
grant all privileges on all tables in schema cron to postgres with grant option;
239-
236+
revoke all on table cron.job from postgres;
237+
grant select on table cron.job to postgres with grant option;
240238
END IF;
241-
242239
END;
243240
$$;
244241

@@ -1018,7 +1015,7 @@ CREATE EVENT TRIGGER issue_graphql_placeholder ON sql_drop
10181015
--
10191016

10201017
CREATE EVENT TRIGGER issue_pg_cron_access ON ddl_command_end
1021-
WHEN TAG IN ('CREATE SCHEMA')
1018+
WHEN TAG IN ('CREATE EXTENSION')
10221019
EXECUTE FUNCTION extensions.grant_pg_cron_access();
10231020

10241021

0 commit comments

Comments
 (0)