【问题标题】:stop WCF from caching / re-using security tokens (SecurityContextToken)阻止 WCF 缓存/重用安全令牌 (SecurityContextToken)
【发布时间】:2013-03-12 19:47:55
【问题描述】:

我正在使用带有以下 wsHttpBinding 的 WCF 消息级别安全性

  <security mode="Message">
    <message clientCredentialType="Windows" establishSecurityContext="false" />
  </security>
  • 每次调用服务都是一个单独的操作,不需要保留任何会话状态。

  • 我遇到了负载平衡器的问题,因为 WCF 不断重复使用安全令牌,因此如果第一次调用转到 NodeA,它会创建一个可重复使用的安全令牌。如果将该令牌传递给 NodeB,则 MessageSecurityException

  • 似乎微软对此的回答是使用粘性会话,这是我们探索过的,但在我们的设置中没有意义

有没有办法简单地强制 WCF 在每次调用时创建一个新的安全令牌? (在使用带有 Windows 凭据类型的消息级别安全性时?

更新

我在客户端/服务器上设置跟踪,我可以看到令牌被缓存了 24 小时。

<ServiceToken>
<SessionTokenType>System.ServiceModel.Security.Tokens.BufferedGenericXmlSecurityToken</SessionTokenType>
<ValidFrom>2013-03-23T21:21:32.569Z</ValidFrom>
<ValidTo>2013-03-24T07:21:32.569Z</ValidTo>
<InternalTokenReference>LocalIdKeyIdentifierClause(LocalId = 'uuid-291b4a38-af17-4832-bc7a-6fb65dcc3c3c-18', Owner = 'System.ServiceModel.Security.Tokens.SecurityContextSecurityToken')</InternalTokenReference>

IssuanceTokenProvider 使用了缓存的服务令牌。

我尝试使用以下方法禁用令牌兑现:

IssuedTokenClientCredential itcc = service.ClientCredentials.IssuedToken;
itcc.CacheIssuedTokens = false;
itcc.LocalIssuerAddress = new EndpointAddress("http://localhost:####/myservice");
itcc.LocalIssuerBinding = new WSHttpBinding("my_wsHttp_bindingConfig");
itcc.MaxIssuedTokenCachingTime = new TimeSpan(0,0,0);

但是查看 wcf 跟踪,上面似乎根本不影响协商。

我仍然看到使用了缓存的令牌。

【问题讨论】:

    标签: wcf wcf-security ws-security


    【解决方案1】:

    经过大量研究,并通过 WCF 跟踪,并与 Microsoft 联系,我找到了这个问题的根源。

    1. 在使用消息级别安全性时,WCF 会发出基于 Security Context Token 的身份验证 (SCT)

    2. 这种类型的身份验证仅依赖于粘性会话,无法绕过它。

    3. 有一个设置应该禁用它,EstablishSecurityContext=false,但这不起作用。设置后,我可以在跟踪中看到 SCT 像以前一样被使用(我让微软的某个人确认我在这里没有做任何不寻常的事情)。此设置可能还有另一个依赖项,但一位高级 MS 工程师不知道为什么此设置也不起作用。

    4. 这留下了一些选择

      一个。对 Kerberos 使用“一次性”调用 - 我没有对此进行探索,因为在我的场景中打开 kerberos 会更让人头疼

      b.使用基于 NTLM 的身份验证的自定义绑定 - 我试过这个,但 SCT 仍在使用,所以它对我不起作用

      c。使用具有自定义令牌发行服务的联合安全性。这可以更好地控制令牌的发行方式,但有不必要的(在我的情况下)必须管理的开销

      d.使用带有 TransportCredentialOnly 安全模式的基本 http 绑定。这很好,因为它会停止 SCT 协商,同时仍然传递 Windows 凭据。

    4.d 对我来说是最简单的,因为除了配置之外我不需要做很多更改。我放弃了 wshttpbinding 功能,但到目前为止还可以,因为此对话是在受信任的网络中进行的。

    【讨论】:

      猜你喜欢
      • 2012-04-05
      • 2014-04-18
      • 2011-08-14
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      • 2021-10-26
      • 2021-01-22
      • 1970-01-01
      相关资源
      最近更新 更多