Skip to content

feat: gate private_key_jwt in the custom provider admin API - #2935

Merged
cemalkilic merged 1 commit into
cemalkilic/auth-2047-migration-and-model-client-auth-methodfrom
cemalkilic/auth-2053-gate-private_key_jwt-in-the-custom
Nov 17, 2026
Merged

cemalkilic merged 1 commit into
cemalkilic/auth-2047-migration-and-model-client-auth-methodfrom
cemalkilic/auth-2053-gate-private_key_jwt-in-the-custom

Conversation

@cemalkilic

@cemalkilic cemalkilic commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

The custom provider admin API now accepts client_auth_method and client_assertion_audience.

  • private_key_jwt is only allowed for OIDC providers, and only when client assertions are enabled and a signing key is configured. Otherwise it's a 400.
  • private_key_jwt providers can't have a client secret. Switching methods clears the other method's fields, and switching back to client_secret requires a secret.
  • If the flag gets turned off later, existing private_key_jwt providers can still be edited and switched back to client_secret.
  • Get and list return the method and audience, never the secret.

openapi.yaml is updated.

Tests

custom_oauth_admin_client_auth_test.go covers validation, the flag being off, and switching methods both ways.

Stack

  1. feat: add experimental config for client assertion signing keys #2932
  2. feat: sign and cache private_key_jwt client assertions #2933
  3. feat: add client auth method to custom OAuth providers #2934
  4. feat: gate private_key_jwt in the custom provider admin API #2935 👈
  5. feat: use client assertions in the custom OIDC token exchange #2936

Comment thread internal/api/custom_oauth_admin.go Resolved
@cemalkilic
cemalkilic force-pushed the cemalkilic/auth-2053-gate-private_key_jwt-in-the-custom branch from c4c3973 to d773d9c Compare November 17, 2026 15:29
The custom OAuth provider admin API accepts client_auth_method and
client_assertion_audience. private_key_jwt is only allowed for OIDC
providers while client assertions are enabled and a signing key is
configured; otherwise the request is rejected with 400.

private_key_jwt providers must not have a client secret, and switching
method clears the other method's fields. Switching to client_secret
requires a secret. Get and list return the method and audience, never
the secret. openapi.yaml is updated accordingly.
@cemalkilic
cemalkilic force-pushed the cemalkilic/auth-2053-gate-private_key_jwt-in-the-custom branch from d773d9c to 2b756a3 Compare November 17, 2026 15:59
@cemalkilic
cemalkilic merged commit f78a61d into master Nov 17, 2026
17 checks passed
@cemalkilic
cemalkilic deleted the cemalkilic/auth-2053-gate-private_key_jwt-in-the-custom branch November 17, 2026 16:19
cemalkilic added a commit that referenced this pull request Nov 17, 2026
## What

First PR in a stack that lets custom OIDC providers authenticate to the
token endpoint with `private_key_jwt` (RFC 7523) instead of a client
secret. Everything ships behind an experimental flag.

This one only adds the config. Nothing reads it yet.

- `GOTRUE_EXPERIMENTAL_CLIENT_ASSERTION_ENABLED`
- `GOTRUE_EXPERIMENTAL_CLIENT_ASSERTION_KEYS`: a JWK set in the same
format as `GOTRUE_JWT_KEYS`. RS256 only, plain or KMS-backed, exactly
one key with `key_ops: ["sign"]`.
- `GOTRUE_EXPERIMENTAL_CLIENT_ASSERTION_ISSUER`: optional `iss`
override.

Startup fails if an assertion key shares a kid or key material with a
JWT key, or if the issuer override equals the JWT issuer, so these keys
can never be used for sessions.

## Tests

`internal/conf/client_assertion_test.go` covers the valid setups (plain
and KMS keys) and every rejected one.

## Stack

1. #2932 👈
1. #2933
1. #2934
1. #2935
1. #2936
cemalkilic added a commit that referenced this pull request Nov 17, 2026
## What

Adds `ClientAssertionCache`, which signs client assertions and caches
one per provider. With a KMS key, that means one signing call per
provider about every 10 minutes instead of one per login.

- Assertions live 15 minutes and get replaced when less than 5 minutes
are left.
- Concurrent requests for the same provider share one signing call.
- The cache key includes the signing kid and issuer, so a key rotation
stops serving old assertions.
- Expired entries are dropped whenever a new one is stored.

Not wired up yet, that happens at the end of the stack.

