Add TCP Middlewares support

This commit is contained in:
Romain 2021-06-11 15:30:05 +02:00 committed by GitHub
parent 679def0151
commit fc9f41b955
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
134 changed files with 5865 additions and 1852 deletions

View file

@ -3,7 +3,7 @@
Prefixing the Path Prefixing the Path
{: .subtitle } {: .subtitle }
![AddPrefix](../assets/img/middleware/addprefix.png) ![AddPrefix](../../assets/img/middleware/addprefix.png)
The AddPrefix middleware updates the path of a request before forwarding it. The AddPrefix middleware updates the path of a request before forwarding it.

View file

@ -3,7 +3,7 @@
Adding Basic Authentication Adding Basic Authentication
{: .subtitle } {: .subtitle }
![BasicAuth](../assets/img/middleware/basicauth.png) ![BasicAuth](../../assets/img/middleware/basicauth.png)
The BasicAuth middleware restricts access to your services to known users. The BasicAuth middleware restricts access to your services to known users.

View file

@ -3,7 +3,7 @@
How to Read the Request before Forwarding It How to Read the Request before Forwarding It
{: .subtitle } {: .subtitle }
![Buffering](../assets/img/middleware/buffering.png) ![Buffering](../../assets/img/middleware/buffering.png)
The Buffering middleware limits the size of requests that can be forwarded to services. The Buffering middleware limits the size of requests that can be forwarded to services.

View file

@ -3,7 +3,7 @@
When One Isn't Enough When One Isn't Enough
{: .subtitle } {: .subtitle }
![Chain](../assets/img/middleware/chain.png) ![Chain](../../assets/img/middleware/chain.png)
The Chain middleware enables you to define reusable combinations of other pieces of middleware. The Chain middleware enables you to define reusable combinations of other pieces of middleware.
It makes reusing the same groups easier. It makes reusing the same groups easier.

View file

@ -3,7 +3,7 @@
Don't Waste Time Calling Unhealthy Services Don't Waste Time Calling Unhealthy Services
{: .subtitle } {: .subtitle }
![CircuitBreaker](../assets/img/middleware/circuitbreaker.png) ![CircuitBreaker](../../assets/img/middleware/circuitbreaker.png)
The circuit breaker protects your system from stacking requests to unhealthy services, resulting in cascading failures. The circuit breaker protects your system from stacking requests to unhealthy services, resulting in cascading failures.

View file

@ -3,7 +3,7 @@
Compress Responses before Sending them to the Client Compress Responses before Sending them to the Client
{: .subtitle } {: .subtitle }
![Compress](../assets/img/middleware/compress.png) ![Compress](../../assets/img/middleware/compress.png)
The Compress middleware uses gzip compression. The Compress middleware uses gzip compression.

View file

@ -3,7 +3,7 @@
Adding Digest Authentication Adding Digest Authentication
{: .subtitle } {: .subtitle }
![BasicAuth](../assets/img/middleware/digestauth.png) ![BasicAuth](../../assets/img/middleware/digestauth.png)
The DigestAuth middleware restricts access to your services to known users. The DigestAuth middleware restricts access to your services to known users.

View file

@ -3,7 +3,7 @@
It Has Never Been Easier to Say That Something Went Wrong It Has Never Been Easier to Say That Something Went Wrong
{: .subtitle } {: .subtitle }
![ErrorPages](../assets/img/middleware/errorpages.png) ![ErrorPages](../../assets/img/middleware/errorpages.png)
The ErrorPage middleware returns a custom page in lieu of the default, according to configured ranges of HTTP Status codes. The ErrorPage middleware returns a custom page in lieu of the default, according to configured ranges of HTTP Status codes.

View file

@ -3,7 +3,7 @@
Using an External Service to Forward Authentication Using an External Service to Forward Authentication
{: .subtitle } {: .subtitle }
![AuthForward](../assets/img/middleware/authforward.png) ![AuthForward](../../assets/img/middleware/authforward.png)
The ForwardAuth middleware delegates authentication to an external service. The ForwardAuth middleware delegates authentication to an external service.
If the service answers with a 2XX code, access is granted, and the original request is performed. If the service answers with a 2XX code, access is granted, and the original request is performed.

View file

