Fix auth-response-headers whitespace trimming in ingress-nginx provider

This commit is contained in:
Michael 2026-03-23 14:14:04 +01:00 committed by GitHub
parent 4fa1f31f79
commit 930ff2aa09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 3 deletions

View File

@ -7,7 +7,7 @@ metadata:
annotations:
nginx.ingress.kubernetes.io/auth-url: "http://whoami.default.svc/"
nginx.ingress.kubernetes.io/auth-method: "GET"
nginx.ingress.kubernetes.io/auth-response-headers: "X-Foo"
nginx.ingress.kubernetes.io/auth-response-headers: "X-Foo, X-Bar"
spec:
ingressClassName: nginx

View File

@ -1004,7 +1004,14 @@ func applyForwardAuthConfiguration(routerName string, ingressConfig ingressConfi
return errors.New("empty auth-url found in ingress annotations")
}
authResponseHeaders := strings.Split(ptr.Deref(ingressConfig.AuthResponseHeaders, ""), ",")
var authResponseHeaders []string
if raw := ptr.Deref(ingressConfig.AuthResponseHeaders, ""); raw != "" {
for h := range strings.SplitSeq(raw, ",") {
if trimmed := strings.TrimSpace(h); trimmed != "" {
authResponseHeaders = append(authResponseHeaders, trimmed)
}
}
}
forwardMiddlewareName := routerName + "-forward-auth"
conf.HTTP.Middlewares[forwardMiddlewareName] = &dynamic.Middleware{

View File

@ -196,7 +196,7 @@ func TestLoadIngresses(t *testing.T) {
"default-ingress-with-forwardauth-rule-0-path-0-forward-auth": {
ForwardAuth: &dynamic.ForwardAuth{
Address: "http://whoami.default.svc/",
AuthResponseHeaders: []string{"X-Foo"},
AuthResponseHeaders: []string{"X-Foo", "X-Bar"},
},
},
},