Docker容器在aws fargate SSL问题上运行

m528fe3b  于 2023-02-03  发布在  Docker
关注(0)|答案(1)|浏览(142)

我正在尝试让我的.net核心API on在awsfargate上live。我已经在AWS上创建了一个应用程序负载平衡器,并为80和443端口添加了侦听器。
在我的容器中,我将8080端口暴露于80,将8081端口暴露于443。
下面是我的任务定义文件

{
    "ipcMode": null,
    "executionRoleArn": "my-esc-roles",
    "containerDefinitions":
    [
        {
            "dnsSearchDomains": null,
            "environmentFiles": null,
            "logConfiguration":
            {
                "logDriver": "awslogs",
                "secretOptions": null,
                "options":
                {
                    "awslogs-group": "/ecs/my-tasks",
                    "awslogs-region": "us-east-1",
                    "awslogs-stream-prefix": "ecs"
                }
            },
            "entryPoint":
            [],
            "portMappings":
            [
                {
                    "hostPort": 8080,
                    "protocol": "tcp",
                    "containerPort": 8080
                },
                {
                    "hostPort": 8081,
                    "protocol": "tcp",
                    "containerPort": 8081
                }
            ],
            "command":
            [],
            "linuxParameters": null,
            "cpu": 0,
            "environment":
            [],
            "resourceRequirements": null,
            "ulimits": null,
            "dnsServers": null,
            "mountPoints":
            [],
            "workingDirectory": null,
            "secrets":
            [               
                {
                    "valueFrom": "LiveDb",
                    "name": "LiveDb"
                },
                {
                    "valueFrom": "SSLPath",
                    "name": "ASPNETCORE_Kestrel__Certificates__Default__Path"
                },
                {
                    "valueFrom": "SSLPassword",
                    "name": "ASPNETCORE_Kestrel__Certificates__Default__Password"
                }
            ],
            "dockerSecurityOptions": null,
            "memory": 500,
            "memoryReservation": 400,
            "volumesFrom":
            [],
            "stopTimeout": null,
            "image": "my-ecr-repo/image:latest",
            "startTimeout": null,
            "firelensConfiguration": null,
            "dependsOn": null,
            "disableNetworking": null,
            "interactive": null,
            "healthCheck": null,
            "essential": true,
            "links": null,
            "hostname": null,
            "extraHosts": null,
            "pseudoTerminal": null,
            "user": null,
            "readonlyRootFilesystem": null,
            "dockerLabels": null,
            "systemControls": null,
            "privileged": null,
            "name": "my-container"
        }
    ],
    "placementConstraints":
    [],
    "memory": "2048",
    "taskRoleArn": "**********************",
    "compatibilities":
    [
        "EC2",
        "FARGATE"
    ],
    "taskDefinitionArn": "*******************",
    "family": "supplierportal-tasks",
    "requiresAttributes":
    [
        {
            "targetId": null,
            "targetType": null,
            "value": null,
            "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
        },
        {
            "targetId": null,
            "targetType": null,
            "value": null,
            "name": "ecs.capability.execution-role-awslogs"
        },
        {
            "targetId": null,
            "targetType": null,
            "value": null,
            "name": "com.amazonaws.ecs.capability.ecr-auth"
        },
        {
            "targetId": null,
            "targetType": null,
            "value": null,
            "name": "ecs.capability.secrets.ssm.environment-variables"
        },
        {
            "targetId": null,
            "targetType": null,
            "value": null,
            "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
        },
        {
            "targetId": null,
            "targetType": null,
            "value": null,
            "name": "ecs.capability.task-eni"
        }
    ],
    "pidMode": null,
    "requiresCompatibilities":
    [
        "FARGATE"
    ],
    "networkMode": "awsvpc",
    "runtimePlatform":
    {
        "operatingSystemFamily": "LINUX",
        "cpuArchitecture": null
    },
    "cpu": "1024",
    "revision": 10,
    "status": "ACTIVE",
    "inferenceAccelerators": null,
    "proxyConfiguration": null,
    "volumes":
    []
}

这是我的文件

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

ENV ASPNETCORE_URLS=http://+:8080;https://+:8081

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["WebAPI/WebAPI.csproj", "WebAPI/"]
RUN dotnet restore "WebAPI/WebAPI.csproj"
COPY . .
WORKDIR "/src/WebAPI"
RUN dotnet build "WebAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebAPI.dll"]

当谈到端口80时,一切都工作正常。但在端口443上,我无法设置SSL。
这是我收到的错误日志。

Unhandled exception. Interop+Crypto+OpenSslCryptographicException: error:2006D080:BIO routines:BIO_new_file:no such file

我已经将pfx文件存储在s3中,但它不工作。我应该将pfx文件放在哪里才能将其部署到容器中?
我在S3上使用了以下SSL路径。

s3://mycert/WebAPI.pfx => did not work
https://my-cert.s3.amazonaws.com/ebAPI.pfx => did not work
arn:aws:s3:::my-cert/WebAPI.pfx => did not work
92dk7w1h

92dk7w1h1#

我已经将pfx文件存储在s3中,但它不工作。我应该将pfx文件放在哪里才能将其部署到容器中?
您需要在Docker容器的启动过程中添加一个步骤,以便使用AWS CLI工具或AWS SDK将文件从S3复制到容器中。
您实际上只需要安装在负载平衡器上的SSL证书,除非您有某种端到端加密的法规要求。应用程序负载平衡器正在执行SSL终止,这样用户的Web浏览器和AWS专用网络之间的网络连接将被加密。负载平衡器上的SSL侦听器"的端口443可以将通信转发到您的未加密端口8080

相关问题