@ -3,7 +3,7 @@
Managing Request/Response headers Managing Request/Response headers
{: .subtitle } {: .subtitle }
![Headers](../assets/img/middleware/headers.png) ![Headers](../../assets/img/middleware/headers.png)
The Headers middleware manages the headers of requests and responses. The Headers middleware manages the headers of requests and responses.
@ -349,7 +349,7 @@ The `hostsProxyHeaders` option is a set of header keys that may hold a proxied h
!!! warning !!! warning
Deprecated in favor of [EntryPoint redirection](../routing/entrypoints.md#redirection) or the [RedirectScheme middleware](./redirectscheme.md). Deprecated in favor of [EntryPoint redirection](../../routing/entrypoints.md#redirection) or the [RedirectScheme middleware](./redirectscheme.md).
The `sslRedirect` only allow HTTPS requests when set to `true`. The `sslRedirect` only allow HTTPS requests when set to `true`.
@ -357,7 +357,7 @@ The `sslRedirect` only allow HTTPS requests when set to `true`.
!!! warning !!! warning
Deprecated in favor of [EntryPoint redirection](../routing/entrypoints.md#redirection) or the [RedirectScheme middleware](./redirectscheme.md). Deprecated in favor of [EntryPoint redirection](../../routing/entrypoints.md#redirection) or the [RedirectScheme middleware](./redirectscheme.md).
Set `sslTemporaryRedirect` to `true` to force an SSL redirection using a 302 (instead of a 301). Set `sslTemporaryRedirect` to `true` to force an SSL redirection using a 302 (instead of a 301).

View file

@ -3,7 +3,7 @@
Limiting the Number of Simultaneous In-Flight Requests Limiting the Number of Simultaneous In-Flight Requests
{: .subtitle } {: .subtitle }
![InFlightReq](../assets/img/middleware/inflightreq.png) ![InFlightReq](../../assets/img/middleware/inflightreq.png)
To proactively prevent services from being overwhelmed with high load, the number of allowed simultaneous in-flight requests can be limited. To proactively prevent services from being overwhelmed with high load, the number of allowed simultaneous in-flight requests can be limited.

View file

@ -3,7 +3,7 @@
Limiting Clients to Specific IPs Limiting Clients to Specific IPs
{: .subtitle } {: .subtitle }
![IpWhiteList](../assets/img/middleware/ipwhitelist.png) ![IpWhiteList](../../assets/img/middleware/ipwhitelist.png)
IPWhitelist accepts / refuses requests based on the client IP. IPWhitelist accepts / refuses requests based on the client IP.

View file

@ -0,0 +1,149 @@
# HTTP Middlewares
Controlling connections
{: .subtitle }
![Overview](../../assets/img/middleware/overview.png)
## Configuration Example
```yaml tab="Docker"
# As a Docker Label
whoami:
# A container that exposes an API to show its IP address
image: traefik/whoami
labels:
# Create a middleware named `foo-add-prefix`
- "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo"
# Apply the middleware named `foo-add-prefix` to the router named `router1`
- "traefik.http.routers.router1.middlewares=foo-add-prefix@docker"
```
```yaml tab="Kubernetes IngressRoute"
# As a Kubernetes Traefik IngressRoute
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: middlewares.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: Middleware
plural: middlewares
singular: middleware
scope: Namespaced
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: stripprefix
spec:
stripPrefix:
prefixes:
- /stripit
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroute
spec:
# more fields...
routes:
# more fields...
middlewares:
- name: stripprefix
```
```yaml tab="Consul Catalog"
# Create a middleware named `foo-add-prefix`
- "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo"
# Apply the middleware named `foo-add-prefix` to the router named `router1`
- "traefik.http.routers.router1.middlewares=foo-add-prefix@consulcatalog"
```
```json tab="Marathon"
"labels": {
"traefik.http.middlewares.foo-add-prefix.addprefix.prefix": "/foo",
"traefik.http.routers.router1.middlewares": "foo-add-prefix@marathon"
}
```
```yaml tab="Rancher"
# As a Rancher Label
labels:
# Create a middleware named `foo-add-prefix`
- "traefik.http.middlewares.foo-add-prefix.addprefix.prefix=/foo"
# Apply the middleware named `foo-add-prefix` to the router named `router1`
- "traefik.http.routers.router1.middlewares=foo-add-prefix@rancher"
```
```toml tab="File (TOML)"
# As TOML Configuration File
[http.routers]
[http.routers.router1]
service = "myService"
middlewares = ["foo-add-prefix"]
rule = "Host(`example.com`)"
[http.middlewares]
[http.middlewares.foo-add-prefix.addPrefix]
prefix = "/foo"
[http.services]
[http.services.service1]
[http.services.service1.loadBalancer]
[[http.services.service1.loadBalancer.servers]]
url = "http://127.0.0.1:80"
```
```yaml tab="File (YAML)"
# As YAML Configuration File
http:
routers:
router1:
service: myService
middlewares:
- "foo-add-prefix"
rule: "Host(`example.com`)"
middlewares:
foo-add-prefix:
addPrefix:
prefix: "/foo"
services:
service1:
loadBalancer:
servers:
- url: "http://127.0.0.1:80"
```
## Available HTTP Middlewares
| Middleware | Purpose | Area |
|-------------------------------------------|---------------------------------------------------|-----------------------------|
| [AddPrefix](addprefix.md) | Add a Path Prefix | Path Modifier |
| [BasicAuth](basicauth.md) | Basic auth mechanism | Security, Authentication |
| [Buffering](buffering.md) | Buffers the request/response | Request Lifecycle |
| [Chain](chain.md) | Combine multiple pieces of middleware | Middleware tool |
| [CircuitBreaker](circuitbreaker.md) | Stop calling unhealthy services | Request Lifecycle |
| [Compress](compress.md) | Compress the response | Content Modifier |
| [DigestAuth](digestauth.md) | Adds Digest Authentication | Security, Authentication |
| [Errors](errorpages.md) | Define custom error pages | Request Lifecycle |
| [ForwardAuth](forwardauth.md) | Authentication delegation | Security, Authentication |
| [Headers](headers.md) | Add / Update headers | Security |
| [IPWhiteList](ipwhitelist.md) | Limit the allowed client IPs | Security, Request lifecycle |
| [InFlightReq](inflightreq.md) | Limit the number of simultaneous connections | Security, Request lifecycle |
| [PassTLSClientCert](passtlsclientcert.md) | Adding Client Certificates in a Header | Security |
| [RateLimit](ratelimit.md) | Limit the call frequency | Security, Request lifecycle |
| [RedirectScheme](redirectscheme.md) | Redirect easily the client elsewhere | Request lifecycle |
| [RedirectRegex](redirectregex.md) | Redirect the client elsewhere | Request lifecycle |
| [ReplacePath](replacepath.md) | Change the path of the request | Path Modifier |
| [ReplacePathRegex](replacepathregex.md) | Change the path of the request | Path Modifier |
| [Retry](retry.md) | Automatically retry the request in case of errors | Request lifecycle |
| [StripPrefix](stripprefix.md) | Change the path of the request | Path Modifier |
| [StripPrefixRegex](stripprefixregex.md) | Change the path of the request | Path Modifier |

View file

@ -248,7 +248,7 @@ PassTLSClientCert can add two headers to the request:
!!! info !!! info
* The headers are filled with escaped string so it can be safely placed inside a URL query. * The headers are filled with escaped string so it can be safely placed inside a URL query.
* These options only work accordingly to the [MutualTLS configuration](../https/tls.md#client-authentication-mtls). * These options only work accordingly to the [MutualTLS configuration](../../https/tls.md#client-authentication-mtls).
That is to say, only the certificates that match the `clientAuth.clientAuthType` policy are passed. That is to say, only the certificates that match the `clientAuth.clientAuthType` policy are passed.
The following example shows a complete certificate and explains each of the middleware options. The following example shows a complete certificate and explains each of the middleware options.

View file

@ -9,7 +9,7 @@ Attached to the routers, pieces of middleware are a means of tweaking the reques
There are several available middleware in Traefik, some can modify the request, the headers, some are in charge of redirections, some add authentication, and so on. There are several available middleware in Traefik, some can modify the request, the headers, some are in charge of redirections, some add authentication, and so on.
Pieces of middleware can be combined in chains to fit every scenario. Middlewares that use the same protocol can be combined into chains to fit every scenario.
!!! warning "Provider Namespace" !!! warning "Provider Namespace"
@ -121,26 +121,6 @@ http:
## Available Middlewares ## Available Middlewares
| Middleware | Purpose | Area | A list of HTTP middlewares can be found [here](http/overview.md).
|-------------------------------------------|---------------------------------------------------|-----------------------------|
| [AddPrefix](addprefix.md) | Add a Path Prefix | Path Modifier | A list of TCP middlewares can be found [here](tcp/overview.md).
| [BasicAuth](basicauth.md) | Basic auth mechanism | Security, Authentication |
| [Buffering](buffering.md) | Buffers the request/response | Request Lifecycle |
| [Chain](chain.md) | Combine multiple pieces of middleware | Middleware tool |
| [CircuitBreaker](circuitbreaker.md) | Stop calling unhealthy services | Request Lifecycle |
| [Compress](compress.md) | Compress the response | Content Modifier |
| [DigestAuth](digestauth.md) | Adds Digest Authentication | Security, Authentication |
| [Errors](errorpages.md) | Define custom error pages | Request Lifecycle |
| [ForwardAuth](forwardauth.md) | Authentication delegation | Security, Authentication |
| [Headers](headers.md) | Add / Update headers | Security |
| [IPWhiteList](ipwhitelist.md) | Limit the allowed client IPs | Security, Request lifecycle |
| [InFlightReq](inflightreq.md) | Limit the number of simultaneous connections | Security, Request lifecycle |
| [PassTLSClientCert](passtlsclientcert.md) | Adding Client Certificates in a Header | Security |
| [RateLimit](ratelimit.md) | Limit the call frequency | Security, Request lifecycle |
| [RedirectScheme](redirectscheme.md) | Redirect easily the client elsewhere | Request lifecycle |
| [RedirectRegex](redirectregex.md) | Redirect the client elsewhere | Request lifecycle |
| [ReplacePath](replacepath.md) | Change the path of the request | Path Modifier |
| [ReplacePathRegex](replacepathregex.md) | Change the path of the request | Path Modifier |
| [Retry](retry.md) | Automatically retry the request in case of errors | Request lifecycle |
| [StripPrefix](stripprefix.md) | Change the path of the request | Path Modifier |
| [StripPrefixRegex](stripprefixregex.md) | Change the path of the request | Path Modifier |

View file

@ -0,0 +1,67 @@
# IPWhiteList
Limiting Clients to Specific IPs
{: .subtitle }
IPWhitelist accepts / refuses connections based on the client IP.
## Configuration Examples
```yaml tab="Docker"
# Accepts connections from defined IP
labels:
- "traefik.tcp.middlewares.test-ipwhitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7"
```
```yaml tab="Kubernetes"
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: test-ipwhitelist
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
- 192.168.1.7
```
```yaml tab="Consul Catalog"
# Accepts request from defined IP
- "traefik.tcp.middlewares.test-ipwhitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7"
```
```json tab="Marathon"
"labels": {
"traefik.tcp.middlewares.test-ipwhitelist.ipwhitelist.sourcerange": "127.0.0.1/32,192.168.1.7"
}
```
```yaml tab="Rancher"
# Accepts request from defined IP
labels:
- "traefik.tcp.middlewares.test-ipwhitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7"
```
```toml tab="File (TOML)"
# Accepts request from defined IP
[tcp.middlewares]
[tcp.middlewares.test-ipwhitelist.ipWhiteList]
sourceRange = ["127.0.0.1/32", "192.168.1.7"]
```
```yaml tab="File (YAML)"
# Accepts request from defined IP
http:
middlewares:
test-ipwhitelist:
ipWhiteList:
sourceRange:
- "127.0.0.1/32"
- "192.168.1.7"
```
## Configuration Options
### `sourceRange`
The `sourceRange` option sets the allowed IPs (or ranges of allowed IPs by using CIDR notation).

View file

@ -0,0 +1,134 @@
# TCP Middlewares
Controlling connections
{: .subtitle }
![Overview](../../assets/img/middleware/overview.png)
## Configuration Example
```yaml tab="Docker"
# As a Docker Label
whoami:
# A container that exposes an API to show its IP address
image: traefik/whoami
labels:
# Create a middleware named `foo-ip-whitelist`
- "traefik.tcp.middlewares.foo-ip-whitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7"
# Apply the middleware named `foo-ip-whitelist` to the router named `router1`
- "traefik.tcp.routers.router1.middlewares=foo-ip-whitelist@docker"
```
```yaml tab="Kubernetes IngressRoute"
# As a Kubernetes Traefik IngressRoute
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: middlewaretcps.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: MiddlewareTCP
plural: middlewaretcps
singular: middlewaretcp
scope: Namespaced
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: foo-ip-whitelist
spec:
ipWhiteList:
sourcerange:
- 127.0.0.1/32
- 192.168.1.7
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroute
spec:
# more fields...
routes:
# more fields...
middlewares:
- name: foo-ip-whitelist
```
```yaml tab="Consul Catalog"
# Create a middleware named `foo-ip-whitelist`
- "traefik.tcp.middlewares.foo-ip-whitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7"
# Apply the middleware named `foo-ip-whitelist` to the router named `router1`
- "traefik.tcp.routers.router1.middlewares=foo-ip-whitelist@consulcatalog"
```
```json tab="Marathon"
"labels": {
"traefik.tcp.middlewares.foo-ip-whitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7",
"traefik.tcp.routers.router1.middlewares=foo-ip-whitelist@marathon"
}
```
```yaml tab="Rancher"
# As a Rancher Label
labels:
# Create a middleware named `foo-ip-whitelist`
- "traefik.tcp.middlewares.foo-ip-whitelist.ipwhitelist.sourcerange=127.0.0.1/32, 192.168.1.7"
# Apply the middleware named `foo-ip-whitelist` to the router named `router1`
- "traefik.tcp.routers.router1.middlewares=foo-ip-whitelist@rancher"
```
```toml tab="File (TOML)"
# As TOML Configuration File
[tcp.routers]
[tcp.routers.router1]
service = "myService"
middlewares = ["foo-ip-whitelist"]
rule = "Host(`example.com`)"
[tcp.middlewares]
[tcp.middlewares.foo-ip-whitelist.ipWhiteList]
sourceRange = ["127.0.0.1/32", "192.168.1.7"]
[tcp.services]
[tcp.services.service1]
[tcp.services.service1.loadBalancer]
[[tcp.services.service1.loadBalancer.servers]]
address = "10.0.0.10:4000"
[[tcp.services.service1.loadBalancer.servers]]
address = "10.0.0.11:4000"
```
```yaml tab="File (YAML)"
# As YAML Configuration File
tcp:
routers:
router1:
service: myService
middlewares:
- "foo-ip-whitelist"
rule: "Host(`example.com`)"
middlewares:
foo-ip-whitelist:
ipWhiteList:
sourceRange:
- "127.0.0.1/32"
- "192.168.1.7"
services:
service1:
loadBalancer:
servers:
- address: "10.0.0.10:4000"
- address: "10.0.0.11:4000"
```
## Available TCP Middlewares
| Middleware | Purpose | Area |
|-------------------------------------------|---------------------------------------------------|-----------------------------|
| [IPWhiteList](ipwhitelist.md) | Limit the allowed client IPs | Security, Request lifecycle |

View file

@ -327,7 +327,7 @@ With Traefik v2 it is applied on an entry point or a [Router](../routing/routers
To apply a redirection: To apply a redirection:
- on an entry point, the [HTTP redirection](../routing/entrypoints.md#redirection) has to be configured. - on an entry point, the [HTTP redirection](../routing/entrypoints.md#redirection) has to be configured.
- on a router, one of the redirect middlewares, [RedirectRegex](../middlewares/redirectregex.md) or [RedirectScheme](../middlewares/redirectscheme.md), has to be configured and added to the router middlewares list. - on a router, one of the redirect middlewares, [RedirectRegex](../middlewares/http/redirectregex.md) or [RedirectScheme](../middlewares/http/redirectscheme.md), has to be configured and added to the router middlewares list.
!!! example "Global HTTP to HTTPS redirection" !!! example "Global HTTP to HTTPS redirection"
@ -545,7 +545,7 @@ Use Case: Incoming requests to `http://example.org/admin` are forwarded to the w
with the path `/admin` stripped, e.g. to `http://<IP>:<port>/`. In this case, you must: with the path `/admin` stripped, e.g. to `http://<IP>:<port>/`. In this case, you must:
- First, configure a router named `admin` with a rule matching at least the path prefix with the `PathPrefix` keyword, - First, configure a router named `admin` with a rule matching at least the path prefix with the `PathPrefix` keyword,
- Then, define a middleware of type [`stripprefix`](../middlewares/stripprefix.md), which removes the prefix `/admin`, associated to the router `admin`. - Then, define a middleware of type [`stripprefix`](../middlewares/http/stripprefix.md), which removes the prefix `/admin`, associated to the router `admin`.
!!! example "Strip Path Prefix When Forwarding to Backend" !!! example "Strip Path Prefix When Forwarding to Backend"
@ -660,12 +660,12 @@ with the path `/admin` stripped, e.g. to `http://<IP>:<port>/`. In this case, yo
??? question "What About Other Path Transformations?" ??? question "What About Other Path Transformations?"
Instead of removing the path prefix with the [`stripprefix` middleware](../../middlewares/stripprefix/), you can also: Instead of removing the path prefix with the [`stripprefix` middleware](../../middlewares/http/stripprefix/), you can also:
- Add a path prefix with the [`addprefix` middleware](../../middlewares/addprefix/) - Add a path prefix with the [`addprefix` middleware](../../middlewares/http/addprefix/)
- Replace the complete path of the request with the [`replacepath` middleware](../../middlewares/replacepath/) - Replace the complete path of the request with the [`replacepath` middleware](../../middlewares/http/replacepath/)
- ReplaceRewrite path using Regexp with the [`replacepathregex` middleware](../../middlewares/replacepathregex/) - ReplaceRewrite path using Regexp with the [`replacepathregex` middleware](../../middlewares/http/replacepathregex/)
- And a lot more on the [`middlewares` page](../../middlewares/overview/) - And a lot more on the [`HTTP middlewares` page](../../middlewares/http/overview/)
## ACME (LetsEncrypt) ## ACME (LetsEncrypt)

View file

@ -395,7 +395,7 @@ The support of the `networking.k8s.io/v1beta1` API Version will stop in Kubernet
For simple HTTP to HTTPS redirection, you may use [EntryPoints redirections](../routing/entrypoints.md#redirection). For simple HTTP to HTTPS redirection, you may use [EntryPoints redirections](../routing/entrypoints.md#redirection).
For more advanced use cases, you can use either the [RedirectScheme middleware](../middlewares/redirectscheme.md) or the [RedirectRegex middleware](../middlewares/redirectregex.md). For more advanced use cases, you can use either the [RedirectScheme middleware](../middlewares/http/redirectscheme.md) or the [RedirectRegex middleware](../middlewares/http/redirectregex.md).
### Headers middleware: accessControlAllowOrigin ### Headers middleware: accessControlAllowOrigin

View file

@ -66,8 +66,8 @@ with a router attached to the service `api@internal` in the
to allow defining: to allow defining:
- One or more security features through [middlewares](../middlewares/overview.md) - One or more security features through [middlewares](../middlewares/overview.md)
like authentication ([basicAuth](../middlewares/basicauth.md) , [digestAuth](../middlewares/digestauth.md), like authentication ([basicAuth](../middlewares/http/basicauth.md) , [digestAuth](../middlewares/http/digestauth.md),
[forwardAuth](../middlewares/forwardauth.md)) or [whitelisting](../middlewares/ipwhitelist.md). [forwardAuth](../middlewares/http/forwardauth.md)) or [whitelisting](../middlewares/http/ipwhitelist.md).
- A [router rule](#dashboard-router-rule) for accessing the dashboard, - A [router rule](#dashboard-router-rule) for accessing the dashboard,
through Traefik itself (sometimes referred as "Traefik-ception"). through Traefik itself (sometimes referred as "Traefik-ception").

View file

@ -159,7 +159,9 @@
- "traefik.http.services.service01.loadbalancer.server.port=foobar" - "traefik.http.services.service01.loadbalancer.server.port=foobar"
- "traefik.http.services.service01.loadbalancer.server.scheme=foobar" - "traefik.http.services.service01.loadbalancer.server.scheme=foobar"
- "traefik.http.services.service01.loadbalancer.serverstransport=foobar" - "traefik.http.services.service01.loadbalancer.serverstransport=foobar"
- "traefik.tcp.middlewares.middleware00.ipwhitelist.sourcerange=foobar, foobar"
- "traefik.tcp.routers.tcprouter0.entrypoints=foobar, foobar" - "traefik.tcp.routers.tcprouter0.entrypoints=foobar, foobar"
- "traefik.tcp.routers.tcprouter0.middlewares=foobar, foobar"
- "traefik.tcp.routers.tcprouter0.rule=foobar" - "traefik.tcp.routers.tcprouter0.rule=foobar"
- "traefik.tcp.routers.tcprouter0.service=foobar" - "traefik.tcp.routers.tcprouter0.service=foobar"
- "traefik.tcp.routers.tcprouter0.tls=true" - "traefik.tcp.routers.tcprouter0.tls=true"
@ -171,6 +173,7 @@
- "traefik.tcp.routers.tcprouter0.tls.options=foobar" - "traefik.tcp.routers.tcprouter0.tls.options=foobar"
- "traefik.tcp.routers.tcprouter0.tls.passthrough=true" - "traefik.tcp.routers.tcprouter0.tls.passthrough=true"
- "traefik.tcp.routers.tcprouter1.entrypoints=foobar, foobar" - "traefik.tcp.routers.tcprouter1.entrypoints=foobar, foobar"
- "traefik.tcp.routers.tcprouter1.middlewares=foobar, foobar"
- "traefik.tcp.routers.tcprouter1.rule=foobar" - "traefik.tcp.routers.tcprouter1.rule=foobar"
- "traefik.tcp.routers.tcprouter1.service=foobar" - "traefik.tcp.routers.tcprouter1.service=foobar"
- "traefik.tcp.routers.tcprouter1.tls=true" - "traefik.tcp.routers.tcprouter1.tls=true"

View file

@ -310,6 +310,7 @@
[tcp.routers] [tcp.routers]
[tcp.routers.TCPRouter0] [tcp.routers.TCPRouter0]
entryPoints = ["foobar", "foobar"] entryPoints = ["foobar", "foobar"]
middlewares = ["foobar", "foobar"]
service = "foobar" service = "foobar"
rule = "foobar" rule = "foobar"
[tcp.routers.TCPRouter0.tls] [tcp.routers.TCPRouter0.tls]
@ -326,6 +327,7 @@
sans = ["foobar", "foobar"] sans = ["foobar", "foobar"]
[tcp.routers.TCPRouter1] [tcp.routers.TCPRouter1]
entryPoints = ["foobar", "foobar"] entryPoints = ["foobar", "foobar"]
middlewares = ["foobar", "foobar"]
service = "foobar" service = "foobar"
rule = "foobar" rule = "foobar"
[tcp.routers.TCPRouter1.tls] [tcp.routers.TCPRouter1.tls]
@ -362,6 +364,10 @@
[[tcp.services.TCPService02.weighted.services]] [[tcp.services.TCPService02.weighted.services]]
name = "foobar" name = "foobar"
weight = 42 weight = 42
[tcp.middlewares]
[tcp.middlewares.Middleware00]
[tcp.middlewares.Middleware00.ipWhiteList]
sourceRange = ["foobar", "foobar"]
[udp] [udp]
[udp.routers] [udp.routers]

View file

@ -350,6 +350,9 @@ tcp:
entryPoints: entryPoints:
- foobar - foobar
- foobar - foobar
middlewares:
- foobar
- foobar
service: foobar service: foobar
rule: foobar rule: foobar
tls: tls:
@ -369,6 +372,9 @@ tcp:
entryPoints: entryPoints:
- foobar - foobar
- foobar - foobar
middlewares:
- foobar
- foobar
service: foobar service: foobar
rule: foobar rule: foobar
tls: tls:
@ -384,6 +390,12 @@ tcp:
sans: sans:
- foobar - foobar
- foobar - foobar
middlewares:
Middleware00:
ipWhiteList:
sourceRange:
- foobar
- foobar
services: services:
TCPService01: TCPService01:
loadBalancer: loadBalancer:

View file

@ -27,6 +27,21 @@ spec:
singular: middleware singular: middleware
scope: Namespaced scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: middlewaretcps.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: MiddlewareTCP
plural: middlewaretcps
singular: middlewaretcp
scope: Namespaced
--- ---
apiVersion: apiextensions.k8s.io/v1beta1 apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition kind: CustomResourceDefinition

View file

@ -34,6 +34,7 @@ rules:
- traefik.containo.us - traefik.containo.us
resources: resources:
- middlewares - middlewares
- middlewaretcps
- ingressroutes - ingressroutes
- traefikservices - traefikservices
- ingressroutetcps - ingressroutetcps

View file

@ -147,6 +147,8 @@ spec:
services: services:
- name: whoamitcp - name: whoamitcp
port: 8080 port: 8080
middlewares:
- name: ipwhitelist
tls: tls:
secretName: foosecret secretName: foosecret
passthrough: false passthrough: false

View file

@ -220,8 +220,12 @@
| `traefik/http/services/Service03/weighted/sticky/cookie/name` | `foobar` | | `traefik/http/services/Service03/weighted/sticky/cookie/name` | `foobar` |
| `traefik/http/services/Service03/weighted/sticky/cookie/sameSite` | `foobar` | | `traefik/http/services/Service03/weighted/sticky/cookie/sameSite` | `foobar` |
| `traefik/http/services/Service03/weighted/sticky/cookie/secure` | `true` | | `traefik/http/services/Service03/weighted/sticky/cookie/secure` | `true` |
| `traefik/tcp/middlewares/Middleware00/ipWhiteList/sourceRange/0` | `foobar` |
| `traefik/tcp/middlewares/Middleware00/ipWhiteList/sourceRange/1` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/entryPoints/0` | `foobar` | | `traefik/tcp/routers/TCPRouter0/entryPoints/0` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/entryPoints/1` | `foobar` | | `traefik/tcp/routers/TCPRouter0/entryPoints/1` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/middlewares/0` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/middlewares/1` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/rule` | `foobar` | | `traefik/tcp/routers/TCPRouter0/rule` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/service` | `foobar` | | `traefik/tcp/routers/TCPRouter0/service` | `foobar` |
| `traefik/tcp/routers/TCPRouter0/tls/certResolver` | `foobar` | | `traefik/tcp/routers/TCPRouter0/tls/certResolver` | `foobar` |
@ -235,6 +239,8 @@
| `traefik/tcp/routers/TCPRouter0/tls/passthrough` | `true` | | `traefik/tcp/routers/TCPRouter0/tls/passthrough` | `true` |
| `traefik/tcp/routers/TCPRouter1/entryPoints/0` | `foobar` | | `traefik/tcp/routers/TCPRouter1/entryPoints/0` | `foobar` |
| `traefik/tcp/routers/TCPRouter1/entryPoints/1` | `foobar` | | `traefik/tcp/routers/TCPRouter1/entryPoints/1` | `foobar` |
| `traefik/tcp/routers/TCPRouter1/middlewares/0` | `foobar` |
| `traefik/tcp/routers/TCPRouter1/middlewares/1` | `foobar` |
| `traefik/tcp/routers/TCPRouter1/rule` | `foobar` | | `traefik/tcp/routers/TCPRouter1/rule` | `foobar` |
| `traefik/tcp/routers/TCPRouter1/service` | `foobar` | | `traefik/tcp/routers/TCPRouter1/service` | `foobar` |
| `traefik/tcp/routers/TCPRouter1/tls/certResolver` | `foobar` | | `traefik/tcp/routers/TCPRouter1/tls/certResolver` | `foobar` |

View file

@ -47,6 +47,21 @@ spec:
properties: properties:
match: match:
type: string type: string
middlewares:
description: Middlewares contains references to MiddlewareTCP
resources.
items:
description: ObjectReference is a generic reference to a Traefik
resource.
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
type: array
services: services:
items: items:
description: ServiceTCP defines an upstream to proxy traffic. description: ServiceTCP defines an upstream to proxy traffic.

View file

@ -0,0 +1,59 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: middlewaretcps.traefik.containo.us
spec:
group: traefik.containo.us
names:
kind: MiddlewareTCP
listKind: MiddlewareTCPList
plural: middlewaretcps
singular: middlewaretcp
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: MiddlewareTCP is a specification for a MiddlewareTCP resource.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: MiddlewareTCPSpec holds the MiddlewareTCP configuration.
properties:
ipWhiteList:
description: TCPIPWhiteList holds the TCP ip white list configuration.
properties:
sourceRange:
items:
type: string
type: array
type: object
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

View file

@ -22,7 +22,7 @@ If they do, the router might transform the request using pieces of [middleware](
## Example with a File Provider ## Example with a File Provider
Below is an example of a full configuration file for the [file provider](../providers/file.md) that forwards `http://domain/whoami/` requests to a service reachable on `http://private/whoami-service/`. Below is an example of a full configuration file for the [file provider](../providers/file.md) that forwards `http://domain/whoami/` requests to a service reachable on `http://private/whoami-service/`.
In the process, Traefik will make sure that the user is authenticated (using the [BasicAuth middleware](../middlewares/basicauth.md)). In the process, Traefik will make sure that the user is authenticated (using the [BasicAuth middleware](../middlewares/http/basicauth.md)).
Static configuration: Static configuration:

View file

@ -263,7 +263,7 @@ you'd add the tag `traefik.http.services.{name-of-your-choice}.loadbalancer.pass
You can declare pieces of middleware using tags starting with `traefik.http.middlewares.{name-of-your-choice}.`, followed by the middleware type/options. You can declare pieces of middleware using tags starting with `traefik.http.middlewares.{name-of-your-choice}.`, followed by the middleware type/options.
For example, to declare a middleware [`redirectscheme`](../../middlewares/redirectscheme.md) named `my-redirect`, you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme: https`. For example, to declare a middleware [`redirectscheme`](../../middlewares/http/redirectscheme.md) named `my-redirect`, you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme: https`.
More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md). More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md).

View file

@ -419,7 +419,7 @@ you'd add the label `traefik.http.services.<name-of-your-choice>.loadbalancer.pa
You can declare pieces of middleware using labels starting with `traefik.http.middlewares.<name-of-your-choice>.`, You can declare pieces of middleware using labels starting with `traefik.http.middlewares.<name-of-your-choice>.`,
followed by the middleware type/options. followed by the middleware type/options.
For example, to declare a middleware [`redirectscheme`](../../middlewares/redirectscheme.md) named `my-redirect`, For example, to declare a middleware [`redirectscheme`](../../middlewares/http/redirectscheme.md) named `my-redirect`,
you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme=https`. you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme=https`.
More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md). More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md).

View file

@ -268,7 +268,7 @@ you'd add the label `traefik.http.services.{name-of-your-choice}.loadbalancer.pa
You can declare pieces of middleware using labels starting with `traefik.http.middlewares.{name-of-your-choice}.`, followed by the middleware type/options. You can declare pieces of middleware using labels starting with `traefik.http.middlewares.{name-of-your-choice}.`, followed by the middleware type/options.
For example, to declare a middleware [`redirectscheme`](../../middlewares/redirectscheme.md) named `my-redirect`, you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme: https`. For example, to declare a middleware [`redirectscheme`](../../middlewares/http/redirectscheme.md) named `my-redirect`, you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme: https`.
More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md). More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md).

View file

@ -293,7 +293,7 @@ For example, to change the passHostHeader behavior, you'd add the label `"traefi
You can declare pieces of middleware using labels starting with `traefik.http.middlewares.{middleware-name-of-your-choice}.`, followed by the middleware type/options. You can declare pieces of middleware using labels starting with `traefik.http.middlewares.{middleware-name-of-your-choice}.`, followed by the middleware type/options.
For example, to declare a middleware [`redirectscheme`](../../middlewares/redirectscheme.md) named `my-redirect`, you'd write `"traefik.http.middlewares.my-redirect.redirectscheme.scheme": "https"`. For example, to declare a middleware [`redirectscheme`](../../middlewares/http/redirectscheme.md) named `my-redirect`, you'd write `"traefik.http.middlewares.my-redirect.redirectscheme.scheme": "https"`.
More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md). More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md).

