我正在使用安装在 Windows / IIS 上的 Grafana。我想将其与其他 Web 服务一起托管在反向代理子域名后面,并使用 Azure AD(又名 Entra ID)身份验证。那就是
https://grafana.example.com
。
我已在
custom.ini
中正确配置了 AzureAd 登录。我可以转到 http://localhost:3000
并可以成功使用“Microsoft 登录”按钮使用 AzureAD 登录。Woot。
我现在正在遵循 Grafana 在 https://grafana.com/tutorials/run-grafana-behind-a-proxy/#configure-iis 和 https://grafana.com/tutorials/iis/ 提供的说明,但它们主要将托管作为子路径,而不是作为“根”站点。
我已经安装了 IIS 重写模块。对于 IIS,我创建了一个新的“空”网站,然后根据说明添加了入站规则 - 匹配
(.*)
并重写为 http://localhost:3000/{R:1}
。这也有效 - 我可以转到 https://grafana.example.com
,它会加载登录页面。甜甜的!
但是,当我使用 FQDN 中的“Microsoft 登录”按钮时,它只会将我重定向回登录页面。
使用网络检查器,我看到 localhost 和 grafana.example.com 之间有不同的重定向行为:
localhost 返回 302,位置标头为
https://loign.microsoft.com/{tenantId}/oauthv2/v2.0/blahblahblah
- 这是预期的。
grafana.example.com 返回 302,Location 标头为
https://grafana.example.com/{tenantId}/blahblahblah
AzureAD 集成忽略我的 OAuth 提供商的
auth_url
设置,我错过了什么?
注意:我还启用了具有垃圾值的秘密等的 Google OAuth,并得到了相同的行为。这感觉像是我的服务器或所有 OAuth 提供商的错误或配置错误。
一种可能的解决方法是使用出站重写规则来匹配特定的“不正确”重定向。不过感觉有点 hacky - Grafana 模块应该生成正确的 URL。
<outboundRules>
<rule name="HeaderRewrite" preCondition="IsRedirect" enabled="true">
<match serverVariable="RESPONSE_Location" pattern="https://grafana.example.com/{tenantId}/oauth2/v2.0/authorize(.*)" />
<action type="Rewrite" value="https://login.microsoft.com/{tenantId}/oauth2/v2.0/authorize{R:1}" />
</rule>
<preConditions>
<preCondition name="IsRedirect">
<add input="{RESPONSE_STATUS}" pattern="3\d\d" />
</preCondition>
</preConditions>
</outboundRules>