traefik_filter_on_field

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 3 Imported by: 0

README

Filter on Field

Allows for filtering Traefik Requests based on parameters that are passed in to the request matching a particular regular expression.

Pipeline Status Latest Release

Configuration Examples

Docker
label:
- traefik.http.middlewares.<middlewareName>.traefikFilterOnField.fieldName='<fieldName>'
- traefik.http.middlewares.<middlewareName>.traefikFilterOnField.disallowedContent='<disallowedRegex1>,<disallowedRegex2>'
- traefik.http.middlewares.<middlewareName>.traefikFilterOnField.responseMessage="<Response Message>"
File (YAML)
http:
  routers:
    <routerName>:
      service: <serviceName>
      middlewares:
      - <middlewareName>
  middlewares:
    <middlewareName>:
      plugin:
        traefikFilterOnField:
          fieldName: <fieldName>
          disallowedContent:
            - <disallowedRegex1>
            - <disallowedRegex2>
          responseMessage: <Response Message>

Parameter Precedence

Parameters are approached in the following order:

  1. PUT or POST Form Fields
  2. GET Query String Fields.

⚠ If the same field exists in bothe a URL Query String and a Form Request, only the Form Request Field will be evaluated

Disallowing Use Of A Parameter

middleware:
  filter-all-requests-with-disallowed-field:
    plugin:
      traefikFilterOnField:
        fieldName: disallowedField
        disallowedContent:
        # Regex that matches everything...
        - .*

Documentation

Overview

This is the filter_on_field plugin. It contains the code that implements the Traefik interfaces, and filters requests based on the parameters passed in the configuration, allowing all values except those that match the disallowed content.

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)

Create a new instance of the filter. This is called by Traefik when the plugin is loaded and returns a new instance of the filter. It takes a configuration struct, the next handler in the chain, and the name of the filter.

Types

type Config

type Config struct {

	//  The name of the field to filter on
	FieldName string `yaml:"fieldName" json:"fieldName" toml:"fieldName" redis:"fieldName"`

	// The message to return when disallowed content is found.  This is returned as the Error Response body.
	ResponseMessage string `yaml:"responseMessage" json:"responseMessage" toml:"responseMessage" redis:"responseMessage"`

	// A group of regular expressions representing content that is not allowed
	DisallowedContent []string `yaml:"disallowedContent" json:"disallowedContent" toml:"disallowedContent" redis:"disallowedContent"`
}

A configuration struct for the filter. This is populated from the Traefik configuration, regardless of whether it's used via the dynamic configuration or the static configuration.

func CreateConfig added in v1.0.0

func CreateConfig() *Config

Create a default version of the configuration.

type FilterOnField

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

The Filter On Field Struct that implements all of the Traefik interfaces in order to be used as a Traefik middleware plugin.

func (*FilterOnField) ServeHTTP

func (f *FilterOnField) ServeHTTP(rw http.ResponseWriter, req *http.Request)

The ServeHTTP method is called by Traefik when a request is received. It takes a response writer and a request. When the checks pass, it calls the next handler in the chain. When the checks fail, it returns an error response.

Jump to

Keyboard shortcuts

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