【问题标题】:Double hop IIS to SQL Server authentication works locally, doesn't work remotely双跳 IIS 到 SQL Server 身份验证在本地工作,不能在远程工作
【发布时间】:2021-05-15 04:51:15
【问题描述】:

一个关于双跳认证浏览器的问题 -> IIS (ASP.NET WebForms app) -> SQL Server.

我有一个带有 Web.config 的 WebForms 网站,如下所示:

<?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <sectionGroup name="devExpress">
          ...some DevExpress settings here...
        </sectionGroup>
      </configSections>
      <connectionStrings>
        <add name="ConnStringName" connectionString="Data Source=SERVER_NAME;Initial Catalog=DB_NAME;Trusted_Connection=Yes;Integrated Security=SSPI;Persist Security Info=False;Connect Timeout=0" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <system.web>
        <identity impersonate="true" />
        ...
        <authentication mode="Windows" />
        <authorization>
          <deny users="?" />
        </authorization>
        ...
        <httpRuntime maxRequestLength="4096" requestValidationMode="4.0" executionTimeout="110" targetFramework="4.5.2" />
        <pages validateRequest="true" clientIDMode="Predictable">
        ...
        </pages>
        <sessionState mode="InProc" timeout="60"></sessionState>
      </system.web>
      <system.webServer>
        <defaultDocument>
          <files>
            <clear />
            <add value="Default.aspx" />
          </files>
        </defaultDocument>
        ...
        <validation validateIntegratedModeConfiguration="false" />
      ...
    </configuration>

我需要它像这样工作:当域中的任何用户在浏览器中打开站点时,ASP.NET Web 窗体应用程序在他的 Windows 凭据下运行。然后必须使用相同的凭据来验证 ASP.NET 应用程序使用 SqlConnection 类进行的数据库调用。

为清楚起见:SQL Server 配置为使用 Windows 身份验证。必须有权访问应用程序和数据库的用户包含在特定的 AD 组中。该组列在 DB 的 Security - Logins 列表中,具有 data_reader、data_writer 权限(并且它们还可以执行存储的过程)。

最有趣的是它真正是如何工作的:
#1。当我在 IIS 所在的服务器上打开浏览器时,键入 http://localhost:port/ - 它按预期工作。
#2。当我在 PC 上打开浏览器时,输入 http://server-name:port/ - 它会捕获 SqlConnection 打开错误:

System.Data.SqlClient.SqlException
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

在这两种情况下,Context.User.Identity.Name 和 WindowsIdentity.GetCurrent().Name 都是正确的。

为什么这两种情况会给出不同的结果?如何让 #2 像 #1 一样工作?

【问题讨论】:

    标签: sql-server iis webforms kerberos windows-authentication


    【解决方案1】:

    由于这是双跳身份验证方案,您必须启用Kerberos Constrained Delegation。参见例如Setting up Kerberos Authentication for a Website in IIS

    【讨论】:

    • 第二个链接失效
    • Hum 看起来在 Edge 而不是 Firefox 中有效,不知道为什么
    • @DavidBrowne-Microsoft,该说明中的某些步骤与 SPN 有关。如果我理解正确,SPN 只需要通过特定主机名而不是 servername:port 来访问站点。所以我假设,如果我只希望它通过 servername:port 地址工作,则可以完全跳过 SPN 步骤。对吗?
    • Kerberos 身份验证要求运行服务的服务帐户注册 SPN。没有 SPN 身份验证将回退到 NTLM,它无法进行委派。
    猜你喜欢
    • 2017-06-25
    • 2020-04-01
    • 2021-05-10
    • 2021-05-07
    • 2017-03-01
    • 2013-09-29
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    相关资源
    最近更新 更多