Refuse recursive requests

Co-authored-by: Michael <michael.matur@gmail.com>
This commit is contained in:
Romain 2023-11-21 15:08:06 +01:00 committed by GitHub
parent 088fe3c270
commit 186e3e1541
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 519 additions and 243 deletions

View file

@ -529,6 +529,13 @@ providers:
# ...
```
??? info "Default rule and Traefik service"
The exposure of the Traefik container, combined with the default rule mechanism,
can lead to create a router targeting itself in a loop.
In this case, to prevent an infinite loop,
Traefik adds an internal middleware to refuse the request if it comes from the same router.
### `connectAware`
_Optional, Default=false_

View file

@ -466,6 +466,13 @@ providers:
# ...
```
??? info "Default rule and Traefik service"
The exposure of the Traefik container, combined with the default rule mechanism,
can lead to create a router targeting itself in a loop.
In this case, to prevent an infinite loop,
Traefik adds an internal middleware to refuse the request if it comes from the same router.
### `swarmMode`
_Optional, Default=false_

View file

@ -263,6 +263,13 @@ providers:
# ...
```
??? info "Default rule and Traefik service"
The exposure of the Traefik container, combined with the default rule mechanism,
can lead to create a router targeting itself in a loop.
In this case, to prevent an infinite loop,
Traefik adds an internal middleware to refuse the request if it comes from the same router.
### `refreshSeconds`
_Optional, Default=15_

View file

@ -142,6 +142,13 @@ providers:
# ...
```
??? info "Default rule and Traefik service"
The exposure of the Traefik container, combined with the default rule mechanism,
can lead to create a router targeting itself in a loop.
In this case, to prevent an infinite loop,
Traefik adds an internal middleware to refuse the request if it comes from the same router.
### `dialerTimeout`
_Optional, Default=5s_

View file

@ -377,6 +377,13 @@ providers:
# ...
```
??? info "Default rule and Traefik service"
The exposure of the Traefik container, combined with the default rule mechanism,
can lead to create a router targeting itself in a loop.
In this case, to prevent an infinite loop,
Traefik adds an internal middleware to refuse the request if it comes from the same router.
### `constraints`
_Optional, Default=""_

View file

@ -125,6 +125,13 @@ providers:
# ...
```
??? info "Default rule and Traefik service"
The exposure of the Traefik container, combined with the default rule mechanism,
can lead to create a router targeting itself in a loop.
In this case, to prevent an infinite loop,
Traefik adds an internal middleware to refuse the request if it comes from the same router.
### `enableServiceHealthFilter`
_Optional, Default=true_

View file

@ -48,6 +48,7 @@ type Router struct {
Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"`
Priority int `json:"priority,omitempty" toml:"priority,omitempty,omitzero" yaml:"priority,omitempty" export:"true"`
TLS *RouterTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty" file:"allowEmpty" kv:"allowEmpty" export:"true"`
DefaultRule bool `json:"-" toml:"-" yaml:"-" label:"-" file:"-"`
}
// +k8s:deepcopy-gen=true

View file

@ -0,0 +1,61 @@
package denyrouterrecursion
import (
"errors"
"hash/fnv"
"net/http"
"strconv"
"github.com/containous/alice"
"github.com/traefik/traefik/v2/pkg/log"
)
const xTraefikRouter = "X-Traefik-Router"
type DenyRouterRecursion struct {
routerName string
routerNameHash string
next http.Handler
}
// WrapHandler Wraps router to alice.Constructor.
func WrapHandler(routerName string) alice.Constructor {
return func(next http.Handler) (http.Handler, error) {
return New(routerName, next)
}
}
// New creates a new DenyRouterRecursion.
// DenyRouterRecursion middleware is an internal middleware used to avoid infinite requests loop on the same router.
func New(routerName string, next http.Handler) (*DenyRouterRecursion, error) {
if routerName == "" {
return nil, errors.New("routerName cannot be empty")
}
return &DenyRouterRecursion{
routerName: routerName,
routerNameHash: makeHash(routerName),
next: next,
}, nil
}
// ServeHTTP implements http.Handler.
func (l *DenyRouterRecursion) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
if req.Header.Get(xTraefikRouter) == l.routerNameHash {
log.WithoutContext().Debugf("Rejecting request in provenance of the same router (%q) to stop potential infinite loop.", l.routerName)
rw.WriteHeader(http.StatusBadRequest)
return
}
req.Header.Set(xTraefikRouter, l.routerNameHash)
l.next.ServeHTTP(rw, req)
}
func makeHash(routerName string) string {
hasher := fnv.New64()
// purposely ignoring the error, as no error can be returned from the implementation.
_, _ = hasher.Write([]byte(routerName))
return strconv.FormatUint(hasher.Sum64(), 16)
}

View file

@ -0,0 +1,38 @@
package denyrouterrecursion
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestServeHTTP(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "", nil)
require.NoError(t, err)
_, err = New("", http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {}))
require.Error(t, err)
next := 0
m, err := New("myRouter", http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {
next++
}))
require.NoError(t, err)
recorder := httptest.NewRecorder()
m.ServeHTTP(recorder, req)
assert.Equal(t, http.StatusOK, recorder.Code)
assert.Equal(t, "995d26092d19a224", m.routerNameHash)
assert.Equal(t, m.routerNameHash, req.Header.Get(xTraefikRouter))
assert.Equal(t, 1, next)
recorder = httptest.NewRecorder()
m.ServeHTTP(recorder, req)
assert.Equal(t, 1, next)
assert.Equal(t, http.StatusBadRequest, recorder.Code)
}

View file

@ -349,7 +349,7 @@ func BuildTCPRouterConfiguration(ctx context.Context, configuration *dynamic.TCP
continue
}
if len(router.Service) == 0 {
if router.Service == "" {
if len(configuration.Services) > 1 {
delete(configuration.Routers, routerName)
loggerRouter.
@ -368,7 +368,7 @@ func BuildTCPRouterConfiguration(ctx context.Context, configuration *dynamic.TCP
func BuildUDPRouterConfiguration(ctx context.Context, configuration *dynamic.UDPConfiguration) {
for routerName, router := range configuration.Routers {
loggerRouter := log.FromContext(ctx).WithField(log.RouterName, routerName)
if len(router.Service) > 0 {
if router.Service != "" {
continue
}
@ -413,9 +413,12 @@ func BuildRouterConfiguration(ctx context.Context, configuration *dynamic.HTTPCo
delete(configuration.Routers, routerName)
continue
}
// Flag default rule routers to add the denyRouterRecursion middleware.
router.DefaultRule = true
}
if len(router.Service) == 0 {
if router.Service == "" {
if len(configuration.Services) > 1 {
delete(configuration.Routers, routerName)
loggerRouter.

View file

@ -49,8 +49,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`foo.bar`)",
Service: "Test",
Rule: "Host(`foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -99,8 +100,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: `Host("Test.foo.bar")`,
Service: "Test",
Rule: `Host("Test.foo.bar")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -233,8 +235,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -318,8 +321,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -371,8 +375,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -454,8 +459,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -529,12 +535,14 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -599,8 +607,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -658,8 +667,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -714,8 +724,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -765,8 +776,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1024,8 +1036,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1081,8 +1094,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1128,8 +1142,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1179,8 +1194,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1242,8 +1258,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1308,8 +1325,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1381,8 +1399,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1626,8 +1645,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1675,8 +1695,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1934,8 +1955,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1985,6 +2007,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
Middlewares: []string{"Middleware1"},
},
},
@ -2375,8 +2398,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2458,8 +2482,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2656,12 +2681,14 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test-97077516270503695": {
Service: "Test-97077516270503695",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test-97077516270503695",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -54,8 +54,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`foo.bar`)",
Service: "Test",
Rule: "Host(`foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -109,8 +110,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.foo.bar`)",
Service: "Test",
Rule: "Host(`Test.foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -166,8 +168,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: `Host("Test.foo.bar")`,
Service: "Test",
Rule: `Host("Test.foo.bar")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -321,8 +324,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -532,8 +536,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -602,12 +607,14 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -688,8 +695,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -747,8 +755,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1114,8 +1123,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1198,8 +1208,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1263,8 +1274,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1322,8 +1334,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1404,8 +1417,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1489,8 +1503,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1587,8 +1602,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1977,8 +1993,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2034,8 +2051,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2281,8 +2299,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2515,8 +2534,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2575,6 +2595,7 @@ func Test_buildConfiguration(t *testing.T) {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Middlewares: []string{"Middleware1"},
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -3025,8 +3046,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -3194,8 +3216,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -50,8 +50,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`foo.bar`)",
Service: "Test",
Rule: "Host(`foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -100,8 +101,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.foo.bar`)",
Service: "Test",
Rule: "Host(`Test.foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -152,8 +154,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: `Host("Test.foo.bar")`,
Service: "Test",
Rule: `Host("Test.foo.bar")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -292,8 +295,9 @@ func TestDefaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -482,8 +486,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -542,12 +547,14 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -618,8 +625,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -672,8 +680,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1004,8 +1013,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1073,8 +1083,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1128,8 +1139,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1182,8 +1194,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1254,8 +1267,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1329,8 +1343,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1412,8 +1427,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1753,8 +1769,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1805,8 +1822,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1857,8 +1875,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2243,8 +2262,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2298,6 +2318,7 @@ func Test_buildConfiguration(t *testing.T) {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Middlewares: []string{"Middleware1"},
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -2708,8 +2729,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -58,8 +58,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -124,8 +125,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -169,6 +171,7 @@ func TestBuildConfiguration(t *testing.T) {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Middlewares: []string{"Middleware1"},
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -387,12 +390,14 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"foo": {
Service: "foo",
Rule: "Host(`foo.marathon.localhost`)",
Service: "foo",
Rule: "Host(`foo.marathon.localhost`)",
DefaultRule: true,
},
"bar": {
Service: "bar",
Rule: "Host(`bar.marathon.localhost`)",
Service: "bar",
Rule: "Host(`bar.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -439,8 +444,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -485,8 +491,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -714,12 +721,14 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
"app2": {
Service: "Service1",
Rule: "Host(`app2.marathon.localhost`)",
Service: "Service1",
Rule: "Host(`app2.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -756,12 +765,14 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
"app2": {
Service: "app2",
Rule: "Host(`app2.marathon.localhost`)",
Service: "app2",
Rule: "Host(`app2.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -825,12 +836,14 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
"app2": {
Service: "app2",
Rule: "Host(`app2.marathon.localhost`)",
Service: "app2",
Rule: "Host(`app2.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1041,8 +1054,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1085,8 +1099,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1341,8 +1356,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1385,8 +1401,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1428,8 +1445,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"a_b_app": {
Service: "a_b_app",
Rule: `Host("app.b.a.marathon.localhost")`,
Service: "a_b_app",
Rule: `Host("app.b.a.marathon.localhost")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1752,8 +1770,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "bar",
Rule: "Host(`app.marathon.localhost`)",
Service: "bar",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1812,8 +1831,9 @@ func TestBuildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"app": {
Service: "bar",
Rule: "Host(`app.marathon.localhost`)",
Service: "bar",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -42,8 +42,9 @@ func Test_defaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`example.com`)",
Service: "Test",
Rule: "Host(`example.com`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -92,8 +93,9 @@ func Test_defaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: `Host("Test.example.com")`,
Service: "Test",
Rule: `Host("Test.example.com")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -181,8 +183,9 @@ func Test_defaultRule(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -251,8 +254,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.test`)",
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -305,12 +309,14 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.test`)",
Service: "Test1",
Rule: "Host(`Test1.traefik.test`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.test`)",
Service: "Test2",
Rule: "Host(`Test2.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -375,8 +381,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -434,8 +441,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -490,8 +498,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -541,8 +550,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -801,8 +811,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -858,8 +869,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -905,8 +917,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -956,8 +969,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1020,8 +1034,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1087,8 +1102,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1255,8 +1271,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1304,8 +1321,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1533,8 +1551,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1585,6 +1604,7 @@ func Test_buildConfig(t *testing.T) {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Middlewares: []string{"Middleware1"},
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1974,8 +1994,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2057,8 +2078,9 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2254,12 +2276,14 @@ func Test_buildConfig(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
"Test-1234154071633021619": {
Service: "Test-1234154071633021619",
Rule: "Host(`Test.traefik.test`)",
Service: "Test-1234154071633021619",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -44,8 +44,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -98,12 +99,14 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -166,12 +169,14 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -421,8 +426,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -473,6 +479,7 @@ func Test_buildConfiguration(t *testing.T) {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Middlewares: []string{"Middleware1"},
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -585,8 +592,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -893,8 +901,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -964,8 +973,9 @@ func Test_buildConfiguration(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -11,6 +11,7 @@ import (
"github.com/traefik/traefik/v2/pkg/log"
"github.com/traefik/traefik/v2/pkg/metrics"
"github.com/traefik/traefik/v2/pkg/middlewares/accesslog"
"github.com/traefik/traefik/v2/pkg/middlewares/denyrouterrecursion"
metricsMiddle "github.com/traefik/traefik/v2/pkg/middlewares/metrics"
"github.com/traefik/traefik/v2/pkg/middlewares/recovery"
"github.com/traefik/traefik/v2/pkg/middlewares/tracing"
@ -202,6 +203,10 @@ func (m *Manager) buildHTTPHandler(ctx context.Context, router *runtime.RouterIn
chain = chain.Append(metricsMiddle.WrapRouterHandler(ctx, m.metricsRegistry, routerName, provider.GetQualifiedName(ctx, router.Service)))
}
if router.DefaultRule {
chain = chain.Append(denyrouterrecursion.WrapHandler(routerName))
}
return chain.Extend(*mHandler).Append(tHandler).Then(sHandler)
}