-
-
Notifications
You must be signed in to change notification settings - Fork 182
fix: evtrigs ownership #1489
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix: evtrigs ownership #1489
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,8 +42,6 @@ nix run github:supabase/postgres/mybranch#dbmate-tool -- --version 15 | |
|
||
aiming to provide a single source of truth for migrations on the platform that can be depended upon by those components. For more information on goals see [the RFC](https://www.notion.so/supabase/Centralize-SQL-Migrations-cd3847ae027d4f2bba9defb2cc82f69a) | ||
|
||
|
||
|
||
## How it was Created | ||
|
||
Migrations were pulled (in order) from: | ||
|
@@ -53,9 +51,8 @@ Migrations were pulled (in order) from: | |
|
||
For compatibility with hosted projects, we include [migrate.sh](migrate.sh) that executes migrations in the same order as ami build: | ||
|
||
1. Run all `db/init-scripts` with `postgres` superuser role. | ||
2. Run all `db/migrations` with `supabase_admin` superuser role. | ||
3. Finalize role passwords with `/etc/postgresql.schema.sql` if present. | ||
1. Run all `db/migrations` with `supabase_admin` superuser role. | ||
2. Finalize role passwords with `/etc/postgresql.schema.sql` if present. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is a way to test that these ownerships won't regress toward the end of the AMI build too? That kind of testing has proven valuable over time/worth covering usually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you covered this now |
||
|
||
Additionally, [supabase/postgres](https://github.com/supabase/postgres/blob/develop/ansible/playbook-docker.yml#L9) image contains several migration scripts to configure default extensions. These are run first by docker entrypoint and included in ami by ansible. | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
-- migrate:up | ||
|
||
-- Set up realtime | ||
-- 1. Create publication supabase_realtime if it doesn't already exist | ||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_catalog.pg_publication | ||
where pubname = 'supabase_realtime' | ||
) | ||
then | ||
create publication supabase_realtime; | ||
end if; | ||
end | ||
$$; | ||
|
||
-- Supabase super admin | ||
alter user supabase_admin with superuser createdb createrole replication bypassrls; | ||
|
||
-- Supabase replication user | ||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_roles | ||
where rolname = 'supabase_replication_admin' | ||
) | ||
then | ||
create user supabase_replication_admin with | ||
login | ||
replication; | ||
end if; | ||
end | ||
$$; | ||
|
||
-- Supabase read-only user | ||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_roles | ||
where rolname = 'supabase_read_only_user' | ||
) | ||
then | ||
create role supabase_read_only_user with | ||
login | ||
bypassrls; | ||
end if; | ||
end | ||
$$; | ||
grant pg_read_all_data to supabase_read_only_user; | ||
|
||
-- Extension namespacing | ||
create schema if not exists extensions; | ||
create extension if not exists "uuid-ossp" with schema extensions; | ||
create extension if not exists pgcrypto with schema extensions; | ||
create extension if not exists pgjwt with schema extensions; | ||
|
||
-- Set up auth roles for the developer | ||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_roles | ||
where rolname = 'anon' | ||
) | ||
then | ||
create role anon nologin noinherit; | ||
end if; | ||
end | ||
$$; | ||
|
||
-- "logged in" user: web_user, app_user, etc | ||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_roles | ||
where rolname = 'authenticated' | ||
) | ||
then | ||
create role authenticated nologin noinherit; | ||
end if; | ||
end | ||
$$; | ||
|
||
-- allow developers to create JWT's that bypass their policies | ||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_roles | ||
where rolname = 'service_role' | ||
) | ||
then | ||
create role service_role nologin noinherit bypassrls; | ||
end if; | ||
end | ||
$$; | ||
|
||
do $$ | ||
begin | ||
if not exists ( | ||
select 1 from pg_roles | ||
where rolname = 'authenticator' | ||
) | ||
then | ||
create role authenticator login noinherit; | ||
end if; | ||
end | ||
$$; | ||
|
||
|
||
grant anon to authenticator; | ||
grant authenticated to authenticator; | ||
grant service_role to authenticator; | ||
grant supabase_admin to authenticator; | ||
|
||
-- These are required so that the users receive grants whenever "postgres" creates tables/function | ||
grant usage on schema public to postgres, anon, authenticated, service_role; | ||
alter default privileges for role postgres in schema public grant all on tables to postgres, anon, authenticated, service_role; | ||
alter default privileges for role postgres in schema public grant all on functions to postgres, anon, authenticated, service_role; | ||
alter default privileges for role postgres in schema public grant all on sequences to postgres, anon, authenticated, service_role; | ||
|
||
-- Allow Extensions to be used in the API | ||
grant usage on schema extensions to postgres, anon, authenticated, service_role; | ||
|
||
-- Set up namespacing | ||
alter user supabase_admin SET search_path TO public, extensions; -- don't include the "auth" schema | ||
|
||
-- These are required so that the users receive grants whenever "supabase_admin" creates tables/function | ||
alter default privileges for user supabase_admin in schema public grant all | ||
on sequences to postgres, anon, authenticated, service_role; | ||
alter default privileges for user supabase_admin in schema public grant all | ||
on tables to postgres, anon, authenticated, service_role; | ||
alter default privileges for user supabase_admin in schema public grant all | ||
on functions to postgres, anon, authenticated, service_role; | ||
|
||
-- Set short statement/query timeouts for API roles | ||
alter role anon set statement_timeout = '3s'; | ||
alter role authenticated set statement_timeout = '8s'; | ||
|
||
-- migrate:down |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this after the regression tests, which offer better error reporting.