【问题标题】:How can I use Route 53 as the DNS Challenge for Lets Encrypt in Traefik?如何在 Traefik 中使用 Route 53 作为 Lets Encrypt 的 DNS 挑战?
【发布时间】:2017-12-15 15:42:19
【问题描述】:

我的本​​地域是home.turtlesystems.co.uk。我在该域内的本地 Docker Swarm 集群上使用 Traefik。

由于集群没有直接的 Internet 访问,我无法对 Lets Encrypt 使用 HTTPS 质询,因此我尝试使用 Route53 作为 DNS 提供程序。

我在 Route53 中为我的主域设置了一个区域,这是我拥有的 turtlesystems.co.uk 的子域。

我的traefik.toml 文件如下所示:

debug = true

defaultEntryPoints = ["http", "https"]

[entryPoints]
   [entryPoints.http]
   address = ":80"
      [entryPoints.http.redirect]
      entryPoint = "https"
   [entryPoints.https]
   address = ":443"
      [entryPoints.https.tls]


# Enable ACME (Let's Encrypt) automate SSL
[acme]
email = "xxxxxxxxxxxxxxxxxxxx"
storage = "/etc/traefik/acme.json"
dnsProvider = "route53"
entryPoint = "https"
onDemand = true
onHostRule = true
acmeLogging = true

[[acme.domains]]
main = "home.turtlesystems.co.uk"

# Allow access to the Web UI
[web]
address = ":8080"

# Configure how docker will be run
[docker]
endpoint = "unix://var/run/docker.sock"
domain = "traefik"
watch = true
exposedbydefault = false
swarmmode = true

我为 Portainer 创建了一个具有以下 Traefik 标签的服务:

traefik.port=9000
traefik.docker.network=traefik-net
traefik.frontend.rule=Host:turtle-host-03.home.turtlesystems.co.uk;PathStripPrefix:/portainer
traefik.backend=portainer
traefik.enable=true
traefik.backend.loadbalancer=wrr

由于我在traefik.toml 文件中启用了acmeLogging,因此我希望获得有关正在发生或未发生的事情的更多信息,但我只获得以下信息日志:

reverse_proxy.1.rqebssg613a8@turtle-host-03    | legolog: 2017/12/15 13:16:32 [INFO][home.turtlesystems.co.uk] AuthURL: https://acme-v01.api.letsencrypt.org/acme/authz/z52B_D2iHeITPqT_7K-Z-Y-ieir3VT4l1qGW6tShrd8
reverse_proxy.1.rqebssg613a8@turtle-host-03    | legolog: 2017/12/15 13:16:32 [INFO][turtle-host-03.home.turtlesystems.co.uk] AuthURL: https://acme-v01.api.letsencrypt.org/acme/authz/OxWRpDR3KZm4E0nGngVSRZgF3iE2nhQ3jlNaWtxbd08
reverse_proxy.1.rqebssg613a8@turtle-host-03    | legolog: 2017/12/15 13:16:32 [INFO][home.turtlesystems.co.uk] acme: Could not find solver for: tls-sni-01
reverse_proxy.1.rqebssg613a8@turtle-host-03    | legolog: 2017/12/15 13:16:32 [INFO][home.turtlesystems.co.uk] acme: Trying to solve DNS-01
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:06Z" level=debug msg="Look for provided certificate to validate [turtle-host-03.home.turtlesystems.co.uk]..."
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:06Z" level=debug msg="Look for provided certificate to validate [turtle-host-03.home.turtlesystems.co.uk]..."
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:06Z" level=debug msg="No provided certificate found for domains [turtle-host-03.home.turtlesystems.co.uk], get ACME certificate."
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:06Z" level=debug msg="Challenge GetCertificate turtle-host-03.home.turtlesystems.co.uk"
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:06Z" level=debug msg="No provided certificate found for domains [turtle-host-03.home.turtlesystems.co.uk], get ACME certificate."
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:06Z" level=debug msg="Challenge GetCertificate turtle-host-03.home.turtlesystems.co.uk"
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:07Z" level=debug msg="Look for provided certificate to validate [turtle-host-03.home.turtlesystems.co.uk]..."
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:07Z" level=debug msg="No provided certificate found for domains [turtle-host-03.home.turtlesystems.co.uk], get ACME certificate."
reverse_proxy.1.rqebssg613a8@turtle-host-03    | time="2017-12-15T13:17:07Z" level=debug msg="Challenge GetCertificate turtle-host-03.home.turtlesystems.co.uk"
reverse_proxy.1.rqebssg613a8@turtle-host-03    | legolog: 2017/12/15 13:17:10 [INFO][home.turtlesystems.co.uk] Checking DNS record propagation using [127.0.0.11:53]

