Windows 主机和 Linux 容器的 ASP.NET Core 8 HTTPS 证书问题

问题描述 投票:0回答:1

我在 Windows 上运行 Docker Desktop,但使用 Linux 容器。我尝试在 ASP.NET Core 8 应用程序中设置 HTTPS,但 SSL 身份验证失败。证书在 Windows 上生成并挂载到 Linux 容器中。

环境

  • 主机操作系统:Windows
  • 运行 Linux 容器的 Docker 桌面
  • ASP.NET Core 8
  • 使用
    dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p VerySecurePassword123@!
    ->
    dotnet dev-certs https --trust
  • 生成的证书

错误

dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[39]
2024-11-14T02:09:35.774407159Z       Connection id "0HN84A5GB7LGC" accepted.
2024-11-14T02:09:35.774414059Z dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[1]
2024-11-14T02:09:35.774430660Z       Connection id "0HN84A5GB7LGC" started.
2024-11-14T02:09:35.776304532Z dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1]
2024-11-14T02:09:35.776340833Z       Failed to authenticate HTTPS connection.
2024-11-14T02:09:35.776346834Z       System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received.
2024-11-14T02:09:35.776350934Z          at System.Net.Security.SslStream.GetFrameSize(ReadOnlySpan`1 buffer)
2024-11-14T02:09:35.776354134Z          at System.Net.Security.SslStream.EnsureFullTlsFrameAsync[TIOAdapter](CancellationToken cancellationToken, Int32 estimatedSize)
2024-11-14T02:09:35.776357734Z          at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
2024-11-14T02:09:35.776362534Z          at System.Net.Security.SslStream.ReceiveHandshakeFrameAsync[TIOAdapter](CancellationToken cancellationToken)
2024-11-14T02:09:35.776365734Z          at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)
2024-11-14T02:09:35.776369135Z          at System.Net.Security.SslStream.ProcessAuthenticationWithTelemetryAsync(Boolean isAsync, CancellationToken cancellationToken)
2024-11-14T02:09:35.776373135Z          at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context)
2024-11-14T02:09:35.776377135Z dbug: Microsoft.AspNetCore.Server.Kestrel.Connections[2]
2024-11-14T02:09:35.776381235Z       Connection id "0HN84A5GB7LGC" stopped.
2024-11-14T02:09:35.776534441Z dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7]
2024-11-14T02:09:35.776547141Z       Connection id "0HN84A5GB7LGC" sending FIN because: "The Socket transport's send loop completed gracefully."

我该如何解决这个问题?我只需要使用 HTTPS 运行它来进行开发,以测试 nuget 包是否可以在 Linux 上运行。证书类型并不重要,无论它是受密码保护还是无密码。

配置

docker-compose.yml

services:
  pr.orderservice.webapi:
    image: pr.orderservice.webapi
    build:
      context: .
      dockerfile: OrderService/PR.OrderService.WebApi/Dockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_Kestrel__Certificates__Default__Password=VerySecurePassword123@!
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx
    ports:
      - "5000:80"
      - "44362:443"
    volumes:
      - ${USERPROFILE}\.aspnet\https:/https/:ro

Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["OrderService/PR.OrderService.WebApi/PR.OrderService.WebApi.csproj", "OrderService/PR.OrderService.WebApi/"]
COPY ["BuildingBlocks/PR.BuildingBlocks.EventBus/PR.BuildingBlocks.EventBus.csproj", "BuildingBlocks/PR.BuildingBlocks.EventBus/"]
COPY ["BuildingBlocks/PR.BuildingBlocks.Common/PR.BuildingBlocks.Common.csproj", "BuildingBlocks/PR.BuildingBlocks.Common/"]
COPY ["BuildingBlocks/PR.BuildingBlocks.Testing/PR.BuildingBlocks.Testing.csproj", "BuildingBlocks/PR.BuildingBlocks.Testing/"]
COPY ["BuildingBlocks/PR.BuildingBlocks.WebCommon/PR.BuildingBlocks.WebCommon.csproj", "BuildingBlocks/PR.BuildingBlocks.WebCommon/"]
COPY ["BuildingBlocks/PR.BuildingBlocks.CustomExceptions/PR.BuildingBlocks.CustomExceptions.csproj", "BuildingBlocks/PR.BuildingBlocks.CustomExceptions/"]
COPY ["BuildingBlocks/PR.MultiTenancyServer.AspNetCore/PR.MultiTenancyServer.AspNetCore.csproj", "BuildingBlocks/PR.MultiTenancyServer.AspNetCore/"]
COPY ["BuildingBlocks/PR.MultiTenancyServer.Core/PR.MultiTenancyServer.Core.csproj", "BuildingBlocks/PR.MultiTenancyServer.Core/"]
COPY ["OrderService/PR.OrderService.Persistence.Database/PR.OrderService.Persistence.Database.csproj", "OrderService/PR.OrderService.Persistence.Database/"]
COPY ["BuildingBlocks/PR.MultiTenancyServer.EFCore/PR.MultiTenancyServer.EFCore.csproj", "BuildingBlocks/PR.MultiTenancyServer.EFCore/"]
COPY ["BuildingBlocks/PR.MultiTenancyServer.Stores/PR.MultiTenancyServer.Stores.csproj", "BuildingBlocks/PR.MultiTenancyServer.Stores/"]
COPY ["OrderService/PR.OrderService.Domain/PR.OrderService.Domain.csproj", "OrderService/PR.OrderService.Domain/"]
COPY ["OrderService/PR.OrderService.Common/PR.OrderService.Common.csproj", "OrderService/PR.OrderService.Common/"]
COPY ["OrderService/PR.OrderService.Persistence/PR.OrderService.Persistence.csproj", "OrderService/PR.OrderService.Persistence/"]
COPY ["OrderService/PR.OrderService.Services.Resilience/PR.OrderService.Services.Resilience.csproj", "OrderService/PR.OrderService.Services.Resilience/"]
COPY ["OrderService/PR.OrderService.Services/PR.OrderService.Services.csproj", "OrderService/PR.OrderService.Services/"]
COPY ["BuildingBlocks/PR.IntegrationEvents.Commons/PR.IntegrationEvents.Commons.csproj", "BuildingBlocks/PR.IntegrationEvents.Commons/"]
RUN dotnet restore "OrderService/PR.OrderService.WebApi/PR.OrderService.WebApi.csproj"
COPY . .
WORKDIR "/src/OrderService/PR.OrderService.WebApi"
RUN dotnet build "PR.OrderService.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "PR.OrderService.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PR.OrderService.WebApi.dll"]
windows docker asp.net-core https linux-containers
1个回答
0
投票

您的应用程序似乎认为传入请求格式错误。

确保测试时使用的是 HTTPS。

© www.soinside.com 2019 - 2024. All rights reserved.