authentik开源身份认证与管理平台-与 Grafana 集成(12)

张开发
2026/5/30 3:02:06 15 分钟阅读
authentik开源身份认证与管理平台-与 Grafana 集成(12)
文章目录什么是 Grafana准备authentik配置Grafana 配置DockerStandaloneHelm角色映射Grafana 配置注意事项什么是 GrafanaGrafana 是一个多平台开源分析和交互式可视化网络应用程序。当连接到支持的数据源时它可以提供网络图表、图形和警报。企业版 Grafana 也提供附加功能。它可以通过插件系统进行扩展。准备在本指南中使用了以下占位符grafana.company 是 Grafana 安装的 FQDN。authentik.company 是 authentik 安装的 FQDN。authentik配置为了支持将 Grafana 与 authentik 集成您需要在 authentik 中创建一个应用程序/提供程序对。作为管理员登录到 authentik 并打开 authentik 管理员界面。导航至应用程序 应用程序然后单击使用提供程序创建以创建应用程序和提供程序对。 或者您可以先单独创建提供程序然后创建应用程序并将其连接到提供程序。应用程序 提供一个描述性名称、一个可选的应用程序类型组、策略引擎模式和可选的 UI 设置。应用名称Grafana, Slug会自动带出grafana选择提供者类型 选择OAuth2/OpenID Connect作为提供者类型。配置提供者 提供名称或接受自动提供的名称、用于此提供者的授权流程以及以下必需配置。注意客户端 ID、 客户端密钥和 slug 值因为它们将在稍后需要。设置一个 Strict 重定向 URI 为 https://grafana.company/login/generic_oauth 。将注销 URI 设置为 https://grafana.company/logout 。将“注销方式”设置为“前端通道”。选择任何可用的签署密钥。确保禁用加密。配置绑定 可选您可以创建一个 绑定 策略、组或用户来管理用户“我的应用程序”页面上应用程序的列表和访问权限。单击提交以保存新应用程序和提供程序。Grafana 配置Docker如果您的 Grafana 实例在 Docker 中运行请设置以下环境变量environment:GF_AUTH_GENERIC_OAUTH_ENABLED:trueGF_AUTH_GENERIC_OAUTH_NAME:authentikGF_AUTH_GENERIC_OAUTH_CLIENT_ID:Client ID from aboveGF_AUTH_GENERIC_OAUTH_CLIENT_SECRET:Client Secret from aboveGF_AUTH_GENERIC_OAUTH_SCOPES:openid profile emailGF_AUTH_GENERIC_OAUTH_AUTH_URL:https://authentik.company/application/o/authorize/GF_AUTH_GENERIC_OAUTH_TOKEN_URL:https://authentik.company/application/o/token/GF_AUTH_GENERIC_OAUTH_API_URL:https://authentik.company/application/o/userinfo/GF_AUTH_SIGNOUT_REDIRECT_URL:https://authentik.company/application/o/application_slug/end-session/# Optionally enable auto-login (bypasses Grafana login screen)GF_AUTH_OAUTH_AUTO_LOGIN:true# Optionally map user groups to Grafana rolesGF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH:contains(groups[*], Grafana Admins) Admin || contains(groups[*], Grafana Editors) Editor || Viewer# Required if Grafana is running behind a reverse proxyGF_SERVER_ROOT_URL:https://grafana.companyStandalone如果您使用配置文件必须设置以下选项[auth]signout_redirect_urlhttps://authentik.company/application/o/application_slug/end-session/# Optionally enable auto-loginoauth_auto_logintrue[auth.generic_oauth]nameauthentik enabledtrueclient_idClient ID from aboveclient_secretClient Secret from abovescopesopenid email profile auth_urlhttps://authentik.company/application/o/authorize/ token_urlhttps://authentik.company/application/o/token/ api_urlhttps://authentik.company/application/o/userinfo/# Optionally map user groups to Grafana rolesrole_attribute_pathcontains(groups,Grafana Admins)Admin||contains(groups,Grafana Editors)Editor||ViewerHelm如果您使用的是 Helm 的 values.yaml 文件您必须设置以下选项grafana.ini:auth:signout_redirect_url:https://authentik.company/application/o/application_slug/end-session/oauth_auto_login:trueauth.generic_oauth:name:authentikenabled:trueclient_id:Client ID from aboveclient_secret:Client Secret from abovescopes:openid profile emailauth_url:https://authentik.company/application/o/authorize/token_url:https://authentik.company/application/o/token/api_url:https://authentik.company/application/o/userinfo/# Optionally map user groups to Grafana rolesrole_attribute_path:contains(groups,Grafana Admins)Admin||contains(groups,Grafana Editors)Editor||Viewer角色映射在上面的配置中您可以看到一个角色映射示例。登录时此配置会查看当前用户所属的组。如果找到指定的组名称之一用户将被授予在 Grafana 中的相应角色。在上面的示例中指定的组名称之一是“Grafana Admins”。如果用户是该组的成员则在 Grafana 中授予“管理员”角色。如果用户不是“Grafana Admins”组的成员它会跳到查看用户是否是“Grafana 编辑器”组的成员。如果是它会授予“编辑器”角色。最后如果用户未被发现是这些组中的任何一个成员则会返回授予“查看者”角色。有关组/角色映射的更多信息请参见 grafana 的文档 。Grafana 配置注意事项为了确保重定向在 Grafana 中正常工作请确保配置中的 root_url 正确地反映用户通过代理访问 Grafana 的方式。例如如果您的 Grafana 实例位于代理后面且通过代理访问的是 https://grafana.company则将 root_url 设置为 https://grafana.company。这可确保 OAuth 和其他重定向使用正确的 URL例如 https://grafana.company/login/generic_oauth 而不是默认使用诸如 localhost:3000。如果您在第一次使用 OAuth 登录到 grafana 时遇到“user does not belong to org” 错误请检查您是否有 ID 为“1”的组织如果没有请在 grafana 配置文件中添加以下内容[users]auto_assign_orgtrueauto_assign_org_idid-of-your-default-organization

更多文章