【问题标题】:WCF service behind loadbalancer with custom authorization具有自定义授权的负载均衡器后面的 WCF 服务
【发布时间】:2019-11-14 05:47:51
【问题描述】:

我们的环境基于通过 WCF 公开服务的服务器应用程序。 Out 客户使用负载平衡器 - F5。客户端应用程序通过安全通道访问它,然后它使用非安全 HTTP 通道。客户端和服务器都使用WsHttpBinding

客户端 HTTPS F5 HTTP 服务器

我设法使用这样的配置,但我们的服务使用基于 JWT 令牌的自定义授权,然后出现问题。

我测试了很多配置,但都出现了各种错误。

客户端当前配置:

var binding = new WSHttpBinding();
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

binding.Security.Mode = SecurityMode.TransportWithMessageCredential;

binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Message.NegotiateServiceCredential = true;

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

服务器配置如下:

var binding = new WSHttpBinding();
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

host.Description.Behaviors.Find<ServiceBehaviorAttribute>().AddressFilterMode = AddressFilterMode.Any;

binding.Security.Mode = SecurityMode.None;

binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Message.NegotiateServiceCredential = true;

binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;

host.Description.Behaviors.Find<ServiceAuthorizationBehavior>().ServiceAuthorizationManager = new JWTAuthorizationManager();

客户端应用程序以这种方式设置授权标头:

channelFactory.Credentials.UserName.UserName = userId;
credentialBehaviour.UserName.Password = token;

当前状态是请求转到服务,但在 JWTAuthorizationManager 的 CheckAccess() 方法中,HttpRequestHeader.Authorization 为空。此外 System.ServiceModel.MustUnderstandSoapException 被抛出。当我将客户端的 Security.Mode 切换到 Transport 时,同样的事情发生了,但没有抛出异常。

我不熟悉这项技术的细节,也不确定到底会发生什么。

更新: 我检查了服务收到的内容。我看到消息中存在安全标头,但由于安全模式设置为无,服务无法解释这一点。我无法将其设置为 Message,因为它需要服务器计算机上的证书,我们不想要这个。

【问题讨论】:

  • 目前我看到了两个解决方案,但我不知道如何实现它们: 1. 在服务器上使用 BasicHttpBinding 和 TransportCredentialOnly 安全模式。它在没有负载均衡器的情况下工作得很好,但是当客户端需要通过使用 WsHttpBinding 使用安全通道到 F5 时,SOAP 版本会发生变化。 2. 使用 WsHttpBinding 等价物,SecurityMode None 的可能性。我试过 CustomBinding 但没有运气。

标签: wcf authorization load-balancing wshttpbinding f5


【解决方案1】:

我在服务器端使用 CustomBinding 解决了这个问题:

var binding = new CustomBinding();
var securityHeader = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityHeader.AllowInsecureTransport = true;
securityHeader.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
securityHeader.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
securityHeader.IncludeTimestamp = true;

var textEncoding = new TextMessageEncodingBindingElement();
textEncoding.MessageVersion = MessageVersion.Soap12WSAddressing10;
binding.Elements.Add(textEncoding);

var httpTransport = new HttpTransportBindingElement();
httpTransport.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
httpTransport.MaxReceivedMessageSize = int.MaxValue;
httpTransport.MaxBufferPoolSize = int.MaxValue;
binding.Elements.Add(httpTransport);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-07
    • 2012-06-06
    • 2011-04-19
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 2019-07-12
    • 2013-04-11
    相关资源
    最近更新 更多