【问题标题】:Https in Asp.net core docker with certificate from azure keyvault not working带有来自 azure keyvault 的证书的 Asp.net 核心 docker 中的 Https 无法正常工作
【发布时间】:2021-06-09 07:56:46
【问题描述】:

我在 docker 和 Azure Service Fabric 中有一个 Asp.net core 3.1 Web 应用程序。

asp.net 核心 Web 应用已启用 https 并从 AzureKeyVault 获取其证书。部署时,似乎 https 没有响应,但 http 可以工作。

控制台主机看起来如此

public static void ConfigureKestrelServer(this IWebHostBuilder host)
    {
        try
        { 
            host.ConfigureKestrel(options =>
            {
               
                options.ConfigureHttpsDefaults(listenOptions =>
                {
                    listenOptions.ServerCertificate = GetCertificateFromStore();
                });

            });
        }
        catch (System.Exception e)
        {
            throw;
        }
    }

    public static X509Certificate2 GetCertificateFromStore()
    {
        return  AzureKeyVaultExtensions.GetCertificateSecretAsync().GetAwaiter().GetResult();
    }

上面的代码可以在部署时下载证书。 docker 文件是这样的

FROM  mcr.microsoft.com/dotnet/core/aspnet:3.1    
ARG source
WORKDIR /app
ADD ${source} . 
ENV APP_UTILS=C:\\app 
VOLUME ${APP_UTILS}    
EXPOSE 80
EXPOSE 443 
ENTRYPOINT ["dotnet", "MyWebApp.dll"]

【问题讨论】:

  • 尝试将ENTRYPOINT移到EXPOSE下方。

标签: c# docker asp.net-core azure-keyvault


【解决方案1】:

您可能应该在容器前面的某处执行 SSL 终止。但是如果你想在容器中做,我相信你也需要通过Service Fabric映射端口。

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-tutorial-package-containers#configure-communication-and-container-port-to-host-port-mapping

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-service-manifest-resources#example-specifying-an-https-endpoint-for-your-service

您可能需要在这里输入第二个条目:

<Resources>
  <Endpoints>
      <!-- This endpoint is used by the communication listener to obtain the port number on which to
           listen. Note that if your service is partitioned, this port is shared with
           replicas of different partitions that are placed in your code. -->
      <Endpoint Name="ServiceEndpoint1" Protocol="http"/>
      <Endpoint Name="ServiceEndpoint2" Protocol="http" Port="80"/>
      <Endpoint Name="ServiceEndpoint3" Protocol="https"/>
      <Endpoint Name="ServiceEndpoint4" Protocol="https" Port="14023"/>
  </Endpoints>
</Resources>

还有一个bin更多信息specifically on HTTPs,但你需要检查哪个部分适用于你的设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 2017-07-10
    • 2020-09-27
    • 2014-12-11
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多