【问题标题】:Let's encrypt SSL with traefick on ECS Fargate让我们在 ECS Fargate 上使用 traefick 加密 SSL
【发布时间】:2020-12-10 13:25:02
【问题描述】:

我已经尝试解决这个问题好几天了,但没有任何运气:

情况:

我在 AWS 上有一个使用 Fargate 的 ECS 集群,该集群包含一个 Traefick 2.3.4 实例和其他容器。我使用 Traefick 作为反向代理将请求转发到其他容器。 使用 HTTP 一切正常,所以我决定添加到 Traefick 的安全连接。我已经尝试了在 Internet 上可以找到的所有内容,但没有任何效果,当我尝试使用 curl 连接到指定域时,它返回:

curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number

这里有一些我做过的测试:

traefick.yml:

log:
  level: DEBUG

api:
  dashboard: true

entryPoints:
  web:
    address: :80
    http:
      redirections:
        entryPoint:
          to: websecure
          scheme: https
  websecure:
    address: ":443"

providers:
  ecs:
    clusters:
      - tools-cluster
    region: eu-west-2
    exposedByDefault: false

certificatesResolvers:
  letsencrypt:
    acme:
      caServer: https://acme-staging-v02.api.letsencrypt.org/directory
      email: #########################
      storage: acme.json
      httpchallenge:
        entrypoint: web

标签:

"dockerLabels": {
        "traefik.enable": "true",
        "traefik.http.services.traefik.loadbalancer.server.port": "8080",
        "traefik.http.routers.traefik.rule": "Host(`${host}`)",
        "traefik.http.routers.traefik.entrypoints": "websecure",
        "traefik.http.routers.traefik.tls.certresolver": "letsencrypt",
        "traefik.http.routers.traefik.service": "api@internal"
      }

此版本返回此错误:

rror: 400 :: urn:ietf:params:acme:error:connection :: Fetching https://traefik.baaluu.com/.well-known/acme-challenge/td8IdOvJ1_GkigY-jPYaA4YsgeiS5FUiuUS-avbpsuY: Error getting validation data, url

它尝试检索该数据,但它无法检索,因为它被重定向到 https 并且它无法检索,因为 https 不起作用,我也尝试过不使用自动重定向,它返回类似的错误,它无法检索该数据。

但是按照这个guide它应该可以正常工作。

所以我决定使用以下配置转移到 dnsChallenge: Traefick.yml

log:
  level: DEBUG

api:
  dashboard: true

entryPoints:
  web:
    address: :80
  websecure:
    address: ":443"

providers:
  ecs:
    clusters:
      - tools-cluster
    region: eu-west-2
    exposedByDefault: false

certificatesResolvers:
  letsencrypt:
    acme:
      caServer: https://acme-staging-v02.api.letsencrypt.org/directory
      email: ######################
      storage: acme.json
      dnsChallenge:
        provider: route53
        delayBeforeCheck: 3

和以前一样的标签:

"dockerLabels": {
        "traefik.enable": "true",
        "traefik.http.services.traefik.loadbalancer.server.port": "8080",
        "traefik.http.routers.traefik.rule": "Host(`${host}`)",
        "traefik.http.routers.traefik.entrypoints": "websecure",
        "traefik.http.routers.traefik.tls.certresolver": "letsencrypt",
        "traefik.http.routers.traefik.service": "api@internal"
      }

仍然没有,我在日志中有这个:AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/170242259" 该网址包含:

{
  "type": "urn:ietf:params:acme:error:malformed",
  "detail": "Method not allowed",
  "status": 405
}

我做的最新测试是删除暂存ca服务器:

log:
  level: DEBUG

api:
  dashboard: true

entryPoints:
  web:
    address: :80
  websecure:
    address: :443

providers:
  ecs:
    clusters:
      - tools-cluster
    region: eu-west-2
    exposedByDefault: false

certificatesResolvers:
  letsencrypt:
    acme:
      email: ###############
      storage: acme.json
      dnsChallenge:
        provider: route53
        delayBeforeCheck: 2

ssl 仍然无法工作,但我在日志中看不到任何错误消息:这是我收到的关于证书的最后一条消息:

Try to challenge certificate for domain [traefik.baaluu.com] found in HostSNI rule" providerName=letsencrypt.acme routerName=traefik@ecs rule="Host(`traefik.baaluu.com`)"

