【问题标题】:Impersonation not working - Asp.Net core 3.1 application with Windows Authentication hosting in IIS模拟不起作用 - 在 IIS 中托管 Windows 身份验证的 Asp.Net 核心 3.1 应用程序
【发布时间】:2020-07-16 04:50:52
【问题描述】:

我创建了一个 Blazor 服务器应用程序 (.Net core 3.1)。该应用程序使用 Windows 身份验证。该应用程序需要访问一些 Windows 服务,如文件共享、集成安全数据库等。因此它具有以下模拟代码。

var identity = await IdentityProvider.GetIdentityAsync();

if (identity.IsAuthenticated && identity is WindowsIdentity wid)
{
    return WindowsIdentity.RunImpersonated(wid.AccessToken, () =>
    {
        Fun1(....); // Should be called using the authentication of logged in user
    });

Fun1() 应该使用正在使用该应用程序的 Windows 用户的身份而不是用于运行网站的帐户来调用。

例如,我的网站的应用程序池的标识是MyDomain\UserX。当用户MyDomain\UserY 使用该网站时。我希望函数Fun1() 被模拟为MyDomain\UserY 而不是MyDomain\UserX

我在 IIS 上创建了一个网站,发布了代码,禁用了匿名身份验证并启用了 Windows 身份验证。但是,函数Fun1() 仍然是使用应用程序池中的身份调用的吗?是否应该更改 Active Directory 中的任何设置?

【问题讨论】:

  • 类似的场景,类似的代码。在 try-catch 中,它在我的机器上正常工作时从 IIS 向我返回 ACCESS_DENIED。似乎使用了正确的标识,因为 WindowsIdentity.GetCurrent().Name 在 RunImpersonated 中返回正确的标识。可能和这个有关:github.com/dotnet/runtime/issues/29935

标签: c# asp.net-core iis windows-authentication blazor


【解决方案1】:

为了使用登录用户的凭据(访问您的 API 而不是站点的应用程序池身份的用户)访问数据库,您需要设置 Kerberos 约束委派。请参考:https://docs.microsoft.com/en-us/windows-server/security/kerberos/kerberos-constrained-delegation-overview

https://blogs.uw.edu/kool/2016/10/26/kerberos-delegation-in-active-directory/#:~:text=What%20is%20Kerberos%20Delegation%3F,tier%20is%20the%20web%20site.

这可能对您没有帮助,因为这个问题是很久以前提出的。但如果其他人处于相同情况,可能会有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多