tomMoulard / htransformation

A Traefik plugin to change on the fly header's value of a request
MIT License
77 stars 13 forks source link

Docker-compose configuration #32

Closed arcogabbo closed 2 years ago

arcogabbo commented 2 years ago

Hi, i'm trying to configure this plugin entirely on a docker-compose by labels and commands on traefik. At the moment this is my configuration:

traefik:
    image: traefik:v2.8
    command: |-
      --entrypoints.web.address=:80
      --entrypoints.web.forwardedHeaders.insecure=true
      --entrypoints.websecure.address=:8080
      --entrypoints.websecure.forwardedHeaders.insecure=true
      --providers.docker=true
      --providers.docker.network=my-network
      --log.level=DEBUG
      --experimental.plugins.htransformation.modulename=github.com/tomMoulard/htransformation
      --experimental.plugins.htransformation.version=v0.2.5
    ports:
      - ${PORT}:${PORT}
      - 8080:8080
    networks:
      - my-network
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    labels:
      - "traefik.http.middlewares.testHeader.headers.customrequestheaders.x-user-id=unused"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[0].Rule.Name=test"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[0].Rule.Header=header1"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[0].Rule.Value=header-renamed"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[0].Rule.Type=Rename"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[1].Rule.Name=test2"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[1].Rule.Header=header3"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[1].Rule.Value=something"
      - "traefik.http.middlewares.ht.plugin.htransformation.Rules[1].Rule.Type=Set"
      - "traefik.http.middlewares.testHeader.headers.customrequestheaders.x-user-note=unused"

However i don't see any effects on the requests and i'm wondering why. Previously i tried with #23 pattern with no success. I also tried with the following patterns:

    - "traefik.http.middlewares.ht.plugin.htransformation.Rules[0].Name=test"
    ....
    - "traefik.http.middlewares.ht.plugin.htransformation.rules[0].Name=test"
    ....

Am I doing something wrong? Thanks in advance

tomMoulard commented 2 years ago

Hello @arcogabbo,

Thanks for using this Traefik Plugin,

Indeed, your labels are missing a value. When using your example, I got plugin: unknown plugin type: Rules entryPointName=http routerName=whoami@docker.

The correct label should be traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].foo: bar

Here's an example ```yml version: '3.9' services: traefik: image: traefik:v2.8 command: - --providers.docker - --experimental.plugins.htransformation.modulename=github.com/tomMoulard/htransformation - --experimental.plugins.htransformation.version=v0.2.5 ports: - "80:80" volumes: - /var/run/docker.sock:/var/run/docker.sock whoami: image: traefik/whoami labels: traefik.http.routers.whoami.rule: Host(`whoami.localhost`) traefik.http.routers.whoami.middlewares: myhtransformation traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Header: NewHeader traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Name: header addition traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Type: Set traefik.http.middlewares.myhtransformation.plugin.htransformation.Rules[0].Value: True ``` ``` $ curl http://whoami.localhost GET / HTTP/1.1 Host: whoami.localhost ... Newheader: true ```