## Tests

Claims and headers, refresh timing, cache keys, concurrent signing,
invalidation, eviction, and signing with a fake KMS.

## Stack

1. #2932
1. #2933 👈
1. #2934
1. #2935
1. #2936
cemalkilic added a commit that referenced this pull request Nov 17, 2026
## What

Adds `client_auth_method` (`client_secret` by default, so existing rows
don't change) and `client_assertion_audience` to
`custom_oauth_providers`, with check constraints:

- `client_secret` providers must have a secret, `private_key_jwt`
providers must have an empty one.
- The audience is either NULL or 1 to 2048 characters.

## Why `client_secret` stays NOT NULL

`private_key_jwt` providers store an empty string instead of NULL. Older
versions read `client_secret` into a plain `string`, so a NULL would
break every query that loads all custom providers on old pods during a
rolling deploy or after a rollback. If an old version loads a
`private_key_jwt` provider, it sends a token request with no secret and
the provider rejects it.

## Tests

Model round trip, the constraints, and switching between methods.

## Stack

1. #2932
1. #2933
1. #2934 👈
1. #2935
1. #2936
cemalkilic added a commit that referenced this pull request Nov 17, 2026
## What

Last PR in the stack. For `private_key_jwt` providers, the authorization
code exchange sends `client_assertion` and `client_assertion_type` in
the form body instead of a client secret, with no Basic auth header.

- Fails closed: a `private_key_jwt` provider can't be loaded when
assertions are disabled, no signing key is configured, or the provider
isn't OIDC, so no request goes out.
- On `invalid_client`, the cached assertion is dropped and the rejection
is logged without the assertion.
- New metrics for signing latency and errors, and `invalid_client`
responses per provider.

The assertion has `iss` and `sub` set to the client_id (`iss` can be
overridden), and `aud` is the issuer unless the provider sets an
audience. Assertions are reused for up to 10 minutes and have no `jti`,
so providers that require single-use assertions won't accept them.

## Tests

Exact shape of the token request, cache reuse, failing closed,
`invalid_client` handling, and an end-to-end test that loads a
`private_key_jwt` provider and checks the exchange sends a valid
assertion.

## Stack

1. #2932
1. #2933
1. #2934
1. #2935
1. #2936 👈
cemalkilic added a commit to supabase-community/terraform-provider-gotrue that referenced this pull request Nov 18, 2026
## What

Adds support for the new custom provider admin API params from
supabase/auth#2935:

- `client_auth_method`: `client_secret` (default) or `private_key_jwt`
- `client_assertion_audience`: overrides the `aud` claim of client
assertions (max 2048 chars)

`client_secret` is now optional.

## Behaviour

- **Plan-time validation** (`CustomizeDiff`) mirrors the server rules,
so mistakes fail at `plan` instead of as a 400 at `apply`:
- `client_secret` is required for `client_secret` and must not be set
for `private_key_jwt`
  - `private_key_jwt` is only allowed for `oidc` providers
  - `client_assertion_audience` is only allowed with `private_key_jwt`

  Values unknown until apply are left for the server to check.
- **Older auth servers keep working**: the default method is not sent on
create, and a response without `client_auth_method` is read as
`client_secret`.
- **Audience is only sent for `private_key_jwt` providers.** The server
clears it on a switch to `client_secret`, and rejects any audience (even
`""`) while client assertions are disabled. Sending it would break
switching back after the flag is turned off. Removing the audience on a
`private_key_jwt` provider sends `""`, which clears it.

## Tests

`gotrue/custom_oauth_provider_test.go` covers each validation rule, the
request bodies for create and update (switching methods both ways,
changing and removing the audience), and reading from a server that
doesn't return the method.

## Follow-up

supabase-community/pulumi-gotrue will be bumped to the tag cut from this
PR.
cemalkilic added a commit to supabase-community/pulumi-gotrue that referenced this pull request Nov 18, 2026
## What

Picks up the new custom provider admin API params from
supabase/auth#2935, via supabase-community/terraform-provider-gotrue#9:

- `clientAuthMethod`: `client_secret` (default) or `private_key_jwt`
- `clientAssertionAudience`: overrides the `aud` claim of client
assertions

`clientSecret` is now optional.

Schema and Go, Node.js, Python and .NET SDKs are regenerated. Only the
`CustomOauthProvider` files changed.

Bumps `terraform-provider-gotrue` to `v1.1.4`.
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