Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(self-hosted): align OAuth and OIDC discovery api-gw routes with the platform (#51493)

Inder Singh31a74e866384
diff --git a/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx b/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx
index 810946f9ed3..1f220e319f1 100644
--- a/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx
+++ b/apps/docs/content/guides/self-hosting/self-hosted-envoy.mdx
@@ -104,29 +104,31 @@ sh run.sh restart api-gw
Routes are matched in the order declared. The first matching prefix wins. Protected routes require a valid `apikey` header; open routes pass through without API key validation.
-| Path prefix | Upstream | Path rewrite | Access control | Notes |
-| ----------------------------------------- | --------- | ------------------------ | -------------- | ---------------------------------------------------------------------------------------------------------- |
-| `/auth/v1/verify` | auth | `/verify` | Open | Email verification |
-| `/auth/v1/callback` | auth | `/callback` | Open | OAuth callback |
-| `/auth/v1/authorize` | auth | `/authorize` | Open | OAuth authorize |
-| `/auth/v1/.well-known/jwks.json` | auth | `/.well-known/jwks.json` | Open | JWKS for third-party verification |
-| `/.well-known/oauth-authorization-server` | auth | - | Open | OAuth 2.0 Authorization Server Metadata (RFC 8414) |
-| `/auth/v1/sso/saml/acs` | auth | `/sso/saml/acs` | Open | SAML assertion consumer |
-| `/auth/v1/sso/saml/metadata` | auth | `/sso/saml/metadata` | Open | SAML metadata |
-| `/functions/v1/` | functions | `/` | `sb_` keys | Rejects invalid and conflicting `sb_` keys; others pass; 160s idle timeout, 410s upstream response timeout |
-| `/storage/v1/` | storage | `/` | Bypass | Storage performs its own authorization |
-| `/auth/v1/` | auth | `/` | API key | Protected Auth endpoints |
-| `/rest/v1/` | rest | `/` | API key | PostgREST Open API root (requires secret key) |
-| `/rest/v1/*` | rest | `/` | API key | PostgREST data endpoints |
-| `/graphql/v1` | rest | `/rpc/graphql` | API key | pg_graphql (adds `Content-Profile: graphql_public`) |
-| `/realtime/v1/api/tenants` | realtime | - | Denied | Realtime management API (blocked by default) |
-| `/realtime/v1/api/openapi` | realtime | - | Denied | Realtime OpenAPI spec (blocked by default) |
-| `/realtime/v1/api` | realtime | `/api` | API key | Realtime REST API (broadcast, channels, ping) |
-| `/realtime/v1/` | realtime | `/socket/` | API key | Realtime WebSocket |
-| `/pg/` | meta | `/` | API key | postgres-meta / Studio database operations (requires secret key) |
-| `/api/mcp` | studio | - | Denied | MCP endpoint (blocked by default via RBAC DENY) |
-| `/mcp` | studio | `/api/mcp` | Denied | MCP endpoint (blocked by default via RBAC DENY) |
-| `/` (catch-all) | studio | - | Basic auth | Dashboard; strips inbound `Authorization` header |
+| Path prefix | Upstream | Path rewrite | Access control | Notes |
+| ------------------------------------------------- | --------- | ----------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------- |
+| `/auth/v1/verify` | auth | `/verify` | Open | Email verification |
+| `/auth/v1/callback` | auth | `/callback` | Open | OAuth callback |
+| `/auth/v1/authorize` | auth | `/authorize` | Open | OAuth authorize |
+| `/auth/v1/.well-known/jwks.json` | auth | `/.well-known/jwks.json` | Open | JWKS for third-party verification |
+| `/auth/v1/.well-known/oauth-authorization-server` | auth | `/.well-known/oauth-authorization-server` | Open | OAuth 2.0 Authorization Server Metadata |
+| `/auth/v1/.well-known/openid-configuration` | auth | `/.well-known/openid-configuration` | Open | OpenID Connect discovery |
+| `/.well-known/oauth-authorization-server/auth/v1` | auth | `/.well-known/oauth-authorization-server` | Open | OAuth 2.0 Authorization Server Metadata at the RFC 8414 path for the `/auth/v1` issuer |
+| `/auth/v1/sso/saml/acs` | auth | `/sso/saml/acs` | Open | SAML assertion consumer |
+| `/auth/v1/sso/saml/metadata` | auth | `/sso/saml/metadata` | Open | SAML metadata |
+| `/functions/v1/` | functions | `/` | `sb_` keys | Rejects invalid and conflicting `sb_` keys; others pass; 160s idle timeout, 410s upstream response timeout |
+| `/storage/v1/` | storage | `/` | Bypass | Storage performs its own authorization |
+| `/auth/v1/` | auth | `/` | API key | Protected Auth endpoints |
+| `/rest/v1/` | rest | `/` | API key | PostgREST Open API root (requires secret key) |
+| `/rest/v1/*` | rest | `/` | API key | PostgREST data endpoints |
+| `/graphql/v1` | rest | `/rpc/graphql` | API key | pg_graphql (adds `Content-Profile: graphql_public`) |
+| `/realtime/v1/api/tenants` | realtime | - | Denied | Realtime management API (blocked by default) |
+| `/realtime/v1/api/openapi` | realtime | - | Denied | Realtime OpenAPI spec (blocked by default) |
+| `/realtime/v1/api` | realtime | `/api` | API key | Realtime REST API (broadcast, channels, ping) |
+| `/realtime/v1/` | realtime | `/socket/` | API key | Realtime WebSocket |
+| `/pg/` | meta | `/` | API key | postgres-meta / Studio database operations (requires secret key) |
+| `/api/mcp` | studio | - | Denied | MCP endpoint (blocked by default via RBAC DENY) |
+| `/mcp` | studio | `/api/mcp` | Denied | MCP endpoint (blocked by default via RBAC DENY) |
+| `/` (catch-all) | studio | - | Basic auth | Dashboard; strips inbound `Authorization` header |
<Admonition type="note">
diff --git a/docker/tests/test-auth-keys.sh b/docker/tests/test-auth-keys.sh
index e92905adffc..f66594911d6 100644
--- a/docker/tests/test-auth-keys.sh
+++ b/docker/tests/test-auth-keys.sh
@@ -275,10 +275,26 @@ jwks_has_oct=$(echo "$jwks_content" | jq -r '[.keys[] | .kty] | if any(. == "oct
check "JWKS contains EC public key" "true" "$jwks_has_ec"
check "JWKS does NOT contain symmetric key" "false" "$jwks_has_oct"
-#echo ""
-#echo "--- OAuth metadata endpoint ---"
-#check "well-known oauth (no auth)" "200" \
-# "$(http_status "$BASE_URL/.well-known/oauth-authorization-server")"
+echo ""
+echo "--- OAuth and OIDC discovery ---"
+check "OIDC discovery (no auth)" "200" \
+ "$(http_status "$BASE_URL/auth/v1/.well-known/openid-configuration")"
+
+# Auth returns 404 feature_disabled while its OAuth server is off (the default),
+# so either the metadata or that error shows the request reached Auth.
+oauth_metadata_reached() {
+ if curl -s "$BASE_URL$1" | grep -qE '"issuer"|"feature_disabled"'; then
+ echo "true"
+ else
+ echo "false"
+ fi
+}
+check "OAuth metadata at RFC 8414 path (no auth)" "true" \
+ "$(oauth_metadata_reached /.well-known/oauth-authorization-server/auth/v1)"
+check "OAuth metadata under /auth/v1 (no auth)" "true" \
+ "$(oauth_metadata_reached /auth/v1/.well-known/oauth-authorization-server)"
+check "OAuth metadata at bare root path not routed to Auth" "false" \
+ "$(oauth_metadata_reached /.well-known/oauth-authorization-server)"
echo ""
echo "--- Realtime WebSocket upgrade ---"
diff --git a/docker/volumes/api/envoy/lds.template.yaml b/docker/volumes/api/envoy/lds.template.yaml
index a414496cee2..aff4b7b6d29 100644
--- a/docker/volumes/api/envoy/lds.template.yaml
+++ b/docker/volumes/api/envoy/lds.template.yaml
@@ -173,14 +173,73 @@ resources:
- any: true
- match:
- prefix: /.well-known/oauth-authorization-server
+ prefix: /auth/v1/.well-known/oauth-authorization-server
route:
cluster: auth
+ prefix_rewrite: /.well-known/oauth-authorization-server
timeout: 30s
request_headers_to_add:
- header:
key: X-Forwarded-Prefix
- value: /.well-known/oauth-authorization-server
+ value: /auth/v1/.well-known/oauth-authorization-server
+ append_action: ADD_IF_ABSENT
+ typed_per_filter_config:
+ envoy.filters.http.basic_auth:
+ '@type': >-
+ type.googleapis.com/envoy.config.route.v3.FilterConfig
+ disabled: true
+ envoy.filters.http.rbac:
+ '@type': >-
+ type.googleapis.com/envoy.extensions.filters.http.rbac.v3.RBACPerRoute
+ rbac:
+ rules:
+ action: ALLOW
+ policies:
+ allow_all:
+ permissions:
+ - any: true
+ principals:
+ - any: true
+
+ - match:
+ prefix: /auth/v1/.well-known/openid-configuration
+ route:
+ cluster: auth
+ prefix_rewrite: /.well-known/openid-configuration
+ timeout: 30s
+ request_headers_to_add:
+ - header:
+ key: X-Forwarded-Prefix
+ value: /auth/v1/.well-known/openid-configuration
+ append_action: ADD_IF_ABSENT
+ typed_per_filter_config:
+ envoy.filters.http.basic_auth:
+ '@type': >-
+ type.googleapis.com/envoy.config.route.v3.FilterConfig
+ disabled: true
+ envoy.filters.http.rbac:
+ '@type': >-
+ type.googleapis.com/envoy.extensions.filters.http.rbac.v3.RBACPerRoute
+ rbac:
+ rules:
+ action: ALLOW
+ policies:
+ allow_all:
+ permissions:
+ - any: true
+ principals:
+ - any: true
+
+ - match:
+ path: /.well-known/oauth-authorization-server/auth/v1
+ route:
+ cluster: auth
+ prefix_rewrite: /.well-known/oauth-authorization-server
+ timeout: 30s
+ request_headers_to_add:
+ - header:
+ key: X-Forwarded-Prefix
+ value: /.well-known/oauth-authorization-server/auth/v1
append_action: ADD_IF_ABSENT
typed_per_filter_config:
envoy.filters.http.basic_auth:
diff --git a/docker/volumes/api/kong.yml b/docker/volumes/api/kong.yml
index 74a04c0ecb1..71f7bebd06d 100644
--- a/docker/volumes/api/kong.yml
+++ b/docker/volumes/api/kong.yml
@@ -77,6 +77,26 @@ services:
- /auth/v1/.well-known/jwks.json
plugins:
- name: cors
+ - name: auth-v1-open-well-known-oauth
+ _comment: 'Auth: /auth/v1/.well-known/oauth-authorization-server -> http://auth:9999/.well-known/oauth-authorization-server'
+ url: http://auth:9999/.well-known/oauth-authorization-server
+ routes:
+ - name: auth-v1-open-well-known-oauth
+ strip_path: true
+ paths:
+ - /auth/v1/.well-known/oauth-authorization-server
+ plugins:
+ - name: cors
+ - name: auth-v1-open-well-known-openid
+ _comment: 'Auth: /auth/v1/.well-known/openid-configuration -> http://auth:9999/.well-known/openid-configuration'
+ url: http://auth:9999/.well-known/openid-configuration
+ routes:
+ - name: auth-v1-open-well-known-openid
+ strip_path: true
+ paths:
+ - /auth/v1/.well-known/openid-configuration
+ plugins:
+ - name: cors
- name: auth-v1-open-sso-acs
url: "http://auth:9999/sso/saml/acs"
@@ -387,13 +407,13 @@ services:
## OAuth 2.0 Authorization Server Metadata (RFC 8414)
- name: well-known-oauth
- _comment: 'Auth: /.well-known/oauth-authorization-server -> http://auth:9999/.well-known/oauth-authorization-server'
+ _comment: 'Auth: /.well-known/oauth-authorization-server/auth/v1 -> http://auth:9999/.well-known/oauth-authorization-server'
url: http://auth:9999/.well-known/oauth-authorization-server
routes:
- name: well-known-oauth
strip_path: true
paths:
- - /.well-known/oauth-authorization-server
+ - /.well-known/oauth-authorization-server/auth/v1
plugins:
- name: cors
diff --git a/docker/volumes/proxy/caddy/Caddyfile b/docker/volumes/proxy/caddy/Caddyfile
index b899e5ecf1d..f067c935d0a 100644
--- a/docker/volumes/proxy/caddy/Caddyfile
+++ b/docker/volumes/proxy/caddy/Caddyfile
@@ -1,5 +1,5 @@
{$PROXY_DOMAIN} {
- @supabase_api path /auth/v1/* /rest/v1/* /graphql/v1 /realtime/v1/* /storage/v1/* /functions/v1/* /mcp /sso/* /.well-known/oauth-authorization-server
+ @supabase_api path /auth/v1/* /rest/v1/* /graphql/v1 /realtime/v1/* /storage/v1/* /functions/v1/* /mcp /sso/* /.well-known/oauth-authorization-server/auth/v1
handle @supabase_api {
reverse_proxy api-gw:8000
diff --git a/docker/volumes/proxy/nginx/supabase-nginx.conf.tpl b/docker/volumes/proxy/nginx/supabase-nginx.conf.tpl
index 91419f269f6..e02f34f451d 100644
--- a/docker/volumes/proxy/nginx/supabase-nginx.conf.tpl
+++ b/docker/volumes/proxy/nginx/supabase-nginx.conf.tpl
@@ -96,7 +96,7 @@ server {
proxy_pass http://api_gw_upstream;
}
- location = /.well-known/oauth-authorization-server {
+ location = /.well-known/oauth-authorization-server/auth/v1 {
proxy_pass http://api_gw_upstream;
}
}