Hi,
I just spend a few hours trying to find out why Grafana can’t accept login from Google OAuth2 authentication.
Grafana complains about not finding the oauth_state
cookie at the end of the oAuth tunnel (/login/google?state=(...)
. But the cookie is sent !
Usually I know how to investigate this kind of problem… but not today because everything looks clean and the cookie is sent by the browser. I’m looking for new ideas !
Step by step description:
-
Grafana send the user to
https://accounts.google.com/signin/oauth/consent?(...)
, great. -
The authorisation tunnel is doing it’s job
-
google redirect to
https://mydomain.com/login/google?state=(...)
. The browser provides two cookiesoauth_state
andoauth_code_verifier
affected to the right domain (no problem with samesite policy, it would be too easy !). -
the endpoint
/login/google
logs:
[auth.oauth.state.missing] missing state cookie
and send the user to the /login page with a 302
Context
-
Grafana dockerized
grafana/grafana:11.2.2
, no plugin, minimal config. -
Deployed on cloudrun, can be accessed by mydomain.com
-
No error, nothing strange before the endpoint
/login/google
Everything work in localhost:xxxx
Note that when I run the same docker image locally, everything is fine, grafana find the cookie.
(localhost is added to Authorized JavaScript origins and redirect uri along side the real domain, GF_SERVER_ROOT_URL is ajusted)
Grafana config
[security]
disable_initial_admin_creation = true
; admin_user = admin
cookie_samesite = lax
[auth.basic]
disable_login_form = true
enabled = false
[auth.google]
enabled = true
allow_sign_up = true
auto_login = false
client_id = CLIENT_ID
client_secret = CLIENT_SECRET
scopes = openid email profile
auth_url = https://accounts.google.com/o/oauth2/v2/auth
token_url = https://oauth2.googleapis.com/token
api_url = https://openidconnect.googleapis.com/v1/userinfo
allowed_domains = alfred-eyes.ai
hosted_domain = alfred-eyes.ai
use_pkce = true
use_refresh_token = true
skip_org_role_sync = false
role_attribute_path = "'Editor'"
also theses env var are set
-
GF_AUTH_GOOGLE_CLIENT_ID
-
GF_AUTH_GOOGLE_CLIENT_SECRET
-
GF_SERVER_ROOT_URL
I don’t know where to look at from here.
The cookie tab for /login/google?state=(…)