traefik_plugin_geoblock

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

README

traefik-plugin-geoblock

Build Status Go Report Card Latest GitHub release License

traefik-plugin-geoblock is a traefik plugin to whitelist requests based on geolocation

This projects includes IP2Location LITE data available from lite.ip2location.com.

Configuration

Static
Local
experimental:
  localPlugins:
    geoblock:
      moduleName: github.com/nscuro/traefik-plugin-geoblock
Pilot
pilot:
  token: "xxxxxxxxx"

experimental:
  plugins:
    geoblock:
      moduleName: github.com/nscuro/traefik-plugin-geoblock
      version: v0.1.1
Dynamic
http:
  middlewares:
    geoblock:
      plugin:
        geoblock:
          # Whether or not to enable geoblocking.
          enabled: true
          # Path to the ip2location database.
          databaseFilePath: /plugins-local/src/github.com/nscuro/traefik-plugin-geoblock/IP2LOCATION-LITE-DB1.IPV6.BIN
          # Countries to allow requests from, using ISO 3166-1 alpha-2 codes.
          # See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements
          allowedCountries: [ "AT", "CH", "DE" ]
          # Whether or not requests from private networks should be allowed.
          allowPrivate: true

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAllowed = errors.New("not allowed")

Functions

func New

func New(_ context.Context, next http.Handler, cfg *Config, name string) (http.Handler, error)

Types

type Config

type Config struct {
	Enabled          bool
	DatabaseFilePath string
	AllowedCountries []string
	AllowPrivate     bool
}

func CreateConfig

func CreateConfig() *Config

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (Plugin) CheckAllowed

func (p Plugin) CheckAllowed(ip string) (string, error)

CheckAllowed checks whether a given IP address is allowed according to the configured allowed countries.

func (Plugin) GetRemoteIPs

func (p Plugin) GetRemoteIPs(req *http.Request) (ips []string)

GetRemoteIPs collects the remote IPs from the X-Forwarded-For and X-Real-IP headers.

func (Plugin) Lookup

func (p Plugin) Lookup(ip string) (string, error)

Lookup queries the ip2location database for a given IP address.

func (Plugin) ServeHTTP

func (p Plugin) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL