如何在 Kestrel 上运行的 ASP.NET Core 应用程序中与 gMSA 帐户协商身份验证

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

我有一个 ASP.NET Core Web API,它在使用 Kestrel Web 服务器的本地 AD 环境测试中作为 gMSA(组托管服务帐户)下的 Windows 服务运行。

应用程序使用协商身份验证(无后备策略):

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate();  
...  
app.UseAuthentication();  
app.UseAuthorization();

我也有这条路线:

app.MapGet("/",
        [Authorize](HttpContext context) =>
        {
            var identity = context.User.Identity;
            if (identity is null)            
                return Results.Ok("user is null");            

            var username = identity.Name;
            if (username is null)            
                return Results.Ok("username is null");

            return Results.Ok
            (new { Username = identity.Name.Split('\\')[1] }); });

现在,当我启动服务并发送

GET
请求时:

Invoke-RestMethod -Method Get -Uri 'https://server.domain.net' -UseDefaultCredentials -Verbose

当请求从运行应用程序的同一服务器发送时,我得到以下响应

VERBOSE: Requested HTTP/1.1 GET with 0-byte payload
VERBOSE: Received HTTP/1.1 response of content type application/json of unknown size
VERBOSE: Content encoding: utf-8

username
--------
User

现在,当我从域中的任何其他计算机(使用同一用户)发送请求时,我得到以下信息:

VERBOSE: Requested HTTP/1.1 GET with 0-byte payload
VERBOSE: Received HTTP/1.1 0-byte response of content type
Invoke-RestMethod: Response status code does not indicate success: 401 (Unauthorized).

注意:出于测试目的,在所有计算机上禁用防火墙,SPN 设置正确(至少我遵循了 Microsoft 支持文章)

造成这种行为的原因是什么?

asp.net-core-webapi kerberos kestrel-http-server negotiate gmsa
1个回答
0
投票

我明白了:
我错误地创建了 gMSA 帐户

New-ADServiceAccount -Name 'service-gMSA' -DNSHostname 'server.domain.net'

我向 gMSA 帐户提供的

DNSHostname
等于在 gMSA 帐户下运行服务的服务器的 FQDN。

所以正确的命令是:

New-ADServiceAccount -Name 'service-gMSA' -DNSHostname 'service-gMSA.domain.net'
© www.soinside.com 2019 - 2024. All rights reserved.