我正在尝试为 grafana 实例配置 Google Oauth2。
我的 grafana 在 ALB 后面的 Amazon EC2 实例中运行。 ALB 使用 SSL,但不使用 grafana 实例。
我在 Grafana 上设置了 Oauth2,我可以看到“使用 google 登录”按钮。 但是,当我按下它并选择我的 Google 帐户时,我收到以下错误:
Error 400: redirect_uri_mismatch
http://grafana.acme-live.co.uk:3000/login/google
google端的配置很简单,我输入了我的 “授权的 JavaScript 起源”:
https://grafana.acme-live.co.uk
和“授权重定向URL”:
https://grafana.acme-live.co.uk:3000/login/google
我的grafana.ini文件:
protocol = http
http_port = 3000
domain = grafana.acme-live.co.uk
root_url = %(protocol)s://%(domain)s:%(http_port)s/
enabled = true
client_id = acme.apps.googleusercontent.com
client_secret = acme-ACME
scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
auth_url = https://accounts.google.com/o/oauth2/auth
token_url = https://accounts.google.com/o/oauth2/token
allowed_domains = grafana.acme-live.co.uk
allow_sign_up = true
在我看来,GoogleOauth 很困惑,因为它期望通过 SSL 发出身份验证请求,但 grafana 服务器以纯 HTTP 发送请求。
完成 AUTH 流程后,Google 尝试通过端口 3000 联系 grafana 服务器,但它正在该端口上访问负载均衡器,而负载均衡器不会监听该端口:
当grafana位于应用程序负载均衡器后面时,如何配置grafana以使用Oauth2?
谢谢
最佳答案
https://grafana.com/docs/grafana/latest/auth/google/
You may have to set the root_url option of [server] for the callback URL to be correct. For example in case you are serving Grafana behind a proxy.
那是你的问题。所以尝试一下(我猜你想在 http://grafana.acme-live.co.uk
上公开它,而不是在端口 3000 上):
[server]
root_url = https://grafana.acme.co.uk/
Google 客户端配置中的“授权重定向 URL”:
https://grafana.acme-live.co.uk/login/google
关于oauth - 当grafana位于应用程序负载均衡器后面时,如何配置grafana以使用Oauth2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72174677/