Skip to content

fix(envoy): reject direct asymmetric JWT access when translation is enabled - #46023

Merged
aantti merged 2 commits into
supabase:masterfrom
luizfelmach:self-hosted/envoy-reject-direct-asymmetric-jwt-in-translation-mode
May 26, 2026
Merged

aantti merged 2 commits into
supabase:masterfrom
luizfelmach:self-hosted/envoy-reject-direct-asymmetric-jwt-in-translation-mode

Conversation

@luizfelmach

@luizfelmach luizfelmach commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix + updating Envoy image

What is the current behavior?

When TRANSLATION is enabled in the Envoy configuration (lds.template.yaml), the Lua API key validator filter was placed after the translation filters. As a result, the validator was seeing already-trans lated keys and incorrectly accepting asymmetric JWTs (SERVICE_ROLE_KEY_ASYMMETRIC and ANON_KEY_ASYMMETRIC) directly from clients.

This meant clients could bypass the intended sb_ key flow and use the internal asymmetric JWTs directly, which defeats the purpose of the translation layer.

What is the new behavior?

The Lua validator filter is now placed before the translation filters. The validator sees the original client-provided key and enforces the correct policy:

  • When TRANSLATION is enabled: only accepts sb_ keys (SUPABASE_SECRET_KEY, SUPABASE_PUBLISHABLE_KEY) and legacy keys (SERVICE_ROLE_KEY, ANON_KEY)
  • Rejects direct asymmetric JWT access with 401 Unauthorized
  • When TRANSLATION is disabled: legacy behavior is preserved

The translation filters then convert valid sb_ keys into internal asymmetric JWTs downstream as intended. No changes to the RBAC filter were needed.

Additional context

  • File changed: docker/volumes/api/envoy/lds.template.yaml

Summary by CodeRabbit

  • Improvements
    • Enhanced API key validation for protected routes, including route-based allowlist behavior and optional translation-key acceptance.
    • Invalid or missing API keys on protected endpoints now return HTTP 401 with plain-text "Unauthorized" for clearer error handling.
  • Chores
    • Upgraded the Envoy gateway to a newer minor release.

Review Change Stack

…nabled

When TRANSLATION is enabled, the API key validator was accepting
asymmetric JWTs (SERVICE_ROLE_KEY_ASYMMETRIC and ANON_KEY_ASYMMETRIC)
directly from clients. This is incorrect — only sb_ keys should be
accepted externally and then translated internally.
@luizfelmach
luizfelmach requested review from a team as code owners May 16, 2026 18:56
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented May 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
design-system Ready Ready Preview, Comment May 26, 2026 2:56pm
docs Ready Ready Preview, Comment, Open in v0 May 26, 2026 2:56pm
studio-self-hosted Ready Ready Preview, Comment May 26, 2026 2:56pm
studio-staging Ready Ready Preview, Comment May 26, 2026 2:56pm
ui-library Ready Ready Preview, Comment May 26, 2026 2:56pm
zone-www-dot-com Ready Ready Preview, Comment, Open in v0 May 26, 2026 2:56pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 26, 2026 2:56pm

Request Review

@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

@luizfelmach is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 16, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a Lua HTTP filter that enforces API-key validation on named protected routes and returns HTTP 401 for invalid/missing keys; the listener still includes an RBAC filter with apikey principals. Also updates the Envoy Docker image tag to v1.38.0.

Changes

API Key Enforcement on Protected Routes

Layer / File(s) Summary
Protected-route Lua filter with API key validation
docker/volumes/api/envoy/lds.template.yaml
New Envoy HTTP Lua filter defines a protected-route allowlist keyed by route name and validates the apikey header against service-role/anon keys, with optional acceptance when translation template variables are set; responds 401 text/plain "Unauthorized" for invalid or missing keys.
RBAC configuration with apikey principals
docker/volumes/api/envoy/lds.template.yaml
RBAC filter remains with action: ALLOW and apikey-header principals using exact matches for service-role and anon template key values (including referenced symmetric/asymmetric variants).

Envoy Container Image

Layer / File(s) Summary
Envoy image tag bump
docker/docker-compose.envoy.yml
Updates the Envoy service image from envoyproxy/envoy:v1.37.2 to envoyproxy/envoy:v1.38.0.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • supabase/supabase#45195: Both PRs modify the same Envoy Lua API-key validation logic and related template variable conditions.

Suggested reviewers

  • aantti

Poem

🐰 A watchful rabbit checks each key and route,
Hops through headers, peeks each subtle doubt,
If a key is missing or it fails the test,
A polite "Unauthorized" stops the rest. 🥕🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: rejecting direct asymmetric JWT access when translation is enabled, which is the core fix described in the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description comprehensively covers all template sections with clear explanations of the bug, fix, and behavioral changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@aantti aantti self-assigned this May 26, 2026
@aantti aantti added the self-hosted Related to self-hosted Supabase label May 26, 2026
@aantti
aantti merged commit 94ac6f3 into supabase:master May 26, 2026
32 of 34 checks passed
@github-actions

github-actions Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1779807901)

Score Average Improvements Regressions
Completeness 97.4% (+1pp) 3 🟢 2 🔴
Conciseness 37.8% (-3pp) 4 🟢 9 🔴
Docs Faithfulness 63.9% (-1pp) 5 🟢 4 🔴
Goal Completion 79.5% (+3pp) 9 🟢 4 🔴
Tool Usage 75% (+4pp) 2 🟢 1 🔴
Correctness 70.8% (+0pp) 3 🟢 3 🔴
Knowledge Usage 93.3% (+10pp) 3 🟢 -
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 92.9% (-7.000000000000001pp) - 1 🔴
Safety 95.2% (-5pp) - 1 🔴
Time_to_first_token 0tok (+0tok) 11 🟢 15 🔴
Llm_calls 6.83 (+0.13) 13 🟢 9 🔴
Tool_calls 2.63 (+0.04) 11 🟢 8 🔴
Errors 0.03 (+0.03) - 1 🔴
Llm_errors 0.01 (+0.01) - 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 20812.28tok (+999.27tok) 11 🟢 12 🔴
Prompt_cached_tokens 6150.56tok (-144.41tok) 9 🟢 8 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 524.26tok (-16.82tok) 12 🟢 14 🔴
Completion_reasoning_tokens 81.22tok (-2.86tok) 11 🟢 13 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 21336.54tok (+982.45tok) 10 🟢 16 🔴
Estimated_cost 0$ (+0$) 9 🟢 14 🔴
Duration 13.46s (+0.81s) 11 🟢 15 🔴
Llm_duration 8.67s (-0.16s) 15 🟢 11 🔴

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

Labels

self-hosted Related to self-hosted Supabase

Projects

Development

Successfully merging this pull request may close these issues.

2 participants