Traefik
Remember to first do: touch ./data/acme.json and chmod 0600 ./data/acme.json so that file to folder mounting error is avoided.
This configuration works in tandem with a self-hosted Technitium authoritative name server, with Traefik making its requests to it via RFC 2136. The TSIG key and settings must first be created in Technitium.
docker-compose.yml
version: '3.3'
services:
traefik:
image: traefik:v2.9.5
container_name: traefik
restart: always
security_opt:
- no-new-privileges:true
networks:
- traefik
ports:
- 80:80
- 443:443
- 8080:8080
environment:
- "RFC2136_NAMESERVER=ns1.zcyph.cc"
- "RFC2136_TSIG_ALGORITHM=hmac-sha256."
- "RFC2136_TSIG_KEY=zkeytest"
- "RFC2136_TSIG_SECRET=LV2rH5ctYtOjos99rOu7I/Di5ZklnCS/gwQ6M57CMZQ="
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/traefik.yml:/traefik.yml:ro
- ./data/acme.json:/acme.json
- ./data/config.yml:/config.yml:ro
# - ./data/acme-staging.json:/acme-staging.json
networks:
traefik:
external: true
./data/config.yml
http:
routers:
dashboard:
rule: "Host(`traefik.zcyph.cc`)"
middlewares:
- auth
tls:
certResolver: technitium
service: api@internal
nextcloudsnap:
entryPoints:
- https
rule: "Host(`cloud.zcyph.cc`)"
middlewares:
- default-headers
tls:
certResolver: technitium
service: nextcloudsnap
pihole:
entryPoints:
- https
rule: "Host(`pi.zcyph.cc`)"
middlewares:
- default-headers
- adminpihole
tls:
certResolver: technitium
service: pihole
services:
nextcloudsnap:
loadBalancer:
servers:
- url: "http://192.168.1.8:8111"
passHostHeader: true
pihole:
loadBalancer:
servers:
- url: "http://192.168.1.156:80/"
passHostHeader: true
middlewares:
adminpihole:
addPrefix:
prefix: "/admin"
dashboard:
addPrefix:
prefix: "/dashboard/"
https-redirect:
redirectScheme:
scheme: https
auth:
basicAuth:
users:
- "marc:$apr1$yl37dc8x$KSpE5pG4wVm92kU7XMND20"
default-headers:
headers:
frameDeny: true
sslRedirect: true
browserXssFilter: true
contentTypeNosniff: true
forceSTSHeader: true
stsIncludeSubdomains: true
stsPreload: true
stsSeconds: 15552000
customFrameOptionsValue: SAMEORIGIN
customRequestHeaders:
X-Forwarded-Proto: https
secured:
chain:
middlewares:
- default-headers
./data/traefik.yml
api:
dashboard: true
debug: true
entryPoints:
http:
address: ":80"
http:
redirections:
entrypoint:
to: https
scheme: https
https:
address: ":443"
http:
tls:
certResolver: technitium
domains:
- main: zcyph.cc
sans:
- "*.zcyph.cc"
serversTransport:
insecureSkipVerify: true
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
file:
directory: /
watch: true
certificatesResolvers:
technitium:
acme:
email: ig71hslr@postbin.me
storage: acme.json
caServer: https://acme-v02.api.letsencrypt.org/directory
# caServer: https://acme-staging-v02.api.letsencrypt.org/directory
keyType: EC384
dnsChallenge:
provider: rfc2136
Traefik will perform a DNS challenge, request certificate and store certificate in data/acme.json.
Traefik will not automatically create the actual DNS record, that still has to be done manually, or scripted.
traefik-certs-dumper
Official tool to dump certs from acme.json. Installed Go version and ran with:
traefik-certs-dumper file --source ./acme.json --dest ./dump/test
ACME-DNS
acme-dns provides a way to do a DNS challenge enabling wildcard certificates to be pulled for use with local HTTPS without needing cloudflare. It can optionally be self-hosted too. Remember to touch data/acme-dns first.
The new configuration looks like:
version: '3.3'
services:
traefik:
image: traefik:latest
container_name: traefik
restart: always
security_opt:
- no-new-privileges:true
networks:
- traefik
ports:
- 80:80
- 443:443
- 8080:8080
environment:
# - "CF_API_EMAIL=ig71hslr@postbin.me"
# - "CF_API_KEY=98621881b8f4b1a3e9ccec3962f548f761c97"
- ACME_DNS_API_BASE=https://auth.acme-dns.io
- ACME_DNS_STORAGE_PATH=/acme-dns
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/traefik.yml:/traefik.yml:ro
- ./data/acme.json:/acme.json
- ./data/config.yml:/config.yml:ro
- ./data/acme-dns:/acme-dns
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik"
- "traefik.http.routers.traefik-secure.entrypoints=https"
- "traefik.http.routers.traefik-secure.rule=Host(`traefik.zcyph.cc`)"
- "traefik.http.routers.traefik-secure.service=api@internal"
- "traefik.http.routers.traefik-secure.tls.certresolver=le-dns"
- "traefik.http.routers.traefik-secure.tls.domains[0].main=zcyph.cc"
- "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.zcyph.cc"
networks:
traefik:
external: true
Do docker-compose down -v and make a backup and then clear certs:
cp data/acme.json data/acmebakjson
rm data/acme.json
touch data/acme.json
chmod 600 data/acme.json
The data/traefik.yml now looks like:
api:
dashboard: true
debug: true
entryPoints:
http:
address: ":80"
http:
redirections:
entrypoint:
to: https
scheme: https
https:
address: ":443"
http:
tls:
certResolver: le-dns
domains:
- main: zcyph.cc
sans:
- "*.zcyph.cc"
serversTransport:
insecureSkipVerify: true
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
file:
directory: /
watch: true
certificatesResolvers:
myresolver:
acme:
email: ig71hslr@postbin.me
storage: acme.json
keyType: EC384
# caServer: https://acme-staging-v02.api.letsencrypt.org/directory
tlsChallenge: {}
le-dns:
acme:
email: ig71hslr@postbin.me
storage: acme.json
# caServer: https://acme-staging-v02.api.letsencrypt.org/directory
keyType: EC384
dnsChallenge:
provider: acme-dns
When making changes, uncomment the staging server first. In the docker compose for individual services, set the resolver to myresolver for public and le-dns for internal services that require certs.
Then docker-compose up -d and wait for the error in the docker-compose logs -f and check data/acme-dns with:
cat data/acme-dns | jq and it should contain entries for the domains, for example:
{
"pi.zcyph.cc": {
"fulldomain": "2d535055-a38d-45b2-b332-323a9b60040a.auth.acme-dns.io",
"subdomain": "2d535055-a38d-45b2-b332-323a9b60040a",
"username": "7a751692-5f3f-4613-985b-0cabff9a041c",
"password": "BovnFGFW36EqMrOEmXsTQTAtLLszZNgyHnLtHMFL",
"server_url": "https://auth.acme-dns.io"
},
"portainer.zcyph.cc": {
"fulldomain": "27ca0fe5-76ed-4042-a809-568b969f08a7.auth.acme-dns.io",
"subdomain": "27ca0fe5-76ed-4042-a809-568b969f08a7",
"username": "9522a7c5-b2b2-4daa-a0a1-616b6a81469e",
"password": "n5b934G20-W2pvT4UPmSUrR7OGp-nGWt5NpYY7zK",
"server_url": "https://auth.acme-dns.io"
},
"proot.zcyph.cc": {
"fulldomain": "a7e0a311-2cef-427b-85bc-6a33e63b2f71.auth.acme-dns.io",
"subdomain": "a7e0a311-2cef-427b-85bc-6a33e63b2f71",
"username": "721dd6cb-1fee-4f69-8b60-4c7cb330cc7f",
"password": "CJLqq_X5ickAKmLUEb1hoh7JU4PVE7mmdXomDIqV",
"server_url": "https://auth.acme-dns.io"
},
"traefik.zcyph.cc": {
"fulldomain": "23eaba42-6e3b-4e47-9899-f985fdc92fbd.auth.acme-dns.io",
"subdomain": "23eaba42-6e3b-4e47-9899-f985fdc92fbd",
"username": "70a38856-41e1-4f5c-9423-2835e50cdfa9",
"password": "qaK8z2BxOy6xoaAjzIIhzmIPhxm43QBcudGt-Jrd",
"server_url": "https://auth.acme-dns.io"
},
"wiki.zcyph.cc": {
"fulldomain": "4257f25e-b496-4f94-bff4-e7da4001c05b.auth.acme-dns.io",
"subdomain": "4257f25e-b496-4f94-bff4-e7da4001c05b",
"username": "4076777e-53cd-48d2-8ed6-262744a6e606",
"password": "kNW7Syu4NOJZKHzcQ5f_X14QNAzrdhyeWP22RiLO",
"server_url": "https://auth.acme-dns.io"
},
"zcyph.cc": {
"fulldomain": "9628bf55-19ba-4580-9854-73d018dc9e1a.auth.acme-dns.io",
"subdomain": "9628bf55-19ba-4580-9854-73d018dc9e1a",
"username": "57d3e3d8-f2b0-4e44-864d-43c2e00f2d56",
"password": "5wSLmk9XmHXDfM-W590_k_FF5pxNKeLcJfc3HTLC",
"server_url": "https://auth.acme-dns.io"
}
}
Create a CNAME for each entry, for example: _acme-challenge.wiki.zcyph.cc that points to 4257f25e-b496-4f94-bff4-e7da4001c05b.auth.acme-dns.io. Once those changes propogate, restart the container and confirm it's working.