middleflare

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Build Status

middleflare

a small traefik middleware plugin to remap CF-Connecting-IP over the top of X-Real-IP and X-Forwarded-For.

This has been done before but I didn't like the other implementations & wanted an excuse to do a golang thing.

Probably do not use this in production. Also, it looks like it maps CF-Visitor's "scheme" value, but it doesn't yet.

Configuration

Define the plugin:

# Static configuration

experimental:
  plugins:
    middleflare:
      moduleName: github.com/neggles/middleflare
      version: v0.0.2
Example configuration:
# Dynamic configuration

http:
  routers:
    my-router:
      rule: host(`demo.localhost`)
      service: service-foo
      entryPoints:
        - web
      middlewares:
        - middleflare

  services:
   service-foo:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:5000
  
  middlewares:
    middleflare:
      plugin:
        middleflare:
          includeDefault: true
          trustedProxies: []
Kubernetes CRDs:

TODO: Add these when it's not 1:30am...

Documentation

Overview

Package middleflare is a Traefik plugin that maps Cloudflare headers to standard headers.

Index

Constants

View Source
const (
	XRealIP         = "X-Real-IP"
	XForwardedFor   = "X-Forwarded-For"
	XForwardedProto = "X-Forwarded-Proto"
	XForwardedHost  = "X-Forwarded-Host"
	XTrustedProxy   = "X-Trusted-Proxy"
	CFConnectingIP  = "CF-Connecting-IP"
	CFVisitor       = "CF-Visitor"
)

Header name constants.

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 CFHeaderWriter plugin.

Types

type CFHeaderWriter

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

CFHeaderWriter is a plugin that maps CF-Connecting-IP to X-Real-IP and X-Forwarded-For.

func (*CFHeaderWriter) ServeHTTP

func (writer *CFHeaderWriter) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler interface.

type CheckResult

type CheckResult struct {
	IsValid   bool
	IsTrusted bool
	ProxyAddr netip.Addr
}

CheckResult is the return from an IP trust check.

type Config

type Config struct {
	TrustedProxies []string `json:"trustedProxies,omitempty"`
	IncludeDefault bool     `json:"includeDefault,omitempty"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

Directories

Path Synopsis
Package cfaddrs provides a list of Cloudflare's IP addresses, a function to check if an IP address is in a list of netip.Prefix, and a function to parse a list of CIDR strings into a list of netip.Prefix.
Package cfaddrs provides a list of Cloudflare's IP addresses, a function to check if an IP address is in a list of netip.Prefix, and a function to parse a list of CIDR strings into a list of netip.Prefix.

Jump to

Keyboard shortcuts

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