Skip to content

Commit

Permalink
Merge 8fc6101 into 7d4cd1b
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Sep 28, 2017
2 parents 7d4cd1b + 8fc6101 commit 8fab488
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 37 deletions.
18 changes: 0 additions & 18 deletions controllers/nginx/pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"net"
"net/url"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -150,7 +149,6 @@ var (
"serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} {
return struct{ First, Second interface{} }{all, server}
},
"buildAuthSignURL": buildAuthSignURL,
"isValidClientBodyBufferSize": isValidClientBodyBufferSize,
"buildForwardedFor": buildForwardedFor,
}
Expand Down Expand Up @@ -567,22 +565,6 @@ func buildNextUpstream(input interface{}) string {
return strings.Join(nextUpstreamCodes, " ")
}

func buildAuthSignURL(input interface{}) string {
s, ok := input.(string)
if !ok {
glog.Errorf("expected an 'string' type but %T was returned", input)
return ""
}

u, _ := url.Parse(s)
q := u.Query()
if len(q) == 0 {
return fmt.Sprintf("%v?rd=$request_uri", s)
}

return fmt.Sprintf("%v&rd=$request_uri", s)
}

// buildRandomUUID return a random string to be used in the template
func buildRandomUUID() string {
s := uuid.New()
Expand Down
18 changes: 0 additions & 18 deletions controllers/nginx/pkg/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,24 +310,6 @@ func TestBuildResolvers(t *testing.T) {
}
}

func TestBuildAuthSignURL(t *testing.T) {
urlOne := "http://google.com"
validUrlOne := "http://google.com?rd=$request_uri"

urlTwo := "http://google.com?cat"
validUrlTwo := "http://google.com?cat&rd=$request_uri"

authSignURLOne := buildAuthSignURL(urlOne)
if authSignURLOne != validUrlOne {
t.Errorf("Expected '%v' but returned '%v'", validUrlOne, authSignURLOne)
}

authSignURLTwo := buildAuthSignURL(urlTwo)
if authSignURLTwo != validUrlTwo {
t.Errorf("Expected '%v' but returned '%v'", validUrlTwo, authSignURLTwo)
}
}

func TestBuildNextUpstream(t *testing.T) {
nextUpstream := "timeout http_500 http_502 non_idempotent"
validNextUpstream := "timeout http_500 http_502"
Expand Down
5 changes: 4 additions & 1 deletion controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ stream {
{{ end }}

{{ if not (empty $location.ExternalAuth.SigninURL) }}
error_page 401 = {{ buildAuthSignURL $location.ExternalAuth.SigninURL }};
error_page 401 = $location.ExternalAuth.SigninURL;
{{ end }}

{{/* if the location contains a rate limit annotation, create one */}}
Expand Down Expand Up @@ -743,6 +743,9 @@ stream {
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Scheme $pass_access_scheme;

{{/* This header is used for external authentication */}}
proxy_set_header X-Auth-Request-Redirect $request_uri;

# mitigate HTTPoxy Vulnerability
# https://www.nginx.com/blog/mitigating-the-httpoxy-vulnerability-with-nginx/
proxy_set_header Proxy "";
Expand Down

0 comments on commit 8fab488

Please sign in to comment.