Repository navigation
create supabase_admin_monitor role for monitoring services #2642
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
Open
TheOtherBrian1
wants to merge
5
commits into
develop
Choose a base branch
from
feat/supabase-monitor-role
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+425
−15
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8653927
create supabase_admin_monitor role for monitoring services
TheOtherBrian1 ab5e2e0
Merge remote-tracking branch 'origin/develop' into feat/supabase-moni…
Copilot 395af07
fix: sync monitor role test output and apply formatter
TheOtherBrian1 7ff856f
fix: sync PG17 monitor role test output and apply formatter
TheOtherBrian1 6623665
Merge branch 'develop' into feat/supabase-monitor-role
TheOtherBrian1 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
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
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,100 @@ | ||
| -- supabase_monitor_admin: passwordless, read-only | ||
| -- monitoring role ( | ||
| -- migrations/db/init-scripts/00000000000000-initial-schema.sql). | ||
| -- attributes: login, no password, bypassrls, nothing else | ||
| select rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, | ||
| rolreplication, rolbypassrls, rolconnlimit, rolpassword is null as no_password | ||
| from pg_authid where rolname = 'supabase_monitor_admin'; | ||
| rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolbypassrls | rolconnlimit | no_password | ||
| ----------+------------+---------------+-------------+-------------+----------------+--------------+--------------+------------- | ||
| f | t | f | f | t | f | t | 2 | t | ||
| (1 row) | ||
|
|
||
| -- per-role settings (read-only by default, empty search_path, timeouts) | ||
| select unnest(rolconfig) as setting from pg_roles where rolname = 'supabase_monitor_admin' order by 1; | ||
| setting | ||
| ---------------------------------------- | ||
| default_transaction_read_only=on | ||
| idle_in_transaction_session_timeout=3s | ||
| lock_timeout=3s | ||
| search_path="" | ||
| statement_timeout=3s | ||
| transaction_read_only=on | ||
| (6 rows) | ||
|
|
||
| -- memberships: exactly pg_monitor and pg_read_all_data | ||
| select roleid::regrole::text as role, admin_option | ||
| from pg_auth_members where member = 'supabase_monitor_admin'::regrole order by 1; | ||
| role | admin_option | ||
| ------------------+-------------- | ||
| pg_monitor | f | ||
| pg_read_all_data | f | ||
| (2 rows) | ||
|
|
||
| -- nobody is a member of it | ||
| select count(*) from pg_auth_members where roleid = 'supabase_monitor_admin'::regrole; | ||
| count | ||
| ------- | ||
| 0 | ||
| (1 row) | ||
|
|
||
| -- owns nothing and holds no object-level ACL entries anywhere | ||
| select count(*) from pg_shdepend | ||
| where refclassid = 'pg_authid'::regclass | ||
| and refobjid = 'supabase_monitor_admin'::regrole | ||
| and deptype in ('o', 'a'); | ||
| count | ||
| ------- | ||
| 0 | ||
| (1 row) | ||
|
|
||
| -- no CREATE on the database | ||
| select has_database_privilege('supabase_monitor_admin', current_database(), 'CREATE'); | ||
| has_database_privilege | ||
| ------------------------ | ||
| f | ||
| (1 row) | ||
|
|
||
| -- reads every table regardless of RLS, but cannot write. NOTE: this uses | ||
| -- SET SESSION AUTHORIZATION, which a future supautils impersonation guard | ||
| -- would block; switch to a probe role with identical grants when that lands | ||
| -- (see quick_explainer.md). | ||
| create table public.monitor_probe (id int); | ||
| insert into public.monitor_probe values (1), (2); | ||
| alter table public.monitor_probe enable row level security; | ||
| alter table public.monitor_probe force row level security; | ||
| alter table public.monitor_probe owner to postgres; | ||
| set session authorization supabase_monitor_admin; | ||
| select count(*) from public.monitor_probe; | ||
| count | ||
| ------- | ||
| 2 | ||
| (1 row) | ||
|
|
||
| insert into public.monitor_probe values (3); | ||
| ERROR: permission denied for table monitor_probe | ||
| reset session authorization; | ||
| drop table public.monitor_probe; | ||
| -- reserved role (supautils.conf.j2): the non-superuser postgres role cannot | ||
| -- grant it, modify it, grant to it, or drop it. Same pattern as | ||
| -- supautils_reserved_roles.sql. | ||
| begin; | ||
| set role postgres; | ||
| savepoint s; | ||
| grant supabase_monitor_admin to postgres; | ||
| ERROR: "supabase_monitor_admin" role memberships are reserved, only superusers can grant them | ||
| rollback to savepoint s; | ||
| alter role supabase_monitor_admin password 'x'; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| alter role supabase_monitor_admin set search_path = public; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| grant authenticated to supabase_monitor_admin; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| drop role supabase_monitor_admin; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| reset role; | ||
| rollback; |
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,109 @@ | ||
| -- supabase_monitor_admin: passwordless, read-only, for monitoring from localhost | ||
| -- migrations/db/init-scripts/00000000000000-initial-schema.sql) | ||
| -- attributes: login, no password, bypassrls, nothing else | ||
| -- only accessible via localhost | ||
| select rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, | ||
| rolreplication, rolbypassrls, rolconnlimit, rolpassword is null as no_password | ||
| from pg_authid where rolname = 'supabase_monitor_admin'; | ||
| rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolbypassrls | rolconnlimit | no_password | ||
| ----------+------------+---------------+-------------+-------------+----------------+--------------+--------------+------------- | ||
| f | t | f | f | t | f | t | 2 | t | ||
| (1 row) | ||
|
|
||
| -- per-role settings (read-only by default, empty search_path, timeouts) | ||
| select unnest(rolconfig) as setting from pg_roles where rolname = 'supabase_monitor_admin' order by 1; | ||
| setting | ||
| ---------------------------------------- | ||
| default_transaction_read_only=on | ||
| idle_in_transaction_session_timeout=3s | ||
| lock_timeout=3s | ||
| search_path="" | ||
| statement_timeout=3s | ||
| transaction_read_only=on | ||
| (6 rows) | ||
|
|
||
| -- memberships: exactly pg_monitor and pg_read_all_data (inherited; the role is | ||
| -- a plain INHERIT role). SET ROLE to them only drops privileges, checked below. | ||
| select roleid::regrole::text as role, admin_option, inherit_option, set_option | ||
| from pg_auth_members where member = 'supabase_monitor_admin'::regrole order by 1; | ||
| role | admin_option | inherit_option | set_option | ||
| ------------------+--------------+----------------+------------ | ||
| pg_monitor | f | t | t | ||
| pg_read_all_data | f | t | t | ||
| (2 rows) | ||
|
|
||
| -- nobody is a member of it | ||
| select count(*) from pg_auth_members where roleid = 'supabase_monitor_admin'::regrole; | ||
| count | ||
| ------- | ||
| 0 | ||
| (1 row) | ||
|
|
||
| -- owns nothing and holds no object-level ACL entries anywhere | ||
| -- keep in mind, the postgres role can assign it access to objects at a later point, but that's fine. | ||
| select count(*) from pg_shdepend | ||
| where refclassid = 'pg_authid'::regclass | ||
| and refobjid = 'supabase_monitor_admin'::regrole | ||
| and deptype in ('o', 'a'); | ||
| count | ||
| ------- | ||
| 0 | ||
| (1 row) | ||
|
|
||
| -- no CREATE on the database | ||
| select has_database_privilege('supabase_monitor_admin', current_database(), 'CREATE'); | ||
| has_database_privilege | ||
| ------------------------ | ||
| f | ||
| (1 row) | ||
|
|
||
| -- reads every table regardless of RLS, but cannot write; SET ROLE to a | ||
| -- predefined role only loses privileges (BYPASSRLS stays with supabase_monitor_admin, | ||
| -- so the RLS-protected rows disappear). NOTE: this uses SET SESSION | ||
| -- AUTHORIZATION, which supautils impersonation may block | ||
| create table public.monitor_probe (id int); | ||
| insert into public.monitor_probe values (1), (2); | ||
| alter table public.monitor_probe enable row level security; | ||
| alter table public.monitor_probe force row level security; | ||
| alter table public.monitor_probe owner to postgres; | ||
| set session authorization supabase_monitor_admin; | ||
| select count(*) from public.monitor_probe; | ||
| count | ||
| ------- | ||
| 2 | ||
| (1 row) | ||
|
|
||
| insert into public.monitor_probe values (3); | ||
| ERROR: permission denied for table monitor_probe | ||
| set role pg_read_all_data; | ||
| select count(*) from public.monitor_probe; | ||
| count | ||
| ------- | ||
| 0 | ||
| (1 row) | ||
|
|
||
| reset session authorization; | ||
| drop table public.monitor_probe; | ||
| -- reserved role (supautils.conf.j2): the non-superuser postgres role cannot | ||
| -- grant it, modify it, grant to it, or drop it. Same pattern as | ||
| -- supautils_reserved_roles.sql. | ||
| begin; | ||
| set role postgres; | ||
| savepoint s; | ||
| grant supabase_monitor_admin to postgres; | ||
| ERROR: "supabase_monitor_admin" role memberships are reserved, only superusers can grant them | ||
| rollback to savepoint s; | ||
| alter role supabase_monitor_admin password 'x'; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| alter role supabase_monitor_admin set search_path = public; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| grant authenticated to supabase_monitor_admin; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| drop role supabase_monitor_admin; | ||
| ERROR: "supabase_monitor_admin" is a reserved role, only superusers can modify it | ||
| rollback to savepoint s; | ||
| reset role; | ||
| rollback; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
according to docs this should be in its own migration
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.
Thanks for looking over the PR, @mmlb! I was following the example set in the request:
It created the
supabase_etl_adminuser.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.
yeah we don't have CI catching this atm and if its not a test then it doesn't get enforced :(, but I'd appreciate doing as the docs say