【问题标题】:ASP double hop request in kerberos delegation scenariokerberos 委托场景中的 ASP 双跳请求
【发布时间】:2018-03-02 23:37:07
【问题描述】:

请帮忙! 我需要我的 asp 应用程序来请求具有模拟用户凭据的远程系统。但总是得到 401 Unauthorized 错误。 我从这里进行了所有配置:https://support.microsoft.com/en-us/help/810572/how-to-configure-an-asp-net-application-for-a-delegation-scenario Kerberos 已在我的应用程序和我的测试远程应用程序中配置并运行(我在提琴手中看到了 kerberos 票证)。委派、spns 等一切都已配置完毕。

这是我使用 System.Net.Http.httpclient 的代码:

    HttpClientHandler handler = new HttpClientHandler()
{
    UseDefaultCredentials = true,
    PreAuthenticate = true
};

using (HttpClient client = new HttpClient(handler))
{
    client.DefaultRequestHeaders.Accept.Clear();
    var method = new HttpMethod("GET");
    var request = new HttpRequestMessage(method, "http://testdelegationapp.avp.ru/");
    var response = client.SendAsync(request).Result;
}

实际上 http 请求是由 Apppool 帐户发出的(在远程应用 IIS 中限制对 Apppool 帐户的访问时出现 401 错误)

这里:How to get HttpClient to pass credentials along with the request? 声称HttpClient不能将安全令牌传递给另一个线程,最好使用System.Net.WebClient的同步方法

使用 webclient 的代码:

var wi = (WindowsIdentity)HttpContext.User.Identity;
var wic = wi.Impersonate();
try
{
    string URI = "http://testdelegationapp.avp.ru/";
    using (WebClient wc = new WebClient())
    {
        wc.UseDefaultCredentials = true;
        string response = wc.DownloadString(URI);
    }
}
finally
{
    wic.Undo();
}

结果更糟,同样的 401 错误,但在 fiddler 中我可以看到 webclient 使用 NTLM 票证访问远程应用程序!

从这里配置流动令牌抛出线程:Unable to authenticate to ASP.NET Web Api service with HttpClient 也无济于事。 SecurityContext.IsWindowsIdentityFlowSuppressed() 为假。

WindowsIdentity.GetCurrent().Name 和 Thread.CurrentPrincipal.Identity.Name 显示应有的模拟用户。

【问题讨论】:

    标签: httpclient webclient kerberos impersonation delegation


    【解决方案1】:

    所有时间问题都在 chrome 浏览器中,默认情况下它禁止 kerberos 委派。您应该将以下内容添加到注册表:

    Path: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome ; 
    string: AuthNegotiateDelegateWhitelist ; 
    value: *.avp.ru
    

    所以,现在我的工作配置是

    用于 Web 请求的 HttpClient。

    如果您想在 IIS 下执行所有应用程序,则在 IIS 中启用 ASP 模拟 委托凭证。如果您想要特定方法的委托,请使用:

    var wi = (WindowsIdentity)HttpContext.User.Identity;    
    var wic = wi.Impersonate();
    wic.Undo();
    

    HttpClient 在另一个线程中执行请求,因此在 aspnet_config.config 中我们需要进行以下更改:

    <legacyImpersonationPolicy enabled="false"/>
    <alwaysFlowImpersonationPolicy enabled="true"/>
    

    您可以在以下位置找到 aspnet_config.config:

    C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
    C:\Windows\Microsoft.NET\Framework64\v2.0.50727\aspnet.config
    C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet.config
    

    【讨论】:

    • 此场景中使用的客户端操作系统是什么?
    • @T-Heron Windows 10
    猜你喜欢
    • 1970-01-01
    • 2021-11-14
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 2020-02-20
    相关资源
    最近更新 更多