Using dynamic application session cookies with docker swarm backend services

Hi,

I’ve followed the guide at https://www.haproxy.com/blog/haproxy-on-docker-swarm-load-balancing-and-dns-service-discovery/ to setup a haproxy to load balance docker swarm backend services which works well.

I would like to introduce sticky sessions and found the dynamic cookie configuration at https://www.haproxy.com/de/blog/whats-new-haproxy-1-8/ which allows me to use

dynamic-cookie-key MYKEY
cookie SRVID insert dynamic

in this context.

Now to my question: is it possible to setup this kind of session persistence for the usage with application session cookies, like explained in this guide: https://www.haproxy.com/blog/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/

I’m searching for a way to configure a combination of

dynamic-cookie-key MYKEY
cookie SRVID insert dynamic
server-template server-template myapp- 3 myapp-Service:80 check resolvers docker init-addr libc,none

with

cookie JSESSIONID prefix nocache
server s1 192.168.10.11:80 check cookie s1
server s2 192.168.10.21:80 check cookie s2

Any hint very appreciated,

Br,

Klaus

The documentation doesn’t mention any incompatibilities between the two, so I’d suggest you just try:

dynamic-cookie-key MYKEY
cookie JSESSIONID prefix nocache dynamic
server-template server-template myapp- 3 myapp-Service:80 check resolvers docker init-addr libc,none

But … is this really needed? Hijacking an application cookie and modifying it was needed a decade or two ago when some crazy broken implementations only supported a single cookie, I don’t understand the use-case really?

Hi,

thanks for your reply…

the combination

dynamic-cookie-key MYKEY
cookie JSESSIONID prefix nocache dynamic
server-template server-template myapp- 3 myapp-Service:80 check resolvers docker init-addr libc,none

does not work, but as you stated, I think I don’t really need it. I thought of what happens when the JSESSIONID-cookie expires, but that shouldn’t cause a problem.