View file

@ -299,7 +299,7 @@ you'd add the label `traefik.http.services.{name-of-your-choice}.loadbalancer.pa
You can declare pieces of middleware using labels starting with `traefik.http.middlewares.{name-of-your-choice}.`, followed by the middleware type/options. You can declare pieces of middleware using labels starting with `traefik.http.middlewares.{name-of-your-choice}.`, followed by the middleware type/options.
For example, to declare a middleware [`redirectscheme`](../../middlewares/redirectscheme.md) named `my-redirect`, you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme: https`. For example, to declare a middleware [`redirectscheme`](../../middlewares/http/redirectscheme.md) named `my-redirect`, you'd write `traefik.http.middlewares.my-redirect.redirectscheme.scheme: https`.
More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md). More information about available middlewares in the dedicated [middlewares section](../../middlewares/overview.md).

View file

@ -808,6 +808,41 @@ If you want to limit the router scope to a set of entry points, set the entry po
Hence, only TLS routers will be able to specify a domain name with that rule. Hence, only TLS routers will be able to specify a domain name with that rule.
However, non-TLS routers will have to explicitly use that rule with `*` (every domain) to state that every non-TLS request will be handled by the router. However, non-TLS routers will have to explicitly use that rule with `*` (every domain) to state that every non-TLS request will be handled by the router.
### Middlewares
You can attach a list of [middlewares](../../middlewares/overview.md) to each TCP router.
The middlewares will take effect only if the rule matches, and before connecting to the service.
!!! warning "The character `@` is not allowed to be used in the middleware name."
!!! tip "Middlewares order"
Middlewares are applied in the same order as their declaration in **router**.
??? example "With a [middleware](../../middlewares/tcp/overview.md) -- using the [File Provider](../../providers/file.md)"
```toml tab="TOML"
## Dynamic configuration
[tcp.routers]
[tcp.routers.my-router]
rule = "HostSNI(`*`)"
# declared elsewhere
middlewares = ["ipwhitelist"]
service = "service-foo"
```
```yaml tab="YAML"
## Dynamic configuration
tcp:
routers:
my-router:
rule: "HostSNI(`*`)"
# declared elsewhere
middlewares:
- ipwhitelist
service: service-foo
```
### Services ### Services
You must attach a TCP [service](../services/index.md) per TCP router. You must attach a TCP [service](../services/index.md) per TCP router.

View file

@ -116,7 +116,7 @@ The `url` option point to a specific instance.
!!! info "" !!! info ""
Paths in the servers' `url` have no effect. Paths in the servers' `url` have no effect.
If you want the requests to be sent to a specific path on your servers, If you want the requests to be sent to a specific path on your servers,
configure your [`routers`](../routers/index.md) to use a corresponding [middleware](../../middlewares/overview.md) (e.g. the [AddPrefix](../../middlewares/addprefix.md) or [ReplacePath](../../middlewares/replacepath.md)) middlewares. configure your [`routers`](../routers/index.md) to use a corresponding [middleware](../../middlewares/overview.md) (e.g. the [AddPrefix](../../middlewares/http/addprefix.md) or [ReplacePath](../../middlewares/http/replacepath.md)) middlewares.
??? example "A Service with One Server -- Using the [File Provider](../../providers/file.md)" ??? example "A Service with One Server -- Using the [File Provider](../../providers/file.md)"

View file

@ -57,7 +57,7 @@ Beginning with version 1.4, Traefik respects readiness check results if the Trae
Due to the way readiness check results are currently exposed by the Marathon API, ready tasks may be taken into rotation with a small delay. Due to the way readiness check results are currently exposed by the Marathon API, ready tasks may be taken into rotation with a small delay.
It is on the order of one readiness check timeout interval (as configured on the application specification) and guarantees that non-ready tasks do not receive traffic prematurely. It is on the order of one readiness check timeout interval (as configured on the application specification) and guarantees that non-ready tasks do not receive traffic prematurely.
If readiness checks are not possible, a current mitigation strategy is to enable [retries](../middlewares/retry.md) and make sure that a sufficient number of healthy application tasks exist so that one retry will likely hit one of those. If readiness checks are not possible, a current mitigation strategy is to enable [retries](../middlewares/http/retry.md) and make sure that a sufficient number of healthy application tasks exist so that one retry will likely hit one of those.
Apart from its probabilistic nature, the workaround comes at the price of increased latency. Apart from its probabilistic nature, the workaround comes at the price of increased latency.
#### Shutdown #### Shutdown

View file

@ -105,28 +105,33 @@ nav:
- 'Let''s Encrypt': 'https/acme.md' - 'Let''s Encrypt': 'https/acme.md'
- 'Middlewares': - 'Middlewares':
- 'Overview': 'middlewares/overview.md' - 'Overview': 'middlewares/overview.md'
- 'AddPrefix': 'middlewares/addprefix.md' - 'HTTP':
- 'BasicAuth': 'middlewares/basicauth.md' - 'Overview': 'middlewares/http/overview.md'
- 'Buffering': 'middlewares/buffering.md' - 'AddPrefix': 'middlewares/http/addprefix.md'
- 'Chain': 'middlewares/chain.md' - 'BasicAuth': 'middlewares/http/basicauth.md'
- 'CircuitBreaker': 'middlewares/circuitbreaker.md' - 'Buffering': 'middlewares/http/buffering.md'
- 'Compress': 'middlewares/compress.md' - 'Chain': 'middlewares/http/chain.md'
- 'ContentType': 'middlewares/contenttype.md' - 'CircuitBreaker': 'middlewares/http/circuitbreaker.md'
- 'DigestAuth': 'middlewares/digestauth.md' - 'Compress': 'middlewares/http/compress.md'
- 'Errors': 'middlewares/errorpages.md' - 'ContentType': 'middlewares/http/contenttype.md'
- 'ForwardAuth': 'middlewares/forwardauth.md' - 'DigestAuth': 'middlewares/http/digestauth.md'
- 'Headers': 'middlewares/headers.md' - 'Errors': 'middlewares/http/errorpages.md'
- 'IpWhitelist': 'middlewares/ipwhitelist.md' - 'ForwardAuth': 'middlewares/http/forwardauth.md'
- 'InFlightReq': 'middlewares/inflightreq.md' - 'Headers': 'middlewares/http/headers.md'
- 'PassTLSClientCert': 'middlewares/passtlsclientcert.md' - 'IpWhitelist': 'middlewares/http/ipwhitelist.md'
- 'RateLimit': 'middlewares/ratelimit.md' - 'InFlightReq': 'middlewares/http/inflightreq.md'
- 'RedirectRegex': 'middlewares/redirectregex.md' - 'PassTLSClientCert': 'middlewares/http/passtlsclientcert.md'
- 'RedirectScheme': 'middlewares/redirectscheme.md' - 'RateLimit': 'middlewares/http/ratelimit.md'
- 'ReplacePath': 'middlewares/replacepath.md' - 'RedirectRegex': 'middlewares/http/redirectregex.md'
- 'ReplacePathRegex': 'middlewares/replacepathregex.md' - 'RedirectScheme': 'middlewares/http/redirectscheme.md'
- 'Retry': 'middlewares/retry.md' - 'ReplacePath': 'middlewares/http/replacepath.md'
- 'StripPrefix': 'middlewares/stripprefix.md' - 'ReplacePathRegex': 'middlewares/http/replacepathregex.md'
- 'StripPrefixRegex': 'middlewares/stripprefixregex.md' - 'Retry': 'middlewares/http/retry.md'
- 'StripPrefix': 'middlewares/http/stripprefix.md'
- 'StripPrefixRegex': 'middlewares/http/stripprefixregex.md'
- 'TCP':
- 'Overview': 'middlewares/tcp/overview.md'
- 'IpWhitelist': 'middlewares/tcp/ipwhitelist.md'
- 'Plugins & Traefik Pilot': 'plugins/index.md' - 'Plugins & Traefik Pilot': 'plugins/index.md'
- 'Operations': - 'Operations':
- 'CLI': 'operations/cli.md' - 'CLI': 'operations/cli.md'

View file

@ -245,6 +245,21 @@ spec:
properties: properties:
match: match:
type: string type: string
middlewares:
description: Middlewares contains references to MiddlewareTCP
resources.
items:
description: ObjectReference is a generic reference to a Traefik
resource.
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
type: array
services: services:
items: items:
description: ServiceTCP defines an upstream to proxy traffic. description: ServiceTCP defines an upstream to proxy traffic.
@ -989,6 +1004,65 @@ status:
conditions: [] conditions: []
storedVersions: [] storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: middlewaretcps.traefik.containo.us
spec:
group: traefik.containo.us
names:
kind: MiddlewareTCP
listKind: MiddlewareTCPList
plural: middlewaretcps
singular: middlewaretcp
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: MiddlewareTCP is a specification for a MiddlewareTCP resource.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: MiddlewareTCPSpec holds the MiddlewareTCP configuration.
properties:
ipWhiteList:
description: TCPIPWhiteList holds the TCP ip white list configuration.
properties:
sourceRange:
items:
type: string
type: array
type: object
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
--- ---
apiVersion: apiextensions.k8s.io/v1 apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition kind: CustomResourceDefinition

View file

@ -0,0 +1,55 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.tcp]
address = ":8093"
[api]
insecure = true
[providers.file]
filename = "{{ .SelfFilename }}"
## dynamic configuration ##
[tcp]
[tcp.routers]
[tcp.routers.to-whoami-a]
entryPoints = ["tcp"]
rule = "HostSNI(`whoami-a.test`)"
service = "whoami-a"
middlewares = ["blocking-ipwhitelist"]
[tcp.routers.to-whoami-a.tls]
passthrough = true
[tcp.routers.to-whoami-b]
entryPoints = ["tcp"]
rule = "HostSNI(`whoami-b.test`)"
service = "whoami-b"
middlewares = ["allowing-ipwhitelist"]
[tcp.routers.to-whoami-b.tls]
passthrough = true
[tcp.services]
[tcp.services.whoami-a.loadBalancer]
[[tcp.services.whoami-a.loadBalancer.servers]]
address = "localhost:8081"
[tcp.services.whoami-b.loadBalancer]
[[tcp.services.whoami-b.loadBalancer.servers]]
address = "localhost:8082"
[tcp.middlewares]
[tcp.middlewares.allowing-ipwhitelist.ipWhiteList]
sourceRange = ["127.0.0.1/32"]
[tcp.middlewares.blocking-ipwhitelist.ipWhiteList]
sourceRange = ["127.127.127.127/32"]
[[tls.certificates]]
certFile = "fixtures/tcp/whoami-c.crt"
keyFile = "fixtures/tcp/whoami-c.key"

View file

@ -200,6 +200,30 @@ func (s *TCPSuite) TestCatchAllNoTLSWithHTTPS(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
} }
func (s *TCPSuite) TestMiddlewareWhiteList(c *check.C) {
file := s.adaptFile(c, "fixtures/tcp/ip-whitelist.toml", struct{}{})
defer os.Remove(file)
cmd, display := s.traefikCmd(withConfigFile(file))
defer display(c)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer s.killCmd(cmd)
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 50*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("HostSNI(`whoami-a.test`)"))
c.Assert(err, checker.IsNil)
// Traefik not passes through, ipWhitelist closes connection
_, err = guessWho("127.0.0.1:8093", "whoami-a.test", true)
c.Assert(err, checker.NotNil)
// Traefik passes through, termination handled by whoami-b
out, err := guessWho("127.0.0.1:8093", "whoami-b.test", true)
c.Assert(err, checker.IsNil)
c.Assert(out, checker.Contains, "whoami-b")
}
func welcome(addr string) (string, error) { func welcome(addr string) (string, error) {
tcpAddr, err := net.ResolveTCPAddr("tcp", addr) tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
if err != nil { if err != nil {

View file

@ -40,6 +40,7 @@ type RunTimeRepresentation struct {
Middlewares map[string]*runtime.MiddlewareInfo `json:"middlewares,omitempty"` Middlewares map[string]*runtime.MiddlewareInfo `json:"middlewares,omitempty"`
Services map[string]*serviceInfoRepresentation `json:"services,omitempty"` Services map[string]*serviceInfoRepresentation `json:"services,omitempty"`
TCPRouters map[string]*runtime.TCPRouterInfo `json:"tcpRouters,omitempty"` TCPRouters map[string]*runtime.TCPRouterInfo `json:"tcpRouters,omitempty"`
TCPMiddlewares map[string]*runtime.TCPMiddlewareInfo `json:"tcpMiddlewares,omitempty"`
TCPServices map[string]*runtime.TCPServiceInfo `json:"tcpServices,omitempty"` TCPServices map[string]*runtime.TCPServiceInfo `json:"tcpServices,omitempty"`
UDPRouters map[string]*runtime.UDPRouterInfo `json:"udpRouters,omitempty"` UDPRouters map[string]*runtime.UDPRouterInfo `json:"udpRouters,omitempty"`
UDPServices map[string]*runtime.UDPServiceInfo `json:"udpServices,omitempty"` UDPServices map[string]*runtime.UDPServiceInfo `json:"udpServices,omitempty"`
@ -107,6 +108,8 @@ func (h Handler) createRouter() *mux.Router {
router.Methods(http.MethodGet).Path("/api/tcp/routers/{routerID}").HandlerFunc(h.getTCPRouter) router.Methods(http.MethodGet).Path("/api/tcp/routers/{routerID}").HandlerFunc(h.getTCPRouter)
router.Methods(http.MethodGet).Path("/api/tcp/services").HandlerFunc(h.getTCPServices) router.Methods(http.MethodGet).Path("/api/tcp/services").HandlerFunc(h.getTCPServices)
router.Methods(http.MethodGet).Path("/api/tcp/services/{serviceID}").HandlerFunc(h.getTCPService) router.Methods(http.MethodGet).Path("/api/tcp/services/{serviceID}").HandlerFunc(h.getTCPService)
router.Methods(http.MethodGet).Path("/api/tcp/middlewares").HandlerFunc(h.getTCPMiddlewares)
router.Methods(http.MethodGet).Path("/api/tcp/middlewares/{middlewareID}").HandlerFunc(h.getTCPMiddleware)
router.Methods(http.MethodGet).Path("/api/udp/routers").HandlerFunc(h.getUDPRouters) router.Methods(http.MethodGet).Path("/api/udp/routers").HandlerFunc(h.getUDPRouters)
router.Methods(http.MethodGet).Path("/api/udp/routers/{routerID}").HandlerFunc(h.getUDPRouter) router.Methods(http.MethodGet).Path("/api/udp/routers/{routerID}").HandlerFunc(h.getUDPRouter)
@ -136,6 +139,7 @@ func (h Handler) getRuntimeConfiguration(rw http.ResponseWriter, request *http.R
Middlewares: h.runtimeConfiguration.Middlewares, Middlewares: h.runtimeConfiguration.Middlewares,
Services: siRepr, Services: siRepr,
TCPRouters: h.runtimeConfiguration.TCPRouters, TCPRouters: h.runtimeConfiguration.TCPRouters,
TCPMiddlewares: h.runtimeConfiguration.TCPMiddlewares,
TCPServices: h.runtimeConfiguration.TCPServices, TCPServices: h.runtimeConfiguration.TCPServices,
UDPRouters: h.runtimeConfiguration.UDPRouters, UDPRouters: h.runtimeConfiguration.UDPRouters,
UDPServices: h.runtimeConfiguration.UDPServices, UDPServices: h.runtimeConfiguration.UDPServices,

View file

@ -47,6 +47,7 @@ func (h Handler) getOverview(rw http.ResponseWriter, request *http.Request) {
TCP: schemeOverview{ TCP: schemeOverview{
Routers: getTCPRouterSection(h.runtimeConfiguration.TCPRouters), Routers: getTCPRouterSection(h.runtimeConfiguration.TCPRouters),
Services: getTCPServiceSection(h.runtimeConfiguration.TCPServices), Services: getTCPServiceSection(h.runtimeConfiguration.TCPServices),
Middlewares: getTCPMiddlewareSection(h.runtimeConfiguration.TCPMiddlewares),
}, },
UDP: schemeOverview{ UDP: schemeOverview{
Routers: getUDPRouterSection(h.runtimeConfiguration.UDPRouters), Routers: getUDPRouterSection(h.runtimeConfiguration.UDPRouters),
@ -160,6 +161,25 @@ func getTCPServiceSection(services map[string]*runtime.TCPServiceInfo) *section
} }
} }
func getTCPMiddlewareSection(middlewares map[string]*runtime.TCPMiddlewareInfo) *section {
var countErrors int
var countWarnings int
for _, mid := range middlewares {
switch mid.Status {
case runtime.StatusDisabled:
countErrors++
case runtime.StatusWarning:
countWarnings++
}
}
return &section{
Total: len(middlewares),
Warnings: countWarnings,
Errors: countErrors,
}
}
func getUDPRouterSection(routers map[string]*runtime.UDPRouterInfo) *section { func getUDPRouterSection(routers map[string]*runtime.UDPRouterInfo) *section {
var countErrors int var countErrors int
var countWarnings int var countWarnings int

View file

@ -171,6 +171,31 @@ func TestHandler_Overview(t *testing.T) {
Status: runtime.StatusDisabled, Status: runtime.StatusDisabled,
}, },
}, },
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"ipwhitelist1@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
Status: runtime.StatusEnabled,
},
"ipwhitelist2@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
},
"ipwhitelist3@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
Status: runtime.StatusDisabled,
},
},
TCPRouters: map[string]*runtime.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"tcpbar@myprovider": { "tcpbar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{

View file

@ -43,6 +43,22 @@ func newTCPServiceRepresentation(name string, si *runtime.TCPServiceInfo) tcpSer
} }
} }
type tcpMiddlewareRepresentation struct {
*runtime.TCPMiddlewareInfo
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
Type string `json:"type,omitempty"`
}
func newTCPMiddlewareRepresentation(name string, mi *runtime.TCPMiddlewareInfo) tcpMiddlewareRepresentation {
return tcpMiddlewareRepresentation{
TCPMiddlewareInfo: mi,
Name: name,
Provider: getProviderName(name),
Type: strings.ToLower(extractType(mi.TCPMiddleware)),
}
}
func (h Handler) getTCPRouters(rw http.ResponseWriter, request *http.Request) { func (h Handler) getTCPRouters(rw http.ResponseWriter, request *http.Request) {
results := make([]tcpRouterRepresentation, 0, len(h.runtimeConfiguration.TCPRouters)) results := make([]tcpRouterRepresentation, 0, len(h.runtimeConfiguration.TCPRouters))
@ -147,6 +163,58 @@ func (h Handler) getTCPService(rw http.ResponseWriter, request *http.Request) {
} }
} }
func (h Handler) getTCPMiddlewares(rw http.ResponseWriter, request *http.Request) {
results := make([]tcpMiddlewareRepresentation, 0, len(h.runtimeConfiguration.Middlewares))
criterion := newSearchCriterion(request.URL.Query())
for name, mi := range h.runtimeConfiguration.TCPMiddlewares {
if keepTCPMiddleware(name, mi, criterion) {
results = append(results, newTCPMiddlewareRepresentation(name, mi))
}
}
sort.Slice(results, func(i, j int) bool {
return results[i].Name < results[j].Name
})
rw.Header().Set("Content-Type", "application/json")
pageInfo, err := pagination(request, len(results))
if err != nil {
writeError(rw, err.Error(), http.StatusBadRequest)
return
}
rw.Header().Set(nextPageHeader, strconv.Itoa(pageInfo.nextPage))
err = json.NewEncoder(rw).Encode(results[pageInfo.startIndex:pageInfo.endIndex])
if err != nil {
log.FromContext(request.Context()).Error(err)
writeError(rw, err.Error(), http.StatusInternalServerError)
}
}
func (h Handler) getTCPMiddleware(rw http.ResponseWriter, request *http.Request) {
middlewareID := mux.Vars(request)["middlewareID"]
rw.Header().Set("Content-Type", "application/json")
middleware, ok := h.runtimeConfiguration.TCPMiddlewares[middlewareID]
if !ok {
writeError(rw, fmt.Sprintf("middleware not found: %s", middlewareID), http.StatusNotFound)
return
}
result := newTCPMiddlewareRepresentation(middlewareID, middleware)
err := json.NewEncoder(rw).Encode(result)
if err != nil {
log.FromContext(request.Context()).Error(err)
writeError(rw, err.Error(), http.StatusInternalServerError)
}
}
func keepTCPRouter(name string, item *runtime.TCPRouterInfo, criterion *searchCriterion) bool { func keepTCPRouter(name string, item *runtime.TCPRouterInfo, criterion *searchCriterion) bool {
if criterion == nil { if criterion == nil {
return true return true
@ -162,3 +230,11 @@ func keepTCPService(name string, item *runtime.TCPServiceInfo, criterion *search
return criterion.withStatus(item.Status) && criterion.searchIn(name) return criterion.withStatus(item.Status) && criterion.searchIn(name)
} }
func keepTCPMiddleware(name string, item *runtime.TCPMiddlewareInfo, criterion *searchCriterion) bool {
if criterion == nil {
return true
}
return criterion.withStatus(item.Status) && criterion.searchIn(name)
}

View file

@ -507,6 +507,223 @@ func TestHandler_TCP(t *testing.T) {
statusCode: http.StatusNotFound, statusCode: http.StatusNotFound,
}, },
}, },
{
desc: "all middlewares",
path: "/api/tcp/middlewares",
conf: runtime.Configuration{
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"ipwhitelist1@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
"ipwhitelist2@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.2/32"},
},
},
UsedBy: []string{"test@myprovider"},
},
"ipwhitelist1@anotherprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider"},
},
},
},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
jsonFile: "testdata/tcpmiddlewares.json",
},
},
{
desc: "middlewares filtered by status",
path: "/api/tcp/middlewares?status=enabled",
conf: runtime.Configuration{
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"ipwhitelist@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
Status: runtime.StatusEnabled,
},
"ipwhitelist2@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.2/32"},
},
},
UsedBy: []string{"test@myprovider"},
Status: runtime.StatusDisabled,
},
"ipwhitelist@anotherprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider"},
Status: runtime.StatusEnabled,
},
},
},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
jsonFile: "testdata/tcpmiddlewares-filtered-status.json",
},
},
{
desc: "middlewares filtered by search",
path: "/api/tcp/middlewares?search=ipwhitelist",
conf: runtime.Configuration{
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"bad@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
Status: runtime.StatusEnabled,
},
"ipwhitelist@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"test@myprovider"},
Status: runtime.StatusDisabled,
},
"ipwhitelist@anotherprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider"},
Status: runtime.StatusEnabled,
},
},
},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
jsonFile: "testdata/tcpmiddlewares-filtered-search.json",
},
},
{
desc: "all middlewares, 1 res per page, want page 2",
path: "/api/tcp/middlewares?page=2&per_page=1",
conf: runtime.Configuration{
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"ipwhitelist@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
"ipwhitelist2@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.2/32"},
},
},
UsedBy: []string{"test@myprovider"},
},
"ipwhitelist@anotherprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider"},
},
},
},
expected: expected{
statusCode: http.StatusOK,
nextPage: "3",
jsonFile: "testdata/tcpmiddlewares-page2.json",
},
},
{
desc: "one middleware by id",
path: "/api/tcp/middlewares/ipwhitelist@myprovider",
conf: runtime.Configuration{
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"ipwhitelist@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
"ipwhitelist2@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.2/32"},
},
},
UsedBy: []string{"test@myprovider"},
},
"ipwhitelist@anotherprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider"},
},
},
},
expected: expected{
statusCode: http.StatusOK,
jsonFile: "testdata/tcpmiddleware-ipwhitelist.json",
},
},
{
desc: "one middleware by id, that does not exist",
path: "/api/tcp/middlewares/foo@myprovider",
conf: runtime.Configuration{
TCPMiddlewares: map[string]*runtime.TCPMiddlewareInfo{
"ipwhitelist@myprovider": {
TCPMiddleware: &dynamic.TCPMiddleware{
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
},
},
expected: expected{
statusCode: http.StatusNotFound,
},
},
{
desc: "one middleware by id, but no config",
path: "/api/tcp/middlewares/foo@myprovider",
conf: runtime.Configuration{},
expected: expected{
statusCode: http.StatusNotFound,
},
},
} }
for _, test := range testCases { for _, test := range testCases {

View file

@ -22,6 +22,11 @@
} }
}, },
"tcp": { "tcp": {
"middlewares": {
"errors": 1,
"total": 3,
"warnings": 0
},
"routers": { "routers": {
"errors": 1, "errors": 1,
"total": 3, "total": 3,

View file

@ -22,6 +22,11 @@
} }
}, },
"tcp": { "tcp": {
"middlewares": {
"errors": 0,
"total": 0,
"warnings": 0
},
"routers": { "routers": {
"errors": 0, "errors": 0,
"total": 0, "total": 0,

View file

@ -22,6 +22,11 @@
} }
}, },
"tcp": { "tcp": {
"middlewares": {
"errors": 0,
"total": 0,
"warnings": 0
},
"routers": { "routers": {
"errors": 0, "errors": 0,
"total": 0, "total": 0,

View file

@ -32,6 +32,11 @@
"plugin-test" "plugin-test"
], ],
"tcp": { "tcp": {
"middlewares": {
"errors": 0,
"total": 0,
"warnings": 0
},
"routers": { "routers": {
"errors": 0, "errors": 0,
"total": 0, "total": 0,

View file

@ -0,0 +1,13 @@
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist@myprovider",
"provider": "myprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider",
"test@myprovider"
]
}

View file

@ -0,0 +1 @@
[]

View file

@ -0,0 +1,26 @@
[
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist@anotherprovider",
"provider": "anotherprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider"
]
},
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist@myprovider",
"provider": "myprovider",
"status": "disabled",
"type": "ipwhitelist",
"usedBy": [
"test@myprovider"
]
}
]

View file

@ -0,0 +1,27 @@
[
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist@anotherprovider",
"provider": "anotherprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider"
]
},
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist@myprovider",
"provider": "myprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider",
"test@myprovider"
]
}
]

View file

@ -0,0 +1,14 @@
[
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist@anotherprovider",
"provider": "anotherprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider"
]
}
]

39
pkg/api/testdata/tcpmiddlewares.json vendored Normal file
View file

@ -0,0 +1,39 @@
[
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist1@anotherprovider",
"provider": "anotherprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider"
]
},
{
"ipWhiteList": {
"sourceRange": ["127.0.0.1/32"]
},
"name": "ipwhitelist1@myprovider",
"provider": "myprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"bar@myprovider",
"test@myprovider"
]
},
{
"ipWhiteList": {
"sourceRange": ["127.0.0.2/32"]
},
"name": "ipwhitelist2@myprovider",
"provider": "myprovider",
"status": "enabled",
"type": "ipwhitelist",
"usedBy": [
"test@myprovider"
]
}
]

View file

@ -12,6 +12,7 @@ import (
type TCPConfiguration struct { type TCPConfiguration struct {
Routers map[string]*TCPRouter `json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty" export:"true"` Routers map[string]*TCPRouter `json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty" export:"true"`
Services map[string]*TCPService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty" export:"true"` Services map[string]*TCPService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty" export:"true"`
Middlewares map[string]*TCPMiddleware `json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
} }
// +k8s:deepcopy-gen=true // +k8s:deepcopy-gen=true
@ -48,6 +49,7 @@ func (w *TCPWRRService) SetDefaults() {
// TCPRouter holds the router configuration. // TCPRouter holds the router configuration.
type TCPRouter struct { type TCPRouter struct {
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" export:"true"` EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty" export:"true"`
Middlewares []string `json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty" export:"true"` Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty" export:"true"`
Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"` Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"`
TLS *RouterTCPTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"` TLS *RouterTCPTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`

View file

@ -0,0 +1,15 @@
package dynamic
// +k8s:deepcopy-gen=true
// TCPMiddleware holds the TCPMiddleware configuration.
type TCPMiddleware struct {
IPWhiteList *TCPIPWhiteList `json:"ipWhiteList,omitempty" toml:"ipWhiteList,omitempty" yaml:"ipWhiteList,omitempty" export:"true"`
}
// +k8s:deepcopy-gen=true
// TCPIPWhiteList holds the TCP ip white list configuration.
type TCPIPWhiteList struct {
SourceRange []string `json:"sourceRange,omitempty" toml:"sourceRange,omitempty" yaml:"sourceRange,omitempty"`
}

View file

@ -1295,6 +1295,21 @@ func (in *TCPConfiguration) DeepCopyInto(out *TCPConfiguration) {
(*out)[key] = outVal (*out)[key] = outVal
} }
} }
if in.Middlewares != nil {
in, out := &in.Middlewares, &out.Middlewares
*out = make(map[string]*TCPMiddleware, len(*in))
for key, val := range *in {
var outVal *TCPMiddleware
if val == nil {
(*out)[key] = nil
} else {
in, out := &val, &outVal
*out = new(TCPMiddleware)
(*in).DeepCopyInto(*out)
}
(*out)[key] = outVal
}
}
return return
} }
@ -1308,6 +1323,48 @@ func (in *TCPConfiguration) DeepCopy() *TCPConfiguration {
return out return out
} }
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TCPIPWhiteList) DeepCopyInto(out *TCPIPWhiteList) {
*out = *in
if in.SourceRange != nil {
in, out := &in.SourceRange, &out.SourceRange
*out = make([]string, len(*in))
copy(*out, *in)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TCPIPWhiteList.
func (in *TCPIPWhiteList) DeepCopy() *TCPIPWhiteList {
if in == nil {
return nil
}
out := new(TCPIPWhiteList)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TCPMiddleware) DeepCopyInto(out *TCPMiddleware) {
*out = *in
if in.IPWhiteList != nil {
in, out := &in.IPWhiteList, &out.IPWhiteList
*out = new(TCPIPWhiteList)
(*in).DeepCopyInto(*out)
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TCPMiddleware.
func (in *TCPMiddleware) DeepCopy() *TCPMiddleware {
if in == nil {
return nil
}
out := new(TCPMiddleware)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *TCPRouter) DeepCopyInto(out *TCPRouter) { func (in *TCPRouter) DeepCopyInto(out *TCPRouter) {
*out = *in *out = *in
@ -1316,6 +1373,11 @@ func (in *TCPRouter) DeepCopyInto(out *TCPRouter) {
*out = make([]string, len(*in)) *out = make([]string, len(*in))
copy(*out, *in) copy(*out, *in)
} }
if in.Middlewares != nil {
in, out := &in.Middlewares, &out.Middlewares
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.TLS != nil { if in.TLS != nil {
in, out := &in.TLS, &out.TLS in, out := &in.TLS, &out.TLS
*out = new(RouterTCPTLSConfig) *out = new(RouterTCPTLSConfig)

View file

@ -169,6 +169,8 @@ func TestDecodeConfiguration(t *testing.T) {
"traefik.http.services.Service1.loadbalancer.server.port": "8080", "traefik.http.services.Service1.loadbalancer.server.port": "8080",
"traefik.http.services.Service1.loadbalancer.sticky": "false", "traefik.http.services.Service1.loadbalancer.sticky": "false",
"traefik.http.services.Service1.loadbalancer.sticky.cookie.name": "fui", "traefik.http.services.Service1.loadbalancer.sticky.cookie.name": "fui",
"traefik.tcp.middlewares.Middleware0.ipwhitelist.sourcerange": "foobar, fiibar",
"traefik.tcp.routers.Router0.rule": "foobar", "traefik.tcp.routers.Router0.rule": "foobar",
"traefik.tcp.routers.Router0.entrypoints": "foobar, fiibar", "traefik.tcp.routers.Router0.entrypoints": "foobar, fiibar",
"traefik.tcp.routers.Router0.service": "foobar", "traefik.tcp.routers.Router0.service": "foobar",
@ -225,6 +227,13 @@ func TestDecodeConfiguration(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{
"Middleware0": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"foobar", "fiibar"},
},
},
},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Service0": { "Service0": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -696,6 +705,13 @@ func TestEncodeConfiguration(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{
"Middleware0": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"foobar", "fiibar"},
},
},
},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Service0": { "Service0": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -1289,6 +1305,7 @@ func TestEncodeConfiguration(t *testing.T) {
"traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme": "foobar", "traefik.HTTP.Services.Service1.LoadBalancer.server.Scheme": "foobar",
"traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name0": "foobar", "traefik.HTTP.Services.Service0.LoadBalancer.HealthCheck.Headers.name0": "foobar",
"traefik.TCP.Middlewares.Middleware0.IPWhiteList.SourceRange": "foobar, fiibar",
"traefik.TCP.Routers.Router0.Rule": "foobar", "traefik.TCP.Routers.Router0.Rule": "foobar",
"traefik.TCP.Routers.Router0.EntryPoints": "foobar, fiibar", "traefik.TCP.Routers.Router0.EntryPoints": "foobar, fiibar",
"traefik.TCP.Routers.Router0.Service": "foobar", "traefik.TCP.Routers.Router0.Service": "foobar",

View file

@ -19,6 +19,7 @@ const (
type Configuration struct { type Configuration struct {
Routers map[string]*RouterInfo `json:"routers,omitempty"` Routers map[string]*RouterInfo `json:"routers,omitempty"`
Middlewares map[string]*MiddlewareInfo `json:"middlewares,omitempty"` Middlewares map[string]*MiddlewareInfo `json:"middlewares,omitempty"`
TCPMiddlewares map[string]*TCPMiddlewareInfo `json:"tcpMiddlewares,omitempty"`
Services map[string]*ServiceInfo `json:"services,omitempty"` Services map[string]*ServiceInfo `json:"services,omitempty"`
TCPRouters map[string]*TCPRouterInfo `json:"tcpRouters,omitempty"` TCPRouters map[string]*TCPRouterInfo `json:"tcpRouters,omitempty"`
TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"` TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"`
@ -74,6 +75,13 @@ func NewConfig(conf dynamic.Configuration) *Configuration {
runtimeConfig.TCPServices[k] = &TCPServiceInfo{TCPService: v, Status: StatusEnabled} runtimeConfig.TCPServices[k] = &TCPServiceInfo{TCPService: v, Status: StatusEnabled}
} }
} }
if len(conf.TCP.Middlewares) > 0 {
runtimeConfig.TCPMiddlewares = make(map[string]*TCPMiddlewareInfo, len(conf.TCP.Middlewares))
for k, v := range conf.TCP.Middlewares {
runtimeConfig.TCPMiddlewares[k] = &TCPMiddlewareInfo{TCPMiddleware: v, Status: StatusEnabled}
}
}
} }
if conf.UDP != nil { if conf.UDP != nil {
@ -177,6 +185,15 @@ func (c *Configuration) PopulateUsedBy() {
sort.Strings(c.TCPServices[k].UsedBy) sort.Strings(c.TCPServices[k].UsedBy)
} }
for midName, mid := range c.TCPMiddlewares {
// lazily initialize Status in case caller forgot to do it
if mid.Status == "" {
mid.Status = StatusEnabled
}
sort.Strings(c.TCPMiddlewares[midName].UsedBy)
}
for routerName, routerInfo := range c.UDPRouters { for routerName, routerInfo := range c.UDPRouters {
// lazily initialize Status in case caller forgot to do it // lazily initialize Status in case caller forgot to do it
if routerInfo.Status == "" { if routerInfo.Status == "" {

View file

@ -112,3 +112,33 @@ func (s *TCPServiceInfo) AddError(err error, critical bool) {
s.Status = StatusWarning s.Status = StatusWarning
} }
} }
// TCPMiddlewareInfo holds information about a currently running middleware.
type TCPMiddlewareInfo struct {
*dynamic.TCPMiddleware // dynamic configuration
// Err contains all the errors that occurred during service creation.
Err []string `json:"error,omitempty"`
Status string `json:"status,omitempty"`
UsedBy []string `json:"usedBy,omitempty"` // list of TCP routers and services using that middleware.
}
// AddError adds err to s.Err, if it does not already exist.
// If critical is set, m is marked as disabled.
func (m *TCPMiddlewareInfo) AddError(err error, critical bool) {
for _, value := range m.Err {
if value == err.Error() {
return
}
}
m.Err = append(m.Err, err.Error())
if critical {
m.Status = StatusDisabled
return
}
// only set it to "warning" if not already in a worse state
if m.Status != StatusDisabled {
m.Status = StatusWarning
}
}

View file

@ -0,0 +1,65 @@
package tcpipwhitelist
import (
"context"
"errors"
"fmt"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/ip"
"github.com/traefik/traefik/v2/pkg/log"
"github.com/traefik/traefik/v2/pkg/middlewares"
"github.com/traefik/traefik/v2/pkg/tcp"
)
const (
typeName = "IPWhiteListerTCP"
)
// ipWhiteLister is a middleware that provides Checks of the Requesting IP against a set of Whitelists.
type ipWhiteLister struct {
next tcp.Handler
whiteLister *ip.Checker
name string
}
// New builds a new TCP IPWhiteLister given a list of CIDR-Strings to whitelist.
func New(ctx context.Context, next tcp.Handler, config dynamic.TCPIPWhiteList, name string) (tcp.Handler, error) {
logger := log.FromContext(middlewares.GetLoggerCtx(ctx, name, typeName))
logger.Debug("Creating middleware")
if len(config.SourceRange) == 0 {
return nil, errors.New("sourceRange is empty, IPWhiteLister not created")
}
checker, err := ip.NewChecker(config.SourceRange)
if err != nil {
return nil, fmt.Errorf("cannot parse CIDR whitelist %s: %w", config.SourceRange, err)
}
logger.Debugf("Setting up IPWhiteLister with sourceRange: %s", config.SourceRange)
return &ipWhiteLister{
whiteLister: checker,
next: next,
name: name,
}, nil
}
func (wl *ipWhiteLister) ServeTCP(conn tcp.WriteCloser) {
ctx := middlewares.GetLoggerCtx(context.Background(), wl.name, typeName)
logger := log.FromContext(ctx)
addr := conn.RemoteAddr().String()
err := wl.whiteLister.IsAuthorized(addr)
if err != nil {
logger.Errorf("Connection from %s rejected: %v", addr, err)
conn.Close()
return
}
logger.Debugf("Connection from %s accepted", addr)
wl.next.ServeTCP(conn)
}

View file

@ -0,0 +1,139 @@
package tcpipwhitelist
import (
"context"
"io/ioutil"
"net"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/traefik/traefik/v2/pkg/config/dynamic"
"github.com/traefik/traefik/v2/pkg/tcp"
)
func TestNewIPWhiteLister(t *testing.T) {
testCases := []struct {
desc string
whiteList dynamic.TCPIPWhiteList
expectedError bool
}{
{
desc: "Empty config",
whiteList: dynamic.TCPIPWhiteList{},
expectedError: true,
},
{
desc: "invalid IP",
whiteList: dynamic.TCPIPWhiteList{
SourceRange: []string{"foo"},
},
expectedError: true,
},
{
desc: "valid IP",
whiteList: dynamic.TCPIPWhiteList{
SourceRange: []string{"10.10.10.10"},
},
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
next := tcp.HandlerFunc(func(conn tcp.WriteCloser) {})
whiteLister, err := New(context.Background(), next, test.whiteList, "traefikTest")
if test.expectedError {
assert.Error(t, err)
} else {
require.NoError(t, err)
assert.NotNil(t, whiteLister)
}
})
}
}
func TestIPWhiteLister_ServeHTTP(t *testing.T) {
testCases := []struct {
desc string
whiteList dynamic.TCPIPWhiteList
remoteAddr string
expected string
}{
{
desc: "authorized with remote address",
whiteList: dynamic.TCPIPWhiteList{
SourceRange: []string{"20.20.20.20"},
},
remoteAddr: "20.20.20.20:1234",
expected: "OK",
},
{
desc: "non authorized with remote address",
whiteList: dynamic.TCPIPWhiteList{
SourceRange: []string{"20.20.20.20"},
},
remoteAddr: "20.20.20.21:1234",
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
next := tcp.HandlerFunc(func(conn tcp.WriteCloser) {
write, err := conn.Write([]byte("OK"))
require.NoError(t, err)
assert.Equal(t, 2, write)
err = conn.Close()
require.NoError(t, err)
})
whiteLister, err := New(context.Background(), next, test.whiteList, "traefikTest")
require.NoError(t, err)
server, client := net.Pipe()
go func() {
whiteLister.ServeTCP(&contextWriteCloser{client, addr{test.remoteAddr}})
}()
read, err := ioutil.ReadAll(server)
require.NoError(t, err)
assert.Equal(t, test.expected, string(read))
})
}
}
type contextWriteCloser struct {
net.Conn
addr
}
type addr struct {
remoteAddr string
}
func (a addr) Network() string {
panic("implement me")
}
func (a addr) String() string {
return a.remoteAddr
}
func (c contextWriteCloser) CloseWrite() error {
panic("implement me")
}
func (c contextWriteCloser) RemoteAddr() net.Addr { return c.addr }
func (c contextWriteCloser) Context() context.Context {
return context.Background()
}

View file

@ -27,6 +27,7 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter), Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService), Services: make(map[string]*dynamic.TCPService),
Middlewares: make(map[string]*dynamic.TCPMiddleware),
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
Routers: make(map[string]*dynamic.UDPRouter), Routers: make(map[string]*dynamic.UDPRouter),
@ -55,6 +56,9 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration
middlewaresToDelete := map[string]struct{}{} middlewaresToDelete := map[string]struct{}{}
middlewares := map[string][]string{} middlewares := map[string][]string{}
middlewaresTCPToDelete := map[string]struct{}{}
middlewaresTCP := map[string][]string{}
var sortedKeys []string var sortedKeys []string
for key := range configurations { for key := range configurations {
sortedKeys = append(sortedKeys, key) sortedKeys = append(sortedKeys, key)
@ -111,6 +115,13 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration
middlewaresToDelete[middlewareName] = struct{}{} middlewaresToDelete[middlewareName] = struct{}{}
} }
} }
for middlewareName, middleware := range conf.TCP.Middlewares {
middlewaresTCP[middlewareName] = append(middlewaresTCP[middlewareName], root)
if !AddMiddlewareTCP(configuration.TCP, middlewareName, middleware) {
middlewaresTCPToDelete[middlewareName] = struct{}{}
}
}
} }
for serviceName := range servicesToDelete { for serviceName := range servicesToDelete {
@ -155,6 +166,12 @@ func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration
delete(configuration.HTTP.Middlewares, middlewareName) delete(configuration.HTTP.Middlewares, middlewareName)
} }
for middlewareName := range middlewaresTCPToDelete {
logger.WithField(log.MiddlewareName, middlewareName).
Errorf("TCP Middleware defined multiple times with different configurations in %v", middlewaresTCP[middlewareName])
delete(configuration.TCP.Middlewares, middlewareName)
}
return configuration return configuration
} }
@ -193,6 +210,16 @@ func AddRouterTCP(configuration *dynamic.TCPConfiguration, routerName string, ro
return reflect.DeepEqual(configuration.Routers[routerName], router) return reflect.DeepEqual(configuration.Routers[routerName], router)
} }
// AddMiddlewareTCP Adds a middleware to a configurations.
func AddMiddlewareTCP(configuration *dynamic.TCPConfiguration, middlewareName string, middleware *dynamic.TCPMiddleware) bool {
if _, ok := configuration.Middlewares[middlewareName]; !ok {
configuration.Middlewares[middlewareName] = middleware
return true
}
return reflect.DeepEqual(configuration.Middlewares[middlewareName], middleware)
}
// AddServiceUDP adds a service to a configuration. // AddServiceUDP adds a service to a configuration.
func AddServiceUDP(configuration *dynamic.UDPConfiguration, serviceName string, service *dynamic.UDPService) bool { func AddServiceUDP(configuration *dynamic.UDPConfiguration, serviceName string, service *dynamic.UDPService) bool {
if _, ok := configuration.Services[serviceName]; !ok { if _, ok := configuration.Services[serviceName]; !ok {

View file

@ -38,6 +38,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -86,6 +87,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -132,6 +134,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -173,6 +176,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -214,6 +218,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -294,6 +299,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -348,6 +354,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -416,6 +423,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -473,6 +481,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -527,6 +536,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -576,6 +586,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -624,6 +635,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -670,6 +682,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -717,6 +730,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -765,6 +779,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -825,6 +840,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -880,6 +896,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -925,6 +942,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -974,6 +992,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1035,6 +1054,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1099,6 +1119,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1170,6 +1191,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1233,6 +1255,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1299,6 +1322,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1358,6 +1382,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1407,6 +1432,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1454,6 +1480,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1501,6 +1528,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1550,6 +1578,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1579,6 +1608,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1608,6 +1638,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1637,6 +1668,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1668,6 +1700,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1699,6 +1732,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1746,6 +1780,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1785,6 +1820,62 @@ func Test_buildConfiguration(t *testing.T) {
}, },
}, },
}, },
{
desc: "Middlewares used in TCP router",
items: []itemData{
{
ID: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.tcp.routers.Test.rule": "HostSNI(`foo.bar`)",
"traefik.tcp.middlewares.Middleware1.ipwhitelist.sourcerange": "foobar, fiibar",
"traefik.tcp.routers.Test.middlewares": "Middleware1",
},
Address: "127.0.0.1",
Port: "80",
Status: api.HealthPassing,
},
},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"Test": {
Service: "Test",
Rule: "HostSNI(`foo.bar`)",
Middlewares: []string{"Middleware1"},
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"Middleware1": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"foobar", "fiibar"},
},
},
},
Services: map[string]*dynamic.TCPService{
"Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
},
TerminationDelay: Int(100),
},
},
},
},
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
{ {
desc: "tcp with label", desc: "tcp with label",
items: []itemData{ items: []itemData{
@ -1809,6 +1900,7 @@ func Test_buildConfiguration(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Test": { "Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -1869,6 +1961,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1895,6 +1988,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Test": { "Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -1946,6 +2040,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2007,6 +2102,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2055,6 +2151,7 @@ func Test_buildConfiguration(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2154,6 +2251,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2199,6 +2297,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2254,6 +2353,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2281,6 +2381,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{

View file

@ -47,6 +47,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -100,6 +101,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -155,6 +157,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -208,6 +211,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -256,6 +260,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -304,6 +309,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -394,6 +400,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -432,6 +439,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -470,6 +478,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -506,6 +515,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -574,6 +584,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -658,6 +669,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -715,6 +727,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -771,6 +784,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -825,6 +839,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -880,6 +895,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -936,6 +952,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -996,6 +1013,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1070,6 +1088,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1152,6 +1171,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1215,6 +1235,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1272,6 +1293,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1352,6 +1374,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1435,6 +1458,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1531,6 +1555,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1611,6 +1636,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1702,6 +1728,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1777,6 +1804,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1852,6 +1880,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1911,6 +1940,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1966,6 +1996,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2021,6 +2052,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2076,6 +2108,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2112,6 +2145,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2150,6 +2184,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2187,6 +2222,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2226,6 +2262,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2265,6 +2302,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2320,6 +2358,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2359,6 +2398,70 @@ func Test_buildConfiguration(t *testing.T) {
}, },
}, },
}, },
{
desc: "Middlewares used in TCP router",
containers: []dockerData{
{
ServiceName: "Test",
Name: "Test",
Labels: map[string]string{
"traefik.tcp.routers.Test.rule": "HostSNI(`foo.bar`)",
"traefik.tcp.middlewares.Middleware1.ipwhitelist.sourcerange": "foobar, fiibar",
"traefik.tcp.routers.Test.middlewares": "Middleware1",
},
NetworkSettings: networkSettings{
Ports: nat.PortMap{
nat.Port("80/tcp"): []nat.PortBinding{},
},
Networks: map[string]*networkData{
"bridge": {
Name: "bridge",
Addr: "127.0.0.1",
},
},
},
},
},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"Test": {
Service: "Test",
Rule: "HostSNI(`foo.bar`)",
Middlewares: []string{"Middleware1"},
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"Middleware1": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"foobar", "fiibar"},
},
},
},
Services: map[string]*dynamic.TCPService{
"Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
},
TerminationDelay: Int(100),
},
},
},
},
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
{ {
desc: "tcp with label", desc: "tcp with label",
containers: []dockerData{ containers: []dockerData{
@ -2391,6 +2494,7 @@ func Test_buildConfiguration(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Test": { "Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2459,6 +2563,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2493,6 +2598,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Test": { "Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2552,6 +2658,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2621,6 +2728,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2700,6 +2808,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2767,6 +2876,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2802,6 +2912,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2859,6 +2970,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{

View file

@ -40,6 +40,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -88,6 +89,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -138,6 +140,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -186,6 +189,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -229,6 +233,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -272,6 +277,7 @@ func TestDefaultRule(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -357,6 +363,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -390,6 +397,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -423,6 +431,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -454,6 +463,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -512,6 +522,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -586,6 +597,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -638,6 +650,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -689,6 +702,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -738,6 +752,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -788,6 +803,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -839,6 +855,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -894,6 +911,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -958,6 +976,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1025,6 +1044,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1078,6 +1098,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1130,6 +1151,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1200,6 +1222,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1273,6 +1296,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1354,6 +1378,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1424,6 +1449,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1500,6 +1526,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1566,6 +1593,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1631,6 +1659,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1685,6 +1714,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1735,6 +1765,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1785,6 +1816,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1840,6 +1872,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1904,6 +1937,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1954,6 +1988,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -1985,6 +2020,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2018,6 +2054,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2052,6 +2089,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2085,6 +2123,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2119,6 +2158,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2153,6 +2193,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2203,6 +2244,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
UDP: &dynamic.UDPConfiguration{ UDP: &dynamic.UDPConfiguration{
@ -2242,6 +2284,65 @@ func Test_buildConfiguration(t *testing.T) {
}, },
}, },
}, },
{
desc: "Middlewares used in TCP router",
containers: []ecsInstance{
instance(
name("Test"),
labels(map[string]string{
"traefik.tcp.routers.Test.rule": "HostSNI(`foo.bar`)",
"traefik.tcp.middlewares.Middleware1.ipwhitelist.sourcerange": "foobar, fiibar",
"traefik.tcp.routers.Test.middlewares": "Middleware1",
}),
iMachine(
mState(ec2.InstanceStateNameRunning),
mPrivateIP("127.0.0.1"),
mPorts(
mPort(0, 80, "tcp"),
),
),
),
},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"Test": {
Service: "Test",
Rule: "HostSNI(`foo.bar`)",
Middlewares: []string{"Middleware1"},
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"Middleware1": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"foobar", "fiibar"},
},
},
},
Services: map[string]*dynamic.TCPService{
"Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
},
TerminationDelay: Int(100),
},
},
},
},
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
{ {
desc: "tcp with label", desc: "tcp with label",
containers: []ecsInstance{ containers: []ecsInstance{
@ -2269,6 +2370,7 @@ func Test_buildConfiguration(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Test": { "Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2332,6 +2434,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2361,6 +2464,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"Test": { "Test": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2415,6 +2519,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -2479,6 +2584,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2548,6 +2654,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2610,6 +2717,7 @@ func Test_buildConfiguration(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2640,6 +2748,7 @@ func Test_buildConfiguration(t *testing.T) {
expected: &dynamic.Configuration{ expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"foo": { "foo": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{

View file

@ -212,6 +212,7 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter), Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService), Services: make(map[string]*dynamic.TCPService),
Middlewares: make(map[string]*dynamic.TCPMiddleware),
}, },
TLS: &dynamic.TLSConfiguration{ TLS: &dynamic.TLSConfiguration{
Stores: make(map[string]tls.Store), Stores: make(map[string]tls.Store),
@ -290,6 +291,14 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
} }
} }
for name, conf := range c.TCP.Middlewares {
if _, exists := configuration.TCP.Middlewares[name]; exists {
logger.WithField(log.MiddlewareName, name).Warn("TCP middleware already configured, skipping")
} else {
configuration.TCP.Middlewares[name] = conf
}
}
for name, conf := range c.TCP.Services { for name, conf := range c.TCP.Services {
if _, exists := configuration.TCP.Services[name]; exists { if _, exists := configuration.TCP.Services[name]; exists {
logger.WithField(log.ServiceName, name).Warn("TCP service already configured, skipping") logger.WithField(log.ServiceName, name).Warn("TCP service already configured, skipping")
@ -414,6 +423,7 @@ func (p *Provider) decodeConfiguration(filePath, content string) (*dynamic.Confi
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter), Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService), Services: make(map[string]*dynamic.TCPService),
Middlewares: make(map[string]*dynamic.TCPMiddleware),
}, },
TLS: &dynamic.TLSConfiguration{ TLS: &dynamic.TLSConfiguration{
Stores: make(map[string]tls.Store), Stores: make(map[string]tls.Store),

View file

@ -36,6 +36,7 @@ type Client interface {
GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP GetIngressRouteTCPs() []*v1alpha1.IngressRouteTCP
GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP GetIngressRouteUDPs() []*v1alpha1.IngressRouteUDP
GetMiddlewares() []*v1alpha1.Middleware GetMiddlewares() []*v1alpha1.Middleware
GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP
GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error)
GetTraefikServices() []*v1alpha1.TraefikService GetTraefikServices() []*v1alpha1.TraefikService
GetTLSOptions() []*v1alpha1.TLSOption GetTLSOptions() []*v1alpha1.TLSOption
@ -166,6 +167,7 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
factoryCrd := externalversions.NewSharedInformerFactoryWithOptions(c.csCrd, resyncPeriod, externalversions.WithNamespace(ns), externalversions.WithTweakListOptions(matchesLabelSelector)) factoryCrd := externalversions.NewSharedInformerFactoryWithOptions(c.csCrd, resyncPeriod, externalversions.WithNamespace(ns), externalversions.WithTweakListOptions(matchesLabelSelector))
factoryCrd.Traefik().V1alpha1().IngressRoutes().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().IngressRoutes().Informer().AddEventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().Middlewares().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().Middlewares().Informer().AddEventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().MiddlewareTCPs().Informer().AddEventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().IngressRouteTCPs().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().IngressRouteTCPs().Informer().AddEventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().IngressRouteUDPs().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().IngressRouteUDPs().Informer().AddEventHandler(eventHandler)
factoryCrd.Traefik().V1alpha1().TLSOptions().Informer().AddEventHandler(eventHandler) factoryCrd.Traefik().V1alpha1().TLSOptions().Informer().AddEventHandler(eventHandler)
@ -270,6 +272,20 @@ func (c *clientWrapper) GetMiddlewares() []*v1alpha1.Middleware {
return result return result
} }
func (c *clientWrapper) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP {
var result []*v1alpha1.MiddlewareTCP
for ns, factory := range c.factoriesCrd {
middlewares, err := factory.Traefik().V1alpha1().MiddlewareTCPs().Lister().List(labels.Everything())
if err != nil {
log.Errorf("Failed to list TCP middlewares in namespace %s: %v", ns, err)
}
result = append(result, middlewares...)
}
return result
}
// GetTraefikService returns the named service from the given namespace. // GetTraefikService returns the named service from the given namespace.
func (c *clientWrapper) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) { func (c *clientWrapper) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) {
if !c.isWatchedNamespace(namespace) { if !c.isWatchedNamespace(namespace) {

View file

@ -34,6 +34,7 @@ type clientMock struct {
ingressRouteTCPs []*v1alpha1.IngressRouteTCP ingressRouteTCPs []*v1alpha1.IngressRouteTCP
ingressRouteUDPs []*v1alpha1.IngressRouteUDP ingressRouteUDPs []*v1alpha1.IngressRouteUDP
middlewares []*v1alpha1.Middleware middlewares []*v1alpha1.Middleware
middlewareTCPs []*v1alpha1.MiddlewareTCP
tlsOptions []*v1alpha1.TLSOption tlsOptions []*v1alpha1.TLSOption
tlsStores []*v1alpha1.TLSStore tlsStores []*v1alpha1.TLSStore
traefikServices []*v1alpha1.TraefikService traefikServices []*v1alpha1.TraefikService
@ -66,6 +67,8 @@ func newClientMock(paths ...string) clientMock {
c.ingressRouteUDPs = append(c.ingressRouteUDPs, o) c.ingressRouteUDPs = append(c.ingressRouteUDPs, o)
case *v1alpha1.Middleware: case *v1alpha1.Middleware:
c.middlewares = append(c.middlewares, o) c.middlewares = append(c.middlewares, o)
case *v1alpha1.MiddlewareTCP:
c.middlewareTCPs = append(c.middlewareTCPs, o)
case *v1alpha1.TraefikService: case *v1alpha1.TraefikService:
c.traefikServices = append(c.traefikServices, o) c.traefikServices = append(c.traefikServices, o)
case *v1alpha1.TLSOption: case *v1alpha1.TLSOption:
@ -101,6 +104,10 @@ func (c clientMock) GetMiddlewares() []*v1alpha1.Middleware {
return c.middlewares return c.middlewares
} }
func (c clientMock) GetMiddlewareTCPs() []*v1alpha1.MiddlewareTCP {
return c.middlewareTCPs
}
func (c clientMock) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) { func (c clientMock) GetTraefikService(namespace, name string) (*v1alpha1.TraefikService, bool, error) {
for _, svc := range c.traefikServices { for _, svc := range c.traefikServices {
if svc.Namespace == namespace && svc.Name == name { if svc.Namespace == namespace && svc.Name == name {

View file

@ -0,0 +1,41 @@
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
namespace: default
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
---
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
namespace: foo
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- match: HostSNI(`foo.com`)
services:
- name: whoamitcp
port: 8000
middlewares:
- name: ipwhitelist
- name: ipwhitelist
namespace: foo

View file

@ -0,0 +1,44 @@
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
namespace: default
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
---
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
namespace: foo
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- match: HostSNI(`foo.com`)
services:
- name: whoamitcp
port: 8000
middlewares:
- name: ipwhitelist
- name: ipwhitelist
namespace: foo
- name: ipwhitelist@file
- name: ipwhitelist-foo@file
namespace: foo

View file

@ -0,0 +1,48 @@
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
namespace: default
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
---
apiVersion: traefik.containo.us/v1alpha1
kind: MiddlewareTCP
metadata:
name: ipwhitelist
namespace: cross-ns
spec:
ipWhiteList:
sourceRange:
- 127.0.0.1/32
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
name: test.route
namespace: default
spec:
entryPoints:
- foo
routes:
- match: HostSNI(`foo.com`)
services:
- name: whoamitcp
port: 8000
middlewares:
- name: ipwhitelist
- match: HostSNI(`bar.com`)
services:
- name: whoamitcp
port: 8000
middlewares:
- name: ipwhitelist
namespace: cross-ns

View file

@ -0,0 +1,138 @@
/*
The MIT License (MIT)
Copyright (c) 2016-2020 Containous SAS; 2020-2021 Traefik Labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
"context"
v1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
schema "k8s.io/apimachinery/pkg/runtime/schema"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
)
// FakeMiddlewareTCPs implements MiddlewareTCPInterface
type FakeMiddlewareTCPs struct {
Fake *FakeTraefikV1alpha1
ns string
}
var middlewaretcpsResource = schema.GroupVersionResource{Group: "traefik.containo.us", Version: "v1alpha1", Resource: "middlewaretcps"}
var middlewaretcpsKind = schema.GroupVersionKind{Group: "traefik.containo.us", Version: "v1alpha1", Kind: "MiddlewareTCP"}
// Get takes name of the middlewareTCP, and returns the corresponding middlewareTCP object, and an error if there is any.
func (c *FakeMiddlewareTCPs) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.MiddlewareTCP, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(middlewaretcpsResource, c.ns, name), &v1alpha1.MiddlewareTCP{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.MiddlewareTCP), err
}
// List takes label and field selectors, and returns the list of MiddlewareTCPs that match those selectors.
func (c *FakeMiddlewareTCPs) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.MiddlewareTCPList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(middlewaretcpsResource, middlewaretcpsKind, c.ns, opts), &v1alpha1.MiddlewareTCPList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.MiddlewareTCPList{ListMeta: obj.(*v1alpha1.MiddlewareTCPList).ListMeta}
for _, item := range obj.(*v1alpha1.MiddlewareTCPList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested middlewareTCPs.
func (c *FakeMiddlewareTCPs) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(middlewaretcpsResource, c.ns, opts))
}
// Create takes the representation of a middlewareTCP and creates it. Returns the server's representation of the middlewareTCP, and an error, if there is any.
func (c *FakeMiddlewareTCPs) Create(ctx context.Context, middlewareTCP *v1alpha1.MiddlewareTCP, opts v1.CreateOptions) (result *v1alpha1.MiddlewareTCP, err error) {
obj, err := c.Fake.
Invokes(testing.NewCreateAction(middlewaretcpsResource, c.ns, middlewareTCP), &v1alpha1.MiddlewareTCP{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.MiddlewareTCP), err
}
// Update takes the representation of a middlewareTCP and updates it. Returns the server's representation of the middlewareTCP, and an error, if there is any.
func (c *FakeMiddlewareTCPs) Update(ctx context.Context, middlewareTCP *v1alpha1.MiddlewareTCP, opts v1.UpdateOptions) (result *v1alpha1.MiddlewareTCP, err error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(middlewaretcpsResource, c.ns, middlewareTCP), &v1alpha1.MiddlewareTCP{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.MiddlewareTCP), err
}
// Delete takes name of the middlewareTCP and deletes it. Returns an error if one occurs.
func (c *FakeMiddlewareTCPs) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(middlewaretcpsResource, c.ns, name), &v1alpha1.MiddlewareTCP{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeMiddlewareTCPs) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
action := testing.NewDeleteCollectionAction(middlewaretcpsResource, c.ns, listOpts)
_, err := c.Fake.Invokes(action, &v1alpha1.MiddlewareTCPList{})
return err
}
// Patch applies the patch and returns the patched middlewareTCP.
func (c *FakeMiddlewareTCPs) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.MiddlewareTCP, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(middlewaretcpsResource, c.ns, name, pt, data, subresources...), &v1alpha1.MiddlewareTCP{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.MiddlewareTCP), err
}

View file

@ -52,6 +52,10 @@ func (c *FakeTraefikV1alpha1) Middlewares(namespace string) v1alpha1.MiddlewareI
return &FakeMiddlewares{c, namespace} return &FakeMiddlewares{c, namespace}
} }
func (c *FakeTraefikV1alpha1) MiddlewareTCPs(namespace string) v1alpha1.MiddlewareTCPInterface {
return &FakeMiddlewareTCPs{c, namespace}
}
func (c *FakeTraefikV1alpha1) ServersTransports(namespace string) v1alpha1.ServersTransportInterface { func (c *FakeTraefikV1alpha1) ServersTransports(namespace string) v1alpha1.ServersTransportInterface {
return &FakeServersTransports{c, namespace} return &FakeServersTransports{c, namespace}
} }

View file

@ -34,6 +34,8 @@ type IngressRouteUDPExpansion interface{}
type MiddlewareExpansion interface{} type MiddlewareExpansion interface{}
type MiddlewareTCPExpansion interface{}
type ServersTransportExpansion interface{} type ServersTransportExpansion interface{}
type TLSOptionExpansion interface{} type TLSOptionExpansion interface{}

View file

@ -0,0 +1,186 @@
/*
The MIT License (MIT)
Copyright (c) 2016-2020 Containous SAS; 2020-2021 Traefik Labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1
import (
"context"
"time"
scheme "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned/scheme"
v1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// MiddlewareTCPsGetter has a method to return a MiddlewareTCPInterface.
// A group's client should implement this interface.
type MiddlewareTCPsGetter interface {
MiddlewareTCPs(namespace string) MiddlewareTCPInterface
}
// MiddlewareTCPInterface has methods to work with MiddlewareTCP resources.
type MiddlewareTCPInterface interface {
Create(ctx context.Context, middlewareTCP *v1alpha1.MiddlewareTCP, opts v1.CreateOptions) (*v1alpha1.MiddlewareTCP, error)
Update(ctx context.Context, middlewareTCP *v1alpha1.MiddlewareTCP, opts v1.UpdateOptions) (*v1alpha1.MiddlewareTCP, error)
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.MiddlewareTCP, error)
List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.MiddlewareTCPList, error)
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.MiddlewareTCP, err error)
MiddlewareTCPExpansion
}
// middlewareTCPs implements MiddlewareTCPInterface
type middlewareTCPs struct {
client rest.Interface
ns string
}
// newMiddlewareTCPs returns a MiddlewareTCPs
func newMiddlewareTCPs(c *TraefikV1alpha1Client, namespace string) *middlewareTCPs {
return &middlewareTCPs{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the middlewareTCP, and returns the corresponding middlewareTCP object, and an error if there is any.
func (c *middlewareTCPs) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.MiddlewareTCP, err error) {
result = &v1alpha1.MiddlewareTCP{}
err = c.client.Get().
Namespace(c.ns).
Resource("middlewaretcps").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of MiddlewareTCPs that match those selectors.
func (c *middlewareTCPs) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.MiddlewareTCPList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1alpha1.MiddlewareTCPList{}
err = c.client.Get().
Namespace(c.ns).
Resource("middlewaretcps").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested middlewareTCPs.
func (c *middlewareTCPs) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("middlewaretcps").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a middlewareTCP and creates it. Returns the server's representation of the middlewareTCP, and an error, if there is any.
func (c *middlewareTCPs) Create(ctx context.Context, middlewareTCP *v1alpha1.MiddlewareTCP, opts v1.CreateOptions) (result *v1alpha1.MiddlewareTCP, err error) {
result = &v1alpha1.MiddlewareTCP{}
err = c.client.Post().
Namespace(c.ns).
Resource("middlewaretcps").
VersionedParams(&opts, scheme.ParameterCodec).
Body(middlewareTCP).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a middlewareTCP and updates it. Returns the server's representation of the middlewareTCP, and an error, if there is any.
func (c *middlewareTCPs) Update(ctx context.Context, middlewareTCP *v1alpha1.MiddlewareTCP, opts v1.UpdateOptions) (result *v1alpha1.MiddlewareTCP, err error) {
result = &v1alpha1.MiddlewareTCP{}
err = c.client.Put().
Namespace(c.ns).
Resource("middlewaretcps").
Name(middlewareTCP.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(middlewareTCP).
Do(ctx).
Into(result)
return
}
// Delete takes name of the middlewareTCP and deletes it. Returns an error if one occurs.
func (c *middlewareTCPs) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("middlewaretcps").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *middlewareTCPs) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Namespace(c.ns).
Resource("middlewaretcps").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched middlewareTCP.
func (c *middlewareTCPs) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.MiddlewareTCP, err error) {
result = &v1alpha1.MiddlewareTCP{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("middlewaretcps").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}

View file

@ -38,6 +38,7 @@ type TraefikV1alpha1Interface interface {
IngressRouteTCPsGetter IngressRouteTCPsGetter
IngressRouteUDPsGetter IngressRouteUDPsGetter
MiddlewaresGetter MiddlewaresGetter
MiddlewareTCPsGetter
ServersTransportsGetter ServersTransportsGetter
TLSOptionsGetter TLSOptionsGetter
TLSStoresGetter TLSStoresGetter
@ -65,6 +66,10 @@ func (c *TraefikV1alpha1Client) Middlewares(namespace string) MiddlewareInterfac
return newMiddlewares(c, namespace) return newMiddlewares(c, namespace)
} }
func (c *TraefikV1alpha1Client) MiddlewareTCPs(namespace string) MiddlewareTCPInterface {
return newMiddlewareTCPs(c, namespace)
}
func (c *TraefikV1alpha1Client) ServersTransports(namespace string) ServersTransportInterface { func (c *TraefikV1alpha1Client) ServersTransports(namespace string) ServersTransportInterface {
return newServersTransports(c, namespace) return newServersTransports(c, namespace)
} }

View file

@ -69,6 +69,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource
return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().IngressRouteUDPs().Informer()}, nil return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().IngressRouteUDPs().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("middlewares"): case v1alpha1.SchemeGroupVersion.WithResource("middlewares"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().Middlewares().Informer()}, nil return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().Middlewares().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("middlewaretcps"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().MiddlewareTCPs().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("serverstransports"): case v1alpha1.SchemeGroupVersion.WithResource("serverstransports"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().ServersTransports().Informer()}, nil return &genericInformer{resource: resource.GroupResource(), informer: f.Traefik().V1alpha1().ServersTransports().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("tlsoptions"): case v1alpha1.SchemeGroupVersion.WithResource("tlsoptions"):

View file

@ -40,6 +40,8 @@ type Interface interface {
IngressRouteUDPs() IngressRouteUDPInformer IngressRouteUDPs() IngressRouteUDPInformer
// Middlewares returns a MiddlewareInformer. // Middlewares returns a MiddlewareInformer.
Middlewares() MiddlewareInformer Middlewares() MiddlewareInformer
// MiddlewareTCPs returns a MiddlewareTCPInformer.
MiddlewareTCPs() MiddlewareTCPInformer
// ServersTransports returns a ServersTransportInformer. // ServersTransports returns a ServersTransportInformer.
ServersTransports() ServersTransportInformer ServersTransports() ServersTransportInformer
// TLSOptions returns a TLSOptionInformer. // TLSOptions returns a TLSOptionInformer.
@ -81,6 +83,11 @@ func (v *version) Middlewares() MiddlewareInformer {
return &middlewareInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} return &middlewareInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
} }
// MiddlewareTCPs returns a MiddlewareTCPInformer.
func (v *version) MiddlewareTCPs() MiddlewareTCPInformer {
return &middlewareTCPInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
// ServersTransports returns a ServersTransportInformer. // ServersTransports returns a ServersTransportInformer.
func (v *version) ServersTransports() ServersTransportInformer { func (v *version) ServersTransports() ServersTransportInformer {
return &serversTransportInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} return &serversTransportInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}

View file

@ -0,0 +1,98 @@
/*
The MIT License (MIT)
Copyright (c) 2016-2020 Containous SAS; 2020-2021 Traefik Labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Code generated by informer-gen. DO NOT EDIT.
package v1alpha1
import (
"context"
time "time"
versioned "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/clientset/versioned"
internalinterfaces "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/informers/externalversions/internalinterfaces"
v1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/generated/listers/traefik/v1alpha1"
traefikv1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
watch "k8s.io/apimachinery/pkg/watch"
cache "k8s.io/client-go/tools/cache"
)
// MiddlewareTCPInformer provides access to a shared informer and lister for
// MiddlewareTCPs.
type MiddlewareTCPInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1alpha1.MiddlewareTCPLister
}
type middlewareTCPInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewMiddlewareTCPInformer constructs a new informer for MiddlewareTCP type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewMiddlewareTCPInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredMiddlewareTCPInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredMiddlewareTCPInformer constructs a new informer for MiddlewareTCP type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewFilteredMiddlewareTCPInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.TraefikV1alpha1().MiddlewareTCPs(namespace).List(context.TODO(), options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.TraefikV1alpha1().MiddlewareTCPs(namespace).Watch(context.TODO(), options)
},
},
&traefikv1alpha1.MiddlewareTCP{},
resyncPeriod,
indexers,
)
}
func (f *middlewareTCPInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredMiddlewareTCPInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *middlewareTCPInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&traefikv1alpha1.MiddlewareTCP{}, f.defaultInformer)
}
func (f *middlewareTCPInformer) Lister() v1alpha1.MiddlewareTCPLister {
return v1alpha1.NewMiddlewareTCPLister(f.Informer().GetIndexer())
}

View file

@ -58,6 +58,14 @@ type MiddlewareListerExpansion interface{}
// MiddlewareNamespaceLister. // MiddlewareNamespaceLister.
type MiddlewareNamespaceListerExpansion interface{} type MiddlewareNamespaceListerExpansion interface{}
// MiddlewareTCPListerExpansion allows custom methods to be added to
// MiddlewareTCPLister.
type MiddlewareTCPListerExpansion interface{}
// MiddlewareTCPNamespaceListerExpansion allows custom methods to be added to
// MiddlewareTCPNamespaceLister.
type MiddlewareTCPNamespaceListerExpansion interface{}
// ServersTransportListerExpansion allows custom methods to be added to // ServersTransportListerExpansion allows custom methods to be added to
// ServersTransportLister. // ServersTransportLister.
type ServersTransportListerExpansion interface{} type ServersTransportListerExpansion interface{}

View file

@ -0,0 +1,107 @@
/*
The MIT License (MIT)
Copyright (c) 2016-2020 Containous SAS; 2020-2021 Traefik Labs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Code generated by lister-gen. DO NOT EDIT.
package v1alpha1
import (
v1alpha1 "github.com/traefik/traefik/v2/pkg/provider/kubernetes/crd/traefik/v1alpha1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// MiddlewareTCPLister helps list MiddlewareTCPs.
// All objects returned here must be treated as read-only.
type MiddlewareTCPLister interface {
// List lists all MiddlewareTCPs in the indexer.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1alpha1.MiddlewareTCP, err error)
// MiddlewareTCPs returns an object that can list and get MiddlewareTCPs.
MiddlewareTCPs(namespace string) MiddlewareTCPNamespaceLister
MiddlewareTCPListerExpansion
}
// middlewareTCPLister implements the MiddlewareTCPLister interface.
type middlewareTCPLister struct {
indexer cache.Indexer
}
// NewMiddlewareTCPLister returns a new MiddlewareTCPLister.
func NewMiddlewareTCPLister(indexer cache.Indexer) MiddlewareTCPLister {
return &middlewareTCPLister{indexer: indexer}
}
// List lists all MiddlewareTCPs in the indexer.
func (s *middlewareTCPLister) List(selector labels.Selector) (ret []*v1alpha1.MiddlewareTCP, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.MiddlewareTCP))
})
return ret, err
}
// MiddlewareTCPs returns an object that can list and get MiddlewareTCPs.
func (s *middlewareTCPLister) MiddlewareTCPs(namespace string) MiddlewareTCPNamespaceLister {
return middlewareTCPNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// MiddlewareTCPNamespaceLister helps list and get MiddlewareTCPs.
// All objects returned here must be treated as read-only.
type MiddlewareTCPNamespaceLister interface {
// List lists all MiddlewareTCPs in the indexer for a given namespace.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1alpha1.MiddlewareTCP, err error)
// Get retrieves the MiddlewareTCP from the indexer for a given namespace and name.
// Objects returned here must be treated as read-only.
Get(name string) (*v1alpha1.MiddlewareTCP, error)
MiddlewareTCPNamespaceListerExpansion
}
// middlewareTCPNamespaceLister implements the MiddlewareTCPNamespaceLister
// interface.
type middlewareTCPNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all MiddlewareTCPs in the indexer for a given namespace.
func (s middlewareTCPNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.MiddlewareTCP, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.MiddlewareTCP))
})
return ret, err
}
// Get retrieves the MiddlewareTCP from the indexer for a given namespace and name.
func (s middlewareTCPNamespaceLister) Get(name string) (*v1alpha1.MiddlewareTCP, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1alpha1.Resource("middlewaretcp"), name)
}
return obj.(*v1alpha1.MiddlewareTCP), nil
}

View file

@ -266,6 +266,14 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
} }
} }
for _, middlewareTCP := range client.GetMiddlewareTCPs() {
id := provider.Normalize(makeID(middlewareTCP.Namespace, middlewareTCP.Name))
conf.TCP.Middlewares[id] = &dynamic.TCPMiddleware{
IPWhiteList: middlewareTCP.Spec.IPWhiteList,
}
}
cb := configBuilder{client, p.AllowCrossNamespace} cb := configBuilder{client, p.AllowCrossNamespace}
for _, service := range client.GetTraefikServices() { for _, service := range client.GetTraefikServices() {

View file

@ -18,6 +18,7 @@ import (
func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.TCPConfiguration { func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.TCPConfiguration {
conf := &dynamic.TCPConfiguration{ conf := &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
} }
@ -52,6 +53,12 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
continue continue
} }
mds, err := p.makeMiddlewareTCPKeys(ctx, ingressRouteTCP.Namespace, route.Middlewares)
if err != nil {
logger.Errorf("Failed to create middleware keys: %v", err)
continue
}
serviceName := makeID(ingressRouteTCP.Namespace, key) serviceName := makeID(ingressRouteTCP.Namespace, key)
for _, service := range route.Services { for _, service := range route.Services {
@ -88,6 +95,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
conf.Routers[serviceName] = &dynamic.TCPRouter{ conf.Routers[serviceName] = &dynamic.TCPRouter{
EntryPoints: ingressRouteTCP.Spec.EntryPoints, EntryPoints: ingressRouteTCP.Spec.EntryPoints,
Middlewares: mds,
Rule: route.Match, Rule: route.Match,
Service: serviceName, Service: serviceName,
} }
@ -125,6 +133,35 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
return conf return conf
} }
func (p *Provider) makeMiddlewareTCPKeys(ctx context.Context, ingRouteTCPNamespace string, middlewares []v1alpha1.ObjectReference) ([]string, error) {
var mds []string
for _, mi := range middlewares {
if strings.Contains(mi.Name, providerNamespaceSeparator) {
if len(mi.Namespace) > 0 {
log.FromContext(ctx).
WithField(log.MiddlewareName, mi.Name).
Warnf("namespace %q is ignored in cross-provider context", mi.Namespace)
}
mds = append(mds, mi.Name)
continue
}
ns := ingRouteTCPNamespace
if len(mi.Namespace) > 0 {
if !isNamespaceAllowed(p.AllowCrossNamespace, ingRouteTCPNamespace, mi.Namespace) {
return nil, fmt.Errorf("middleware %s/%s is not in the IngressRouteTCP namespace %s", mi.Namespace, mi.Name, ingRouteTCPNamespace)
}
ns = mi.Namespace
}
mds = append(mds, makeID(ns, mi.Name))
}
return mds, nil
}
func (p *Provider) createLoadBalancerServerTCP(client Client, parentNamespace string, service v1alpha1.ServiceTCP) (*dynamic.TCPService, error) { func (p *Provider) createLoadBalancerServerTCP(client Client, parentNamespace string, service v1alpha1.ServiceTCP) (*dynamic.TCPService, error) {
ns := parentNamespace ns := parentNamespace
if len(service.Namespace) > 0 { if len(service.Namespace) > 0 {

View file

@ -43,6 +43,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -76,6 +77,113 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
},
},
},
},
TLS: &dynamic.TLSConfiguration{},
},
},
{
desc: "Simple Ingress Route, with foo entrypoint and middleware",
paths: []string{"tcp/services.yml", "tcp/with_middleware.yml"},
expected: &dynamic.Configuration{
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
HTTP: &dynamic.HTTPConfiguration{
ServersTransports: map[string]*dynamic.ServersTransport{},
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"default-test.route-fdd3e9338e47a45efefc": {
EntryPoints: []string{"foo"},
Service: "default-test.route-fdd3e9338e47a45efefc",
Middlewares: []string{"default-ipwhitelist", "foo-ipwhitelist"},
Rule: "HostSNI(`foo.com`)",
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"default-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
"foo-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
},
Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
},
},
},
},
TLS: &dynamic.TLSConfiguration{},
},
},
{
desc: "Simple Ingress Route, with foo entrypoint and crossprovider middleware",
paths: []string{"tcp/services.yml", "tcp/with_middleware_crossprovider.yml"},
expected: &dynamic.Configuration{
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
HTTP: &dynamic.HTTPConfiguration{
ServersTransports: map[string]*dynamic.ServersTransport{},
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"default-test.route-fdd3e9338e47a45efefc": {
EntryPoints: []string{"foo"},
Service: "default-test.route-fdd3e9338e47a45efefc",
Middlewares: []string{"default-ipwhitelist", "foo-ipwhitelist", "ipwhitelist@file", "ipwhitelist-foo@file"},
Rule: "HostSNI(`foo.com`)",
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"default-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
"foo-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -115,6 +223,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`bar.com`)", Rule: "HostSNI(`bar.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -167,6 +276,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -207,6 +317,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
Weighted: &dynamic.TCPWeightedRoundRobin{ Weighted: &dynamic.TCPWeightedRoundRobin{
@ -273,6 +384,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
Weighted: &dynamic.TCPWeightedRoundRobin{ Weighted: &dynamic.TCPWeightedRoundRobin{
@ -350,6 +462,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -371,6 +484,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -409,6 +523,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -451,6 +566,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -514,6 +630,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -575,6 +692,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -635,6 +753,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -684,6 +803,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -733,6 +853,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -773,6 +894,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -814,6 +936,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -861,6 +984,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
TLS: &dynamic.RouterTCPTLSConfig{}, TLS: &dynamic.RouterTCPTLSConfig{},
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -904,6 +1028,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -941,6 +1066,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -978,6 +1104,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1024,6 +1151,7 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
Rule: "HostSNI(`*`)", Rule: "HostSNI(`*`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-673acf455cb2dab0b43a": { "default-test.route-673acf455cb2dab0b43a": {
Weighted: &dynamic.TCPWeightedRoundRobin{ Weighted: &dynamic.TCPWeightedRoundRobin{
@ -1112,6 +1240,48 @@ func TestLoadIngressRouteTCPs(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
}, },
}, },
{
desc: "TCP with proxyProtocol Version",
paths: []string{"tcp/services.yml", "tcp/with_proxyprotocol.yml"},
expected: &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{},
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"default-test.route-fdd3e9338e47a45efefc": {
EntryPoints: []string{"foo"},
Service: "default-test.route-fdd3e9338e47a45efefc",
Rule: "HostSNI(`foo.com`)",
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
ProxyProtocol: &dynamic.ProxyProtocol{Version: 2},
},
},
},
},
HTTP: &dynamic.HTTPConfiguration{
ServersTransports: map[string]*dynamic.ServersTransport{},
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
} }
for _, test := range testCases { for _, test := range testCases {
@ -1150,6 +1320,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1171,6 +1342,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1213,6 +1385,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1268,6 +1441,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1321,6 +1495,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1383,6 +1558,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1452,6 +1628,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1504,6 +1681,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1549,6 +1727,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1672,6 +1851,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1738,6 +1918,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -1829,6 +2010,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2006,6 +2188,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2069,6 +2252,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2152,6 +2336,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2222,6 +2407,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2243,6 +2429,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2264,6 +2451,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2294,6 +2482,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2356,6 +2545,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2403,6 +2593,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2467,6 +2658,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2530,6 +2722,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2592,6 +2785,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2643,6 +2837,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2694,6 +2889,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2739,6 +2935,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2782,6 +2979,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2824,6 +3022,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2866,6 +3065,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2908,6 +3108,7 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2950,6 +3151,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -2983,47 +3185,6 @@ func TestLoadIngressRoutes(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
}, },
}, },
{
desc: "TCP with proxyProtocol Version",
paths: []string{"tcp/services.yml", "tcp/with_proxyprotocol.yml"},
expected: &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{},
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"default-test.route-fdd3e9338e47a45efefc": {
EntryPoints: []string{"foo"},
Service: "default-test.route-fdd3e9338e47a45efefc",
Rule: "HostSNI(`foo.com`)",
},
},
Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
ProxyProtocol: &dynamic.ProxyProtocol{Version: 2},
},
},
},
},
HTTP: &dynamic.HTTPConfiguration{
ServersTransports: map[string]*dynamic.ServersTransport{},
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
{ {
desc: "TLS with tls store", desc: "TLS with tls store",
paths: []string{"services.yml", "with_tls_store.yml"}, paths: []string{"services.yml", "with_tls_store.yml"},
@ -3044,6 +3205,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3089,6 +3251,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3134,6 +3297,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3172,6 +3336,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3210,6 +3375,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3248,6 +3414,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3269,6 +3436,7 @@ func TestLoadIngressRoutes(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3333,6 +3501,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3378,6 +3547,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
@ -3427,6 +3597,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3492,6 +3663,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3573,6 +3745,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3609,6 +3782,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3645,6 +3819,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3671,6 +3846,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -3693,6 +3869,7 @@ func TestLoadIngressRouteUDPs(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4043,6 +4220,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4064,6 +4242,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4115,6 +4294,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4208,6 +4388,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4331,6 +4512,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4390,6 +4572,131 @@ func TestCrossNamespace(t *testing.T) {
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
}, },
}, },
{
desc: "TCP middleware cross namespace disallowed",
paths: []string{"tcp/services.yml", "tcp/with_middleware_with_cross_namespace.yml"},
expected: &dynamic.Configuration{
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"default-test.route-fdd3e9338e47a45efefc": {
EntryPoints: []string{"foo"},
Service: "default-test.route-fdd3e9338e47a45efefc",
Middlewares: []string{"default-ipwhitelist"},
Rule: "HostSNI(`foo.com`)",
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"default-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
"cross-ns-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
},
Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
},
},
},
},
HTTP: &dynamic.HTTPConfiguration{
ServersTransports: map[string]*dynamic.ServersTransport{},
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
TLS: &dynamic.TLSConfiguration{},
},
},
{
desc: "TCP middleware cross namespace allowed",
paths: []string{"tcp/services.yml", "tcp/with_middleware_with_cross_namespace.yml"},
allowCrossNamespace: true,
expected: &dynamic.Configuration{
UDP: &dynamic.UDPConfiguration{
Routers: map[string]*dynamic.UDPRouter{},
Services: map[string]*dynamic.UDPService{},
},
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"default-test.route-fdd3e9338e47a45efefc": {
EntryPoints: []string{"foo"},
Service: "default-test.route-fdd3e9338e47a45efefc",
Middlewares: []string{"default-ipwhitelist"},
Rule: "HostSNI(`foo.com`)",
},
"default-test.route-f44ce589164e656d231c": {
EntryPoints: []string{"foo"},
Service: "default-test.route-f44ce589164e656d231c",
Middlewares: []string{"cross-ns-ipwhitelist"},
Rule: "HostSNI(`bar.com`)",
},
},
Middlewares: map[string]*dynamic.TCPMiddleware{
"default-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
"cross-ns-ipwhitelist": {
IPWhiteList: &dynamic.TCPIPWhiteList{
SourceRange: []string{"127.0.0.1/32"},
},
},
},
Services: map[string]*dynamic.TCPService{
"default-test.route-f44ce589164e656d231c": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
},
},
"default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{
Servers: []dynamic.TCPServer{
{
Address: "10.10.0.1:8000",
},
{
Address: "10.10.0.2:8000",
},
},
},
},
},
},
HTTP: &dynamic.HTTPConfiguration{
ServersTransports: map[string]*dynamic.ServersTransport{},
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
TLS: &dynamic.TLSConfiguration{},
},
},
{ {
desc: "TCP cross namespace allowed", desc: "TCP cross namespace allowed",
paths: []string{"tcp/services.yml", "tcp/with_cross_namespace.yml"}, paths: []string{"tcp/services.yml", "tcp/with_cross_namespace.yml"},
@ -4413,6 +4720,7 @@ func TestCrossNamespace(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{ Services: map[string]*dynamic.TCPService{
"default-test.route-fdd3e9338e47a45efefc": { "default-test.route-fdd3e9338e47a45efefc": {
LoadBalancer: &dynamic.TCPServersLoadBalancer{ LoadBalancer: &dynamic.TCPServersLoadBalancer{
@ -4448,6 +4756,7 @@ func TestCrossNamespace(t *testing.T) {
Rule: "HostSNI(`foo.com`)", Rule: "HostSNI(`foo.com`)",
}, },
}, },
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4494,6 +4803,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
TLS: &dynamic.TLSConfiguration{}, TLS: &dynamic.TLSConfiguration{},
@ -4515,6 +4825,7 @@ func TestCrossNamespace(t *testing.T) {
}, },
TCP: &dynamic.TCPConfiguration{ TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{}, Routers: map[string]*dynamic.TCPRouter{},
Middlewares: map[string]*dynamic.TCPMiddleware{},
Services: map[string]*dynamic.TCPService{}, Services: map[string]*dynamic.TCPService{},
}, },
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
@ -4555,6 +4866,8 @@ func TestCrossNamespace(t *testing.T) {
crdObjects = append(crdObjects, o) crdObjects = append(crdObjects, o)
case *v1alpha1.Middleware: case *v1alpha1.Middleware:
crdObjects = append(crdObjects, o) crdObjects = append(crdObjects, o)
case *v1alpha1.MiddlewareTCP:
crdObjects = append(crdObjects, o)
case *v1alpha1.TraefikService: case *v1alpha1.TraefikService:
crdObjects = append(crdObjects, o) crdObjects = append(crdObjects, o)
case *v1alpha1.TLSOption: case *v1alpha1.TLSOption:
@ -4584,7 +4897,7 @@ func TestCrossNamespace(t *testing.T) {
p := Provider{} p := Provider{}
p.SetDefaults() p.SetDefaults()
p.AllowCrossNamespace = func(b bool) *bool { return &b }(test.allowCrossNamespace) p.AllowCrossNamespace = Bool(test.allowCrossNamespace)
conf := p.loadConfigurationFromCRD(context.Background(), client) conf := p.loadConfigurationFromCRD(context.Background(), client)
assert.Equal(t, test.expected, conf) assert.Equal(t, test.expected, conf)
}) })

View file

@ -18,6 +18,8 @@ type IngressRouteTCPSpec struct {
type RouteTCP struct { type RouteTCP struct {
Match string `json:"match"` Match string `json:"match"`
Services []ServiceTCP `json:"services,omitempty"` Services []ServiceTCP `json:"services,omitempty"`
// Middlewares contains references to MiddlewareTCP resources.
Middlewares []ObjectReference `json:"middlewares,omitempty"`
} }
// TLSTCP contains the TLS certificates configuration of the routes. // TLSTCP contains the TLS certificates configuration of the routes.
@ -34,25 +36,13 @@ type TLSTCP struct {
SecretName string `json:"secretName,omitempty"` SecretName string `json:"secretName,omitempty"`
Passthrough bool `json:"passthrough,omitempty"` Passthrough bool `json:"passthrough,omitempty"`
// Options is a reference to a TLSOption, that specifies the parameters of the TLS connection. // Options is a reference to a TLSOption, that specifies the parameters of the TLS connection.
Options *TLSOptionTCPRef `json:"options,omitempty"` Options *ObjectReference `json:"options,omitempty"`
// Store is a reference to a TLSStore, that specifies the parameters of the TLS store. // Store is a reference to a TLSStore, that specifies the parameters of the TLS store.
Store *TLSStoreTCPRef `json:"store,omitempty"` Store *ObjectReference `json:"store,omitempty"`
CertResolver string `json:"certResolver,omitempty"` CertResolver string `json:"certResolver,omitempty"`
Domains []types.Domain `json:"domains,omitempty"` Domains []types.Domain `json:"domains,omitempty"`
} }
// TLSOptionTCPRef is a ref to the TLSOption resources.
type TLSOptionTCPRef struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
}
// TLSStoreTCPRef is a ref to the TLSStore resources.
type TLSStoreTCPRef struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
}
// ServiceTCP defines an upstream to proxy traffic. // ServiceTCP defines an upstream to proxy traffic.
type ServiceTCP struct { type ServiceTCP struct {
Name string `json:"name"` Name string `json:"name"`

View file

@ -0,0 +1,34 @@
package v1alpha1
import (
"github.com/traefik/traefik/v2/pkg/config/dynamic"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// MiddlewareTCP is a specification for a MiddlewareTCP resource.
type MiddlewareTCP struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec MiddlewareTCPSpec `json:"spec"`
}
// +k8s:deepcopy-gen=true
// MiddlewareTCPSpec holds the MiddlewareTCP configuration.
type MiddlewareTCPSpec struct {
IPWhiteList *dynamic.TCPIPWhiteList `json:"ipWhiteList,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// MiddlewareTCPList is a list of MiddlewareTCP resources.
type MiddlewareTCPList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []MiddlewareTCP `json:"items"`
}

View file

@ -0,0 +1,7 @@
package v1alpha1
// ObjectReference is a generic reference to a Traefik resource.
type ObjectReference struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
}

Some files were not shown because too many files have changed in this diff Show more