Use QuoteMeta for cookie name when building canary rules
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Build and Publish Documentation / Doc Process (push) Has been cancelled
Build experimental image on branch / build-webui (push) Has been cancelled
Build experimental image on branch / Build experimental image on branch (push) Has been cancelled

This commit is contained in:
Kevin Pollet 2026-04-14 09:48:05 +02:00 committed by GitHub
parent 7c5b3e8853
commit 2b9ffc4261
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 5 deletions

View file

@ -27,7 +27,7 @@ metadata:
namespace: default
annotations:
nginx.ingress.kubernetes.io/canary: "true"
nginx.ingress.kubernetes.io/canary-by-cookie: "foo"
nginx.ingress.kubernetes.io/canary-by-cookie: "foo.bar"
spec:
ingressClassName: nginx

View file

@ -147,7 +147,7 @@ func (c canaryBackend) AppendCanaryRule(rule string) string {
}
if c.Cookie != "" {
cookieRule := fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=always(;|$)", c.Cookie))
cookieRule := fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=always(;|$)", regexp.QuoteMeta(c.Cookie)))
if c.Header != "" && c.HeaderValue == "" && c.HeaderPattern == "" {
cookieRule = fmt.Sprintf("(%s && !%s)", cookieRule, fmt.Sprintf(`Header(%q, "never")`, c.Header))
}
@ -165,7 +165,7 @@ func (c canaryBackend) AppendNonCanaryRule(rule string) string {
rules = append(rules, fmt.Sprintf(`Header(%q, "never")`, c.Header))
}
if c.Cookie != "" {
rules = append(rules, fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=never(;|$)", c.Cookie)))
rules = append(rules, fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=never(;|$)", regexp.QuoteMeta(c.Cookie))))
}
return fmt.Sprintf("(%s) && (%s)", rule, strings.Join(rules, " || "))

View file

@ -11070,7 +11070,7 @@ func TestLoadIngresses(t *testing.T) {
},
"default-ingress-with-canary-by-cookie-rule-0-path-0-canary": {
EntryPoints: []string{"http"},
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo=always(;|$)"))`,
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo\\.bar=always(;|$)"))`,
RuleSyntax: "default",
Service: "default-ingress-with-canary-by-cookie-whoami-80-canary",
Observability: &dynamic.RouterObservabilityConfig{
@ -11105,7 +11105,7 @@ func TestLoadIngresses(t *testing.T) {
},
"default-ingress-with-canary-by-cookie-rule-0-path-0-canary-tls": {
EntryPoints: []string{"https"},
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo=always(;|$)"))`,
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo\\.bar=always(;|$)"))`,
RuleSyntax: "default",
Service: "default-ingress-with-canary-by-cookie-whoami-80-canary",
Observability: &dynamic.RouterObservabilityConfig{