RestClientBuilder not using session cookies
When using the Integrity Checker, the client uses RestClientBuilder for the http client connection. When this Integrity Checker client connects through a load balancer, it seems that the load balancer's session cookie for server affinity is not being honored and the client bounces between servers causing auth errors because the server is expecting a request session.
We still need some more thorough debugging info here, but we have this so far:
https://gist.github.com/vianneychacon/aa34fbdbce04dcb1427874fab0415e36
On line 183-187 in https://github.com/dotCMS/core/blob/3.5/src/com/dotcms/rest/IntegrityResource.java, we're looking for the @FormDataParam("REQUEST_ID") String requestId to match integrityDataRequestID from servletContext = request.getSession().getServletContext(). If this request has hit a different server from the initial on, this will not be found in the session and we'll 401.
The integrityDataRequestID that we send here came from the response to a client request at line 320, and was sent to the (possibly different) server in the webTarget.request() following that.
Because the integrity data was generated into getIntegrityPath() which defaults to assets share, this should be cluster-aware as long as we can keep the integrityDataRequestID (and any other related data) somewhere cluster-aware and not in local session.
It sounds like you could to pin the receiver to a single server to resolve the issue - or if you want fault tolerance, set up another lb that would send traffic to one receiving server and failover if that one server is not available? Obviously not perfect, but not a terrible solution.
The RestClientBuilder needs to maintain a short lived cache (30m? since last access) of cookies to send which will help enable it to be pinned through load balancers that rely on cookies for load distribution.
PR Master: https://github.com/dotCMS/core/pull/11902
Hi Guys,
Issue seems now fixed by PR mentioned above. After testing changes introduced by PR, issue could not be reproduced anymore against an environment with Load Balancer. As suggested, the solution maintains a short lived cache of cookies per endpoint (30 minutes since last access).
In order to test Integrity Checker on involved scenario/configuration, a two-node dotCMS cluster on AWS Cloud (with a Load Balancer and Nginx in front) was used to act as Integrity Checker's Receiver endpoint.
Thanks to @vianneychacon and @mattyarbrough for the kind support and provisioning the environment. Thanks to @chrismccracken and @wezell for the suggestions in respect to implementation.
I am now leaving this ticket under "In Review" status. To @vianneychacon and @mattyarbrough, please notice and make sure to preserve (at least in the next days) the cluster environment provisioned in cloud as QA team will need to conduct similar tests to confirm expected behavior.
Thanks, Anibal