diff --git a/integration/fixtures/tcp/ip-whitelist.toml b/integration/fixtures/tcp/ip-allowlist.toml similarity index 83% rename from integration/fixtures/tcp/ip-whitelist.toml rename to integration/fixtures/tcp/ip-allowlist.toml index 2718f0544..947a7b714 100644 --- a/integration/fixtures/tcp/ip-whitelist.toml +++ b/integration/fixtures/tcp/ip-allowlist.toml @@ -23,7 +23,7 @@ entryPoints = ["tcp"] rule = "HostSNI(`whoami-a.test`)" service = "whoami-a" - middlewares = ["blocking-ipwhitelist"] + middlewares = ["blocking-allowlist"] [tcp.routers.to-whoami-a.tls] passthrough = true @@ -31,7 +31,7 @@ entryPoints = ["tcp"] rule = "HostSNI(`whoami-b.test`)" service = "whoami-b" - middlewares = ["allowing-ipwhitelist"] + middlewares = ["allowing-allowlist"] [tcp.routers.to-whoami-b.tls] passthrough = true @@ -45,7 +45,7 @@ address = "{{ .WhoamiB }}" [tcp.middlewares] - [tcp.middlewares.allowing-ipwhitelist.ipWhiteList] + [tcp.middlewares.allowing-allowlist.ipAllowList] sourceRange = ["127.0.0.1/32"] - [tcp.middlewares.blocking-ipwhitelist.ipWhiteList] + [tcp.middlewares.blocking-allowlist.ipAllowList] sourceRange = ["127.127.127.127/32"] diff --git a/integration/tcp_test.go b/integration/tcp_test.go index 0a60ae5b4..707dc1c79 100644 --- a/integration/tcp_test.go +++ b/integration/tcp_test.go @@ -249,8 +249,8 @@ func (s *TCPSuite) TestCatchAllNoTLSWithHTTPS(c *check.C) { c.Assert(err, checker.IsNil) } -func (s *TCPSuite) TestMiddlewareWhiteList(c *check.C) { - file := s.adaptFile(c, "fixtures/tcp/ip-whitelist.toml", struct { +func (s *TCPSuite) TestMiddlewareAllowList(c *check.C) { + file := s.adaptFile(c, "fixtures/tcp/ip-allowlist.toml", struct { WhoamiA string WhoamiB string }{ diff --git a/pkg/server/middleware/tcp/middlewares.go b/pkg/server/middleware/tcp/middlewares.go index 7e1ad1e17..5599a956c 100644 --- a/pkg/server/middleware/tcp/middlewares.go +++ b/pkg/server/middleware/tcp/middlewares.go @@ -6,7 +6,9 @@ import ( "strings" "github.com/traefik/traefik/v2/pkg/config/runtime" + "github.com/traefik/traefik/v2/pkg/log" inflightconn "github.com/traefik/traefik/v2/pkg/middlewares/tcp/inflightconn" + "github.com/traefik/traefik/v2/pkg/middlewares/tcp/ipallowlist" ipwhitelist "github.com/traefik/traefik/v2/pkg/middlewares/tcp/ipwhitelist" "github.com/traefik/traefik/v2/pkg/server/provider" "github.com/traefik/traefik/v2/pkg/tcp" @@ -94,8 +96,16 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) ( } } + // IPAllowList + if config.IPAllowList != nil { + middleware = func(next tcp.Handler) (tcp.Handler, error) { + return ipallowlist.New(ctx, next, *config.IPAllowList, middlewareName) + } + } + // IPWhiteList if config.IPWhiteList != nil { + log.FromContext(ctx).Warn("IPWhiteList is deprecated, please use IPAllowList instead.") middleware = func(next tcp.Handler) (tcp.Handler, error) { return ipwhitelist.New(ctx, next, *config.IPWhiteList, middlewareName) }