Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Souin API access running as Traefik plugin #301

Closed
jonasengelmann opened this issue Jan 16, 2023 · 6 comments · Fixed by #302
Closed

Souin API access running as Traefik plugin #301

jonasengelmann opened this issue Jan 16, 2023 · 6 comments · Fixed by #302

Comments

@jonasengelmann
Copy link
Contributor

jonasengelmann commented Jan 16, 2023

I am running Souin as a Traefik plugin which works great so far! Now I want to purge the cache manually using the Souin API, yet I do not know where to access it? Is it even possible in that configuration or do I have to run Souin as a standalone container?
Many thanks for your help!

@darkweak
Copy link
Owner

Hello @jonasengelmann, if I assume your service is running under the domain domain.com you can request the souin api on the url domain.com/souin-api/souin to list keys by default. You can refer to the documentation to get the base endpoints with the required HTTP methods https://github.com/darkweak/souin#apis

@jonasengelmann
Copy link
Contributor Author

Hello @darkweak, thanks for your response! I tried accessing your suggested URL but run into an error.

Here is my very basic docker-compose:

version: "3.8"
services:
  traefik:
      image: traefik:v2.8.8
      command:
        - --providers.docker=true
        - --entrypoints.web.address=:80
        - --experimental.plugins.souin.moduleName=github.com/darkweak/souin
        - --experimental.plugins.souin.version=v1.6.27
      ports:
        - "80:80"
      networks:
        - default
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock:ro

  whoami:
    image: traefik/whoami:latest
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`localhost`)
      - traefik.http.routers.whoami.entrypoints=web
      - traefik.http.routers.whoami.middlewares=http-cache
      - traefik.http.middlewares.http-cache.plugin.souin.api.souin
      - traefik.http.middlewares.http-cache.plugin.souin.default_cache.ttl=10s
      - traefik.http.middlewares.http-cache.plugin.souin.log_level=debug

Accessing http://localhost/souin-api/souin leads to this error:

Recovered from panic in HTTP handler [172.18.0.1:62316 - /souin-api/souin]: runtime error: invalid memory address or nil pointer dereference" middlewareType=Recovery middlewareName=traefik-internal-recovery

Stack: goroutine 139 [running]:
github.com/traefik/traefik/v2/pkg/middlewares/recovery.recoverFunc({0x3d5b340, 0x40049422a0}, 0x4002effa00)
	github.com/traefik/traefik/v2/pkg/middlewares/recovery/recovery.go:46 +0x21c
panic({0x2b8fa00, 0x5b00f50})
	runtime/panic.go:884 +0x20c
github.com/traefik/yaegi/interp.runCfg.func1()
	github.com/traefik/yaegi@v0.14.2/interp/run.go:192 +0x13c
panic({0x2b8fa00, 0x5b00f50})
	runtime/panic.go:884 +0x20c
github.com/traefik/yaegi/interp.runCfg.func1()
	github.com/traefik/yaegi@v0.14.2/interp/run.go:192 +0x13c
panic({0x2b8fa00, 0x5b00f50})
	runtime/panic.go:884 +0x20c
github.com/traefik/yaegi/interp.genFunctionWrapper(0x0)
	github.com/traefik/yaegi@v0.14.2/interp/run.go:951 +0x1c
github.com/traefik/yaegi/interp.genValueAsFunctionWrapper.func1(0x2924a80?)
	github.com/traefik/yaegi@v0.14.2/interp/value.go:154 +0x108
github.com/traefik/yaegi/interp._return.func2(0x4004966a50)
	github.com/traefik/yaegi@v0.14.2/interp/run.go:2443 +0x7c
github.com/traefik/yaegi/interp.runCfg(0x4000975200, 0x4004966a50, 0x40047a6ab8?, 0x31633c0?)
	github.com/traefik/yaegi@v0.14.2/interp/run.go:200 +0x21c
github.com/traefik/yaegi/interp.call.func9(0x4004959e40)
	github.com/traefik/yaegi@v0.14.2/interp/run.go:1438 +0x7b4
github.com/traefik/yaegi/interp.runCfg(0x400461cc60, 0x4004959e40, 0x0?, 0x31633c0?)
	github.com/traefik/yaegi@v0.14.2/interp/run.go:200 +0x21c
github.com/traefik/yaegi/interp.genFunctionWrapper.func2.1({0x40023e6d50, 0x2, 0x4?})
	github.com/traefik/yaegi@v0.14.2/interp/run.go:1022 +0x398
github.com/traefik/yaegi/stdlib._net_http_Handler.ServeHTTP(...)
	github.com/traefik/yaegi@v0.14.2/stdlib/go1_19_net_http.go:290
github.com/traefik/traefik/v2/pkg/middlewares/accesslog.(*FieldHandler).ServeHTTP(0x400322e3c0, {0x3d5b340, 0x40049422a0}, 0x2b3be80?)
	github.com/traefik/traefik/v2/pkg/middlewares/accesslog/field_middleware.go:29 +0x120
github.com/gorilla/mux.(*Router).ServeHTTP(0x4004800600, {0x3d5b340, 0x40049422a0}, 0x4002effa00)
	github.com/gorilla/mux@v1.8.0/mux.go:141 +0x1ec
github.com/traefik/traefik/v2/pkg/middlewares/recovery.(*recovery).ServeHTTP(0x76a8?, {0x3d5b340?, 0x40049422a0?}, 0x30?)
	github.com/traefik/traefik/v2/pkg/middlewares/recovery/recovery.go:32 +0x6c
github.com/traefik/traefik/v2/pkg/middlewares/accesslog.(*FieldHandler).ServeHTTP(0x400322e4c0, {0x3d5b340, 0x40049422a0}, 0x4002effa00?)
	github.com/traefik/traefik/v2/pkg/middlewares/accesslog/field_middleware.go:29 +0x120
github.com/traefik/traefik/v2/pkg/middlewares.(*HTTPHandlerSwitcher).ServeHTTP(0xf8?, {0x3d5b340, 0x40049422a0}, 0x1474de4?)
	github.com/traefik/traefik/v2/pkg/middlewares/handler_switcher.go:23 +0x60
github.com/traefik/traefik/v2/pkg/middlewares/requestdecorator.(*RequestDecorator).ServeHTTP(0x400000ef98, {0x3d5b340, 0x40049422a0}, 0x4002eff500, 0x40047a77a0)
	github.com/traefik/traefik/v2/pkg/middlewares/requestdecorator/request_decorator.go:47 +0x2ac
github.com/traefik/traefik/v2/pkg/middlewares/requestdecorator.WrapHandler.func1.1({0x3d5b340?, 0x40049422a0?}, 0x4001196bd0?)
	github.com/traefik/traefik/v2/pkg/middlewares/requestdecorator/request_decorator.go:89 +0x64
net/http.HandlerFunc.ServeHTTP(0x40002972c0?, {0x3d5b340?, 0x40049422a0?}, 0x9?)
	net/http/server.go:2109 +0x38
github.com/traefik/traefik/v2/pkg/middlewares/forwardedheaders.(*XForwarded).ServeHTTP(0x40002972c0, {0x3d5b340, 0x40049422a0}, 0x4002eff500)
	github.com/traefik/traefik/v2/pkg/middlewares/forwardedheaders/forwarded_header.go:192 +0xdc
net/http.AllowQuerySemicolons.func1({0x3d5b340, 0x40049422a0}, 0x4002eff500)
	net/http/server.go:2974 +0x238
net/http.HandlerFunc.ServeHTTP(0x20?, {0x3d5b340?, 0x40049422a0?}, 0x7b18c?)
	net/http/server.go:2109 +0x38
golang.org/x/net/http2/h2c.h2cHandler.ServeHTTP({{0x3d3a9e0?, 0x400000dd88?}, 0x4000221e00?}, {0x3d5b340, 0x40049422a0}, 0x4002eff500)
	golang.org/x/net@v0.0.0-20220927171203-f486391704dc/http2/h2c/h2c.go:124 +0x410
net/http.serverHandler.ServeHTTP({0x400234d2c0?}, {0x3d5b340, 0x40049422a0}, 0x4002eff500)
	net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x4000344960, {0x3d5d010, 0x4000724060})
	net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
	net/http/server.go:3102 +0x43c
" middlewareName=traefik-internal-recovery middlewareType=Recovery

Did I set up something incorrectly?

@darkweak
Copy link
Owner

IMHO that's a Træfik issue, can you try to downgrade to a lower version? From the given logs that's the Yægi interpreter issue. Anyway I'll try to reproduce and if possible upgrade to the latest Traefik version this evening.

@jonasengelmann
Copy link
Contributor Author

I tried downgrading Traefik until v2.7.0, yet the error persisted. Downgrading further was not possible with this configuration. Really appreciate that you are looking into it so quickly! Many thanks!

@darkweak
Copy link
Owner

That's an issue in the yaegi interpreter but I found a way to patch that. They thought they were able to code a stable interpreter but they are introducing more bugs than they fix and most of the time they are introducing some BC breaks.

Here the interpreter was lost during the code interpretation because it thought the returned handler (here the souin api handler to purge the cache) was nil 🤷‍♂️

@jonasengelmann
Copy link
Contributor Author

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants