grafana: disable PKCE for the generic_oauth flow#600
Merged
Conversation
Grafana is a confidential client authenticated with CLIENT_SECRET_BASIC. PKCE is designed for public clients that cannot protect a client secret; for confidential clients the client secret already authenticates the token exchange and PKCE adds no meaningful security. With use_pkce=true, Grafana generates a code_verifier, stores it in a browser session cookie alongside the OAuth state, then sends it in the token request. If that cookie is absent or invalid (different tab, browser restart, Safari ITP expiry, proxy stripping Set-Cookie), Grafana omits the verifier from the token request. Spring Authorization Server stored the code_challenge at the authorize step, so it now sees a stored challenge with no matching verifier and rejects the exchange — surfacing as "Failed to get token from provider" on the login page. Setting use_pkce=false removes the browser-state dependency and leaves the auth-api client registration unchanged (requirePkce=false). The flow is: authorize → cookie-free state param → code → secret-authenticated token exchange.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Grafana is a confidential OAuth2 client authenticated with
CLIENT_SECRET_BASIC. PKCE is designed for public clients that cannot protect a secret; for confidential clients the client secret already authenticates the token exchange.With
use_pkce: true, Grafana generates acode_verifier, stores it in a browser session cookie alongside the OAuthstate, and sends it in the token request. If that cookie is missing or invalid (different browser tab, browser restart, Safari ITP expiry, a proxy strippingSet-Cookie), Grafana omits the verifier from the token POST. Spring Authorization Server stored thecode_challengeat the authorize step, so it sees a stored challenge with no matching verifier and rejects the request — surfacing as "Failed to get token from provider" on the Grafana login page.use_pkce: falseremoves the browser-state dependency entirely. The auth-api client registration remainsrequirePkce: false, so the flow is: authorize → code (with state, no PKCE) →CLIENT_SECRET_BASIC-authenticated token exchange.After merge: a Grafana pod restart is required (
kubectl -n observability rollout restart deploy grafana) for the new config to take effect. If Grafana login still fails after the restart, also verify that the Vault secrets atsecret/auth-api(auth.clients.grafana.secret) andsecret/platform/observability(grafana.oauth_client_secret) are identical — re-runningtmp.sh'spaircall and restarting both auth-api and Grafana will re-align them.