caddy_maxmind_asn

package module
v0.0.0-...-8a16e18 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: MIT Imports: 9 Imported by: 0

README

caddy-maxmind-asn

Caddy v2 module to filter requests based on ASN.

Installation

You can build Caddy by yourself by installing xcaddy and running:

xcaddy build --with github.com/0x00000024/caddy-maxmind-asn

Requirements

To be able to use this module you will need to have a MaxMind GeoLite2 database, that can be downloaded for free by creating an account. More information about this are available on the official website.

You will specifically need the GeoLite2-ASN.mmdb file.

Usage

You can use this module as a matcher to allow or block a set of Autonomous System Organization. The ASOs are non case-sensitive and will match as long as the ASN contains the provided matcher.

Example: Providing 'allow_asos amazon' will match on AMAZON and AMAZON-12

Caddyfile
  1. Allow access to the website only from ASNs associated with Amazon:
test.example.org {
  @myasn {
    maxmind_asn {
      db_path "/usr/share/MaxMind/GeoLite2-ASN.mmdb"
      allow_asos amazon
    }
  }

   file_server @myasn {
     root /var/www/html
   }
}
  1. Deny access to the website from ASNs associated with Amazon:
test.example.org {
  @myasn {
    maxmind_asn {
      db_path "/usr/share/MaxMind/GeoLite2-ASN.mmdb"
      deny_asos amazon
    }
  }

   file_server @myasn {
     root /var/www/html
   }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxmindASN

type MaxmindASN struct {
	// The path of the MaxMind GeoLite2-ASN.mmd file
	DbPath string `json:"db_path"`

	// A list of
	AllowASOs []string `json:"allow_asos"`
	DenyASOs  []string `json:"deny_asos"`
	// contains filtered or unexported fields
}

Allows to filter requests based on source IP ASO.

func (MaxmindASN) CaddyModule

func (MaxmindASN) CaddyModule() caddy.ModuleInfo

func (*MaxmindASN) Cleanup

func (m *MaxmindASN) Cleanup() error

func (*MaxmindASN) Match

func (m *MaxmindASN) Match(r *http.Request) bool

func (*MaxmindASN) Provision

func (m *MaxmindASN) Provision(ctx caddy.Context) error

func (*MaxmindASN) UnmarshalCaddyfile

func (m *MaxmindASN) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

type Record

type Record struct {
	ASN int    `maxminddb:"autonomous_system_number"`
	ASO string `maxminddb:"autonomous_system_organization"`
}

Jump to

Keyboard shortcuts

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