PascalMinder / geoblock

Traefik middleware plugin - Deny requests based on country of origin
98 stars 10 forks source link

Guidance on how to install isn't clear #26

Closed ramonsmits closed 1 year ago

ramonsmits commented 1 year ago

The README, the geoblock guidance on plugins.traefik.io and the info there underneath the Install Plugin isn't aligned and sort of contradicting.

I'm using Traefik v2.9.0-rc4 and cannot get it to work

What is the CORRECT dynamic configuration path?

Options:

a. - /docker/config/traefik/dynamic-configuration.yml:/etc/traefik/dynamic-configuration.yml (README) b. - "/a/docker/config/traefik/data/dynamic-configuration.yml:/dynamic-configuration.yml" (README, but lower)

What is the correct way to install plugin?

From plugins.traefik.io description:

experimental:
  localPlugins:
    geoblock:
      moduleName: github.com/PascalMinder/GeoBlock

From plugins.traefik.io Install Plugin:

experimental:
  plugins:
    geoblock:
      moduleName: "github.com/PascalMinder/geoblock"
      version: "v0.2.3"

From README:

  1. Download the latest release of the plugin
  2. Add - /docker/config/traefik/plugin/geoblock:/plugins-local/src/github.com/PascalMinder/geoblock/ volume
  3. Add experimental plugin via experimental.localPlugins (instead of experimental.plugins as plugins.traefik.io Install Plugin states)
ramonsmits commented 1 year ago

My current configuration:

traefik docker-compose.yml

version: "3.3"

services:

  traefik:
    image: traefik:v2.9
    container_name: traefik
    volumes:
      - ./traefik.yml:/etc/traefik/traefik.yml
      - /var/run/docker.sock:/var/run/docker.sock
      - ./letsencrypt:/letsencrypt
      - ./dynamic-configuration.yml:/etc/traefik/dynamic-configuration.yml
      - ./geoblock:/plugins-local/src/github.com/PascalMinder/geoblock/
    network_mode: host

dynamic-configuration.yml

http:
  middlewares:
    geoblock:
      plugin:
        GeoBlock:
          allowLocalRequests: true
          logLocalRequests: false
          logAllowedRequests: false
          logApiRequests: true
          api: "https://get.geojs.io/v1/ip/country/{ip}"
          apiTimeoutMs: 750
          cacheSize: 25
          forceMonthlyUpdate: true
          allowUnknownCountries: false
          unknownCountryApiResponse: nil
          countries:
            - NL

traefik.yml

providers:
  file:
    filename: /etc/traefik/dynamic-configuration.yml
    watch: true

experimental:
  localPlugins:
    geoblock:
      moduleName: github.com/PascalMinder/geoblock

whoami docker-compose.yml

version: "3.3"

services:

  whoami:
    image: traefik/whoami:latest
    container_name: whoami
    environment:
       - WHOAMI_PORT_NUMBER=82
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=host(`whoami.smigo.nl`)
      - traefik.http.routers.whoami.entrypoints=http
      - traefik.http.services.whoami.loadbalancer.server.port=82
      - traefik.http.routers.whoami.middlewares=compression,geoblock@file
    network_mode: host

Tried to use geoblock@file and geoblock but both don't work.

PascalMinder commented 1 year ago

The version on plugins.traefik.io has not the last read me. I updated the readme in one of the commits after the last release. That's the reason, that the readme on plugins.traefik.io and on GitHub are not the same. The one on GitHub should be better. ;)

It does not matter to Traefik if you map the configuration to /etc/traefik/dynamic-configuration.yml or /dynamic-configuration.yml. But yes, I see, it is confusing using both in the same readme.

There is an example under docker with everything you need to create the Traefik container and two whoami containers. What I see in your config:

http:
  middlewares:
    geoblock: # i am not sure if this could be a problem with the same name, try using something like my-geoblock
      plugin:
        GeoBlock: # write this in lower case
          allowLocalRequests: true
          logLocalRequests: false
          logAllowedRequests: false
          logApiRequests: true
          api: "https://get.geojs.io/v1/ip/country/{ip}"
          apiTimeoutMs: 750
          cacheSize: 25
          forceMonthlyUpdate: true
          allowUnknownCountries: false
          unknownCountryApiResponse: nil
          countries:
            - NL