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:
My main domain example.com is always covered by cloudflares SSL cert.When running a simple subdomain like whoami the problems start:
- Using
https://acme-staging-v02.api.letsencrypt.org/directoryascaServeron mytraefik.tomlI get a valid LE-cert from their Fake LE Intermediate X1 and this is also displayed when visiting the webpage in FF. - However, using
https://acme-v02.api.letsencrypt.org/directoryascaServeron mytraefik.tomlTraefik uses it's own default-cert.
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
Off the top of my head, I remember my wildcard domains not working unless the base domain was included in the
sanslike: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.
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: