diff --git a/internal/ingress/annotations/authreq/main.go b/internal/ingress/annotations/authreq/main.go index ad38c36b12..87278739f9 100644 --- a/internal/ingress/annotations/authreq/main.go +++ b/internal/ingress/annotations/authreq/main.go @@ -430,7 +430,7 @@ func (a authReq) Parse(ing *networking.Ingress) (interface{}, error) { klog.V(3).InfoS("auth-set-proxy-headers annotation is undefined and will not be set", "err", err) } - cns, _, err := cache.SplitMetaNamespaceKey(proxySetHeaderMap) + cns, cn, err := cache.SplitMetaNamespaceKey(proxySetHeaderMap) if err != nil { return nil, ing_errors.LocationDeniedError{ Reason: fmt.Errorf("error reading configmap name %s from annotation: %w", proxySetHeaderMap, err), @@ -452,7 +452,7 @@ func (a authReq) Parse(ing *networking.Ingress) (interface{}, error) { var proxySetHeaders map[string]string if proxySetHeaderMap != "" { - proxySetHeadersMapContents, err := a.r.GetConfigMap(proxySetHeaderMap) + proxySetHeadersMapContents, err := a.r.GetConfigMap(cns + "/" + cn) if err != nil { return nil, ing_errors.NewLocationDenied(fmt.Sprintf("unable to find configMap %q", proxySetHeaderMap)) } diff --git a/test/e2e/annotations/auth.go b/test/e2e/annotations/auth.go index ddda1dce5f..f8aa8f5e95 100644 --- a/test/e2e/annotations/auth.go +++ b/test/e2e/annotations/auth.go @@ -329,6 +329,27 @@ var _ = framework.DescribeAnnotation("auth-*", func() { }) }) + ginkgo.It(`should set "proxy_set_header 'My-Custom-Header' '42';" when auth-headers are set without specified namespace`, func() { + host := authHost + + annotations := map[string]string{ + "nginx.ingress.kubernetes.io/auth-url": "http://foo.bar/basic-auth/user/password", + "nginx.ingress.kubernetes.io/auth-proxy-set-headers": "auth-headers", + } + + f.CreateConfigMap("auth-headers", map[string]string{ + "My-Custom-Header": "42", + }) + + ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations) + f.EnsureIngress(ing) + + f.WaitForNginxServer(host, + func(server string) bool { + return strings.Contains(server, `proxy_set_header 'My-Custom-Header' '42';`) + }) + }) + ginkgo.It(`should set cache_key when external auth cache is configured`, func() { host := authHost