1

我有一个基于 WSE 3.0 的 Web 服务,在 IIS 6.0 下的 Windows Server 2003 中运行。我希望 Web 服务进程模拟发送 Web 服务请求的客户端用户,但是该服务没有模拟客户端。

Web 应用程序有自己的应用程序池,当前设置为在网络服务标识下运行。Windows Server 2003 计算机帐户已启用 Active Directory 中的委派(至少根据我的 IT 人员)。服务 WSE 策略(在 wse3policyCache.config 中)如下所示:

<policy name="GeneratedServicesPolicy">
    <kerberosSecurity establishSecurityContext="false" renewExpiredSecurityContext="true" requireSignatureConfirmation="false" messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true" ttlInSeconds="300">
        <protection>
            <request signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
            <response signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
            <fault signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
        </protection>
     </kerberosSecurity>
     <requireActionHeader />
</policy>

该服务在其 web.config 中有以下条目(其中包括):

<identity impersonate="false"/>
<authentication mode="Windows"/>

为应用程序启用匿名访问(这是必需的,因为服务不使用传输级安全性,消息级是)。机器帐户已注册以下 SPN:

HOST/RD360-2
HOST/rd360-2.mycompany.com

客户端在其 wse3policyCache.config 中有以下内容:

<policy name="KerbClient">
    <kerberosSecurity establishSecurityContext="false" renewExpiredSecurityContext="true" requireSignatureConfirmation="false" messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true" ttlInSeconds="300">
        <token>
            <kerberos targetPrincipal="HOST/rd360-2.mycompany.com" impersonationLevel="Impersonation" />
        </token>
        <protection>
            <request signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
            <response signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
            <fault signatureOptions="IncludeAddressing, IncludeTimestamp, IncludeSoapBody" encryptBody="false" />
        </protection>
    </kerberosSecurity>
    <requireActionHeader />
</policy>

客户端代码如下所示:

static void Main(string[] args)
{
    AddFloatsWSWse client = new AddFloatsWSWse();
    client.SetPolicy("KerbClient");

    double result = client.AddFloats(2.3, 3.2);
    Console.WriteLine("Result was: '" + result + "'");
}

不过,该服务并没有冒充我的客户身份。我在服务中使用 log4net,当我要求它打印%username到 ASP.NET 跟踪日志中时,它总是NT AUTHORITY\NETWORK SERVICE而不是客户端用户 ID。有什么我做错了吗?有没有什么地方我可以查看 WSE 是否甚至试图执行模拟并失败?我确实在我的事件日志中看到了以下条目(MYDOMAIN 和 MYUSER 在这里被遮盖了):

Event Type: Success Audit
Event Source:   Security
Event Category: Privilege Use 
Event ID:   576
Date:       12/9/2009
Time:       11:07:16 AM
User:       MYDOMAIN\MYUSER
Computer:   RD360-2
Description:
    Special privileges assigned to new logon:
        User Name:  MYUSER
        Domain:     MYDOMAIN
        Logon ID:       (0x0,0x4B410AE)
        Privileges: SeSecurityPrivilege
                SeBackupPrivilege
                SeRestorePrivilege
                SeTakeOwnershipPrivilege
                SeDebugPrivilege
                SeSystemEnvironmentPrivilege
                SeLoadDriverPrivilege
                SeImpersonatePrivilege

----------------------------------------------------------------------------------

Event Type: Success Audit
Event Source:   Security
Event Category: Logon/Logoff 
Event ID:   540
Date:       12/9/2009
Time:       11:07:16 AM
User:       MYDOMAIN\MYUSER
Computer:   RD360-2
Description:
    Successful Network Logon:
        User Name:  MYUSER
        Domain:     MYDOMAIN
        Logon ID:   (0x0,0x4B410AE)
        Logon Type: 3
        Logon Process:  Kerberos
        Authentication Package: Kerberos
        Workstation Name:   
        Logon GUID: {OBFUSCATED}
        Caller User Name:   -
        Caller Domain:  -
        Caller Logon ID:    -
        Caller Process ID: -
        Transited Services: -
        Source Network Address: -
        Source Port:    -

在我的 WSE 跟踪文件中,我确实看到:

<processingStep description="Entering SOAP filter Microsoft.Web.Services3.Design.RequireSoapHeaderAssertion+RequireSoapHeaderFilter" />
<processingStep description="Exited SOAP filter Microsoft.Web.Services3.Design.RequireSoapHeaderAssertion+RequireSoapHeaderFilter" />
<processingStep description="Entering SOAP filter Microsoft.Web.Services3.Design.KerberosAssertion+ServiceInputFilter" />
<processingStep description="Exited SOAP filter Microsoft.Web.Services3.Design.KerberosAssertion+ServiceInputFilter" />

所以至少我知道 Kerberos 扩展正在处理我的 Kerberos 标头。

编辑:我的网络服务然后使用专有客户端通信库调用使用 SSPI/IWA 的另一台服务器(让我们称这第三台服务器为 foo 服务器)。我希望它在第二次调用 foo 服务器时使用客户端的身份。这意味着此客户端通信库调用AcquireCredentialsHandleInitializeSecurityContext使用 foo 服务器的 SPN 和不同的服务。在这种特殊情况下,foo 服务器实际上与 WSE Web 服务在同一台机器上运行(因此它使用 SPNmycompany/rd260-2)。由于第二个跃点是到同一台机器,我希望它使用 NTLM,但它仍然应该模拟我的 Web 服务客户端的用户身份,不是吗?在 foo 服务器的日志中,我看到它接受连接,使用提供的 IWA 安全上下文并告诉我,基于此安全上下文,连接用户是rd36-2$机器帐户,因为 WSE Web 服务在 IIS 中运行在网络服务身份(又与机器帐户相关联)下。在 foo 服务器的日志中,它接收到 IWA 安全上下文后,我最终想查看提交 Web 服务请求的用户的身份。将 foo 服务器移动到另一台机器以查看是否与此有关是否有用?

4

2 回答 2

2

与 WSE 3 一起使用的 Kerberos 令牌是一种消息级安全机制,仅对客户端进行身份验证。它实际上并没有像在 IWA 中那样更改安全上下文,因此您不会在跟踪日志中注意到任何不同之处。为了真正模拟客户,您必须:

  • impersonationLevel="Impersonation"在元素上启用对安全令牌的模拟<kerberos>(您已经完成了);和
  • 让您的 WebMethodWindowsImpersonationContext基于令牌的身份创建一个。

例子:

WindowsIdentity identity =
    (WindowsIdentity)RequestSoapContext.Current.IdentityToken.Identity;
WindowsImpersonationContext impersonationContext = null;
try
{
    impersonationContext = identity.Impersonate();

    // Perform your work here
    // ...
}
finally
{
    if (impersonationContext != null)
    {
        impersonationContext.Undo();
    }
}
于 2009-12-12T16:21:43.200 回答
0

据我所知,情况是当您尝试进行第二跳时,Kerberos 票证被丢弃。在双跳场景中,Kerberos 票证将在第二跳处丢弃。

之后您的身份验证将失败,并且不会切换到 NTLM。

于 2009-12-12T17:40:58.637 回答