Compare commits

..

25 Commits

Author SHA1 Message Date
47b9c06ba9 ipwhitelist -> ipallowlist
iwl is deprecated, ial is the new version
2024-05-02 13:41:09 +02:00
032cbf1820 mydomain -> example 2024-05-02 13:36:51 +02:00
09f3ec9f70 less static configuration, more variables 2024-05-02 13:34:32 +02:00
92f3d7bc79 removed container name - from env example too 2023-12-06 00:06:26 +01:00
9995f30c3b removed container name 2023-04-05 13:13:57 +02:00
026a2a272b Træfik Pilot is deprecated, removed 2023-04-05 12:09:05 +02:00
deb1b7ccb5 moved hsts middleware from section HTTP to section HTTPS 2022-08-16 16:06:40 +02:00
503f438bdf enhanced security through HSTS headers' middleware 2022-08-16 15:53:27 +02:00
a1428f0d3b clarified middlewares' comments 2022-08-16 15:45:53 +02:00
a40e9ad9ad added DNS resolvers for SSL DNS challenge 2022-08-02 12:53:36 +02:00
e2b612e664 added every .env to .gitignore 2022-08-02 12:51:24 +02:00
4633927204 moved from static DNS provider to a dynamic Docker variable and env file 2022-08-02 12:03:51 +02:00
64e726391a removed compose version, not needed anymore
(see https://docs.docker.com/compose/compose-file/#version-top-level-element)
2022-08-02 12:01:33 +02:00
4d4a578b78 variabilized more values, reorganized values in env.example file 2022-01-22 23:27:55 +01:00
39dbe048f5 added standard YAML three-dashes notation 2022-01-22 23:22:01 +01:00
310c237add renamed certificate file 2022-01-22 23:21:37 +01:00
4f46fdcdea removed config folder from .gitignore, added tls config file
actually that was a stupid idea, configs need to be tracked and version controlled
2022-01-15 23:46:54 +01:00
ccb8dee381 renamed repository in README.md 2022-01-15 23:40:46 +01:00
6888d09442 added le-certs.json and config folder to .gitignore 2022-01-15 23:22:57 +01:00
8111b7297b moved log level in proper section in env.example 2022-01-15 23:11:35 +01:00
026fc917e9 renamed Træfik network in compose file, added name variable for it 2022-01-15 23:09:46 +01:00
5b9facf603 renamed directories and environment variables 2022-01-15 22:39:35 +01:00
46a8794a7c rearranged service instructions 2022-01-15 22:35:10 +01:00
ccf95deedc variabilized access log, router name, match rule 2022-01-15 22:22:28 +01:00
f63b75e636 generalize domain name in env.example 2022-01-15 22:22:07 +01:00
6 changed files with 76 additions and 47 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
.env
/.env*
/certs.json

View File

@ -1,3 +1,3 @@
# traefik.bjphoster.com
# Træfik Deployment
Træfik deployment for reverse proxying all the infrastructure

11
config/tls.yml Normal file
View File

@ -0,0 +1,11 @@
---
tls:
options:
default:
minVersion: VersionTLS12
mintls13:
minVersion: VersionTLS13
compatible:
minVersion: VersionTLS11
supercompatible:
minVersion: VersionTLS10

View File

@ -1,74 +1,74 @@
version: "3"
---
services:
traefik:
image: traefik:${TRAEFIK_VERSION}
restart: unless-stopped
command:
# when debugging is needed
- --accesslog=${TRAEFIK_ACCESSLOG}
# enable Træfik dashboard
- --api.dashboard=true
# configure Let's Encrypt automatic certificates
- --certificatesresolvers.letsencrypt.acme.dnschallenge=true
- --certificatesresolvers.letsencrypt.acme.dnschallenge.provider=hetzner
- --certificatesresolvers.letsencrypt.acme.email=${LETSENCRYPT_EMAIL}
- --certificatesresolvers.letsencrypt.acme.keytype=RSA4096
- --certificatesresolvers.letsencrypt.acme.storage=/le-certs.json
- --certificatesresolvers.${TRAEFIK_CERTRESOLVER}.acme.dnschallenge=true
- --certificatesresolvers.${TRAEFIK_CERTRESOLVER}.acme.dnschallenge.provider=${TRAEFIK_DNSPROVIDER}
- --certificatesresolvers.${TRAEFIK_CERTRESOLVER}.acme.dnschallenge.resolvers=${TRAEFIK_DNSRESOLVERS}
- --certificatesresolvers.${TRAEFIK_CERTRESOLVER}.acme.email=${LETSENCRYPT_EMAIL}
- --certificatesresolvers.${TRAEFIK_CERTRESOLVER}.acme.keytype=RSA4096
- --certificatesresolvers.${TRAEFIK_CERTRESOLVER}.acme.storage=/certs.json
# we listen on both HTTP and HTTPS
- --entrypoints.http.address=:80
- --entrypoints.https.address=:443
# logging level
- --log.level=${TRAEFIK_LOGLEVEL}
# Træfik Pilot token (of course retrieved from dotenv)
- --pilot.token=${TRAEFIK_PILOT_TOKEN}
# we only use Docker (for now)
- --providers.docker=true
# and we want to manually specify exposed containers
- --providers.docker.exposedbydefault=false
- --providers.docker.watch=true
# should not need, but just in case, a dynamic config file is also configured
- --providers.file.directory=/dynamic-config
# should not need, but just in case, a folder for dynamic config files is also configured
- --providers.file.directory=/config
- --providers.file.watch=true
container_name: ${TRAEFIK_CONTAINER_NAME}
environment:
- HETZNER_API_KEY=${HETZNER_API_KEY}
image: traefik:${TRAEFIK_VERSION}
env_file:
- ${TRAEFIK_DNSPROVIDER_ENVFILE}
labels:
# expose Træfik using Træfik (dashboard)
- traefik.enable=true
# configure a global whitelist for my home
- traefik.http.middlewares.dashboard-whitelist.ipwhitelist.sourcerange=${TRAEFIK_DASHBOARD_WHITELIST}
# configure the global redirect middleware
- traefik.enable=${TRAEFIK_ENABLED}
- traefik.docker.network=${TRAEFIK_NETWORK}
# configure a global whitelist for accessing the Træfik dashboard
- traefik.http.middlewares.dashboard-whitelist.ipallowlist.sourcerange=${TRAEFIK_DASHBOARD_WHITELIST}
# configure a global middleware for redirecting HTTP to HTTPS
- traefik.http.middlewares.http-to-https.redirectscheme.scheme=https
- traefik.http.middlewares.http-to-https.redirectscheme.permanent=true
# configure a global middleware to harden security through HSTS
- traefik.http.middlewares.hsts.headers.stsSeconds=${TRAEFIK_STS_SECONDS}
- traefik.http.middlewares.hsts.headers.stsIncludeSubdomains=${TRAEFIK_STS_SUBDOMAINS}
- traefik.http.middlewares.hsts.headers.stsPreload=${TRAEFIK_STS_PRELOAD}
### Section HTTP
- traefik.http.routers.http-${TRAEFIK_ROUTER_NAME}.entrypoints=http
# only some people can access the dashboard, hence protect it with it's whitelist
- traefik.http.routers.http-${TRAEFIK_ROUTER_NAME}.middlewares=dashboard-whitelist
- traefik.http.routers.http-${TRAEFIK_ROUTER}.entrypoints=http
# redirect Træfik dashboard to HTTPS only
- traefik.http.routers.http-${TRAEFIK_ROUTER_NAME}.middlewares=http-to-https
- traefik.http.routers.http-${TRAEFIK_ROUTER_NAME}.rule=Host(`${TRAEFIK_MATCHRULE}`)
- traefik.http.routers.http-${TRAEFIK_ROUTER_NAME}.service=api@internal
- traefik.http.routers.http-${TRAEFIK_ROUTER}.middlewares=${TRAEFIK_HTTP_MIDDLEWARES}
- traefik.http.routers.http-${TRAEFIK_ROUTER}.rule=${TRAEFIK_MATCHRULE}
- traefik.http.routers.http-${TRAEFIK_ROUTER}.service=api@internal
### Section HTTPS
- traefik.http.routers.https-${TRAEFIK_ROUTER_NAME}.entrypoints=https
# only some people can access the dashboard, hence protect it with it's whitelist
- traefik.http.routers.https-${TRAEFIK_ROUTER_NAME}.middlewares=dashboard-whitelist
- traefik.http.routers.https-${TRAEFIK_ROUTER}.entrypoints=https
# configure Træfik dashboard to be the exposed service
- traefik.http.routers.https-${TRAEFIK_ROUTER_NAME}.rule=Host(`${TRAEFIK_MATCHRULE}`)
- traefik.http.routers.https-${TRAEFIK_ROUTER_NAME}.service=api@internal
- traefik.http.routers.https-${TRAEFIK_ROUTER}.middlewares=${TRAEFIK_HTTPS_MIDDLEWARES}
- traefik.http.routers.https-${TRAEFIK_ROUTER}.rule=${TRAEFIK_MATCHRULE}
- traefik.http.routers.https-${TRAEFIK_ROUTER}.service=api@internal
# of course, enable TLS and it's certificate provider
- traefik.http.routers.https-${TRAEFIK_ROUTER_NAME}.tls=true
- traefik.http.routers.https-${TRAEFIK_ROUTER_NAME}.tls.certresolver=letsencrypt
- traefik.http.routers.https-${TRAEFIK_ROUTER}.tls=${TRAEFIK_TLSENABLED}
- traefik.http.routers.https-${TRAEFIK_ROUTER}.tls.certresolver=${TRAEFIK_CERTRESOLVER}
networks:
- traefik-proxy
- traefik
ports:
- 80:80
- 443:443
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./config:/dynamic-config:ro
- ./le-certs.json:/le-certs.json
- ${TRAEFIK_DYNAMIC}:/config:ro
- ${TRAEFIK_CERTFILE}:/certs.json
networks:
traefik-proxy:
traefik:
external: true
name: ${TRAEFIK_NETWORK}

1
env.dnsprovider.example Normal file
View File

@ -0,0 +1 @@
HETZNER_API_KEY=

View File

@ -1,14 +1,30 @@
TRAEFIK_VERSION=2.4
TRAEFIK_CONTAINER_NAME=traefik.mydomain.com
TRAEFIK_MATCHRULE=traefik.mydomain.com
TRAEFIK_ROUTER_NAME=traefik_mydomain_com
TRAEFIK_LOGLEVEL=INFO
TRAEFIK_PILOT_TOKEN=
# General environment
TRAEFIK_VERSION=latest
TRAEFIK_CERTRESOLVER=letsencrypt
TRAEFIK_DASHBOARD_WHITELIST=1.2.3.4/24
TRAEFIK_ENABLED=true
TRAEFIK_NETWORK=traefik
TRAEFIK_MATCHRULE=Host(`traefik.example.com`)
TRAEFIK_ROUTER=traefik_example_com
TRAEFIK_HTTP_MIDDLEWARES=dashboard-whitelist,http-to-https
TRAEFIK_HTTPS_MIDDLEWARES=dashboard-whitelist,hsts
# Security
TRAEFIK_TLSENABLED=true
TRAEFIK_STS_SECONDS=15552000
TRAEFIK_STS_SUBDOMAINS=true
TRAEFIK_STS_PRELOAD=true
# Certificate provider
HETZNER_API_KEY=
LETSENCRYPT_EMAIL=admin@mydomain.com
TRAEFIK_DNSPROVIDER=hetzner
TRAEFIK_DNSPROVIDER_ENVFILE=./.env.dnsprovider
TRAEFIK_DNSRESOLVERS=1.1.1.1:53,1.0.0.1:53
LETSENCRYPT_EMAIL=admin@example.com
# Debugging
TRAEFIK_ACCESSLOG=false
TRAEFIK_LOGLEVEL=INFO
# Volumes
TRAEFIK_DYNAMIC=./config
TRAEFIK_CERTFILE=./certs.json