Skip to content

Add Supabase tenant extension#267

Open
jerryhenley wants to merge 1 commit intovectorize-io:mainfrom
jerryhenley:add-supabase-extension
Open

Add Supabase tenant extension#267
jerryhenley wants to merge 1 commit intovectorize-io:mainfrom
jerryhenley:add-supabase-extension

Conversation

@jerryhenley
Copy link

Adds a TenantExtension for validating Supabase JWTs and providing multi-tenant memory isolation. Each authenticated user gets their own PostgreSQL schema.

Features:

  • JWT validation against Supabase Auth API
  • Automatic schema isolation per user
  • Connection pooling with reusable HTTP client
  • Production-tested at BrighterBalance

Includes complete documentation with installation, usage examples, and troubleshooting guide.

Copy link
Collaborator

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks for this contribution! we need to make this part of the api package otherwise users will not abble to use without modifying the package/docker image

@jerryhenley jerryhenley force-pushed the add-supabase-extension branch from 3adb345 to 703c9ea Compare February 1, 2026 03:35
@jerryhenley
Copy link
Author

Thanks for the feedback @nicoloboschi! I've updated the PR to address this:

Moved to built-in package: The extension now lives at hindsight_api.extensions.builtin.supabase_tenant — users just set two env vars and it works out of the box, no package modification needed:

HINDSIGHT_API_TENANT_EXTENSION=hindsight_api.extensions.builtin.supabase_tenant:SupabaseTenantExtension
HINDSIGHT_API_TENANT_SUPABASE_URL=https://your-project.supabase.co

Other changes in this update:

  • Local JWT verification via JWKS — tokens are verified locally using Supabase's public keys (cached 10 min, with rotation handling). No network call per request. Falls back to /auth/v1/user for legacy HS256 projects.
  • Added PyJWT[crypto] dependency to pyproject.toml
  • Added tenant extension lifecycle hooks in api/http.py (on_startup/on_shutdown)
  • Added public tenant_extension property on MemoryEngine
  • 54 unit tests covering init, JWKS auth, legacy auth, schema management, edge cases
  • Updated README to reflect the built-in architecture and JWKS-first approach

The old hindsight-integrations/supabase/supabase_tenant.py file has been removed since it's now built-in.

Move the Supabase tenant extension into the hindsight-api package so users
can enable it with just an environment variable — no file copying or Docker
image modifications needed.

Key improvements over the original submission:
- JWKS-based local JWT verification (no network call per request) with
  automatic fallback to /auth/v1/user for legacy HS256 projects
- Service key is now optional (only needed for HS256 or health checks)
- UUID validation on user IDs before schema name construction
- Schema prefix validation against Postgres identifier rules
- Key rotation handling with automatic JWKS cache refresh
- Proper logging via Python logging module
- Tenant extension lifecycle hooks (on_startup/on_shutdown) wired into
  the server lifespan
- Public tenant_extension property on MemoryEngine
- 54 unit tests covering both verification modes, cache behavior, error
  paths, and the extension loader
- README updated to reflect JWKS-first architecture

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@jerryhenley jerryhenley force-pushed the add-supabase-extension branch from 703c9ea to 1124533 Compare February 1, 2026 03:58
Copy link
Collaborator

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicoloboschi
Copy link
Collaborator

hey @jerryhenley can you rebase and resolve conflicts? after that I will merge the PR

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.

2 participants