azure - HTTPS 不适用于在具有自定义域的 Service Fabric 上运行的 Kestrel 3.2.187/ASPNET Core 2.1.5

标签 azure ssl asp.net-core azure-service-fabric kestrel-http-server

我们正在远程开发集群上运行 Service Fabric 应用程序。它由多个有状态和无状态服务组成,并以在 Kestrel 上运行的多个前端 API 为前端。

到目前为止,由于 Kestrel 尚未用于生产,因此它被配置为使用自签名证书,该证书也用于反向代理和集群本身,并且该服务直接在 Azure 提供的默认域上运行, <app>.<region>.cloudapp.azure.com .

我们现在正处于开发阶段,自签名证书错误正在成为问题,第三方回调拒绝连接,因此现在是开始为其使用正确的域和证书的时候了。

到目前为止,我已经完成了以下工作:

  • 添加了 devcluster.somexampledomain.com 的 A 记录-> 我们的服务的公共(public) IP。
  • 已为 *.someexampledomain.com 创建通配符 Azure 应用程序证书.
  • 已将证​​书导入到 Azure Key Vault。
  • 将证书绑定(bind)到集群的 Vault Secret,将证书拉取到 Cert:/LocalMachine/My/
  • 修改了应用程序配置以在初始化 Kestrel 时使用此证书,并验证在初始化时是否找到了该证书。
    • 尝试过使用或不使用 UseHsts()UseHttpsRedirection()
    • Kestrel 配置为 Listen(IPAddress.IPv6Any, endpoint.Port, ...)UseHttps(X509Certificate2)在选项对象上。
    • UseUrls(string)与默认 Url 一起使用,即 https://+:<port>但尝试手动添加 https://*:<port>甚至是实际的主机名本身。

无论我如何尝试,都无法与服务器建立 HTTPS 连接。尝试仍然使用旧证书的其他临时服务器的端点,它按预期工作。

使用openssl s_client -connect devcluster.someexampledomain.com:<port> -prexit ,我得到:

---
no peer certificate available
---
No client certificate CA names sent
---

ETW 上没有记录任何错误或异常,一切似乎都按顺序进行。我怀疑这可能与证书的 CN 有关,但我已经没有办法尝试找出发生了什么以及如何修复它。

我一直在尝试使用 Fiddler 来研究这个问题,但我并没有从中得到太多, session 以 fiddler.network.https> HTTPS handshake to <myhost> (for #191) failed. System.IO.IOException Authentication failed because the remote party has closed the transport stream. 结束。

有人知道如何在 Kestrel 端添加一些日志记录吗?我认为在运行我的集群的 Azure VM 上安装 Fiddler 不是一个可行的解决方案。

最佳答案

深入研究 Kestrel 源代码后,我发现它记录在 "Microsoft-AspNetCore-Server-Kest​​rel""Microsoft-Extensions-Logging" 下,因此添加转移那些我发现发生了什么事情。

连接因以下异常而终止:

System.ComponentModel.Win32Exception (0x8009030D): The credentials supplied to the package were not recognized
   at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface secModule, String package, CredentialUse intent, SCHANNEL_CRED scc)
   at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(CredentialUse credUsage, SCHANNEL_CRED secureCredential)
   at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(X509Certificate certificate, SslProtocols protocols, EncryptionPolicy policy, Boolean isServer)
   at System.Net.Security.SecureChannel.AcquireServerCredentials(Byte[]& thumbPrint, Byte[] clientHello)
   at System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output)
   at System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32 offset, Int32 count)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.HttpConnection.ApplyConnectionAdaptersAsync()

这使其成为 Certificate problem with a new machine - credentials supplied to package not recognized 的体现.

我花了一些时间试图找出解决这个问题的最佳方法是什么,Service Fabric documentation有一个修改权限的脚本,但这听起来不对。

事实证明,这可以直接在 ApplicationManifest 中完成,如下所示:

<Principals>
    <Users>
        <User Name="NETWORK SERVICE" AccountType="NetworkService" />
    </Users>
</Principals>
<Policies>
    <SecurityAccessPolicies>
        <SecurityAccessPolicy ResourceRef="HttpsCert2" PrincipalRef="NETWORK SERVICE" ResourceType="Certificate" />
    </SecurityAccessPolicies>
</Policies>
<Certificates>
    <SecretsCertificate X509FindValue="[HttpsCertThumbprint]" Name="HttpsCert" />
</Certificates>

为了让 SecurityAccessPolicy 找到 ResourceRef,它必须SecretsCertificate,而不是 端点证书。由于 EndpointBindingPolicy 需要 EndpointCertificate,因此我刚刚添加了 SecretsCertificateEndpointCertificate,但名称不同。他们都引用同一个证书,所以它有效。将它们加倍并不是特别干净,但这就是我现在的解决方案。

关于azure - HTTPS 不适用于在具有自定义域的 Service Fabric 上运行的 Kestrel 3.2.187/ASPNET Core 2.1.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52952446/

相关文章:

java - 使用 letcrypt 证书在 Wildfly 19 上设置 ssl 证书

azure - 无法将面向 net451 或 net46 的 ASP.net core RC2 部署到 Azure Web App

c# - 动态设置每个 Logger 实例的 Nlog 日志级别 ASP.Net Core 2.x

azure - 通过 Azure B2C 登录 Azure AD 用户

c# - 术语 'Add-AzureAccount' 未被识别为 cmdlet、函数、脚本文件的名称

azure - 使用 Azure Automation DSC 更新应用程序

asp.net-core - Asp.net Core 2.1 Identity 的 LockoutEnabled 属性的实际用途是什么?

azure - msal.js loginRedirect() 重复重定向到登录窗口react.js

python - _ssl.c :351: error:140B0009:SSL routines:SSL_CTX_use_PrivateKey_file:PEM lib

ruby-on-rails - rails 中的 SSL 网站将我转发到带有端口 443 后缀的 url