Header Not reachning backend

Hello.

I am at the moment hosting a Traefik container and backend container in Scaleway.

To access containers in Scaleway while they are in private mode, a token must be passed to request header. In postman i use the token to first reach Traefik container and I used middlewares headers to have the token passed to the backend from traefik. But this is not working. Does anyone please have a clue for me ??

Below is my configuration :

```
api:
  insecure: false
  dashboard: true

providers:
  file:
    filename: /etc/traefik/traefik.yaml

entryPoints:
  web:
    address: ":8080" # The port my traefik container is listening

log:
  level: DEBUG

http:
  routers:
    auth-router:
      rule: "Host(`entry.path.io`) && PathPrefix(`/api/v1/`)"
      entryPoints:
        - web
      service: auth-service
      middlewares:
        - security-headers

  middlewares:
    security-headers:
      headers:
        customRequestHeaders:
          X-Auth-Token: xxxxx-something-aaaa-bbbbb-mm

  services:
    auth-service:
      loadBalancer:
        passHostHeader: false
        servers:
          - url: "https://target.path.io"
```

As container are in private mode The scenario is supposed to be :

  • I do a GET in postman to entry.path.io/api/v1 and in header tab i put X-Auth-Token: xxxxx-something-aaaa-bbbbb-mm

  • The request will be redirected to https://target.path.io and as stated in the yaml file, it will add itself again the header X-Auth-Token: xxxxx-something-aaaa-bbbbb-mm , because target container is also in private mode. (This is what is not working :frowning: :frowning:. Because when i pass this backend container to public, it works konwing that my Traefik container is still in private (1st step). It Means traefik is not being able to question the backend adding the header token)

I would appreciate any advice to have this working.

Thank you

Use 3 backticks before and after code/config to make it more readable and preserve spacing, which is important in yaml.

1 Like

customrequestheaders is working for me, it is echoed back by whoami:

services:
  whoami:
    image: traefik/whoami:v1.10
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`whoami.example.com`)
      - traefik.http.middlewares.myRequestHeader.headers.customrequestheaders.X-myRequestHeader=FOO
      - traefik.http.middlewares.myResponseHeader.headers.customresponseheaders.X-myResponseHeader=BAR
      - traefik.http.routers.whoami.middlewares=myRequestHeader,myResponseHeader
      - traefik.http.services.whoami.loadbalancer.server.port=80
      - traefik.http.services.whoami.loadbalancer.passHostHeader=false
1 Like

Hello @bluepuma77 ; Thank you very much for your help

So after testing with the whoami, I realised it was a prefix handing to the backend error.

I had to add in middelware striper option as well to have path as clean as possible.

```
  middlewares:

   auth-striper:
      stripPrefix:
        prefixes:
          - "/auth-service/"
```

We retested and all is fine in private mode, end to end

Thank you for your reaction.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.