Skip to content

db dump drops GRANT and REVOKE lines for functions whose arguments use a type from an excluded schema (e.g. extensions.vector) #7854

In review

Description

@WeitzY

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.sql

Actual 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.

  1. 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;
  2. Dump it:

    supabase db dump --remote "postgresql://postgres:postgres@127.0.0.1:<port>/postgres" -f schema.sql
  3. Look at the privilege lines:

    grep -n "ON FUNCTION" schema.sql
  4. 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>"
  5. 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 for REVOKE

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

  1. atokim4 commented on Nov 29, 2026

    @atokim4

    This also hits supabase db pull. The initial pull in db-pull-run.ts builds its env with schema: [], so EXCLUDED_SCHEMAS is set and the same filter runs, which means the generated remote_schema.sql migration has no REVOKE ... FROM PUBLIC for match_documents-style functions, and every db reset, branch or db push built from it leaves them executable by anon. migration squash goes through dumpSchemaScript too.

    For db dump there is a workaround until it's fixed: with -s public (or any explicit schema list) buildSchemaDumpEnv doesn't set EXCLUDED_SCHEMAS at all, so the filter is skipped and the lines stay. I ran your suggested regex against a few lines (vector/auth.users argument types, ON SCHEMA "extensions", ON FUNCTION "extensions"."foo"(), ON TABLE "auth"."users", a column grant, a public.extensions_t type) and it keeps and skips exactly the right ones, while the current one drops all three argument-type cases.

  2. ckgiri commented on Nov 29, 2026

    @ckgiri

    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 TABLE etc. 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 fixes db pull and migration squash since 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-contribution so I can open a PR?

    Thanks!

  3. added a commit that references this issue on Nov 29, 2026
    5a1c541
  4. self-assigned this
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions