tomMoulard / htransformation

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

Plugin v0.2.7 and Traefik v2.7+ panic due to reflect.Set #41

Closed Michaelhobo closed 1 year ago

Michaelhobo commented 1 year ago

I'm getting the following error when running htransformation plugin with Traefik v2.7+:

src/github.com/tomMoulard/htransformation/htransformation.go:40:3: panic

Error in Go routine: reflect.Set: value of type map[string]*interp.node is not assignable to type map[string]func(http.ResponseWriter, *http.Request, struct { Header string \"yaml:\\\"Header\\\"\"; HeaderPrefix string \"yaml:\\\"HeaderPrefix\\\"\"; Name string \"yaml:\\\"Name\\\"\"; Regexp *regexp.Regexp \"yaml:\\\"-\\\"\"; Sep string \"yaml:\\\"Sep\\\"\"; Type string \"yaml:\\\"Type\\\"\"; Value string \"yaml:\\\"Value\\\"\"; ValueReplace string \"yaml:\\\"ValueReplace\\\"\"; Values []string \"yaml:\\\"Values\\\"\"; SetOnResponse bool \"yaml:\\\"SetOnRequest\\\"\" })

This looks pretty similar to the error in https://github.com/tomMoulard/htransformation/issues/39

tomMoulard commented 1 year ago

I need to reproduce this on my own, but it looks like an error on Yaegi's side.

tomMoulard commented 1 year ago

@Michaelhobo, I am sorry, but I cannot reproduce your issue. Can you provide a reproducible use case, using the docker-compose.yaml example file provided in the repository, for example ?

Michaelhobo commented 1 year ago

Here is the docker-compose.yml file I used

version: '3.9'

services:
  traefik:
    image: traefik:v2.7
    command:
      - --api.insecure=true
      - --providers.docker
      - --providers.file.filename=/rules-htransformation.yaml
      - --log.level=DEBUG
      - --experimental.plugins.htransformation.moduleName=github.com/tomMoulard/htransformation
      - --experimental.plugins.htransformation.version=v0.2.7
    ports:
      - 9000:80
      - 9001:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./rules-htransformation.yaml:/rules-htransformation.yaml
      - .:/plugins-local/src/github.com/tomMoulard/htransformation/
    tty: true

  whoami:
    image: traefik/whoami # https://github.com/traefik/whoami
    command: -name whoami
    labels:
      traefik.http.routers.whoami.rule: Host(`whoami.localhost`)
      traefik.http.routers.whoami.middlewares: htransformation@file

Here's the log from running docker compose up: https://gist.github.com/Michaelhobo/b2dff45b9391168f7cb0bbf6db4eb801

Michaelhobo commented 1 year ago

Also to clarify, we haven't done the Traefik v3 migration yet, so what I mean by "v2.7+" is really "v2.7 <= x < v3.0".

I ran this again with traefik:v3.0, and it does not have that error.

tomMoulard commented 1 year ago

It seems to be fixed in v2.9 by updating yaegi to include fixes (like this one: https://github.com/traefik/yaegi/issues/1447), so you might want to use traefik v2.9+.