A middleware plugin for Traefik that
retrieves Set-Cookie
headers from a custom HTTP/HTTPS request and assigns them
to the Cookie
header of the request which is forwarded to the next Traefik
middleware or Traefik service.
testData:url: https://a-domain.com/a-pathmethod: POSTresponseCookies:- COOKIE-A- COOKIE-B
url
the target of the HTTP/HTTPS requestmethod
the HTTP methodresponseCookies
the variable names of the Set-Cookie
header values in the
HTTP response that will be appended to the Cookie
header of the original
HTTP request.Based on the above testData
, the request, which will be forwarded to the next
Traefik middleware or Traefik service, will contain a Cookie
header with the
value COOKIE-A=<x>; COOKIE-B=<y>
where x
and y
are the values retrieved by
the HTTP request defined in the plugin's configuration.
The reason for developing this plugin for Traefik was one of the limitations of
SonarQube Community Edition 8.9.2 LTS. The limitation was that
SonarQube's Web API was
restricting unauthorized users to hit endpoints, like
api/project_badges/quality_gate
, and retrieve info for private projects. Here,
it should be mentioned that this make sense since a project is private. However,
there was a need by the SonarQube community to retrieve project badges. In
short, this is the story:
Instead of waiting, I decided to solve this issue by deploying a Traefik instance in front of my SonarQube instance and developing a Traefik plugin that implicitly authenticates any requests to the Web API of SonarQube using a "read-only" user.
You will need to modify or extend the below snippets according to your setup.
Notice that this config will authenticate to SonarQube via endpoint
/api/authentication/login
using the relevant query parameters as defined by
SonarQube's Web API (Community Edition 8.9.2 LTS).
pilot:token: <your-token>experimental:plugins:cookie-handler:moduleName: github.com/vaspapadopoulos/traefik-cookie-handler-pluginversion: v0.1.0
http:routers:sonarqube-router:service: sonarquberule: Host(`my-sonarqube.domain.com`)sonarqube-router-badges:service: sonarqubemiddlewares:- sonarQubeBadgesAuthrule: >Host(`my-sonarqube.domain.com`) &&(Path(`/api/project_badges/measure`) && Path(`/api/project_badges/quality_gate`))&&Method(`GET`)middlewares:sonarQubeBadgesAuth:plugin:cookie-handler:url: >http://x.y.z.w:p/api/authentication/login?login=some_user&password=some_passwordmethod: POSTresponseCookies:- JWT-SESSION- XSRF-TOKENservices:sonarqube:loadBalancer:servers:- url: http://x.y.z.w:p/