Traefik middleware that limits the total amount of data that passes through from the internal modules back out to the requesting clients. This plugin can effectively limit the total output from the server.
This plugin requires the use of a local API that maintains the byte totals per request source: https://github.com/AustinHellerRepo/ResetingIncrementerApi.
Basic configuration
testData:resetingIncrementerApiUrl: http://172.26.0.4:38160resetingIncrementerKey: the_service_name
docker-compose example
version: '3.8'services:web:build:context: .dockerfile: docker/Dockerfilecommand: gunicorn api.main:app --bind 0.0.0.0:38155 -w 4 -k uvicorn.workers.UvicornWorkerexpose:- 38155labels:- traefik.enable=true- traefik.http.routers.my_api.rule=Host(`subdomain.domain.com`)- traefik.http.routers.my_api.entrypoints=web- traefik.http.routers.my_api.middlewares=my_middleware- traefik.http.middlewares.my_middleware.plugin.traefikoutboundlimiter.resetingIncrementerApiUrl=http://resetingincrementerapi-web-1:38160- traefik.http.middlewares.my_middleware.plugin.traefikoutboundlimiter.resetingIncrementerKey=the_service_namenetworks:default:name: traefik_router_networkexternal: true
Important:
Starting docker container
docker network inspect traefik_router_network >/dev/null 2>&1 || \docker network create --driver bridge traefik_router_networkdocker-compose up -d
It is necessary to have a ResetingIncrementerApi docker container running such that it is accessible from the middleware.
[Timing]Interval = day_of_monthValue = 1
If you're having issues connecting to the ResetingIncrementerApi docker container, make sure that it's running in the same network. Try a "docker network inspect traefik_router_network" call in order to see that everything is available to each other and what the IP address is for the API.
Steps:
[KeyLimits]new_service = 123; the new_service can output 123 bytes before being restricted
labels:- traefik.http.middlewares.my_middleware.plugin.traefikoutboundlimiter.resetingIncrementerApiUrl=http://resetingincrementerapi-web-1:38160- traefik.http.middlewares.my_middleware.plugin.traefikoutboundlimiter.resetingIncrementerKey=new_service