Fix mirror-target values without path separator and port (#9889)
* Remove variables with $ before feeding into url.Parse Signed-off-by: Gerald Pape <gerald@giantswarm.io> * Do not render invalid request mirroring config Signed-off-by: Gerald Pape <gerald@giantswarm.io> * Remove additional note from docs again Signed-off-by: Gerald Pape <gerald@giantswarm.io> * Include quotes in e2e test for mirror proxy_pass --------- Signed-off-by: Gerald Pape <gerald@giantswarm.io>
This commit is contained in:
parent
4d3e64258c
commit
db49b9da6f
4 changed files with 26 additions and 7 deletions
|
@ -93,12 +93,13 @@ func (a mirror) Parse(ing *networking.Ingress) (interface{}, error) {
|
|||
config.Host, err = parser.GetStringAnnotation("mirror-host", ing)
|
||||
if err != nil {
|
||||
if config.Target != "" {
|
||||
url, err := parser.StringToURL(config.Target)
|
||||
target := strings.Split(config.Target, "$")
|
||||
|
||||
url, err := parser.StringToURL(target[0])
|
||||
if err != nil {
|
||||
config.Host = ""
|
||||
} else {
|
||||
hostname := strings.Split(url.Hostname(), "$")
|
||||
config.Host = hostname[0]
|
||||
config.Host = url.Hostname()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,24 @@ func TestParse(t *testing.T) {
|
|||
Target: "https://test.env.com/$request_uri",
|
||||
Host: "test.env.com",
|
||||
}},
|
||||
{map[string]string{backendURL: "https://test.env.com$request_uri"}, &Config{
|
||||
Source: ngxURI,
|
||||
RequestBody: "on",
|
||||
Target: "https://test.env.com$request_uri",
|
||||
Host: "test.env.com",
|
||||
}},
|
||||
{map[string]string{backendURL: "https://test.env.com:8080$request_uri"}, &Config{
|
||||
Source: ngxURI,
|
||||
RequestBody: "on",
|
||||
Target: "https://test.env.com:8080$request_uri",
|
||||
Host: "test.env.com",
|
||||
}},
|
||||
{map[string]string{backendURL: "https://test.env.com:8080/$request_uri"}, &Config{
|
||||
Source: ngxURI,
|
||||
RequestBody: "on",
|
||||
Target: "https://test.env.com:8080/$request_uri",
|
||||
Host: "test.env.com",
|
||||
}},
|
||||
{map[string]string{requestBody: "off"}, &Config{
|
||||
Source: "",
|
||||
RequestBody: "off",
|
||||
|
|
|
@ -1727,7 +1727,7 @@ func buildMirrorLocations(locs []*ingress.Location) string {
|
|||
mapped := sets.Set[string]{}
|
||||
|
||||
for _, loc := range locs {
|
||||
if loc.Mirror.Source == "" || loc.Mirror.Target == "" {
|
||||
if loc.Mirror.Source == "" || loc.Mirror.Target == "" || loc.Mirror.Host == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -1738,8 +1738,8 @@ func buildMirrorLocations(locs []*ingress.Location) string {
|
|||
mapped.Insert(loc.Mirror.Source)
|
||||
buffer.WriteString(fmt.Sprintf(`location = %v {
|
||||
internal;
|
||||
proxy_set_header Host %v;
|
||||
proxy_pass %v;
|
||||
proxy_set_header Host "%v";
|
||||
proxy_pass "%v";
|
||||
}
|
||||
|
||||
`, loc.Mirror.Source, loc.Mirror.Host, loc.Mirror.Target))
|
||||
|
|
|
@ -60,7 +60,7 @@ var _ = framework.DescribeAnnotation("mirror-*", func() {
|
|||
func(server string) bool {
|
||||
return strings.Contains(server, fmt.Sprintf("mirror /_mirror-%v;", ing.UID)) &&
|
||||
strings.Contains(server, "mirror_request_body on;") &&
|
||||
strings.Contains(server, "proxy_pass https://test.env.com/$request_uri;")
|
||||
strings.Contains(server, `proxy_pass "https://test.env.com/$request_uri";`)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue