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

@ -51,6 +51,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -101,6 +102,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: `Host("Test.foo.bar")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -235,6 +237,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -320,6 +323,7 @@ func Test_buildConfiguration(t *testing.T) {
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -373,6 +377,7 @@ func Test_buildConfiguration(t *testing.T) {
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -456,6 +461,7 @@ func Test_buildConfiguration(t *testing.T) {
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -531,10 +537,12 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -601,6 +609,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -660,6 +669,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -716,6 +726,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -767,6 +778,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1026,6 +1038,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1083,6 +1096,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1130,6 +1144,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1181,6 +1196,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1244,6 +1260,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1310,6 +1327,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1383,6 +1401,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1628,6 +1647,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1677,6 +1697,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1936,6 +1957,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
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"},
},
},
@ -2377,6 +2400,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2460,6 +2484,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2658,10 +2683,12 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test-97077516270503695": {
Service: "Test-97077516270503695",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -56,6 +56,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -111,6 +112,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -168,6 +170,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: `Host("Test.foo.bar")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -323,6 +326,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -534,6 +538,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -604,10 +609,12 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -690,6 +697,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -749,6 +757,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1116,6 +1125,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1200,6 +1210,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1265,6 +1276,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1324,6 +1336,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1406,6 +1419,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1491,6 +1505,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1589,6 +1604,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1979,6 +1995,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2036,6 +2053,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2283,6 +2301,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2517,6 +2536,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
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{
@ -3027,6 +3048,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -3196,6 +3218,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -52,6 +52,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -102,6 +103,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.foo.bar`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -154,6 +156,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: `Host("Test.foo.bar")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -294,6 +297,7 @@ func TestDefaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -484,6 +488,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -544,10 +549,12 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -620,6 +627,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -674,6 +682,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1006,6 +1015,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1075,6 +1085,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1130,6 +1141,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1184,6 +1196,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1256,6 +1269,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1331,6 +1345,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1414,6 +1429,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1755,6 +1771,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1807,6 +1824,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1859,6 +1877,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2245,6 +2264,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
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{
@ -2710,6 +2731,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -60,6 +60,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -126,6 +127,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
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{
@ -389,10 +392,12 @@ func TestBuildConfiguration(t *testing.T) {
"foo": {
Service: "foo",
Rule: "Host(`foo.marathon.localhost`)",
DefaultRule: true,
},
"bar": {
Service: "bar",
Rule: "Host(`bar.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -441,6 +446,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -487,6 +493,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -716,10 +723,12 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
"app2": {
Service: "Service1",
Rule: "Host(`app2.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -758,10 +767,12 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
"app2": {
Service: "app2",
Rule: "Host(`app2.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -827,10 +838,12 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
"app2": {
Service: "app2",
Rule: "Host(`app2.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1043,6 +1056,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1087,6 +1101,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "Service1",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1343,6 +1358,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1387,6 +1403,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "app",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1430,6 +1447,7 @@ func TestBuildConfiguration(t *testing.T) {
"a_b_app": {
Service: "a_b_app",
Rule: `Host("app.b.a.marathon.localhost")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1754,6 +1772,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "bar",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1814,6 +1833,7 @@ func TestBuildConfiguration(t *testing.T) {
"app": {
Service: "bar",
Rule: "Host(`app.marathon.localhost`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -44,6 +44,7 @@ func Test_defaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`example.com`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -94,6 +95,7 @@ func Test_defaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: `Host("Test.example.com")`,
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -183,6 +185,7 @@ func Test_defaultRule(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -253,6 +256,7 @@ func Test_buildConfig(t *testing.T) {
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -307,10 +311,12 @@ func Test_buildConfig(t *testing.T) {
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.test`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -377,6 +383,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -436,6 +443,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -492,6 +500,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -543,6 +552,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -803,6 +813,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -860,6 +871,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -907,6 +919,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -958,6 +971,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Services: map[string]*dynamic.Service{
@ -1022,6 +1036,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{
@ -1089,6 +1104,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1257,6 +1273,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1306,6 +1323,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -1535,6 +1553,7 @@ func Test_buildConfig(t *testing.T) {
"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{
@ -1976,6 +1996,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2059,6 +2080,7 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -2256,10 +2278,12 @@ func Test_buildConfig(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
"Test-1234154071633021619": {
Service: "Test-1234154071633021619",
Rule: "Host(`Test.traefik.test`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},

View file

@ -46,6 +46,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -100,10 +101,12 @@ func Test_buildConfiguration(t *testing.T) {
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -168,10 +171,12 @@ func Test_buildConfiguration(t *testing.T) {
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
DefaultRule: true,
},
"Test2": {
Service: "Test2",
Rule: "Host(`Test2.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -423,6 +428,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
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{
@ -587,6 +594,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -895,6 +903,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
DefaultRule: true,
},
},
Middlewares: map[string]*dynamic.Middleware{},
@ -966,6 +975,7 @@ func Test_buildConfiguration(t *testing.T) {
"Test": {
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)
}