IIS 重写模块 Windows 身份验证
IIS Rewrite Module Windows Authentication
我有两个 asp.net 网络应用程序。
其中一个应用程序是主要的 mvc 网络应用程序,第二个是充当反向代理的网络应用程序,仅包含一个文件 - web.config。
反向代理没有启用任何身份验证模式,但主应用程序有 windows 身份验证。
通过反向代理访问应用程序时,浏览器中会出现弹出窗口,要求提供 windows 凭据。
是否有可能以某种方式通过所有反向代理请求传递一个域用户?当反向代理重定向请求时,它会添加自定义 headers。是否可以从 iis 池或以某种方式硬编码传递用户,以便所有反向代理请求都可以通过 windows auth 传递到主应用程序,然后用户可以通过正常登录页面进行身份验证?
目标是通过反向代理访问主应用程序而无需输入 windows 凭据。
无法在主应用程序上禁用 windows 身份验证。
感谢您的回答。
反向代理web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)"/>
<action type="Rewrite" url="https://main-app.com/{R:1}"/>
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/>
<set name="HTTP_ACCEPT_ENCODING" value=""/>
<set name="HTTP_CUSTOM_ZEW_HEADER" value="True"/>
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://main-app.com/(.*)"/>
<action type="Rewrite" value="http{R:1}://main-app.com/{R:2}"/>
</rule>
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)"/>
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}"/>
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+"/>
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
无法转发 REMOTE_USER
header 因为当存在授权 header 时,请求在身份验证模块运行之前转发,因此身份验证服务器变量是未设置(当映射到 headers 时,它们只是空白)。
您可以使用自定义 HTTP 模块发送经过身份验证的用户自定义 header。
另一种方法是您可以设置 SPN:
我有两个 asp.net 网络应用程序。 其中一个应用程序是主要的 mvc 网络应用程序,第二个是充当反向代理的网络应用程序,仅包含一个文件 - web.config。 反向代理没有启用任何身份验证模式,但主应用程序有 windows 身份验证。 通过反向代理访问应用程序时,浏览器中会出现弹出窗口,要求提供 windows 凭据。 是否有可能以某种方式通过所有反向代理请求传递一个域用户?当反向代理重定向请求时,它会添加自定义 headers。是否可以从 iis 池或以某种方式硬编码传递用户,以便所有反向代理请求都可以通过 windows auth 传递到主应用程序,然后用户可以通过正常登录页面进行身份验证? 目标是通过反向代理访问主应用程序而无需输入 windows 凭据。 无法在主应用程序上禁用 windows 身份验证。 感谢您的回答。
反向代理web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)"/>
<action type="Rewrite" url="https://main-app.com/{R:1}"/>
<serverVariables>
<set name="HTTP_X_ORIGINAL_ACCEPT_ENCODING" value="{HTTP_ACCEPT_ENCODING}"/>
<set name="HTTP_ACCEPT_ENCODING" value=""/>
<set name="HTTP_CUSTOM_ZEW_HEADER" value="True"/>
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://main-app.com/(.*)"/>
<action type="Rewrite" value="http{R:1}://main-app.com/{R:2}"/>
</rule>
<rule name="RestoreAcceptEncoding" preCondition="NeedsRestoringAcceptEncoding">
<match serverVariable="HTTP_ACCEPT_ENCODING" pattern="^(.*)"/>
<action type="Rewrite" value="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}"/>
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html"/>
</preCondition>
<preCondition name="NeedsRestoringAcceptEncoding">
<add input="{HTTP_X_ORIGINAL_ACCEPT_ENCODING}" pattern=".+"/>
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
无法转发 REMOTE_USER
header 因为当存在授权 header 时,请求在身份验证模块运行之前转发,因此身份验证服务器变量是未设置(当映射到 headers 时,它们只是空白)。
您可以使用自定义 HTTP 模块发送经过身份验证的用户自定义 header。
另一种方法是您可以设置 SPN: