Uncategorized

Selfhost Traefik, fully rootless, distroless and 6x smaller than the original image (including defaults and safe Docker socket access!)

Self-Hosting Traefik: A More Secure and Efficient Way to Manage Your Reverse Proxy

A step-by-step guide to self-hosting Traefik, including a fully rootless, distroless, and 6x smaller image

As someone who’s interested in self-hosting and managing their own reverse proxy, you’re likely no stranger to Traefik. This modern HTTP reverse proxy and load balancer makes deploying microservices easy, but have you ever wondered if there’s a more secure and efficient way to run it? In this post, we’ll explore how to self-host Traefik using a fully rootless, distroless, and significantly smaller image.

What’s Wrong with the Original Image?

The original Traefik image is a great starting point, but it has some limitations. For one, it runs as root, which can be a security risk. Additionally, it includes a full Linux distribution, which can make the image larger and more cumbersome. And, let’s be honest, who needs all those extra features and bloat when you’re just trying to run a simple reverse proxy?

Enter the Fully Rootless, Distroless Image

That’s where this new image comes in. By running Traefik as a non-root user (1000:1000) and removing the unnecessary Linux distribution, we can create a much smaller and more secure image. But that’s not all – this image also includes a number of other features that make it more efficient and secure, such as:

  • Auto-updating to the latest version via CI/CD
  • A built-in health check
  • Read-only access to prevent accidental changes
  • Automatic scanning for CVEs before and after publishing
  • A secure and pinned CI/CD process

Comparison Time

So, how does this new image stack up against the original? Here’s a comparison of the two:

Image 11notes/traefik:3.4.4 traefik:3.4.4
Image size on disk 37.1MB 226MB
Process UID/GID 1000/1000 0/0
Distroless? Yes No
Rootless? Yes No

Getting Started with the New Image

So, how do you get started with this new image? It’s actually pretty straightforward. You can use the following compose file to get up and running:

name: "reverse-proxy"
services:
  socket-proxy:
    image: "11notes/socket-proxy:2.1.2"
    read_only: true
    user: "0:108"
    environment:
      TZ: "Europe/Zurich"
    volumes:
      - "/run/docker.sock:/run/docker.sock:ro"
      - "socket-proxy.run:/run/proxy"
    restart: "always"

  traefik:
    depends_on:
      socket-proxy:
        condition: "service_healthy"
    restart: true
    image: "11notes/traefik:3.4.4"
    read_only: true
    labels:
      - "traefik.enable=true"
    environment:
      TZ: "Europe/Zurich"
    command:
      - "--ping.terminatingStatusCode=204"
      - "--global.checkNewVersion=false"
      - "--global.sendAnonymousUsage=false"
      - "--accesslog=true"
      - "--api.dashboard=true"
      - "--api.insecure=false"
      - "--log.level=INFO"
      - "--log.format=json"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.file.directory=/traefik/var"
      - "--entrypoints.http.address=:80"
      - "--entrypoints.http.http.middlewares=default-errors,default-ratelimit,default-ipallowlist-RFC1918"
      - "--entrypoints.https.address=:443"
      - "--entrypoints.https.http.tls=true"
      - "--entrypoints.https.http.middlewares=default-errors,default-ratelimit,default-ipallowlist-RFC1918"
    ports:
      - "80:80/tcp"
      - "443:443/tcp"
    volumes:
      - "var:/traefik/var"
      - "socket-proxy.run:/var/run"
      - "plugins:/plugins-storage"
    networks:
      backend:
      frontend:
    sysctls:
      net.ipv4.ip_unprivileged_port_start: 80
    restart: "always"

Conclusion

In conclusion, self-hosting Traefik using a fully rootless, distroless, and 6x smaller image is a great way to improve the security and efficiency of your reverse proxy. With its auto-updating, health checking, and read-only access, this image is a more secure and efficient way to run Traefik. So why not give it a try and see the difference for yourself?

Samohostowanie Traefik: Bezpieczniejszy i Wydajniejszy Sposób Zarządzania Twoim Serwerem Proxy

Krok-po-kroku przewodnik po samohostowaniu Traefik, w tym obrazie w pełni pozbawionym uprawnień roota, distroless i 6-krotnie mniejszym

Jako osoba zainteresowana samohostowaniem i zarządzaniem własnym serwerem proxy, prawdopodobnie nie jesteś obcy Traefikowi. Ten nowoczesny serwer proxy i load balancer ułatwia wdrożenie mikrousług, ale czy kiedykolwiek zastanawiałeś się, czy istnieje bardziej bezpieczny i wydajniejszy sposób jego uruchomienia? W tym poście, przedstawimy sposób samohostowania Traefik za pomocą obrazu w pełni pozbawionego uprawnień roota, distroless i znacznie mniejszego.

