带有 Keycloak 的 Grafana OAuth
Grafana OAuth with Keycloak
我正在使用 helm 图表。在部署过程中,我覆盖了如下值:
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
在 Keycloke 中,我创建了一个客户端、一个客户端范围、一个客户端范围内的组映射器、一个组并将 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 文档描述性不强,很难理解。
你有几个问题:
Groups mapping: Available in Grafana Enterprise v8.1 and later versions.
您使用的是 Grafana 7.1.5,我想也是免费的 OSS Grafana(不是付费企业版,需要许可证),所以组映射(配置groups_attribute_path
) 在你的情况下是不可能的。
- 您还将 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'
- Grafana 根据 OIDC 响应创建内部用户,因此您想在
auth.generic_oauth
部分注册新用户:
allow_sign_up: true
- 我敢打赌你的
scopes
配置语法错误,应该是:
scopes: openid email profile groups
一般是在Keycloak中使用groups
映射到Grafana中roles
。这是可能的,但更好的逻辑是在 Keycloak 中使用 roles
来映射 Grafana 中的 roles
。 Keycloak/Grafana 有概念 roles/groups,如何为用户使用它们取决于您。我会先从基本的 roles
概念开始。
我正在使用 helm 图表。在部署过程中,我覆盖了如下值:
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
在 Keycloke 中,我创建了一个客户端、一个客户端范围、一个客户端范围内的组映射器、一个组并将 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 文档描述性不强,很难理解。
你有几个问题:
Groups mapping: Available in Grafana Enterprise v8.1 and later versions.
您使用的是 Grafana 7.1.5,我想也是免费的 OSS Grafana(不是付费企业版,需要许可证),所以组映射(配置groups_attribute_path
) 在你的情况下是不可能的。
- 您还将 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'
- Grafana 根据 OIDC 响应创建内部用户,因此您想在
auth.generic_oauth
部分注册新用户:
allow_sign_up: true
- 我敢打赌你的
scopes
配置语法错误,应该是:
scopes: openid email profile groups
一般是在Keycloak中使用groups
映射到Grafana中roles
。这是可能的,但更好的逻辑是在 Keycloak 中使用 roles
来映射 Grafana 中的 roles
。 Keycloak/Grafana 有概念 roles/groups,如何为用户使用它们取决于您。我会先从基本的 roles
概念开始。