【问题标题】:Grafana OAuth with Keycloak带有 Keycloak 的 Grafana OAuth
【发布时间】:2021-12-27 13:53:33
【问题描述】:

我正在使用舵图。在部署过程中,我覆盖如下值:

auth.generic_oauth:  # for SSO
      groups_attribute_path: contains(groups[*], 'GrafanaAdmins') && 'Admin' || 'Viewer'
      enabled: true
      name: Keycloak
      allow_sign_up: false
      client_id: grafana
      client_secret: CLIENT_SECRET
      scopes: openid,email,profile,groups
      team_ids:
      allowed_organizations:
      auth_url: AUTH_URL
      token_url: TOKEN_URL
      api_url: API_URL
      tls_skip_verify_insecure: true

在 Keycoke 中,我创建了一个客户端、一个客户端范围、一个客户端范围内的组映射器、一个组并将 GrafanaAdmins 组分配给一个用户。

我想要实现的目标是能够使用在 Keycloak 中定义的用户登录到 Grafana,该用户也被分配了 GrafanaAdmins 组。

我所拥有的是这个错误:

t=2021-12-27T13:32:18+0000 lvl=warn msg="Not allowing oauth_generic_oauth login, user not found in internal user database and allow signup = false"
t=2021-12-27T13:32:18+0000 lvl=eror msg="invalid username or password" logger=context userId=0 orgId=0 uname=

我不想注册新用户,也不想使用额外的数据库。它应该使用 Keycloak。

Grafana 文档的描述性不是很强,很难绕过它。

【问题讨论】:

  • 您是否使用具有有效许可证的 Grafana Enterprise 8.1+ 版本?
  • 我在 Helm 图表中使用这个 Grafana,应用程序版本 7.1.5

标签: single-sign-on keycloak grafana


【解决方案1】:

你有几个问题:

  1. Grafana documentation 很清楚:

组映射:在 Grafana Enterprise v8.1 及更高版本中可用。

您使用的是 Grafana 7.1.5,我猜也是免费的 OSS Grafana(不是付费企业版,需要许可证),所以 组映射(配置 groups_attribute_path)在你的情况。

  1. 您还将 Grafana 角色映射 (role_attribute_path) 与 Grafana 组映射 (groups_attribute_path) 混合使用,请注意 role != group。所以我猜你想要:
role_attribute_path: contains(groups[*], 'GrafanaAdmins') && 'Admin' || 'Viewer'

代替:

groups_attribute_path: contains(groups[*], 'GrafanaAdmins') && 'Admin' || 'Viewer'
  1. Grafana 根据 OIDC 响应创建内部用户,因此您想在 auth.generic_oauth 部分注册新用户:
allow_sign_up: true
  1. 我敢打赌,您的 scopes 配置语法错误,应该是:
scopes: openid email profile groups

通常,您在 Keycloak 中使用 groups 来映射 Grafana 中的 roles。这是可能的,但更好的逻辑是使用 Keycloak 中的 roles 来映射 Grafana 中的 roles。 Keycloak/Grafana 具有概念角色/组,您将如何为您的用户使用它们取决于您。我会先从基本的roles 概念开始。

【讨论】:

    猜你喜欢
    • 2021-12-17
    • 2022-01-19
    • 2021-05-27
    • 2021-12-17
    • 2019-08-05
    • 2022-11-27
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    相关资源
    最近更新 更多