Co nie tak z oryginalnym obrazem?

Oryginalny obraz Traefik jest dobrym punktem wyjścia, ale ma pewne ograniczenia. Po pierwsze, uruchamia się jako root, co może być ryzykiem bezpieczeństwa. Ponadto, zawiera pełną dystrybucję Linuksa, co może sprawić, że obraz będzie większy i mniej wydajny. A poza tym, kto potrzebuje wszystkich tych dodatkowych funkcji i nakładki, gdy próbuje uruchomić prosty serwer proxy?

Wejście obrazu w pełni pozbawionego uprawnień roota i distroless

To właśnie tutaj pojawia się nowy obraz. Uruchamiając Traefik jako użytkownika niebędącego rootem (1000:1000) i usuwając niepotrzebną dystrybucję Linuksa, możemy utworzyć znacznie mniejszy i bardziej bezpieczny obraz. Ale to nie wszystko – ten obraz zawiera również szereg innych funkcji, które sprawiają, że jest bardziej wydajny i bezpieczny, takich jak:

  • Auto-aktualizacja do najnowszej wersji za pomocą CI/CD
  • Wbudowany test sprawności
  • Dostęp tylko do odczytu, aby zapobiec przypadkowym zmianom
  • Automatyczne skanowanie pod kątem CVE przed i po opublikowaniu
  • Bezpieczny i przypięty proces CI/CD

Czas porównań

Więc, jak ten nowy obraz porównuje się do oryginalnego? Oto porównanie obu:

Obraz 11notes/traefik:3.4.4 traefik:3.4.4
Rozmiar obrazu na dysku 37,1 MB 226 MB
ID procesu UID/GID 1000/1000 0/0
Czy distroless? Tak Nie
Czy pozbawiony uprawnień roota? Tak Nie

Rozpoczęcie pracy z nowym obrazem

Więc, jak rozpocząć pracę z tym nowym obrazem? W rzeczywistości jest to dość proste. Możesz użyć następującego pliku compose, aby rozpocząć:

name: "reverse-proxy"
services:
  socket-proxy:
    image: "11notes/socket-proxy:2.1.2"
    read_only: true
    user: "0:108"
    environment:
      TZ: "Europe/Zurich"
    volumes:
      - "/run/docker.sock:/run/docker.sock:ro"
      - "socket-proxy.run:/run/proxy"
    restart: "always"

  traefik:
    depends_on:
      socket-proxy:
        condition: "service_healthy"
    restart: true
    image: "11notes/traefik:3.4.4"
    read_only: true
    labels:
      - "traefik.enable=true"
    environment:
      TZ: "Europe/Zurich"
    command:
      - "--ping.terminatingStatusCode=204"
      - "--global.checkNewVersion=false"
      - "--global.sendAnonymousUsage=false"
      - "--accesslog=true"
      - "--api.dashboard=true"
      - "--api.insecure=false"
      - "--log.level=INFO"
      - "--log.format=json"
      - "--providers.docker.exposedByDefault=false"
      - "--providers.file.directory=/traefik/var"
      - "--entrypoints.http.address=:80"
      - "--entrypoints.http.http.middlewares=default-errors,default-ratelimit,default-ipallowlist-RFC1918"
      - "--entrypoints.https.address=:443"
      - "--entrypoints.https.http.tls=true"
      - "--entrypoints.https.http.middlewares=default-errors,default-ratelimit,default-ipallowlist-RFC1918"
    ports:
      - "80:80/tcp"
      - "443:443/tcp"
    volumes:
      - "var:/traefik/var"
      - "socket-proxy.run:/var/run"
      - "plugins:/plugins-storage"
    networks:
      backend:
      frontend:
    sysctls:
      net.ipv4.ip_unprivileged_port_start: 80
    restart: "always"

Podsumowanie

Podsumowując, samohostowanie Traefik za pomocą obrazu w pełni pozbawionego uprawnień roota, distroless i 6-krotnie mniejszego jest świetnym sposobem na poprawienie bezpieczeństwa i wydajności Twojego serwera proxy. Z jego auto-aktualizacją, testem sprawności i dostępem tylko do odczytu, ten obraz jest bardziej bezpiecznym i wydajniejszym sposobem na uruchomienie Traefik. Więc, dlaczego nie spróbować i zobaczyć różnicę samemu?

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Appliance - Powered by TurnKey Linux