Skip to content

fix(api): refuse tenant creation without an extension - #2581

Open
officialasishkumar wants to merge 1 commit into
supabase:mainfrom
officialasishkumar:fix/tenant-create-requires-extension
Open

officialasishkumar wants to merge 1 commit into
supabase:mainfrom
officialasishkumar:fix/tenant-create-requires-extension

Conversation

@officialasishkumar

Copy link
Copy Markdown

Why

Creating a tenant without a usable extension returns a 500. With no extensions key, TenantController.update/2 raises Protocol.UndefinedError. With [], or entries missing type or settings, the tenant is inserted first, then Migrations.run_migrations/1 raises MatchError in migration_target/1. That leaves a committed tenant with no database settings, which can never connect or migrate.

What changed

  • New creation_extensions/1 in TenantController does the existing extension filtering and refuses an empty result. The request now gets a 422 "extensions must have at least one extension with a type and settings" before anything is inserted.
  • Updating an existing tenant is unchanged.

Verification

  • Three new tenant_controller_test.exs tests: POST with no extensions, PUT with [], and PUT with an entry that has no settings. Each asserts the 422 and that no tenant was created. On main they fail with the Protocol.UndefinedError and MatchError above; with the fix they pass.
  • test/realtime_web/controllers and test/realtime/api_test.exs: 268 tests, 0 failures.
  • mix format --check-formatted, mix compile --force --warnings-as-errors and mix credo on the changed files pass.

Fixes #2580

Creating a tenant through POST /api/tenants or PUT /api/tenants/:tenant_id
without a usable extension crashed with a 500:

- With no "extensions" key, TenantController.update/2 reduced over nil
  and raised Protocol.UndefinedError.
- With an empty list, or entries lacking "type" or "settings",
  Api.create_tenant/1 inserted the tenant and then
  Migrations.run_migrations/1 raised MatchError in migration_target/1.
  The tenant row stayed committed with no database settings, so it
  could never connect or run its migrations.

The tenant's database settings live in its extension, so a tenant
without one is now refused with a 422 before anything is inserted.
The filtering of extension entries is unchanged; it moved into
creation_extensions/1, which also checks the result isn't empty.

Updates to existing tenants are not affected.

Fixes supabase#2580

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating a tenant without an extension returns 500 and can leave a tenant that can't reach its database

1 participant