Skip to content

syltek/traefik-add-path-group-middleware

Repository files navigation

Playtomic Logo

Traefik Add Path Group Middleware

This repository contains a custom Traefik middleware plugin that extracts the path group (normalized path with IDs replaced by labels) into a request header before forwarding it to the upstream service. ID segments (UUIDs, numeric IDs, alphanumeric slugs) are replaced with labels to create a normalized path group. Useful for grouping requests by path pattern rather than specific IDs.

Plugin Logo

Configuration

Field Type Default Description
headerName string x-path-group Name of the request header to set

Example

The following paths will be normalized to the following path group and added to the x-path-group header:

/v1/users/550e8400-e29b-41d4-a716-446655440000/profile -> /v1/users/uuid/profile
/cars/42/bookings -> /vcars/numeric_id/bookings

Usage in Traefik

If you manage Traefik via a helm_release, plugins are registered in the experimental.plugins block of the Helm values, and then activated per-route using a Middleware CRD.

1. Enable the plugin in the module

Add the plugin to the experimental.plugins block with the desired plugin and version.

experimental = {
  plugins = {
    addPathHeader = {
      moduleName = "github.com/syltek/traefik-add-path-group-middleware"
      version    = "<plugin-version>"
    }
  }
}

2. Create the Middleware resource

Add a Middleware CRD to the extraObjects list in the same Helm release, or deploy it separately as a Kubernetes manifest:

extraObjects = [
  {
    apiVersion = "traefik.io/v1alpha1"
    kind       = "Middleware"
    metadata = {
      name      = "<middleware-name>"
      namespace = "traefik"
    }
    spec = {
      plugin = {
        addPathGroup = {
          headerName = "x-path-group"
        }
      }
    }
  }
]

3. Attach the middleware to a route

Reference the middleware in an IngressRoute or Ingress annotation:

# IngressRoute example
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: my-service
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`my-service.example.com`)
      kind: Rule
      middlewares:
        - name: <middleware-name>
          namespace: traefik
      services:
        - name: my-service
          port: 8080

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages