nscuro/traefik-plugin-geoblock

Install, without Traefik Pilot?

LordMike opened this issue ยท 3 comments

Hey,

This plugin looks cool, but I've never added plugins before. I can see that it's on Traefik Pilot, but to use that I need to subscribe to that. Is there a way to install this plugin w/o that?

Can I place something in the traefik directory to activate the plugin?

Thanks in advance :)

Mike.

Hi Mike ๐Ÿ‘‹

yes, there is a way. In fact, I'm not using pilot either.
What you're looking for is local / private plugins.

I'm running traefik with Docker Compose, so here's what I'm doing:

# docker-compose.yml

version: "3"

services:
  traefik:
    image: "traefik:v2.6.2@sha256:860fc052d2b48c0b05b76c47baeb6fdeea316b8950afc1e230e51f11e2b71157"
    container_name: "traefik"
    ports:
      - "443:443"
    networks:
      - "traefik"
    volumes:
      - "/opt/traefik/config/traefik.yml:/etc/traefik/traefik.yml:ro"
      - "/opt/traefik/config:/etc/traefik/config:ro"
      - "/opt/traefik/plugins:/plugins-local"
      # ...
    restart: unless-stopped

On my host system, the traefik-plugin-geoblock repository is located at:

/opt/traefik/plugins/src/github.com/nscuro/traefik-plugin-geoblock

traefik.yml (static config) then contains:

# traefik.yml

experimental:
  localPlugins:
    geoblock:
      moduleName: github.com/nscuro/traefik-plugin-geoblock

One of the dynamic configs in /opt/traefik/config/dynamic finally defines the middleware based on the plugin:

# geoblock.yml

http:
  middlewares:
    geoblock:
      plugin:
        geoblock:
          enabled: true
          databaseFilePath: /plugins-local/src/github.com/nscuro/traefik-plugin-geoblock/IP2LOCATION-LITE-DB1.IPV6.BIN
          allowedCountries: ["DE"]
          allowPrivate: true
          disallowedStatusCode: 204

Note that databaseFilePath is for the path within the container.
I then activate the middleware using labels on my service containers, like so:

# docker-compose.yml

# ...
      traefik.http.routers.myservice.middlewares: "geoblock@file"

Please let me know if you have further questions! :)

Much appreciated!

And this is only for v2 I assume? :)

Yeah, I don't think traefik v1 supports plugins. At least private plugins are v2 exclusive.