使用 Kerberos 验证端点

问题描述 投票:0回答:1

我在控制台应用程序中托管一个简单的端点,如下所示

string[] prefixes = { "http://+:8080/" };
HttpListener listener = new HttpListener();

foreach (string prefix in prefixes)
{
    listener.Prefixes.Add(prefix);
}

listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
listener.Start();

Console.WriteLine("Listening on port 8080...");

while (true)
{
    HttpListenerContext context = listener.GetContext();
    HttpListenerRequest request = context.Request;
    HttpListenerResponse response = context.Response;

    if (request.HttpMethod == "GET" && request.Url.AbsolutePath == "/api/kerberos/test")
    {
        IIdentity identity = context.User.Identity;
        string responseString = $"Hello, {identity.Name}! You are authenticated using {identity.AuthenticationType}.";
        byte[] buffer = Encoding.UTF8.GetBytes(responseString);

        response.ContentLength64 = buffer.Length;
        response.OutputStream.Write(buffer, 0, buffer.Length);
    }
    else
    {
        response.StatusCode = (int)HttpStatusCode.NotFound;
    }

response.Close();

控制台应用程序正在运行 AD 的 VM 上的 PowerShell 窗口中执行。应用程序运行后,我导航到

http://{FQDN}//api/kerberos/test
,系统会提示我输入我的 Windows 用户名和密码,我总是得到
Hello, DOMAIN\john.smith! You are authenticated using NTLM.
。我需要做什么才能看到
Hello, DOMAIN\user! You are authenticated using Kerberos.

这是我迄今为止尝试过的事情

  1. setspn -Q HTTP/{FQDN}
  2. setspn -S HTTP/{FQDN} john.smith

我觉得这是 SPN 的问题,但我对 Kerberos 还很陌生,因此我们将不胜感激。

谢谢你

c# kerberos
1个回答
0
投票

请使用以下格式进行SPN注册:

http/webserver1.contoso.com:8080

此处 webserver1.contoso.com 是提供 Web 服务器服务的服务器的 FQDN,在您的情况下是域控制器的 FQDN。

如果使用 IIS,此 SPN 应注册在您的应用程序的应用程序池的应用程序池帐户下。

您使用的浏览器应支持 Windows 集成身份验证。

“验证 Web 服务器是否配置为支持 Kerberos 身份验证。为此,请验证 IIS 元数据库中的 NTAuthenticationProviders 密钥设置是否未更改为 NTLM。默认设置为 Negotiate,NTLM。”

您还可以使用 klist 命令检查为 http/webserver1.contoso.com 获取的 Kerberos 票证。

如果您使用 Internet Explorer 浏览器,则应设置以下链接中说明的注册表项:

https://learn.microsoft.com/en-us/troubleshoot/developer/webapps/iis/www-authentication-authorization/troubleshoot-kerberos-failures-ie

“Web 服务器是否使用默认端口 (80) 以外的端口 默认情况下,Internet Explorer 不会在用于请求 Kerberos 票证的 SPN 中包含端口号信息。如果您使用 IIS 在不同端口和身份下托管多个站点,则可能会出现问题。在此配置中,Kerberos 身份验证可能仅适用于特定站点,即使所有 SPN 均已在 Active Directory 中正确声明也是如此。要解决此问题,您必须设置 FEATURE_INCLUDE_PORT_IN_SPN_KB908209 注册表值。 (有关如何声明密钥的信息,请参阅 Internet Explorer 功能密钥部分。)此设置强制 Internet Explorer 在用于请求 Kerberos 票证的 SPN 中包含端口号”

如果您使用Chrome,您可以查看以下链接:

https://support.google.com/chrome/a/answer/10304441?hl=zh-CN

我认为您的登录应该使用当前凭据自动进行。它不应该询问用户名和密码。

© www.soinside.com 2019 - 2024. All rights reserved.