Repository navigation
Make postgres the grantor of pg_net access for anon, authenticated and service_role - #2628
utkarash2991 wants to merge 7 commits into
Conversation
…d service_role Only the grantor can revoke a grant, and supabase_admin was the grantor, so customers could not take pg_net access away from these roles. One routine now does the grants: postgres gets them with grant option, a role that still holds the old grant gets it again from postgres, new projects get none. The event trigger calls the routine, and complete.sh runs the migration file on upgrade since migrations are not replayed there.
PostgreSQL Extension Dependency Analysis: PR #2628
SummaryNo extensions had dependencies with MAJOR version updates. Full Analysis ResultsPostgreSQL 15 Extension DependenciesPostgreSQL 17 Extension DependenciesOrioleDB 17 Extension Dependencies |
PostgreSQL Package Dependency Analysis: PR #2628
SummaryNo packages had MAJOR version updates. Full Analysis ResultsPostgreSQL 15 Dependency ChangesExtracting PostgreSQL 15 dependencies...
Runtime Closure Size
Raw Dependency ClosurePostgreSQL 17 Dependency ChangesExtracting PostgreSQL 17 dependencies...
Runtime Closure Size
Raw Dependency Closure |
Package version diffCompares built package versions in legacyPackages between this PR and the tip of the base branch, per system. aarch64-linux: Closure size: 73 -> 73 (2 paths added, 2 paths removed, delta +0, disk usage +0B).x86_64-linux: Closure size: 74 -> 74 (2 paths added, 2 paths removed, delta +0, disk usage +0B). |
This comment has been minimized.
This comment has been minimized.
supabase_functions_admin only got USAGE on net from the routine and relied on PUBLIC for EXECUTE. pg_net will stop granting PUBLIC, so the routine now grants the role EXECUTE on http_get, http_post and http_delete as supabase_admin, the same way it grants USAGE.
This comment has been minimized.
This comment has been minimized.
brainrake
left a comment
There was a problem hiding this comment.
Grants: Changes needed
New projects get no API role grants: supautils runs create extension with both security flags set, so set role postgres fails inside the trigger and step 2 has nothing to convert. The grantor is whoever runs the GRANT, and only a SECURITY DEFINER function owned by postgres changes that here:
SET ROLE/SET SESSION AUTHORIZATION: blocked by both supautils flags.GRANT ... GRANTED BY postgres: PG requires the grantor to be the current user.ALTER SCHEMA net OWNER TO postgres: not dumped for extension members, and hands postgres the extension's objects.- Grant as supabase_admin in the trigger and convert later: new projects differ until their next pg_upgrade.
The inline suggestions add that helper, dropped and recreated on every run so a superuser never calls a body the customer changed, and reduce step 2 to one rule: a role holding USAGE on net from supabase_admin or postgres gets the full set from postgres, and whatever supabase_admin gave the three roles goes. A fresh install plants USAGE as supabase_admin and the same loop converts it, so the trigger body and signature stay. Firing the trigger on ALTER EXTENSION too lets that loop repair an update that recreates a function.
Restore: OK
Restore checks out as written: the multi-file restore runs with postgres as a superuser, so the routine stays out of the way and the migration replay converts the dump's grants afterwards. The superuser branch is what makes that work, so it should stay.
Tested: OK
Verified on this repo's PG 17 with supautils: fresh install, re-run after a customer revoke, migration with anon revoked by support, USAGE-only revoke, update 0.19.5 to 0.20.4, full revoke then update, and the restore sequence.
Smaller changes needed
The publish workflow's paths filter misses the migration, complete.sh should run the file in one transaction, and the nix test should recreate pg_net as postgres so it goes through supautils.
Merge after supabase/platform#41518 is deployed, per the TODO.
…ER on the net tables off PUBLIC A SECURITY DEFINER helper owned by postgres makes the grants for anon, authenticated and service_role, so they are recorded as made by postgres even inside CREATE EXTENSION where SET ROLE is refused. New projects get the same three grants from postgres. The routine no longer catches errors: the trigger path fails the CREATE or ALTER EXTENSION, the migration and complete.sh warn. The trigger also fires on ALTER EXTENSION. complete.sh runs the file in one transaction. PUBLIC loses TRIGGER, REFERENCES and TRUNCATE on the net tables. postgres keeps TRIGGER and TRUNCATE with grant option.
|
@brainrake Thanks for reviewing the PR. I think I have addressed all your review comments. Can you take a look please ? |
…ants test pg_dump quotes the routine body with $_$ now that it contains $$. The test's queued request could still be in flight when the next test plants a trigger on the response table, so wait for the worker to finish it.
In postgres, only the grantor can revoke a grant. Today supabase_admin grants anon, authenticated and service_role access to schema net and the http functions, so a customer cannot take that access away.
What changes
One routine,
extensions.apply_pg_net_grants(), replaces the grant code in the event trigger and in complete.sh.How it reaches a project
The routine must run after postgres loses superuser. While postgres is a superuser, Postgres records its grants as made by supabase_admin. The routine checks for that and refuses with a warning.
Linear: PSQLEXT-1795, PSQLEXT-1796, PSQLEXT-1797, PSQLEXT-1798