Repository navigation
feat(self-hosted): add api gateway logic for functions - #46810
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
7 Skipped Deployments
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds gateway-specific opaque API-key translation/enforcement for Edge Functions (Kong and Envoy), updates gateway configs and Kong entrypoint to provide translation logic, and extends tests to validate anonymous, legacy, invalid, and opaque-key invocation paths including user-JWT preservation. ChangesOpaque API keys for Edge Functions
Sequence Diagram(s)sequenceDiagram
participant Client
participant Gateway
participant Kong
participant Envoy
participant EdgeRuntime
Client->>Gateway: POST /functions/v1/hello (apikey / Authorization)
Gateway->>Gateway: Strip incoming sb-api-key
Gateway->>Gateway: Evaluate translation ($LUA_FUNCTIONS_EXPR or Envoy Lua) -> sb-api-key or 401
Gateway->>EdgeRuntime: Forward request with sb-api-key and Authorization
EdgeRuntime-->>Client: Function response (200 or 401)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker/tests/test-self-hosted.sh`:
- Around line 428-434: The test "Functions reject invalid apikey" is failing
because Kong's key-auth plugin is configured with an anonymous consumer
fallback, which treats invalid keys like missing keys and returns 200; update
the gateway configuration so the key-auth plugin used for the
/functions/v1/hello route (and any functions routes) has anonymous disabled (or
remove the anonymous consumer) so invalid apikeys are rejected with HTTP 401, or
alternatively add explicit API key validation logic in the gateway that returns
401 when an apikey header is present but not valid; ensure the change affects
the key-auth plugin config referenced by the functions routes so the test
"Functions reject invalid apikey" passes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: a95db56f-0b27-4a7a-9e6c-073485867253
📒 Files selected for processing (5)
docker/tests/test-auth-keys.shdocker/tests/test-self-hosted.shdocker/volumes/api/envoy/lds.template.yamldocker/volumes/api/kong-entrypoint.shdocker/volumes/api/kong.yml
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker/volumes/functions/main/index.ts`:
- Around line 46-48: The condition currently throws when a token exists; change
the check to throw only when the token is missing by inverting the condition
(use the negation of the current `if (token)` check) so that the error path runs
on absent token, and keep the existing error message (or adjust it to clarify
missing/invalid Authorization format) in the same block where the `token`
variable is validated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 4d49c5c6-3500-421f-977f-bdcc66a39a93
📒 Files selected for processing (1)
docker/volumes/functions/main/index.ts
|
Hey @kallebysantos, hey mate... Can I possibly ask you to check the conflicts after @7ttp's changes in PR #48012? 🙏 Cc @luizfelmach |
- test-auth-keys: hello now requires an sb_ apikey (withSupabase); distinguish function rejections (x-supabase-server-error) from gateway rejections - main worker: parse Bearer strictly and fall back to sb-api-key; strip sb-api-key before forwarding to user functions Co-Authored-By: Claude Opus 5.5 <[email protected]>
- docker: hello requires an API key in the apikey header - functions: FUNCTIONS_VERIFY_JWT accepts sb_ keys via the gateway; needs SUPABASE_JWKS Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion Co-Authored-By: Claude Opus 5.5 <[email protected]>
Braintrust eval report
|
Resolve conflicts with supabase#46810 (api gateway logic for functions): - main/index.ts: strip the gateway-minted sb-api-key header before dispatch (master) and tag 5xx worker responses (this PR) - test-self-hosted.sh: keep both new Edge Functions smoke checks Co-Authored-By: Claude Fable 5.1 <[email protected]>
Resolve the Envoy routes table conflict with supabase#46810: keep the new sb_-keys access-control row and append the functions timeout note. Describe the 410s Envoy route timeout as the upstream response timeout. Co-Authored-By: Claude Fable 5.1 <[email protected]>
* feat(operator): translate opaque keys for functions Port supabase/supabase#46810 to the operator Envoy filter and embedded function router. Preserve user Authorization headers and strip the internal compatibility token before invoking user functions. * feat(operator): align function errors and timeouts Port supabase/supabase#50589: structured runtime errors, a 150s request idle limit, 400s worker lifetime, and Envoy timeouts that outlast the runtime. Validate the generated runtime arguments and gateway timeout ordering. * feat(operator): retry retired function workers Port supabase/supabase#50618. Retry only WorkerAlreadyRetired before dispatch, up to three times, preserving request bodies and the streaming tag. Other runtime failures keep their structured response without retrying. * fix(operator): align OAuth and OIDC discovery routes Port supabase/supabase#51493 to Envoy. Expose the platform-compatible discovery paths without API keys, rewrite the RFC 8414 route to Auth, and remove the bare root route. Test routing, access exceptions, and removal when Auth is disabled. * chore(operator): align images with self-hosted v0.8.3 Port supabase/supabase#51839 for the nine operator-managed service images and align the supabase-project example with upstream rustfs/rustfs:1.0.1 and rustfs/rc. Storage v1.81.0 runs one-way database migrations; reverting the image to v1.74.0 after upgrade breaks uploads.
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Adds API key handling to the
/functions/v1/route in both self-hosted gateways (Kong and Envoy), and updates the Edge Functions main worker to use it.Gateway
Previously the route passed requests through with no key handling. Now:
apikey/Authorizationapikey= secret keysb-api-key: <service_role asymmetric JWT>apikey= publishable keysb-api-key: <anon asymmetric JWT>Authorization: Bearer sb_..., noapikeysb_value (legacy key, user JWT, anything else)sb_keyapikeyandAuthorization: Bearer sb_...differsb-api-keysb-api-keyholds the raw JWT (noBearerprefix).Authorizationandapikeyare never modified. Theapikeyquery parameter is not read on this route.Main worker
Only applies when
FUNCTIONS_VERIFY_JWT=true(default isfalse):Authorization: Bearer <jwt>. IfAuthorizationis missing, not a Bearer token, or holds ansb_key, it verifiessb-api-keyinstead. RequiresSUPABASE_JWKSfor asymmetric JWTs.sb-api-keybefore the request reaches the user function.Tests
hellouseswithSupabase({ auth: ["publishable", "secret"] })and requires ansb_key inapikey. The Functions checks intest-auth-keys.shuse thex-supabase-server-errorresponse header to tell function rejections from gateway rejections.Tested locally on Envoy and Kong with
FUNCTIONS_VERIFY_JWTset tofalseandtrue.🤖 Generated with Claude Code