之后就没有更多了: (我很抱歉这张照片,但我找不到从 ECS 中提取该日志的方法)

其他容器仍然可以通过 http 协议访问。

如果我尝试使用 telnet 连接到它,我可以访问该服务:

telnet traefik.baaluu.com 443
Trying 3.8.30.164...
Connected to traefik-1547500306.eu-west-2.elb.amazonaws.com.
Escape character is '^]'.

80后也是如此

在日志中看起来更好,我也发现了这个

retry due to: acme: error: 400 :: POST :: https://acme-v02.api.letsencrypt.org/acme/chall-v3/9205340157/1Wh0tQ :: urn:ietf:params:acme:error:badNonce :: JWS has an invalid anti-replay nonce: \"0004cbkFTGjCALFGDYOmhruMl6_F_fRSj33cOMvdpx5Xd2M\", url: "
time="2020-12-10T13:08:21Z" level=debug msg="legolog: [INFO] retry due to: acme: error: 400 :: POST :: https://acme-v02.api.letsencrypt.org/acme/chall-v3/9205340157/1Wh0tQ :: urn:ietf:params:acme:error:badNonce :: JWS has an invalid anti-replay nonce: \"0004cbkFTGjCALFGDYOmhruMl6_F_fRSj33cOMvdpx5Xd2M\", url: "

包含此网址:https://acme-v02.api.letsencrypt.org/acme/chall-v3/9205340157/1Wh0tQ

{
  "type": "dns-01",
  "status": "valid",
  "url": "https://acme-v02.api.letsencrypt.org/acme/chall-v3/9205340157/1Wh0tQ",
  "token": "44R4gD4_ZmemiCn5rtkqJyWOcjoj09sEgobUvZLH6yc",
  "validationRecord": [
    {
      "hostname": "traefik.baaluu.com"
    }
  ]
}

所以我认为 ssl 已正确生成,但我不确定。

有什么想法或建议吗?

提前致谢。

H2K

编辑:

我已经从仪表板中删除了 ssl,并将它放在另一个容器上,现在进入仪表板内部我可以看到:

所以我认为 ssl 正在为该域工作,但我仍然无法连接到它。

编辑 2:

如果我使用 telnet 连接到端口 443 上的那个 url 并且我请求可以看到内容的页面:

telnet xxxxxxxxxxxxxxxxx 443
Trying 3.10.148.201...
Connected to traefik-1547500306.eu-west-2.elb.amazonaws.com.
Escape character is '^]'.
GET /index.html HTTP/1.1
Host: xxxxxxxxxxxxxxxxx

并且页面的内容出现了,所以不是负载均衡问题或路由问题,看来我可以使用443到达容器,只是ssl不存在。就像有 2 个 http 端口,并且两者的行为方式相同。此刻的443就像一个80端口。

【问题讨论】:

  • 你有没有得到这个?我也遇到了同样的问题

标签: ssl amazon-ecs lets-encrypt traefik aws-fargate


【解决方案1】:

我也花了几天时间试图解决这个问题,所以我能感受到你的痛苦。

该错误具有误导性,该请求甚至无法通过 ALB,更不用说 traefik。

这个问题有两个因素,

  • 首先,当您通过 docker compose 将端口 443 指定为“443:443”时,您会假设这会创建一个 HTTPS 侦听器,它实际上会在 HTTP 协议上为 443 创建一个侦听器。此外,侦听器还将数据发送到 Fargate HTTP 端口并且没有重定向。我不确定这是否是一个错误,或者因为我没有指定目标端口上的协议应该是“x-aws-protocol: https”。

  • 我还发现一些 AWS 文档说,如果您在 ALB 上使用 HTTPS 端口,则需要在 ALB 级别设置 SSL 证书。如果您考虑到集群性质和安全隐患,那么您无法在任务级别终止连接是有道理的(欢迎更好的头脑解释)

考虑到上述情况,我在 ACM 中创建了一个涵盖我需要的所有域的证书,将侦听器更改为 HTTPS 协议并指定了我创建的证书。此时我能够配置 traefik 以接受 traefik 到前端。

【讨论】:

    猜你喜欢
    • 2018-08-30
    • 1970-01-01
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    相关资源
    最近更新 更多