feat: enable customer installation of amcheck (PSQL-1327) - #2240
feat: enable customer installation of amcheck (PSQL-1327)#2240brainrake wants to merge 7 commits into
Conversation
PostgreSQL Extension Dependency Analysis: PR #2240
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 #2240
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 |
|
#2240 (comment) |
|
Backup Testing section in current PR description has an item that does not sound reasonable to me.
Assuming old and new correspond to Postgres 15 and 17, this is not an easy task. I do not yet know what options do our users have for restoring but the most probable methods do not work. Postgres 15 was shipped with amcheck Official support for downgrading to an older major version is explicitly not supported by PostgreSQL via standard restore tools. One can always try to manually fix issues in the dump and attempt to restore. It is highly likely that many iterations of edits and retries are required until you can actually downgrade your database version. |
|
I just used the issue template. I only wrote the first two paragraphs. |
|
@hanefi can you review wether amcheck is safe to enable for users? |
|
I am taking over the review and testing of this PR |
fbb6fd8 to
ac4b183
Compare
|
Will document next step of supadev smoke testing prior requesting review |
44432cb to
77b6c1f
Compare
| supautils.extensions_parameter_overrides = '{"pg_cron":{"schema":"pg_catalog"}}' | ||
| # amcheck must stay pinned to extensions. supautils creates privileged extensions as | ||
| # supabase_admin, whose search_path starts with public, where ALTER DEFAULT PRIVILEGES | ||
| # (init-scripts/00000000000000-initial-schema.sql) grants EXECUTE to anon, authenticated | ||
| # and service_role, i.e. to unauthenticated PostgREST callers. amcheck does no permission | ||
| # check of its own (upstream verify_nbtree.c: "Intentionally not checking permissions"), | ||
| # so EXECUTE alone lets a role check any index in the database, including auth's. In | ||
| # extensions the equivalent rule grants to postgres only. | ||
| # See PSQL-1327 and nix/tests/sql/amcheck.sql. | ||
| supautils.extensions_parameter_overrides = '{"pg_cron":{"schema":"pg_catalog"},"amcheck":{"schema":"extensions"}}' |
There was a problem hiding this comment.
Comment is unnecessary; also let's pin the schema to pg_catalog instead, users can drop the extensions schema
amcheck was in supautils' "may be unsafe" list based on upstream PostgreSQL's general caution around physical data structure exposure in error messages. No Supabase-specific exploit was ever documented. The restriction created a support gap: customers hit corrupted indexes after 15→17 upgrades and could not use bt_index_check() to enumerate and fix individual indexes, forcing full REINDEX DATABASE instead. Move amcheck from the superuser-only list to privileged_extensions so customers can install it. Update nix/tests/prime.sql and prime-superuser.sql to match. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move amcheck from supautils' superuser-only list into privileged_extensions, pinned to the `extensions` schema. The pin is required. In `public`, ALTER DEFAULT PRIVILEGES grants EXECUTE to anon/authenticated/service_role, and amcheck does no permission check of its own — so unauthenticated PostgREST callers could run bt_index_parent_check() and verify_heapam() against any table. In `extensions` the equivalent rule grants to postgres only
fd7ffd3 to
673cab3
Compare
Closes PSQL-1327
What kind of change does this PR introduce?
Moves the amcheck contrib extension into
supautils.privileged_extensionssocustomers can install it, pinned to the
extensionsschema.Additional context
amcheck was on supautils' "may be unsafe" list based on upstream
caution around physical data
structure exposure. Enabling it turned out to require the schema pin:
supabase_admin, whose search_pathstarts with
public.ALTER DEFAULT PRIVILEGES ... IN SCHEMA public(initial-schema.sql) grantsEXECUTE to
postgres, anon, authenticated, service_role. Those are explicitgrants, so amcheck's
REVOKE ALL FROM PUBLICdoes not strip them.verify_nbtree.c:"Intentionally not checking permissions" so EXECUTE means "check any index in
the database".
Verified before the pin:
set role anon; select bt_index_check('auth.users_pkey')succeeded. That would have exposed
bt_index_parent_check()(ShareLock, blockswrites) and
verify_heapam()to unauthenticated PostgREST callers. Inextensionsthe equivalent rule grants to
postgresonly with grant option, so customers canstill share it deliberately.
Tests
nix/tests/sql/amcheck.sql— placement, override enforcement (with schema publicis redirected), the four-role privilege matrix, and the functional path.
nix/ext/tests/amcheck-upgrade.nix15→17pg_upgradepreserves schema andgrants, including through the 1.3→1.4 extension update that creates new functions.
Action Items
supadev trigger-smoke-tests <PR> engines extensionsupgradetarget covers pause-on-old/restore-on-new;single-file backup/restore still manual