oauth - 当grafana位于应用程序负载均衡器后面时,如何配置grafana以使用Oauth2?

标签 oauth grafana

我正在尝试为 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 服务器,但它正在该端口上访问负载均衡器,而负载均衡器不会监听该端口:

https://grafana.acme-live.co.uk:3000/login/google?state=XXYCuMtOvhap1B8urTCCOiXXYCurL8LRXL2yIVDcYUE%3D&code=4/0AX4XfWhGzhjj3JygxB2kMzxa8NMtOvhap1B8QrHhMQQx9ev032k5ChwEJINnbaM94ykRCA&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email%20openid&authuser=0&hd=acme.com&prompt=consent

当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/

相关文章:

javascript - Velocity:如何将txt内容设置为变量

php - 如何对 OAuth 设置保密?

twitter - Twitter OAuth 是否支持在回调 url 中包含空格的 queryString 参数?

elasticsearch - 连字符上的打破字段值

prometheus - PromQL 查询以选择其值包含在给定多选变量中的指标

java - Final 变量不能在封闭类型中赋值

google-app-engine - 使用多个帐户发出 "appcfg.py --oauth update ."?

api - 使用 Grafana API 进行自动身份验证

grafana - 丢失系列/数据的警报

amazon-web-services - Grafana字段类型转换输出不正确的时间戳