Fix forwarding of auth-response-headers to gRPC backends (#7331)

* add e2e test for auth-response-headers annotation

* add e2e test for grpc with auth-response-headers

* fix forwarding of auth header to GRPC backends

* add test case for proxySetHeader(nil)
This commit is contained in:
Tom Hayward 2021-07-12 23:08:29 -07:00 committed by GitHub
parent 21812311ab
commit 62f9dc9516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 136 additions and 22 deletions

View file

@ -565,7 +565,7 @@ func shouldApplyGlobalAuth(input interface{}, globalExternalAuthURL string) bool
return false
}
func buildAuthResponseHeaders(headers []string) []string {
func buildAuthResponseHeaders(proxySetHeader string, headers []string) []string {
res := []string{}
if len(headers) == 0 {
@ -576,7 +576,7 @@ func buildAuthResponseHeaders(headers []string) []string {
hvar := strings.ToLower(h)
hvar = strings.NewReplacer("-", "_").Replace(hvar)
res = append(res, fmt.Sprintf("auth_request_set $authHeader%v $upstream_http_%v;", i, hvar))
res = append(res, fmt.Sprintf("proxy_set_header '%v' $authHeader%v;", h, i))
res = append(res, fmt.Sprintf("%s '%v' $authHeader%v;", proxySetHeader, h, i))
}
return res
}
@ -668,7 +668,7 @@ func buildProxyPass(host string, b interface{}, loc interface{}) string {
var xForwardedPrefix string
if len(location.XForwardedPrefix) > 0 {
xForwardedPrefix = fmt.Sprintf("proxy_set_header X-Forwarded-Prefix \"%s\";\n", location.XForwardedPrefix)
xForwardedPrefix = fmt.Sprintf("%s X-Forwarded-Prefix \"%s\";\n", proxySetHeader(location), location.XForwardedPrefix)
}
return fmt.Sprintf(`