Traefik + docker-compose + LE wildcard cert not working

So what I'm trying to do is to host apps as subdomains on my domain example.comCloudflare handles all the DNS requests:

​

DNS settings Cloudflare

My main domain example.com is always covered by cloudflares SSL cert.When running a simple subdomain like whoami the problems start:

Logs from Traefik container:

level=info msg="legolog: [INFO] [*.examlpe.com] acme: Obtaining bundled SAN certificate"
traefik
level=debug msg="http2: server: error reading preface from client ip:55704: remote error: tls: bad certificate"
level=error msg="Unable to obtain ACME certificate for domains \"*.example.com\" : unable to generate a certificate for the domains [*.example.com]: acme: Error -> One or more domains had a problem:\n[*.example.com] time limit exceeded: last error: NS alan.ns.cloudflare.com. did not return the expected TXT record [fqdn: example.com., value: crypticStuff]: v=spf1 include:spf.efwd.registrar-servers.com ~all ,crypticStuff2\n"

docker-compose.yml

version: '3'

services:
  traefik:
    hostname: traefik
    container_name: traefik
    image: traefik:v1.7.16-alpine
    restart: always
    networks:
      - web
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /root/docker/traefik/traefik.toml:/traefik.toml
      - /root/docker/traefik/acme:/acme
    labels:
      - "traefik.enable=true"
      - "traefik.port=8080"
      - "traefik.backend=traefik"
      - "traefik.frontend.rule=Host:example.com"  
      - "traefik.docker.network=web"
      - "traefik.frontend.headers.SSLRedirect=true"
      - "traefik.frontend.headers.STSSeconds=315360000"
      - "traefik.frontend.headers.browserXSSFilter=true"
      - "traefik.frontend.headers.contentTypeNosniff=true"
      - "traefik.frontend.headers.forceSTSHeader=true"
      - "traefik.frontend.headers.SSLHost=example.com"
      - "traefik.frontend.headers.STSIncludeSubdomains=true"
      - "traefik.frontend.headers.STSPreload=true"
      - "traefik.frontend.headers.frameDeny=true"
    command:
      --api
      --docker
      --configFile=/traefik.toml
    environment:
      - PUID=${PUID}
      - PGID=${PGID}
      - [email protected]
      - CF_API_KEY=yy

  whoami:
    image: "containous/whoami"
    container_name: "simple-service"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.example.com`)"
      - "traefik.http.routers.whoami.entrypoints=https"

networks:
  web:
    external: true

traefik.toml

debug = true

defaultEntryPoints = ["https","http"]

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

[retry]

[redirect]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
watch = true
exposedbydefault = false

[acme]
email = "[email protected]"
storage = "/acme/acme.json"
caServer="https://acme-v02.api.letsencrypt.org/directory"
entryPoint = "https"
OnHostRule = false
acmeLogging = true
[acme.dnsChallenge]
  provider = "cloudflare"
  CF_EMAIL = "[email protected]"
  CF_API_KEY = "yy"

delayBeforeCheck = 0

​

[[acme.domains]]
   main = "*.example.com"

How do I get a LE-cert for all my subdmains?Please help me fix my configs, it took me days to get here :/

​

SOLUTION:

As u/cutety said:

[[acme.domains]]
  main = “*.example.com”
  sans =[“example.com”]

but also the delay had to be changed:

  delayBeforeCheck = "90"

Now there is enough time to place all records and update everything as it should.
Thanks for everyone's help! ;)

Posted Sep 19, 2019, 10:20 AM UTC · edited

65
cutety•

Off the top of my head, I remember my wildcard domains not working unless the base domain was included in the sans like:

[[acme.domains]]
  main = “*.example.com”
  sans =[“example.com”]

Does setting it up like that work?

I actually just upgraded my clusters traefik to version 2 the other week because I was running into issues with multiple domains and certs not working. The upgrade was only a little bit of a pain in the ass, but all my issues have seem to gone away, so it may also be worth looking into just upgrading to version 2.

1
von_AlenbergOP•

Well, v2 is soooo annoying I don't want to bother with it right now.

I made the changes you recommended; watching the traefik log:

level=info msg="legolog: [INFO] [*.example.com, example.com] acme: Obtaining bundled SAN certificate"
level=info msg="legolog: [INFO] [*.example.com] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/9050704"
level=info msg="legolog: [INFO] [example.comm] AuthURL: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/9050705"
level=info msg="legolog: [INFO] [*.example.com] acme: use dns-01 solver"
level=info msg="legolog: [INFO] [example.com] acme: Could not find solver for: tls-alpn-01"
level=info msg="legolog: [INFO] [example.com] acme: Could not find solver for: http-01"
level=info msg="legolog: [INFO] [example.com] acme: use dns-01 solver"
level=info msg="legolog: [INFO] [*.example.comm] acme: Preparing to solve DNS-01"
level=info msg="legolog: [INFO] cloudflare: new record for example.com, ID xxxxxxx"
level=info msg="legolog: [INFO] [example.com] acme: Preparing to solve DNS-01"
level=info msg="legolog: [INFO] cloudflare: new record for example.com, ID yyyyyyy"
level=info msg="legolog: [INFO] [*.example.com] acme: Trying to solve DNS-01"
level=info msg="legolog: [INFO] [*.example.com] acme: Checking DNS record propagation using [127.0.0.11:53]"
level=info msg="legolog: [INFO] Wait for propagation [timeout: 2m0s, interval: 2s]"
level=info msg="legolog: [INFO] [*.example.com] acme: Waiting for DNS record propagation."
level=info msg="legolog: [INFO] [*.i-amboss.com] acme: Waiting for DNS record propagation."
...
level=info msg="legolog: [INFO] Unable to deactivate the authorization: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/9051337"
level=info msg="legolog: [INFO] Unable to deactivate the authorization: https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/9051338"
level=error msg="Error obtaining certificate: acme: Error -> One or more domains had a problem:\n[*.example.com] acme: error: 403 :: urn:ietf:params:acme:error:unauthorized :: Incorrect TXT record \"xxxxxxx\" (and 1 more) found at _acme-challenge.example.com, url: \n[example.com] acme: error: 403 :: urn:ietf:params:acme:error:unauthorized :: Incorrect TXT record \"xxxxxxx\" found at _acme-challenge.example.com, url: \n"
1
ginsuedog•

You can create a cloudflare origin ssl certificate and install it or you will have to setup acme DNS authentication with cloudflare which requires a api key. You may have to remove the dns proxy initially until the certificates are installed.

1
von_AlenbergOP•

Well, acme challenge I'm trying to do as in my initial post. Doesn't work for me.

CF Origin certs don't work either, traefik always serves his default cert...

1
[deleted]•

[deleted]

1
von_AlenbergOP•

Nope.

1