traefik_regex_block

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

traefik-regex-block

Summary

The traefix-regex-block plugin provides middleware for Traefik to detect URLs that match a list of regex patterns and then block those IP addresses for a configurable amount of time. This project took inspiration from the well known Fail2Ban application. This plugin can improve security of a site by detecting when threat actors are scanning your site for known exploitable endpoints. If there are certain patterns that are often scanned for that you know will not be on your site, you can proactively identify when those attempts are made and block the source from further scanning of your site.

Installation

Installation instructions can be found on the Traefik plugin catalog.

Latest Release

The current release is version v0.1.0. This plugin is still in it's early development phase. However, it is fully functional and is in bug testing phase. If you encounter any problems, please provide feedback by opening an issue here.

Configuration

The following settings can be used to configure your plugin.

Block Duration - blockDurationMinutes
  • Required: No
  • Default: 60 minutes

Use this setting to determine how many minutes an IP address will be blocked from your site after each URL attempt that matches a regex pattern.

Regular Expression Pattern List - regexPatterns
  • Required: Yes
  • Default: (none)

You provide a list of regular expression patterns to be used to detect activity you want to block. You can provide any number of patterns to monitor with.

Whitelist IP Addresses - whitelist
  • Required: No
  • Default: (none)

If you want to keep from blocking specific IP addresses, you can use the whitelist feature. This accepts a list of IP addresses as either an IP address on in CIDR notation.

Enable Debug Logging - enableDebug
  • Required: No
  • Default: false

Setting this value to true will show all debug logging for the plugin. Otherwise, logging level is set to an info level for output.

Example

The following configuration will detect any URL traffic that includes /.env or /cgi-bin in the URL. It will block any further requests from the IP address for 2 hours. Logging level is set to show debug messages. It then excludes blocking for any requests from the 127.0.0.1 address, or from a 192.168.0.0/16 network.

    my-regex-block:
      plugin:
        traefik-regex-block:
          blockDurationMinutes: 120
          enableDebug: true
          regexPatterns:
            - \/\.env
            - \/cgi-bin
          whitelist:
            - 127.0.0.1
            - 192.168.0.0/16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New creates a new instance of the RegexBlock.

Types

type ArrayStorage added in v0.1.0

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

ArrayStorage implements BlockStorage using an array.

func (*ArrayStorage) Block added in v0.1.0

func (as *ArrayStorage) Block(ip net.IP, minutes int) error

func (*ArrayStorage) IsBlocked added in v0.1.0

func (as *ArrayStorage) IsBlocked(ip net.IP) bool

func (*ArrayStorage) UnBlock added in v0.1.0

func (as *ArrayStorage) UnBlock(ip net.IP) error

type BlockManager added in v0.1.0

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

BlockManager defines the struct for managing IP addresses.

func ArrayBlockManager added in v0.1.0

func ArrayBlockManager() *BlockManager

func RedisBlockManager added in v0.1.0

func RedisBlockManager(host string) *BlockManager

func (*BlockManager) Block added in v0.1.0

func (im *BlockManager) Block(ip net.IP, minutes int) error

func (*BlockManager) IsBlocked added in v0.1.0

func (im *BlockManager) IsBlocked(ip net.IP) bool

func (*BlockManager) UnBlock added in v0.1.0

func (im *BlockManager) UnBlock(ip net.IP) error

type BlockStorage added in v0.1.0

type BlockStorage interface {
	IsBlocked(ip net.IP) bool
	Block(ip net.IP, minutes int) error
	UnBlock(ip net.IP) error
}

BlockStorage defines the interface for managing IP addresses.

type Config

type Config struct {
	RegexPatterns        []string `json:"regexPatterns,omitempty"`
	BlockDurationMinutes int      `json:"blockDurationMinutes,omitempty"`
	Whitelist            []string `json:"whitelist,omitempty"`
	EnableDebug          bool     `json:"enableDebug,omitempty"`
}

Config defines the configuration options for the plugin.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates a default configuration for the plugin.

type RedisStorage added in v0.1.0

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

RedisStorage implements BlockStorage using a Redis connection.

func (*RedisStorage) Block added in v0.1.0

func (db *RedisStorage) Block(ip net.IP, minutes int) error

func (*RedisStorage) IsBlocked added in v0.1.0

func (as *RedisStorage) IsBlocked(ip net.IP) bool

func (*RedisStorage) UnBlock added in v0.1.0

func (as *RedisStorage) UnBlock(ip net.IP) error

type RegexBlock

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

RegexBlock is a Traefik plugin that blocks requests matching certain regex patterns.

func (*RegexBlock) ServeHTTP

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

ServeHTTP intercepts the request and blocks it if it matches any of the configured regex patterns.

Jump to

Keyboard shortcuts

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