简体   繁体   English

让我们在 ECS Fargate 上用 traefick 加密 SSL

[英]Let's encrypt SSL with traefick on ECS Fargate

I've been trying to solve this for days, but without any luck:几天来我一直在努力解决这个问题,但没有任何运气:

Situation:情况:

I have a ECS cluster on AWS using Fargate, this cluster contains an instance of Traefick 2.3.4 and other containers.我在 AWS 上有一个使用 Fargate 的 ECS 集群,这个集群包含一个 Traefick 2.3.4 实例和其他容器。 I'm using Traefick as reverse proxy to forward the requests to the other containers.我使用 Traefick 作为反向代理将请求转发到其他容器。 Using HTTP everything works fine, so I've decided to add also the secure connection to Traefick.使用 HTTP 一切正常,所以我决定也添加到 Traefick 的安全连接。 I've tried everything that I could find on the Inte.net but nothing works, when I try to connect to the specified domain with curl it returns:我已经尝试了在 Inte.net 上可以找到的所有内容,但没有任何效果,当我尝试使用 curl 连接到指定域时,它返回:

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

Here there are some test that I've done:这里有一些我做过的测试:

traefick.yml: 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

Labels:标签:

"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"
      }

this version returns this error:此版本返回此错误:

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

It tries to retrieve that data but it can't because it is redirected to the https and it can't retrieve because https doesn't work, I've tried also without the auto redirect, and it returns a similar error, it can't retrieve that data.它试图检索该数据,但它不能,因为它被重定向到 https 并且它无法检索,因为 https 不起作用,我也尝试过没有自动重定向,它返回类似的错误,它可以'检索该数据。

But following this guide it should work correctly.但是按照本指南它应该可以正常工作。

So I've decided to move to the dnsChallenge with this configuration: Traefick.yml所以我决定使用以下配置转移到 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

and same labels as before:和以前一样的标签:

"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"
      }

Still nothing, and I've this inside the logs: AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/170242259" That url contains:仍然没有,我在日志中有这个: AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/170242259" url 包含:

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

The latest test that I did is to remove the staging ca server:我所做的最新测试是删除暂存 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

The ssl still doesn't work but I don't see any error message inside the logs: this is the last message that I get about a certificate: 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`)"

And there is not much more after that:之后就没有更多了: 在此处输入图像描述 (I'm sorry for the picture but I don't find a way to extract that logs from ECS) (我对图片感到抱歉,但我找不到从 ECS 中提取日志的方法)

The other containers are still reachable on the http protocol.其他容器仍然可以通过 http 协议访问。

If I try to connect to it using te.net I can reach the service:如果我尝试使用 te.net 连接到它,我可以访问该服务:

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

Same goes for the 80 80后也一样

Looking better inside the logs I've also find this在日志中看起来更好我也发现了这个

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: "

that contains this url: https://acme-v02.api.letsencrypt.org/acme/chall-v3/9205340157/1Wh0tQ包含此 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"
    }
  ]
}

So I suppose that the ssl has been generated correctly but I'm not sure.所以我想 ssl 已经正确生成,但我不确定。

Any idea or suggestion?有什么想法或建议吗?

Thanks in advance.提前致谢。

H2K H2K

Edit:编辑:

I've removed the ssl from the dashboard and I've put it on another container, now entering inside the dashboard I can see this:我从仪表板中删除了 ssl 并将其放在另一个容器上,现在进入仪表板内部我可以看到: 在此处输入图像描述

So I suppose that the ssl is working for that domain, but I still can't connect to it.所以我想 ssl 正在为该域工作,但我仍然无法连接到它。

Edit 2:编辑 2:

with te.net if I connect to that url on the port 443 and I request the page I can see the content:使用 te.net,如果我连接到端口 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

And the content of the page appears, so it is not a load balacer problem or routing problem, it seems that I can reach the container using the 443, simply the ssl is not there.并且出现了页面内容,所以这不是负载均衡器问题或路由问题,似乎我可以使用 443 到达容器,只是 ssl 不存在。 It is like to have 2 http port and both are behaving in the same way.它就像有 2 个 http 端口,两者的行为方式相同。 The 443 at the moment is like a port 80.此刻的 443 就像一个端口 80。

I've have also spent a number of days trying to work it out so i feel your pain.我也花了很多天的时间来解决这个问题,所以我能感受到你的痛苦。

The error is misleading, the request doesn't even make it past the ALB let alone traefik.该错误具有误导性,该请求甚至没有通过 ALB,更不用说 traefik 了。

There are two factors to this issue,这个问题有两个因素,

  • The first being that when you specify a port 443 through docker compose as "443:443" you would assume that this creates a HTTPS listener, it actually creates a listener for 443 on the HTTP protocol.第一个是,当您通过 docker 指定端口 443 组合为“443:443”时,您会假设这会创建一个 HTTPS 侦听器,它实际上会在 HTTP 协议上为 443 创建一个侦听器。 In addition the listener also sent the data to the fargate HTTP port and didn't redirect.此外,侦听器还将数据发送到 fargate HTTP 端口并且没有重定向。 I'm not sure if this is a bug, or because because i haven't specified that the protocol should be "x-aws-protocol: https" on the target port.我不确定这是不是一个错误,或者因为我没有指定协议在目标端口上应该是“x-aws-protocol: https”。

  • I also found some AWS documentation that said if you use a HTTPS port on a ALB that you need an SSL certificate in place at a ALB level.我还发现一些 AWS 文档说,如果您在 ALB 上使用 HTTPS 端口,则需要在 ALB 级别准备好 SSL 证书。 This kind of makes sense that you can't terminate the connection at a task level if you consider the swarm nature and security implications (better minds are welcome to explain)如果你考虑到群体性质和安全隐患,那么你不能在任务级别终止连接是有道理的(欢迎更好的头脑解释)

With the above in mind i created a certificate in the ACM that covered all the the domains that i needed, changed the listener to the HTTPS protocol and specified the certificate i created.考虑到上述情况,我在 ACM 中创建了一个涵盖我需要的所有域的证书,将侦听器更改为 HTTPS 协议并指定了我创建的证书。 At this point i was able to configure traefik to accept traefik to the frontend.在这一点上,我能够配置 traefik 以接受 traefik 到前端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM