Traefik
Used more in the Docker concept, where configuration can be passed through labels. For containers without the overhead of Docker, one can run the binary directly. Idea is that Traefik is likely much more straightforward to configure with very sane defaults (nginx is my preferred reverse proxy, but is a tad overkill to configure and run).
Installation
Official binary releases here.
Absolute barebones setup
# Download file
root:~# FILE="traefik_v3.2.3_linux_amd64.tar.gz"
root:~# URL="https://github.com/traefik/traefik/releases/download/v3.2.3/${FILE}"
root:~# curl -OL ${URL}
# Move binary to sbin
root:~# tar xvf ${FILE}
root:~# mv traefik /usr/sbin/
# Create configuration
root:~# mkdir -p /etc/traefik/providers.d
root:~# ln -s /etc/traefik/traefik.service /etc/systemd/system/traefik.service
root:~# systemctl start traefik
- /etc/traefik/traefik.toml
[entryPoints.web]
address = ":80"
[providers.file]
directory = "/etc/traefik/providers.d"
- /etc/traefik/providers.d/service.toml
[[http.services.SERVICENAME.loadBalancer.servers]]
url = "http://localhost:8000/"
- /etc/traefik/traefik.service
[Unit]
After=network.target
[Service]
User=root
ExecStart=/usr/sbin/traefik
[Install]
WantedBy=multi-user.target
Hardening
Configuration changes
# Create traefik service account and lock down files
root:~# useradd -rMs /bin/false traefik
root:~# chown -R traefik /etc/traefik
root:~# find /etc/traefik \( -type f -exec chmod 600 {} \; \) , \( -type d -exec chmod 755 {} \; \)
- /etc/traefik/traefik.service
...
[Service]
User=traefik
ExecStart=/usr/sbin/traefik
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
NoNewPrivileges=true
RestrictNamespaces=~user
ProtectSystem=strict
PrivateTmp=true
PrivateDevices=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
...
TLS
Simple package for deploying TLS certificates, for use in LXC containers running as root: deploy_traefik_tls.tgz. Unpack, modify setup script to create proxy pass and point to certs and key, then run the script. Destroys any previous Traefik configuration, so watch out!
Configuration changes
- /etc/traefik/traefik.toml
[entryPoints.websecure]
address = ":443"
#[entryPoints.websecure.http]
#tls = {}
[entryPoints.websecure.http2]
maxConcurrentStreams = 250
- /etc/traefik/providers.d/proxy.toml
[http.routers.HTTPS_ROUTER]
rule = "Host(`example.com`)"
service = "SERVICENAME"
[http.routers.HTTPS_ROUTER.tls]
- /etc/traefik/providers.d/tls.toml
[tls.options.modern]
minVersion = "VersionTLS13"
[[tls.certificates]]
certFile = "/etc/traefik/certificates/fullchain.pem"
keyFile = "/etc/traefik/certificates/privkey.pem"
HTTP redirect to HTTPS
[entryPoints.web.http.redirections.entryPoint]
to = "websecure"
scheme = "https"
Integration with Docker
Sometimes one just wants to add a TLS layer to mitigate promiscuous sniffing of HTTP packets, for services that are being spun on the go. Strategy is the same as that of file based provider (TLS is loaded via dynamic config), with the proxy information shifted to Docker labels instead.
See extremely minimal example below, with the following notes:
- docker-compose.yml
services:
MY_SERVICE:
...
labels:
- "traefik.http.routers.service.rule=PathPrefix(`/`)"
- "traefik.http.routers.service.tls=true"
- "traefik.port=80"
traefik:
image: traefik:v3.3
container_name: traefik
ports:
- "8443:443"
volumes:
- "./traefik.toml:/etc/traefik/traefik.toml"
- "/var/run/docker.sock:/var/run/docker.sock"
- traefik.toml
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http2]
maxConcurrentStreams = 250
[providers.docker]
Additional changes if bootstrapping TLS cert
Mount traefik.conf.d/
to /etc/traefik
, then add the certificates:
./
+-- docker-compose.yml
+-- traefik.conf.d/
+-- traefik.toml
+-- traefik_dynamic.toml
+-- fullchain.pem
+-- privkey.pem
- traefik.toml
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http2]
maxConcurrentStreams = 250
[providers.docker]
[providers.file]
filename = "/etc/traefik/traefik_dynamic.toml"
- traefik_dynamic.toml
[tls.options.modern]
minVersion = "VersionTLS13"
[[tls.certificates]]
certFile = "/etc/traefik/fullchain.pem"
keyFile = "/etc/traefik/privkey.pem"