Merge pull request #3786 from Shopify/rewrite-x-forwarded-prefix
Fix x-forwarded-prefix annotation
This commit is contained in:
commit
b87cc5a1a6
8 changed files with 121 additions and 22 deletions
|
|
@ -99,7 +99,7 @@ type Ingress struct {
|
|||
LoadBalancing string
|
||||
UpstreamVhost string
|
||||
Whitelist ipwhitelist.SourceRange
|
||||
XForwardedPrefix bool
|
||||
XForwardedPrefix string
|
||||
SSLCiphers string
|
||||
Logs log.Config
|
||||
LuaRestyWAF luarestywaf.Config
|
||||
|
|
|
|||
|
|
@ -35,5 +35,5 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
|||
// Parse parses the annotations contained in the ingress rule
|
||||
// used to add an x-forwarded-prefix header to the request
|
||||
func (cbbs xforwardedprefix) Parse(ing *extensions.Ingress) (interface{}, error) {
|
||||
return parser.GetBoolAnnotation("x-forwarded-prefix", ing)
|
||||
return parser.GetStringAnnotation("x-forwarded-prefix", ing)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ func TestParse(t *testing.T) {
|
|||
|
||||
testCases := []struct {
|
||||
annotations map[string]string
|
||||
expected bool
|
||||
expected string
|
||||
}{
|
||||
{map[string]string{annotation: "true"}, true},
|
||||
{map[string]string{annotation: "1"}, true},
|
||||
{map[string]string{annotation: ""}, false},
|
||||
{map[string]string{}, false},
|
||||
{nil, false},
|
||||
{map[string]string{annotation: "true"}, "true"},
|
||||
{map[string]string{annotation: "1"}, "1"},
|
||||
{map[string]string{annotation: ""}, ""},
|
||||
{map[string]string{}, ""},
|
||||
{nil, ""},
|
||||
}
|
||||
|
||||
ing := &extensions.Ingress{
|
||||
|
|
|
|||
|
|
@ -503,8 +503,8 @@ func buildProxyPass(host string, b interface{}, loc interface{}) string {
|
|||
if len(location.Rewrite.Target) > 0 {
|
||||
var xForwardedPrefix string
|
||||
|
||||
if location.XForwardedPrefix {
|
||||
xForwardedPrefix = fmt.Sprintf("proxy_set_header X-Forwarded-Prefix \"%s\";\n", path)
|
||||
if len(location.XForwardedPrefix) > 0 {
|
||||
xForwardedPrefix = fmt.Sprintf("proxy_set_header X-Forwarded-Prefix \"%s\";\n", location.XForwardedPrefix)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(`
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ var (
|
|||
Location string
|
||||
ProxyPass string
|
||||
Sticky bool
|
||||
XForwardedPrefix bool
|
||||
XForwardedPrefix string
|
||||
SecureBackend bool
|
||||
enforceRegex bool
|
||||
}{
|
||||
|
|
@ -58,7 +58,7 @@ var (
|
|||
"/",
|
||||
"proxy_pass https://upstream_balancer;",
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
},
|
||||
|
|
@ -68,7 +68,7 @@ var (
|
|||
"/",
|
||||
"proxy_pass https://upstream_balancer;",
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
},
|
||||
|
|
@ -78,7 +78,7 @@ var (
|
|||
"/",
|
||||
"proxy_pass https://upstream_balancer;",
|
||||
true,
|
||||
false,
|
||||
"",
|
||||
true,
|
||||
false,
|
||||
},
|
||||
|
|
@ -88,7 +88,7 @@ var (
|
|||
"/",
|
||||
"proxy_pass http://upstream_balancer;",
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
|
|
@ -98,7 +98,7 @@ var (
|
|||
"/",
|
||||
"proxy_pass http://upstream_balancer;",
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
|
|
@ -110,7 +110,7 @@ var (
|
|||
rewrite "(?i)/" /jenkins break;
|
||||
proxy_pass http://upstream_balancer;`,
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
},
|
||||
|
|
@ -122,7 +122,7 @@ proxy_pass http://upstream_balancer;`,
|
|||
rewrite "(?i)/" /something break;
|
||||
proxy_pass http://upstream_balancer;`,
|
||||
true,
|
||||
false,
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
},
|
||||
|
|
@ -134,7 +134,7 @@ proxy_pass http://upstream_balancer;`,
|
|||
rewrite "(?i)/" /something break;
|
||||
proxy_pass http://upstream_balancer;`,
|
||||
true,
|
||||
false,
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
},
|
||||
|
|
@ -147,7 +147,7 @@ rewrite "(?i)/there" /something break;
|
|||
proxy_set_header X-Forwarded-Prefix "/there";
|
||||
proxy_pass http://upstream_balancer;`,
|
||||
true,
|
||||
true,
|
||||
"/there",
|
||||
false,
|
||||
true,
|
||||
},
|
||||
|
|
@ -157,7 +157,7 @@ proxy_pass http://upstream_balancer;`,
|
|||
`~* "^/something"`,
|
||||
"proxy_pass http://upstream_balancer;",
|
||||
false,
|
||||
false,
|
||||
"",
|
||||
false,
|
||||
true,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -292,7 +292,7 @@ type Location struct {
|
|||
// XForwardedPrefix allows to add a header X-Forwarded-Prefix to the request with the
|
||||
// original location.
|
||||
// +optional
|
||||
XForwardedPrefix bool `json:"xForwardedPrefix,omitempty"`
|
||||
XForwardedPrefix string `json:"xForwardedPrefix,omitempty"`
|
||||
// Logs allows to enable or disable the nginx logs
|
||||
// By default access logs are enabled and rewrite logs are disabled
|
||||
Logs log.Config `json:"logs,omitempty"`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue