From 3fda80b2cf5ebca12da097544c025e988d503fca Mon Sep 17 00:00:00 2001 From: Phil Cameron Date: Wed, 20 Sep 2017 13:01:51 -0400 Subject: [PATCH] Use an annotation to provide a route cookie Route annotation: router.openshift.io/cookie_name can be used to set a cookie name for the route. Added ROUTER_COOKIE_NAME for setting cookie name for all routes. The cookie must pass regex filter "[a-zA-Z0-9_-]+" https://trello.com/c/dZpU26W9 (3) Allow routes to set the cookie names for session stickiness --- images/router/haproxy/conf/haproxy-config.template | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/images/router/haproxy/conf/haproxy-config.template b/images/router/haproxy/conf/haproxy-config.template index 172b030f70a9..1cd0312e47e2 100644 --- a/images/router/haproxy/conf/haproxy-config.template +++ b/images/router/haproxy/conf/haproxy-config.template @@ -22,6 +22,9 @@ {{/* cidrListPattern: Match a space separated list of CIDRs; e.g. 192.168.21.23/24 192.10.2.12 */}} {{- $cidrListPattern := printf `(?:%s(?: +%s)*)` $cidrPattern $cidrPattern -}} +{{/* cookie name pattern: */}} +{{- $cookieNameRE := "[a-zA-Z0-9_-]+" -}} + {{- $timeSpecRE := "[1-9][0-9]*(us|ms|s|m|h|d)?" }} global maxconn {{env "ROUTER_MAX_CONNECTIONS" "20000"}} @@ -377,7 +380,7 @@ backend be_secure:{{$cfgIdx}} {{- end }} {{- if not (isTrue (index $cfg.Annotations "haproxy.router.openshift.io/disable_cookies")) }} - cookie {{$cfg.RoutingKeyName}} insert indirect nocache httponly + cookie {{firstMatch $cookieNameRE (index $cfg.Annotations "router.openshift.io/cookie_name") (env "ROUTER_COOKIE_NAME" "") $cfg.RoutingKeyName}} insert indirect nocache httponly {{- if and (matchValues (print $cfg.TLSTermination) "edge" "reencrypt") (ne $cfg.InsecureEdgeTerminationPolicy "Allow") }} secure {{- end }} {{- end }}{{/* end disable cookies check */}}