A3S GatewayMiddleware
TCP Filter
Limit concurrent connections and apply IP filtering on TCP entrypoints
TCP Filter
tcp-filter is a connection-level filter for TCP entrypoints. It is not an HTTP pipeline middleware and cannot be configured as middlewares "<name>" { type = "tcp-filter" }. Use entrypoint fields instead: max_connections and tcp_allowed_ips.
Behavior
When a TCP connection arrives, the filter checks:
- If
tcp_allowed_ipsis non-empty, the client IP must match one entry. - If
max_connectionsis set, active connections must be below the limit. - Accepted connections hold an RAII permit that decrements the counter on disconnect.
Connections denied by IP do not consume connection capacity.
Configuration
entrypoints "tcp-db" {
address = "0.0.0.0:5432"
protocol = "tcp"
max_connections = 1000
tcp_allowed_ips = ["10.0.0.0/8", "192.168.1.0/24"]
}| Key | Type | Default | Notes |
|---|---|---|---|
max_connections | u32 | unset means unlimited | Maximum concurrent TCP connections. |
tcp_allowed_ips | array<string> | [] | Empty means allow all IPs; supports individual IPs and CIDRs. |
Difference from HTTP Middleware
| Item | HTTP Middleware | TCP Filter |
|---|---|---|
| Location | middlewares "<name>" | entrypoints "<name>" |
| Reference | routers.middlewares | entrypoint fields |
| Object | HTTP request/response | TCP connection |
| Client effect | HTTP status | connection rejected/closed |
Notes
tcp_allowed_ips = []allows all IPs, unlikeip-allow.- Leaving
max_connectionsunset means unlimited connections. - TCP entrypoints do not return HTTP status codes.
- Check whether upstream L4 load balancers preserve the original client IP.
Recommended Baseline
max_connections = 1000
tcp_allowed_ips = ["10.0.0.0/8"]