Setting an Authorization header after a ForwardAuth in Traefik

Viewed 1400

I'm moving from Nginx to Traefik as the reverse-proxy of a Docker Swarm.

Currently, each request coming with a Bearer Token is sent to an authentication service (microservice running in the Swarm) which sends back a JWT when auth is correct. I then need to use this JWT in the Authorization header to the request can be sent to the service it targets.

The current setup with Nginx:

auth_request /auth;
auth_request_set $jwt $upstream_http_jwt;
proxy_set_header "Authorization" "jwt $jwt";

Can this approach be done with Traefik ForwardAuth directly or do I have to add a middleware to create this header once the request has been authenticated ?

1 Answers

This is possible if your authentication service can return the JWT in the Authorization header of its response. Set the authResponseHeaders option of the ForwardAuth middleware to Authorization.

The authResponseHeaders option is the list of headers to copy from the authentication server response and set on forwarded request, replacing any existing conflicting headers.

E.g.

http:
  middlewares:
    auth:
      forwardAuth:
        address: "http://your_auth_server/auth"
        authResponseHeaders:
          - "Authorization"
Related