x9gg_traefik_middleware

package module
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 5 Imported by: 0

README

X9GG Traefik Middleware

⚠️ UNDER ACTIVE DEVELOPMENT ⚠️

Disclaimer: This plugin is a work in progress and is not recommended for production environments without thorough testing. Use at your own risk.

About

This plugin is a multi-purpose security and tracing middleware for Traefik that provides:

  1. Request Tracing - Generate unique IDs for distributed tracing
  2. Service Authentication - Validate API keys for service-to-service communication

Quick Start

# cli static config 

--experimental.plugins.x9gg-traefik-middleware.version=v0.2.0
--experimental.plugins.x9gg-traefik-middleware.modulename=github.com/x9gg/traefik-middleware

# Dynamic configuration
http:
  middlewares:
    x9gg-traefik-middleware:
      plugin:
        x9gg-traefik-middleware:
          trace:
            enabled: true
            headerName: "X-Request-Trace-Id"
          auth:
            enabled: true
            removeKeyNameOnSuccess: false
            removeKeyValueOnSuccess: true
            errorResponseType: plain
            errorMessage: "oh oh"
            keys:
              - name: "service-a" 
                value: "api-key-123"

Features (TBD)

Comming soon

  • IP Access Control - Allow or deny requests based on IP address/range
  • Custom response error

Todos

  • add tests

License

MIT License

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)

Types

type AuthConfig

type AuthConfig struct {
	Enabled                 bool         `json:"enabled"`
	KeyNameHeaderName       string       `json:"keyNameHeaderName"`
	KeyValueHeaderName      string       `json:"keyValueHeaderName"`
	RemoveKeyNameOnSuccess  bool         `json:"removeKeyNameOnSuccess"`
	RemoveKeyValueOnSuccess bool         `json:"removeKeyValueOnSuccess"`
	ErrorResponseType       string       `json:"errorResponseType"`
	ErrorMessage            string       `json:"errorMessage"`
	Keys                    []ServiceKey `json:"keys,omitempty"`
}

type Config

type Config struct {
	Trace TraceConfig `json:"trace"`
	Auth  AuthConfig  `json:"auth"`
}

func CreateConfig

func CreateConfig() *Config

type ServiceKey

type ServiceKey struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type TraceConfig

type TraceConfig struct {
	Enabled       bool   `json:"enabled"`
	ValuePrefix   string `json:"valuePrefix"`
	ValueSuffix   string `json:"valueSuffix"`
	HeaderName    string `json:"headerName"`
	AddToResponse bool   `json:"addToResponse"`
}

type X9GGTraefikMiddleware

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

func (*X9GGTraefikMiddleware) GenerateTraceId

func (m *X9GGTraefikMiddleware) GenerateTraceId() string

func (*X9GGTraefikMiddleware) ServeHTTP

func (m *X9GGTraefikMiddleware) 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