forked from traefik/traefik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d1d8b01
commit e8633d1
Showing
8 changed files
with
177 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
logLevel = "DEBUG" | ||
defaultEntryPoints = ["http"] | ||
|
||
[entryPoints] | ||
[entryPoints.http] | ||
address = ":8000" | ||
[entryPoints.http.proxyProtocol] | ||
trustedIPs = ["{{.HaproxyIP}}"] | ||
|
||
[web] | ||
address = ":8080" | ||
|
||
[file] | ||
|
||
[backends] | ||
[backends.backend1] | ||
[backends.backend1.servers.server1] | ||
url = "http://{{.WhoamiIP}}" | ||
|
||
[frontends] | ||
[frontends.frontend1] | ||
backend = "backend1" | ||
[frontends.frontend1.routes.test_1] | ||
rule = "Path:/whoami" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
logLevel = "DEBUG" | ||
defaultEntryPoints = ["http"] | ||
|
||
[entryPoints] | ||
[entryPoints.http] | ||
address = ":8000" | ||
[entryPoints.http.proxyProtocol] | ||
trustedIPs = ["1.2.3.4"] | ||
|
||
[web] | ||
address = ":8080" | ||
|
||
[file] | ||
|
||
[backends] | ||
[backends.backend1] | ||
[backends.backend1.servers.server1] | ||
url = "http://{{.WhoamiIP}}" | ||
|
||
[frontends] | ||
[frontends.frontend1] | ||
backend = "backend1" | ||
[frontends.frontend1.routes.test_1] | ||
rule = "Path:/whoami" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package integration | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/containous/traefik/integration/try" | ||
"github.com/go-check/check" | ||
checker "github.com/vdemeester/shakers" | ||
) | ||
|
||
type ProxyProtocolSuite struct{ BaseSuite } | ||
|
||
func (s *ProxyProtocolSuite) SetUpSuite(c *check.C) { | ||
s.createComposeProject(c, "proxy-protocol") | ||
s.composeProject.Start(c) | ||
} | ||
|
||
func (s *ProxyProtocolSuite) TestProxyProtocolTrusted(c *check.C) { | ||
gatewayIP := s.composeProject.Container(c, "haproxy").NetworkSettings.Gateway | ||
haproxyIP := s.composeProject.Container(c, "haproxy").NetworkSettings.IPAddress | ||
whoamiIP := s.composeProject.Container(c, "whoami").NetworkSettings.IPAddress | ||
file := s.adaptFile(c, "fixtures/proxy-protocol/with.toml", struct { | ||
HaproxyIP string | ||
WhoamiIP string | ||
}{haproxyIP, whoamiIP}) | ||
defer os.Remove(file) | ||
|
||
cmd, display := s.traefikCmd(withConfigFile(file)) | ||
defer display(c) | ||
err := cmd.Start() | ||
c.Assert(err, checker.IsNil) | ||
defer cmd.Process.Kill() | ||
|
||
err = try.GetRequest("http://"+haproxyIP+"/whoami", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK), try.BodyContains("X-Forwarded-For: "+gatewayIP)) | ||
display(c) | ||
c.Assert(err, checker.IsNil) | ||
} | ||
|
||
func (s *ProxyProtocolSuite) TestProxyProtocolNotTrusted(c *check.C) { | ||
haproxyIP := s.composeProject.Container(c, "haproxy").NetworkSettings.IPAddress | ||
whoamiIP := s.composeProject.Container(c, "whoami").NetworkSettings.IPAddress | ||
file := s.adaptFile(c, "fixtures/proxy-protocol/without.toml", struct { | ||
HaproxyIP string | ||
WhoamiIP string | ||
}{haproxyIP, whoamiIP}) | ||
defer os.Remove(file) | ||
|
||
cmd, display := s.traefikCmd(withConfigFile(file)) | ||
defer display(c) | ||
err := cmd.Start() | ||
c.Assert(err, checker.IsNil) | ||
defer cmd.Process.Kill() | ||
|
||
err = try.GetRequest("http://"+haproxyIP+"/whoami", 500*time.Millisecond, try.StatusCodeIs(http.StatusOK), try.BodyContains("X-Forwarded-For: "+haproxyIP)) | ||
display(c) | ||
c.Assert(err, checker.IsNil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
haproxy: | ||
image: haproxy | ||
volumes: | ||
- ../haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg | ||
|
||
whoami: | ||
image: emilevauge/whoami |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
global | ||
maxconn 4096 | ||
|
||
defaults | ||
log global | ||
mode http | ||
retries 3 | ||
option redispatch | ||
maxconn 2000 | ||
timeout connect 5000 | ||
timeout client 50000 | ||
timeout server 50000 | ||
|
||
frontend TestServerTest | ||
bind 0.0.0.0:80 | ||
mode tcp | ||
default_backend TestServerNodes | ||
|
||
backend TestServerNodes | ||
mode tcp | ||
server TestServer01 172.17.0.1:8000 send-proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters