【问题标题】:Federate grafana with apache2 + mod_auth_mellon to have SSO with SAML将 grafana 与 apache2 + mod_auth_mellon 联合以使用 SAML 进行 SSO
【发布时间】:2024-01-12 19:36:01
【问题描述】:

尝试使用 Okta 作为 IdP 实施 SSO(Single SIgn On),我按照以下步骤操作:

  1. 安装 apache2 + mod_auth_mellon
  2. 在同一主机上安装 grafana
  3. 启用所需的 apache2 模块,如 headers、authzn_core & authz_user 等等……
  4. 生成元数据并配置 mod_auth_mellon
  5. 配置 Grafana。

我的 Apache 配置文件:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
<Location />
    MellonEnable "info"
    MellonSPPrivateKeyFile /etc/apache2/mellon/urn_grafana.key
    MellonSPCertFile /etc/apache2/mellon/urn_grafana.cert
    MellonSPMetadataFile /etc/apache2/mellon/urn_grafana.xml
    MellonIdPMetadataFile /etc/apache2/mellon/idp-metadata.xml
    MellonEndpointPath /grafana
</Location>
    MellonPostDirectory "/var/cache/mod_auth_mellon_postdata"
    ProxyPass /grafana http://127.0.0.1:3000
    ProxyPassReverse /grafana http://127.0.0.1:3000
<Location /grafana>
    MellonEnable "auth"
    MellonPostReplay On
    MellonSamlResponseDump On
    MellonUser "NAME_ID"
    ProxyPassInterpolateEnv On
    RequestHeader set X-WEBAUTH-USER "%{MELLON_username}e"
</Location>
</VirtualHost>

我的 grafana 配置文件:

...
...
    [auth.proxy]
    enabled = true
    header_name = X-WEBAUTH-USER
    header_property = email
    auto_sign_up = true
...
...

我一直在关注官方文档 (github,com/UNINETT/mod_auth_mellon/wiki/GenericSetup),但看起来我做错了什么。

重点是:我的意思是它部分起作用:

当我尝试访问 http://X.X.X.X/grafana 时,我被重定向到 Okta 的页面进行身份验证,然后我再次被重定向到 grafana http://X.X.X.X:3000/login 但我收到了这个:

[{"fieldNames":["User"],"classification":"RequiredError","message":"Required"},{"fieldNames":["Password"],"classification":"RequiredError","message":"Required"}]

一些提示?看起来 Grafana 没有收到任何参数作为用户名或密码。 尝试调试我从 Okta 收到的参数时,我不知道如何使用 PHP 代码来打印标题。 我尝试使用 firefox SAMl tracer 进行调试,但没有成功…… 看起来我没有从 Okta 收到任何额外的标头,所以我有点卡在这里……

提前谢谢你。

更新: 我尝试再次从 0 配置所有内容,现在使用此配置它可以工作,但用户名是(null),所以行为与以前相同,但现在登录到 grafana。实际上,即使没有对 Okta 进行身份验证,它也会登录! :o

Apache 配置文件:

LoadModule auth_mellon_module modules/mod_auth_mellon.so

RequestHeader set X-WEBAUTH-USER "%{MELLON_username}e"
ServerName grafana.xxxxxxxxxxxxxx.aws
ProxyPassInterpolateEnv On
ProxyPass /login/saml !
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ProxyRequests Off
<Location /login>
        MellonEnable "auth"
        #MellonSecureCookie Off
        MellonMergeEnvVars On
        MellonCookieDomain grafana.xxxxxxxxxxxxxx.aws
        MellonCookiePath /
        MellonEndpointPath "/login/saml"
        MellonDefaultLoginPath "/"
        MellonNoCookieErrorPage "http://grafana.xxxxxxxxxxxxxx.aws/no_cookie.html"
        MellonSPentityId "http://grafana.xxxxxxxxxxxxxx.aws"
        MellonSPPrivateKeyFile /etc/httpd/mellon/http_grafana.xxxxxxxxxxxxxx.aws_3000.key
        MellonSPCertFile /etc/httpd/mellon/http_grafana.xxxxxxxxxxxxxx.aws_3000.cert
        MellonIdPMetadataFile /etc/httpd/mellon/idp-metadata.xml
        MellonAuthnContextClassRef "urn:federation:authentication:windows"
        MellonAuthnContextClassRef "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"
</Location>

格拉法纳配置文件:

...
...
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
header_email_name = X-WEBAUTH-EMAIL
header_email_property = email
header_full_name = X-WEBAUTH-NAME
header_full_property = fullname
auto_sign_up = true
...
...

可能与这个问题有关:github,com/grafana/grafana/issues/7049 但令我惊讶的是,没有人发布关于如何使用 mod_auth_mellon 配置 grafana 以便使用 SAML 进行 SSO。

【问题讨论】:

    标签: apache single-sign-on saml-2.0 grafana


    【解决方案1】:

    试试env=MELLON_username,这对我有用。

    RequestHeader set X-WEBAUTH-USER %{MELLON_user}e env=MELLON_user
    RequestHeader set X-WEBAUTH-USER %{MELLON_email}e env=MELLON_email
    RequestHeader set X-WEBAUTH-USER %{MELLON_username}e env=MELLON_username
    

    【讨论】:

    • 请添加有关如何以及在何处添加其他配置或传递参数的更多信息。将有助于分类和轻松尝试。