*Code handling Maxmind db lookup and passing geo headers was cloned from GigiInnovationLabs.
*Code regarding excluding IPs was pulled from soulbalz.
Traefik plugin that registers a custom middleware for getting data from MaxMind GeoIP databases and pass it downstream via HTTP request headers. In the case that a load balancer is sitting in front of your traefik instance, this plugin will get the Real IP (client's ip) and use that for getting the geodata. Often times load balancers will concatenate their ip address to the client's ip and we just want to use the client's ip address.
Supports both GeoIP2 and GeoLite2 databases.
We're using this plugin in Kubernetes, thus the configuration guide is Kubernetes oriented.
You are welcome:
This is ~required in Kubernetes, since MaxMind DB size is bigger,
than data size allowed for ConfigMap or Secret resource.
Assuming you want to try free GeoLite2 database, that is already downloaded locally.
Create custom Dockerfile
FROM traefik:2.4.9
COPY GeoLite2-City.mmdb /var/lib/traefikgeoip2/
Build and publish to a Docker registry
export TDR=${...}docker build -t ${TDR}/traefik:2.4.9 .docker push ${TDR}/traefik:2.4.9
We recommend to use official Helm chart for installing Traefik into Kubernetes cluster.
Below, there's an instruction for adjusting official Helm chart to install the plugin.
Create a file named traefik.yaml, replacing ${TDR} with actual Docker registry path.
image:name: ${TDR}/traefiktag: "2.4.9"additionalArguments:- "--experimental.plugins.geoip2.modulename=github.com/badgeinc/traefikgeoip2badge"- "--experimental.plugins.geoip2.version=v0.0.5"
Install customized Traefik Helm chart.
helm repo add traefik https://helm.traefik.io/traefikhelm repo updatehelm upgrade --install -n traefik --create-namespace \my-traefik traefik/traefik --version 10.1.1 -f ./traefik.yaml
Create a file named mw.yaml
apiVersion: traefik.containo.us/v1alpha1kind: Middlewaremetadata:name: geoip2namespace: traefikspec:plugin:geoip:dbPath: "/var/lib/geoip2/GeoLite2-City.mmdb"excludedNets:- "1.1.1.1/24"
Apply
kubectl apply -f mw.yaml
!!! warning TO BE DEFINED
To run linter and tests execute this command
make preparemake