Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying only the configmap name for 'auth-proxy-set-headers' annotation without requiring namespace #12997

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/ingress/annotations/authreq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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))
}
Expand Down
21 changes: 21 additions & 0 deletions test/e2e/annotations/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading