From 1ec52f0a75af2aec59b6d441b31fb44c08bc5709 Mon Sep 17 00:00:00 2001 From: mifi Date: Thu, 3 Dec 2026 19:52:36 -0300 Subject: [PATCH] A slight rethink... --- compose.future.yaml | 87 +++++++++++++++++++++++++++ compose.yaml | 92 +++++++++++++++++----------- traefik/conf.d/middlewares.yaml | 22 +++---- traefik/traefik.yaml | 102 +++++++++++++------------------- 4 files changed, 195 insertions(+), 108 deletions(-) create mode 100644 compose.future.yaml diff --git a/compose.future.yaml b/compose.future.yaml new file mode 100644 index 0000000..2142f1c --- /dev/null +++ b/compose.future.yaml @@ -0,0 +1,87 @@ +services: + traefik: + image: ${TRAEFIK_IMAGE:-traefik:latest} + container_name: traefik + restart: unless-stopped + + security_opt: + - no-new-privileges:true + + extra_hosts: + - "host.docker.internal:host-gateway" + + command: + - --configFile=/etc/traefik/traefik.yaml + + volumes: + - type: bind + source: ${TRAEFIK_ACME:?TRAEFIK_ACME must be set} + target: /letsencrypt + read_only: false + bind: + create_host_path: false + + - type: bind + source: ${TRAEFIK_YAML:-./traefik/traefik.yaml} + target: /etc/traefik/traefik.yaml + read_only: true + bind: + create_host_path: false + + - type: bind + source: ${TRAEFIK_CONFD:-./traefik/conf.d} + target: /etc/traefik/conf.d + read_only: true + bind: + create_host_path: false + + - type: bind + source: /var/run/docker.sock + target: /var/run/docker.sock + read_only: true + bind: + create_host_path: false + + networks: + - docknet + + labels: + - 'traefik.enable=true' + - 'traefik.docker.network=${NETWORK_NAME:-docknet}' + - 'traefik.http.routers.api.rule=Host(`${CONSOLE_HOST}`)' + - 'traefik.http.routers.api.entrypoints=websecure' + - 'traefik.http.routers.api.service=api@internal' + - 'traefik.http.routers.api.tls=true' + - 'traefik.http.routers.api.tls.certresolver=letsencrypt' + - 'traefik.http.routers.api.middlewares=traefik-auth' + - 'traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_CONSOLE_AUTH}' + + ports: + - "${TRAEFIK_HTTP_PORT:-8342}:80" + - "${TRAEFIK_HTTPS_PORT:-8767}:443" + + environment: + CLOUDFLARE_DNS_API_TOKEN: ${CLOUDFLARE_DNS_API_TOKEN:?Cloudflare DNS API token required} + + healthcheck: + test: + - CMD + - traefik + - healthcheck + - --ping + interval: 30s + timeout: 5s + retries: 3 + start_period: 15s + + logging: + driver: json-file + options: + max-size: "1m" + max-file: "3" + compress: "true" + +networks: + docknet: + name: ${NETWORK_NAME:-docknet} + external: true diff --git a/compose.yaml b/compose.yaml index 05a3fe3..3c054ed 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,19 +1,50 @@ services: traefik: - image: traefik:latest + image: ${TRAEFIK_IMAGE:-traefik:latest} container_name: traefik restart: unless-stopped + extra_hosts: - - "host.docker.internal:host-gateway" + - "host.docker.internal:host-gateway" + + command: + - --configFile=/etc/traefik/traefik.yaml + volumes: - - ${TRAEFIK_YAML:-./traefik/traefik.yaml}:/etc/traefik/traefik.yaml - - ${TRAEFIK_CONFD:-./traefik/conf.d}:/etc/traefik/conf.d - - traefik-acme:/letsencrypt - - /var/run/docker.sock:/var/run/docker.sock + - type: bind + source: ${TRAEFIK_ACME:?TRAEFIK_ACME must be set} + target: /letsencrypt + read_only: false + bind: + create_host_path: false + + - type: bind + source: ${TRAEFIK_YAML:-./traefik/traefik.yaml} + target: /etc/traefik/traefik.yaml + read_only: true + bind: + create_host_path: false + + - type: bind + source: ${TRAEFIK_CONFD:-./traefik/conf.d} + target: /etc/traefik/conf.d + read_only: true + bind: + create_host_path: false + + - type: bind + source: /var/run/docker.sock + target: /var/run/docker.sock + read_only: true + bind: + create_host_path: false + networks: - - docknet + - proxy + labels: - 'traefik.enable=true' + - 'traefik.docker.network=${NETWORK_NAME:-docknet}' - 'traefik.http.routers.api.rule=Host(`${CONSOLE_HOST}`)' - 'traefik.http.routers.api.entrypoints=websecure' - 'traefik.http.routers.api.service=api@internal' @@ -21,42 +52,31 @@ services: - 'traefik.http.routers.api.tls.certresolver=letsencrypt' - 'traefik.http.routers.api.middlewares=traefik-auth' - 'traefik.http.middlewares.traefik-auth.basicauth.users=${TRAEFIK_CONSOLE_AUTH}' + ports: - - 8342:80 - - 8767:443 - - 8080:8080 + - "${TRAEFIK_HTTP_PORT:-8342}:80" + - "${TRAEFIK_HTTPS_PORT:-8767}:443" + - "${TRAEFIK_DASHBOARD_PORT:-8080}:8080" + environment: - CLOUDFLARE_EMAIL=${CLOUDFLARE_EMAIL} - CLOUDFLARE_API_KEY=${CLOUDFLARE_API_KEY} - command: - - --api - # Enable the Trafik dashboard - - --api.dashboard=true - # Tell Traefik to discover containers using the Docker API - - --providers.docker=true - - --providers.docker.exposedByDefault=false - # Set up LetsEncrypt - - --certificatesresolvers.letsencrypt.acme.dnschallenge=true - - --certificatesresolvers.letsencrypt.acme.dnschallenge.provider=cloudflare - - --certificatesresolvers.letsencrypt.acme.email=${CLOUDFLARE_EMAIL} - # Set up an insecure listener that redirects all traffic to TLS - - --entrypoints.web.address=:80 - - --entrypoints.web.http.redirections.entrypoint.to=websecure - - --entrypoints.web.http.redirections.entrypoint.scheme=https - - --entrypoints.websecure.address=:443 - # Set up the TLS configuration for our websecure listener - - --entrypoints.websecure.http.tls=true - - --entrypoints.websecure.http.tls.certResolver=letsencrypt - - --log=true - - --log.level=INFO + + healthcheck: + test: [ "CMD", "traefik", "healthcheck", "--ping" ] + interval: 30s + timeout: 5s + retries: 3 + start_period: 15s + logging: - driver: "json-file" + driver: json-file options: max-size: "1m" + max-file: "3" + compress: "true" networks: - docknet: + proxy: name: ${NETWORK_NAME:-docknet} - -volumes: - traefik-acme: \ No newline at end of file + external: true diff --git a/traefik/conf.d/middlewares.yaml b/traefik/conf.d/middlewares.yaml index 40a6c15..363a858 100644 --- a/traefik/conf.d/middlewares.yaml +++ b/traefik/conf.d/middlewares.yaml @@ -73,20 +73,22 @@ http: X-Frame-Options: "SAMEORIGIN" gzip: compress: {} - hsts-header: + hsts-standard: headers: - # Enable HSTS (Strict Transport Security) - stsSeconds: 63072000 # 2 years + stsSeconds: 31536000 + hsts-strict: + headers: + stsSeconds: 63072000 stsIncludeSubdomains: true - stsPreload: true # for preload list + stsPreload: true internal-ips: - ipWhiteList: + ipAllowList: sourceRange: - - 127.0.0.1/32 - - 192.168.50.1/32 - - 50.116.61.55 - - 173.255.238.101 - - 72.93.250.18 + - 127.0.0.1/32 + - 192.168.50.1/32 + - 50.116.61.55/32 + - 173.255.238.101/32 + - 72.93.250.18/32 redirect-postfixadmin: redirectRegex: regex: "^https://mail\\.mifi\\.holdings/settings/?(.*)" diff --git a/traefik/traefik.yaml b/traefik/traefik.yaml index ea50591..8642a1e 100644 --- a/traefik/traefik.yaml +++ b/traefik/traefik.yaml @@ -1,74 +1,52 @@ api: - dashboard: true + dashboard: true + insecure: false entryPoints: - web: - address: ":80" - http: - redirections: - entryPoint: - to: websecure - scheme: https - websecure: - address: ":443" - traefik: - address: ":8080" + web: + address: ":80" + http: + redirections: + entryPoint: + to: websecure + scheme: https -ping: {} + websecure: + address: ":443" + http: + tls: + certResolver: letsencrypt + + traefik: + address: ":8080" + +ping: + entryPoint: traefik providers: - docker: - endpoint: unix:///var/run/docker.sock - watch: true - exposedByDefault: false - file: - directory: /etc/traefik/conf.d + docker: + endpoint: unix:///var/run/docker.sock + watch: true + exposedByDefault: false + network: docknet + + file: + directory: /etc/traefik/conf.d + watch: true log: - level: info - -accesslog: - filepath: /dev/stdout - format: json - fields: - defaultmode: keep - headers: - defaultmode: keep + level: INFO certificatesResolvers: - letsencrypt: - acme: - email: badmf@mifi.dev - storage: /letsencrypt/acme.json - dnsChallenge: - provider: cloudflare - resolvers: - - 1.1.1.1:53 - - 1.0.0.1:53 - -tls: - stores: - default: - defaultGeneratedCert: - resolver: letsencrypt - domain: - main: mifi.holdings - sans: - - mifi.com.br - - mifi.dev - - mifi.ventures - - fitz.guru - - michael-gerard.com - - asgardianpunk.com - - camilla-rena.com - - dining-it.com - - goodfeatherfarms.com - - mylocalpro.biz - - officelift.net - - starnora.com - - starnoraelizabethfitzpatrick.com - - thenewenglandpalletguy.com - - umlautpress.com + letsencrypt: + acme: + email: badmf@mifi.dev + storage: /letsencrypt/acme.json + dnsChallenge: + provider: cloudflare + resolvers: + - "1.1.1.1:53" + - "1.0.0.1:53" serversTransport: - insecureSkipVerify: false + insecureSkipVerify: false \ No newline at end of file