@@ -2,6 +2,7 @@ package configuration
2
2
3
3
import (
4
4
"fmt"
5
+ "strconv"
5
6
"strings"
6
7
7
8
"github.com/containous/traefik/log"
@@ -11,20 +12,19 @@ import (
11
12
12
13
// EntryPoint holds an entry point configuration of the reverse proxy (ip, port, TLS...)
13
14
type EntryPoint struct {
14
- Address string
15
- TLS * tls.TLS `export:"true"`
16
- Redirect * types.Redirect `export:"true"`
17
- Auth * types.Auth `export:"true"`
18
- WhitelistSourceRange [] string // Deprecated
19
- WhiteList * types. WhiteList `export:"true"`
20
- Compress * Compress `export:"true"`
21
- ProxyProtocol * ProxyProtocol `export:"true"`
22
- ForwardedHeaders * ForwardedHeaders `export:"true"`
15
+ Address string
16
+ TLS * tls.TLS `export:"true"`
17
+ Redirect * types.Redirect `export:"true"`
18
+ Auth * types.Auth `export:"true"`
19
+ WhiteList * types. WhiteList `export:"true"`
20
+ Compress * Compress `export:"true"`
21
+ ProxyProtocol * ProxyProtocol `export:"true"`
22
+ ForwardedHeaders * ForwardedHeaders `export:"true"`
23
+ ClientIPStrategy * types. IPStrategy `export:"true"`
23
24
}
24
25
25
26
// Compress contains compress configuration
26
- type Compress struct {
27
- }
27
+ type Compress struct {}
28
28
29
29
// ProxyProtocol contains Proxy-Protocol configuration
30
30
type ProxyProtocol struct {
@@ -68,11 +68,6 @@ func (ep *EntryPoints) Type() string {
68
68
func (ep * EntryPoints ) Set (value string ) error {
69
69
result := parseEntryPointsConfiguration (value )
70
70
71
- var whiteListSourceRange []string
72
- if len (result ["whitelistsourcerange" ]) > 0 {
73
- whiteListSourceRange = strings .Split (result ["whitelistsourcerange" ], "," )
74
- }
75
-
76
71
var compress * Compress
77
72
if len (result ["compress" ]) > 0 {
78
73
compress = & Compress {}
@@ -84,29 +79,42 @@ func (ep *EntryPoints) Set(value string) error {
84
79
}
85
80
86
81
(* ep )[result ["name" ]] = & EntryPoint {
87
- Address : result ["address" ],
88
- TLS : configTLS ,
89
- Auth : makeEntryPointAuth (result ),
90
- Redirect : makeEntryPointRedirect (result ),
91
- Compress : compress ,
92
- WhitelistSourceRange : whiteListSourceRange ,
93
- WhiteList : makeWhiteList (result ),
94
- ProxyProtocol : makeEntryPointProxyProtocol (result ),
95
- ForwardedHeaders : makeEntryPointForwardedHeaders ( result ),
82
+ Address : result ["address" ],
83
+ TLS : configTLS ,
84
+ Auth : makeEntryPointAuth (result ),
85
+ Redirect : makeEntryPointRedirect (result ),
86
+ Compress : compress ,
87
+ WhiteList : makeWhiteList ( result ) ,
88
+ ProxyProtocol : makeEntryPointProxyProtocol (result ),
89
+ ForwardedHeaders : makeEntryPointForwardedHeaders (result ),
90
+ ClientIPStrategy : makeIPStrategy ( "clientipstrategy" , result ),
96
91
}
97
92
98
93
return nil
99
94
}
100
95
101
96
func makeWhiteList (result map [string ]string ) * types.WhiteList {
102
- var wl * types.WhiteList
103
97
if rawRange , ok := result ["whitelist_sourcerange" ]; ok {
104
- wl = & types.WhiteList {
105
- SourceRange : strings .Split (rawRange , "," ),
106
- UseXForwardedFor : toBool ( result , "whitelist_usexforwardedfor" ),
98
+ return & types.WhiteList {
99
+ SourceRange : strings .Split (rawRange , "," ),
100
+ IPStrategy : makeIPStrategy ( "whitelist_ipstrategy" , result ),
107
101
}
108
102
}
109
- return wl
103
+ return nil
104
+ }
105
+
106
+ func makeIPStrategy (prefix string , result map [string ]string ) * types.IPStrategy {
107
+ depth := toInt (result , prefix + "_depth" )
108
+ excludedIPs := result [prefix + "_excludedips" ]
109
+
110
+ if depth == 0 && len (excludedIPs ) == 0 {
111
+ return nil
112
+ }
113
+
114
+ return & types.IPStrategy {
115
+ Depth : depth ,
116
+ ExcludedIPs : strings .Split (excludedIPs , "," ),
117
+ }
110
118
}
111
119
112
120
func makeEntryPointAuth (result map [string ]string ) * types.Auth {
@@ -184,15 +192,14 @@ func makeEntryPointProxyProtocol(result map[string]string) *ProxyProtocol {
184
192
}
185
193
186
194
if proxyProtocol != nil && proxyProtocol .Insecure {
187
- log .Warn ("ProxyProtocol.Insecure :true is dangerous. Please use 'ProxyProtocol.TrustedIPs:IPs' and remove 'ProxyProtocol.Insecure :true'" )
195
+ log .Warn ("ProxyProtocol.insecure :true is dangerous. Please use 'ProxyProtocol.TrustedIPs:IPs' and remove 'ProxyProtocol.insecure :true'" )
188
196
}
189
197
190
198
return proxyProtocol
191
199
}
192
200
193
201
func makeEntryPointForwardedHeaders (result map [string ]string ) * ForwardedHeaders {
194
- // TODO must be changed to false by default in the next breaking version.
195
- forwardedHeaders := & ForwardedHeaders {Insecure : true }
202
+ forwardedHeaders := & ForwardedHeaders {}
196
203
if _ , ok := result ["forwardedheaders_insecure" ]; ok {
197
204
forwardedHeaders .Insecure = toBool (result , "forwardedheaders_insecure" )
198
205
}
@@ -300,3 +307,14 @@ func toBool(conf map[string]string, key string) bool {
300
307
}
301
308
return false
302
309
}
310
+
311
+ func toInt (conf map [string ]string , key string ) int {
312
+ if val , ok := conf [key ]; ok {
313
+ intVal , err := strconv .Atoi (val )
314
+ if err != nil {
315
+ return 0
316
+ }
317
+ return intVal
318
+ }
319
+ return 0
320
+ }
0 commit comments