Repository navigation
Description
Documentation link
https://supabase.com/docs/reference/cli/supabase-db-dump, section "Note on Privilege Migration" (source: apps/cli/docs/supabase/db/dump.md)
Issue type
Missing documentation
Problem
The note added in #4885 (for #4862) says that when restoring to a new project, "tables inherit ALL privileges from default privileges in the target database". Its fix revokes the default privileges on tables only:
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM anon, authenticated;Functions and sequences have the same problem. A new Supabase database's default privileges in public also give every new function and sequence that postgres creates there to anon and authenticated. pg_dump writes each object's privileges as changes from PostgreSQL's built-in defaults, so a privilege the source took away from anon leaves no line in the dump. On restore, the target's defaults grant it again. With the note's statement run first, the table stays closed, but a function the source had closed to anon can be executed by anon again.
The dump also ends with the source's own ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" ... TO "anon" lines. So after one restore, the target's defaults grant to anon again, and the statements have to run again before any later restore into the same database.
Reproduction with CLI 3.2.0, in local containers of public.ecr.aws/supabase/postgres:17.12.0.000 (one source, three new targets). CLI 3.1.0 gave the same results:
-
On the source, as
postgres:create table public.mech_t (id int); revoke all on table public.mech_t from anon; create function public.mech_fn() returns int language sql as 'select 1'; revoke all on function public.mech_fn() from public, anon; create sequence public.mech_seq; revoke all on sequence public.mech_seq from anon;
-
Dump it with the three commands from the backup and restore guide, using
--remote=<source url>:--role-onlytoroles.sql, the schema toschema.sql, and--use-copy --data-onlytodata.sql. -
Restore into each target with the guide's command:
psql --single-transaction --variable ON_ERROR_STOP=1 --file roles.sql --file schema.sql --command 'SET session_replication_role = replica' --file data.sql --dbname "<target url>"
-
Check on each database:
select has_table_privilege('anon', 'public.mech_t', 'select'), has_function_privilege('anon', 'public.mech_fn()', 'execute'), has_sequence_privilege('anon', 'public.mech_seq', 'usage');
| Database | anon: table | anon: function | anon: sequence |
|---|---|---|---|
| Source | f | f | f |
| Target 1, restore only | t | t | t |
| Target 2, the note's statement run first | f | t | t |
| Target 3, the same statement for tables, functions and sequences run first | f | f | f |
All three restores exited 0 with no error. For these objects, schema.sql has only these lines, none about anon:
REVOKE ALL ON FUNCTION "public"."mech_fn"() FROM PUBLIC;
GRANT ALL ON FUNCTION "public"."mech_fn"() TO "authenticated";
GRANT ALL ON FUNCTION "public"."mech_fn"() TO "service_role";
GRANT ALL ON SEQUENCE "public"."mech_seq" TO "authenticated";
GRANT ALL ON SEQUENCE "public"."mech_seq" TO "service_role";
GRANT ALL ON TABLE "public"."mech_t" TO "authenticated";
GRANT ALL ON TABLE "public"."mech_t" TO "service_role";We first saw this with CLI 2.31.4 on Supabase Cloud, moving a small app from one Free project to a second Free project (both PostgreSQL 17.12, both created with "Automatically expose new tables" ticked). After the restore, an anonymous call to a function that returns the key for the app's PDF service got HTTP 200, where the source answered 401. On that second project, a table and a function dumped with pg_dump gave the same results as targets 1 and 2 above: with the note's statement run first, the table was closed to anon and the function was open.
Suggested improvement
Extend the note to functions and sequences, and say when to run it:
-- Run right before restoring your schema, and again before any later restore into the same database
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM anon, authenticated;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON FUNCTIONS FROM anon, authenticated;
ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon, authenticated;It would also help to put the same step in the backup and restore guide and the restore-to-self-hosted guide. Both use the psql command above, and as of 16 Nov 2026 neither mentions default privileges. In our test, a restore into self-hosted Supabase widened the same grants as the restore into the second Cloud project.
Additional context
- Related: Privileges are not working correctly during migrating between projects due to default privileges being ALL for anon, authenticated #4862 (closed 10 Mar 2026) and fix: add privilege migration note for db dump #4885.
- Environment: Supabase CLI 3.2.0, and 3.1.0 before it (Homebrew, macOS on Apple silicon), Docker 29.9.2, psql 17.9. CLI 3.2.0 ran pg_dump 17.12 in containers of
public.ecr.aws/supabase/postgres:17.12.0.000, and 3.1.0 ran pg_dump 17.11 in17.11.0.018. - Also checked with CLI 3.1.0 and 3.2.0, against a local container that has those roles: the role-only dump no longer includes
supabase_etl_admin,supabase_privileged_roleor their grants. With 2.31.4, those lines in a Cloud project's roles file stopped the guide's restore on both Supabase targets. Thanks for that change.
Activity