feat: add session-cookie-secure annotation (#7399)
This commit is contained in:
parent
8a1a5e93c7
commit
f2e743f561
9 changed files with 50 additions and 18 deletions
|
|
@ -37,6 +37,10 @@ const (
|
|||
|
||||
defaultAffinityCookieName = "INGRESSCOOKIE"
|
||||
|
||||
// This is used to force the Secure flag on the cookie even if the
|
||||
// incoming request is not secured. (https://github.com/kubernetes/ingress-nginx/issues/6812)
|
||||
annotationAffinityCookieSecure = "session-cookie-secure"
|
||||
|
||||
// This is used to control the cookie expires, its value is a number of seconds until the
|
||||
// cookie expires
|
||||
annotationAffinityCookieExpires = "session-cookie-expires"
|
||||
|
|
@ -85,6 +89,8 @@ type Cookie struct {
|
|||
Path string `json:"path"`
|
||||
// Flag that allows cookie regeneration on request failure
|
||||
ChangeOnFailure bool `json:"changeonfailure"`
|
||||
// Secure flag to be set
|
||||
Secure bool `json:"secure"`
|
||||
// SameSite attribute value
|
||||
SameSite string `json:"samesite"`
|
||||
// Flag that conditionally applies SameSite=None attribute on cookie if user agent accepts it.
|
||||
|
|
@ -126,6 +132,11 @@ func (a affinity) cookieAffinityParse(ing *networking.Ingress) *Cookie {
|
|||
klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieSameSite)
|
||||
}
|
||||
|
||||
cookie.Secure, err = parser.GetBoolAnnotation(annotationAffinityCookieSecure, ing)
|
||||
if err != nil {
|
||||
klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieSecure)
|
||||
}
|
||||
|
||||
cookie.ConditionalSameSiteNone, err = parser.GetBoolAnnotation(annotationAffinityCookieConditionalSameSiteNone, ing)
|
||||
if err != nil {
|
||||
klog.V(3).InfoS("Invalid or no annotation value found. Ignoring", "ingress", klog.KObj(ing), "annotation", annotationAffinityCookieConditionalSameSiteNone)
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ func TestIngressAffinityCookieConfig(t *testing.T) {
|
|||
data[parser.GetAnnotationWithPrefix(annotationAffinityCookieMaxAge)] = "3000"
|
||||
data[parser.GetAnnotationWithPrefix(annotationAffinityCookiePath)] = "/foo"
|
||||
data[parser.GetAnnotationWithPrefix(annotationAffinityCookieChangeOnFailure)] = "true"
|
||||
data[parser.GetAnnotationWithPrefix(annotationAffinityCookieSecure)] = "true"
|
||||
ing.SetAnnotations(data)
|
||||
|
||||
affin, _ := NewParser(&resolver.Mock{}).Parse(ing)
|
||||
|
|
@ -114,4 +115,8 @@ func TestIngressAffinityCookieConfig(t *testing.T) {
|
|||
if !nginxAffinity.Cookie.ChangeOnFailure {
|
||||
t.Errorf("expected change of failure parameter set to true but returned %v", nginxAffinity.Cookie.ChangeOnFailure)
|
||||
}
|
||||
|
||||
if !nginxAffinity.Cookie.Secure {
|
||||
t.Errorf("expected secure parameter set to true but returned %v", nginxAffinity.Cookie.Secure)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue