【问题标题】:How can I set IIS Windows Auth Providers with powershell?如何使用 powershell 设置 IIS Windows 身份验证提供程序?
【发布时间】:2013-08-21 14:43:29
【问题描述】:

有没有一种方法可以在 IIS 7.5 中使用 powershell 添加/删除/重新排序 Windows 身份验证提供程序?

我被告知,并且没有发现相反的证据表明 NTLM 提供程序在与 Windows 身份验证一起使用时比协商更快。这可能会或可能不会与 Silverlight 4、.NET 3.5、Windows 2003 Active Directory 和 IIS6 结合使用。

自从告诉我这个声明后,我们已经升级到 IIS7.5 (Server 2008R2)、SilverLight 5 和 .NET 4.5,但 AD 仍然在 2003 功能级别运行。

我的目标是始终确保 NTLM 提供程序列在 IIS 7.5 中启用的提供程序列表的首位。

谢谢

【问题讨论】:

    标签: powershell iis-7.5 windows-authentication


    【解决方案1】:

    使用 powershell 可以做到这一点。 对于我正在使用的场景,我想配置一个特定的站点,而不是更改默认设置。 默认情况下,这在 web.config 中是不可能的,因为所有身份验证设置都设置为 overrideModeDefault="Deny"。这意味着需要直接对 applicationhost.config 进行更改。

    我正在寻找的最终结果是:

    <location path="MySite">
        <system.webServer>
            <security>
                <authentication>
                    <anonymousAuthentication enabled="false" />
                    <windowsAuthentication enabled="true">
                        <providers>
                            <clear />
                            <add value="NTLM" />
                            <add value="Negotiate" />
                        </providers>
                    </windowsAuthentication>
                </authentication>
            </security>
        </system.webServer>
    </location>
    

    通过在重新添加提供者之前执行clear,它们的优先级顺序发生了变化。

    首先禁用匿名身份验证并启用 Windows 身份验证,我使用以下内容:

    Set-WebConfiguration system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\ -Location MySite -Value @{enabled="False"}
    Set-WebConfiguration system.webServer/security/authentication/windowsAuthentication -PSPath IIS:\ -Location MySite -Value @{enabled="True"}
    

    然后添加&lt;clear /&gt;标签:

    Remove-WebConfigurationProperty -PSPath IIS:\ -Location MySite -filter system.webServer/security/authentication/windowsAuthentication/providers -name "."
    

    最后,按顺序添加提供者:

    Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS:\ -Location MySite -Value NTLM
    Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS:\ -Location MySite -Value Negotiate
    

    【讨论】:

    • 你刚刚救了我的培根。非常感谢!
    【解决方案2】:

    您只能启用和禁用以下部分中可用的身份验证方法:

    system.webServer/authentication

    这是因为system.webServer/authentication 不是集合,不支持addremove 配置元素。查看 IIS 配置架构文件:

    C:\Windows\System32\inetsrv\config\schema\IIS_schema.xml

    搜索system.webServer/security/authentication,您会看到该部分的每个子元素都已明确定义,system.webServer/security/authentication 本身没有定义。

    关于排序,尝试更改身份验证方法的顺序没有区别。例如按以下顺序(基本在 Windows Authenticaton 之前):

    <system.webServer>
        <security>
            <authentication>
                <basicAuthentication enabled="true" />
                <windowsAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
    

    当我交换订单时:

    <system.webServer>
        <security>
            <authentication>
                <windowsAuthentication enabled="true" />
                <basicAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
    

    ...总是会导致 IIS 在 401 质询中将以下标头发送到浏览器(使用 Fiddler 捕获):

    HTTP/1.1 401 Unauthorized
    Server: Microsoft-IIS/7.5
    WWW-Authenticate: Negotiate
    WWW-Authenticate: NTLM
    WWW-Authenticate: Basic realm="172.16.3.87"
    

    在上面,IIS 向浏览器表明它支持 Kerberos、NTLM 或基本身份验证方法。开箱即用的这些身份验证方法始终按此顺序排列,与浏览器供应商无关(我尝试过 IE 和 Chrome)。

    根据我使用 Fiddler 的观察,IE 和 Chrome 都尝试使用该浏览器支持的第一个可用方法进行协商。即在这种情况下,IE 和 Chrome 都协商了 Kerberos 身份验证:

    GET http://172.16.3.87:81/ HTTP/1.1
    Host: 172.16.3.87:81
    Connection: keep-alive
    Authorization: Negotiate TlRMTVNTUAABAAAAl4II4gAAAAAAAAAAAAAAAAAAAAAGAbEdAAAADw==
    

    如果您对 Negotiate 值进行 base64 解码,它会显示:

    NTLMSSP
    

    可以通过以下方式删除 Kerberos (Negotiate) 方法:

    <system.webServer>
        <security>
            <authentication>
                <windowsAuthentication enabled="true">
                    <providers>
                        <remove value="Negotiate" />
                    </providers>
                </windowsAuthentication>
                <basicAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
    

    但是尝试通过执行以下操作来更改这些顺序将无效:

    <system.webServer>
        <security>
            <authentication>
                <windowsAuthentication enabled="true">
                    <providers>
                        <remove value="Negotiate" />
                        <remove value="NTLM" />
                        <add value="NTLM" />
                        <add value="Negotiate" />
                    </providers>
                </windowsAuthentication>
                <basicAuthentication enabled="true" />
            </authentication>
        </security>
    </system.webServer>
    

    您仍将按以下顺序收到WWW-Authenticate: 标头:

    WWW-Authenticate: Negotiate
    WWW-Authenticate: NTLM
    WWW-Authenticate: Basic realm="172.16.3.87"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-21
      • 2013-10-28
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 2021-02-28
      • 2015-08-24
      相关资源
      最近更新 更多