Repository navigation
Description
Affected area
Database
Supabase CLI version
3.4.0 (first seen on 3.0.0)
Operating system
Windows 11 (Docker Desktop)
Installation method
npm
Command
supabase db dump --remote "postgresql://postgres:postgres@127.0.0.1:<port>/postgres" -f schema.sqlActual output
supabase db dump leaves out every GRANT and REVOKE line for a function when one of its argument types lives in a schema the dump excludes, for example extensions.vector, extensions.citext or extensions.geometry. After a restore from that file, such a function keeps PostgreSQL's built-in default, so PUBLIC (and with it anon and authenticated) can execute it, even if the source database had revoked that. The restore succeeds with no error or warning.
This hits a common pattern: a pgvector search function like match_documents(query_embedding extensions.vector, ...) that the source had limited to service_role.
With the setup below, grep -n "ON FUNCTION" schema.sql shows privilege lines for plain_fn only:
REVOKE ALL ON FUNCTION "public"."plain_fn"("x" integer) FROM PUBLIC;
GRANT ALL ON FUNCTION "public"."plain_fn"("x" integer) TO "service_role";Plain pg_dump --schema-only --quote-all-identifier --schema public on the same database also writes the two lines for vec_fn:
REVOKE ALL ON FUNCTION "public"."vec_fn"("v" "extensions"."vector") FROM PUBLIC;
GRANT ALL ON FUNCTION "public"."vec_fn"("v" "extensions"."vector") TO "service_role";After restoring schema.sql into a fresh database:
| Function | Source proacl |
Target proacl |
anon can execute on target |
|---|---|---|---|
plain_fn |
{postgres=X/postgres,service_role=X/postgres} |
{postgres=X/postgres,service_role=X/postgres} |
f |
vec_fn |
{postgres=X/postgres,service_role=X/postgres} |
{=X/postgres,postgres=X/postgres,service_role=X/postgres} |
t |
The restore exited 0. On the target, set role anon; select public.vec_fn('[1,2,3]'); returns 1, while select public.plain_fn(1); fails with permission denied for function plain_fn.
Expected behavior
The dump keeps the GRANT and REVOKE lines of a function in a dumped schema, whatever schemas its argument types come from, so vec_fn stays closed to PUBLIC and anon after the restore.
Steps to reproduce
Local container public.ecr.aws/supabase/postgres:17.12.0.002.
-
On a source database, as
postgres:create extension if not exists vector with schema extensions; -- control: no extension type in the arguments create function public.plain_fn(x int) returns int language sql as 'select x'; revoke all on function public.plain_fn(int) from public, anon, authenticated; grant execute on function public.plain_fn(int) to service_role; -- the same, but the argument is extensions.vector create function public.vec_fn(v extensions.vector) returns int language sql as 'select 1'; revoke all on function public.vec_fn(extensions.vector) from public, anon, authenticated; grant execute on function public.vec_fn(extensions.vector) to service_role;
-
Dump it:
supabase db dump --remote "postgresql://postgres:postgres@127.0.0.1:<port>/postgres" -f schema.sql -
Look at the privilege lines:
grep -n "ON FUNCTION" schema.sql -
Restore into a fresh database. To keep db dump: Note on Privilege Migration covers tables only, so functions and sequences regain anon privileges on restore #7647 (target default privileges) out of the result, first run:
alter default privileges in schema public revoke all on functions from anon, authenticated;
then:
psql --single-transaction --variable ON_ERROR_STOP=1 --file schema.sql --dbname "<target url>" -
Check:
select proname, proacl, has_function_privilege('anon', oid, 'execute') as anon_exec from pg_proc where proname in ('plain_fn', 'vec_fn') order by 1;
Docker and service versions
public.ecr.aws/supabase/postgres:17.12.0.002
Additional context
Cause. The filter that skips ACL lines on internal schemas matches the schema name anywhere on the line, including inside the argument list:
apps/cli/src/command-internal/pg-dump.run.ts:new RegExp(`^(GRANT|REVOKE) (.+) ON (.+) "(${excludedSchemaPattern})"`, "u")apps/cli/src/command-internal/pg-dump.scripts.ts:sed -E "s/^GRANT (.+) ON (.+) \"(${EXCLUDED_SCHEMAS:-})\"/-- &/"and the same forREVOKE
Because (.+) is greedy, this line matches on "extensions" inside the parentheses:
REVOKE ALL ON FUNCTION "public"."vec_fn"("v" "extensions"."vector") FROM PUBLIC;The same code is on develop and v3.5.0-beta.6. The filter only needs to check the schema of the object itself, i.e. the first quoted name after ON <object type>. For example, ^(GRANT|REVOKE) .+ ON [A-Z ]+ "(${pattern})"[. ] still skips GRANT USAGE ON SCHEMA "extensions" ..., GRANT ... ON FUNCTION "extensions"."foo"() ... and GRANT ... ON TABLE "auth"."users" ..., but keeps the two vec_fn lines.
Related but separate: #7647 (functions regain anon through the target's default privileges). This bug happens even with that fixed, because the REVOKE ... FROM PUBLIC line itself is missing. The backup and restore guide (https://supabase.com/docs/guides/platform/migrating-within-supabase/backup-restore) uses this dump, so anyone following it is affected.
Activity
atokim4 commentedon Nov 29, 2026
This also hits
supabase db pull. The initial pull indb-pull-run.tsbuilds its env withschema: [], soEXCLUDED_SCHEMASis set and the same filter runs, which means the generatedremote_schema.sqlmigration has noREVOKE ... FROM PUBLICformatch_documents-style functions, and everydb reset, branch ordb pushbuilt from it leaves them executable byanon.migration squashgoes throughdumpSchemaScripttoo.For
db dumpthere is a workaround until it's fixed: with-s public(or any explicit schema list)buildSchemaDumpEnvdoesn't setEXCLUDED_SCHEMASat all, so the filter is skipped and the lines stay. I ran your suggested regex against a few lines (vector/auth.usersargument types,ON SCHEMA "extensions",ON FUNCTION "extensions"."foo"(),ON TABLE "auth"."users", a column grant, apublic.extensions_ttype) and it keeps and skips exactly the right ones, while the current one drops all three argument-type cases.ckgiri commentedon Nov 29, 2026
Hey, I'd like to pick this up if that's ok.
I've got a fix on a branch already:
https://github.com/ckgiri/cli/tree/fix/db-dump-excluded-schema-function-args
Went with basically what @WeitzY suggested, so the filter only looks at the schema right after
ON FUNCTION/ON TABLEetc. instead of anywhere on the line. Changed it in both the TS filter and the sed version in the dump script. Like @atokim4 said, that also fixesdb pullandmigration squashsince they use the same script.Added a few test cases too, including running the schema cases through the actual bash script. The
vec_fn-style lines fail on develop and pass with the change.Can someone add
open-for-contributionso I can open a PR?Thanks!
fix(cli): keep db dump grants on functions with excluded-schema argum…