可以看出它正在尝试使用 DNS 质询,但我没有获得证书。

当我第一次设置这一切时,它确实一切正常,事实上我写了一篇关于它的博客,但现在它没有。当我查看我的 AWS 账户时,我可以看到我为此目的创建的 AWS_ACCESS_KEY 正在被使用,但似乎没有任何内容输入到区域中。

我将 AWS_ACCESS_KEYAWS_SECRET_ACCESS_KEYAWS_REGION 作为环境变量传递给 Portainer 服务。

我可以打开更多日志记录吗?反正有没有在 AWS 中查看 Route 53 的日志?

更新

在玩过这个之后,我注意到 Traefik 正在尝试使用 127.0.0.11:53 作为 DNS 服务器,并尝试检查 TXT 记录是否已创建。

然后我将 --dns--dns-search 添加到 Traefik 服务,但这对 Trafik 用于 DNS 的地址没有任何影响。我可以在 Traefik 中设置其他选项来强制执行此操作吗?

【问题讨论】:

    标签: amazon-route53 traefik


    【解决方案1】:
    1. 转到 AWS,创建 AIM 自定义策略 粘贴以下 JSON 作为策略:

      {
          "Version": "2012-10-17",
          "Statement": [
              {
              "Sid": "",
              "Effect": "Allow",
              "Action": [
                  "route53:ChangeResourceRecordSets",
                  "route53:GetChange",
                  "route53:GetChangeDetails",
                  "route53:ListHostedZones"
              ],
              "Resource": [
                  "*"
              ]
              },
              {
              "Sid": "",
              "Effect": "Allow",
              "Action": [
                  "elasticloadbalancing:DescribeLoadBalancers",
                  "elasticloadbalancing:SetLoadBalancerListenerSSLCertificate"
              ],
              "Resource": [
                  "*"
              ]
              },
              {
              "Sid": "",
              "Effect": "Allow",
              "Action": [
                  "iam:ListServerCertificates",
                  "iam:GetServerCertificate",
                  "iam:UploadServerCertificate"
              ],
              "Resource": [
                  "*"
              ]
              }
          ]
      }
      

    将策略命名为“dnsChallenge”(或任何您喜欢的名称)

    1. 创建新的 AIM 用户并附加上述策略

    复制新用户的密钥,因为您需要将它们设置为环境变量

    1. 转到 AWS Route53 并查看托管区域。 您将需要 2 个 A 记录——yourdomain.com 和 *.yourdomain.com 都指向运行 traefik 的主机的静态 IP。

    复制您要使用通配符的域的托管区域 ID。

    定义以下环境变量,并确保它们在 traefik 启动时可用。

    export AWS_ACCESS_KEY_ID=*****************
    export AWS_SECRET_ACCESS_KEY=**********************************
    export AWS_HOSTED_ZONE_ID=*************
    

    编辑 traefik.toml

    [acme] # Automatically add Let's Encrypt Certificate.
    email = "youremail@gmail.com"
    storage= "acme.json" # Change to fully qualified and exposed path for docker
    entryPoint = "https"
    OnHostRule = false
    acmelogging = true
    
    # caServer = "https://acme-staging-v02.api.letsencrypt.org/directory"
    caServer = "https://acme-v02.api.letsencrypt.org/directory"
    
    [acme.dnsChallenge]
      provider = "route53"
      delayBeforeCheck = 0
    
    [[acme.domains]]
      main = "*.yourdomain.com"
      sans = ["yourdomain.com"]
    

    从那里从命令行运行它并观察消息是个好主意..

    【讨论】:

      【解决方案2】:

      加上 bhlwe 的回答,我会使用更受限制的 IAM 配置文件:

      {
          "Version": "2012-10-17",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Action": [
                      "route53:GetChange",
                      "route53:ListHostedZonesByName"
                  ],
                  "Resource": [
                      "*"
                  ]
              },
              {
                  "Effect": "Allow",
                  "Action": [
                      "route53:ChangeResourceRecordSets"
                  ],
                  "Resource": [
                      "arn:aws:route53:::hostedzone/<INSERT_YOUR_HOSTED_ZONE_ID_HERE>"
                  ]
              }
          ]
      }
      

      【讨论】:

        猜你喜欢
        • 2019-04-13
        • 2021-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-22
        相关资源
        最近更新 更多