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

File access #17

Open
jcchavezs opened this issue May 23, 2024 · 14 comments · Fixed by #23
Open

File access #17

jcchavezs opened this issue May 23, 2024 · 14 comments · Fixed by #23

Comments

@jcchavezs
Copy link
Owner

traefik/traefik#10739

@attrib
Copy link

attrib commented May 31, 2024

Will this include the log path SecDebugLog?

@tiran133
Copy link

I'm using Traefik 3.2.0 I'm trying to load a file, and it does not seem to work.

Traefik static config

experimental:
  plugins:
    coraza-http-wasm-traefik:
      moduleName: "github.com/jcchavezs/coraza-http-wasm-traefik"
      version: "v0.2.2"
      settings:
        mounts:
          - /coraza

/coraza is mounted from the docker host into the Traefik container

Via volumes:

    volumes:
      - ./coraza:/coraza

The folder coraza contains a file named crs-setup.conf

in the middleware, I'm trying to load the file

http:
  middlewares:
    my-coraza-http-wasm-traefik:
      plugin:
        coraza-http-wasm-traefik:
          crsEnabled: true
          directives:
            - Include ./coraza/crs-setup.conf

I get following error

Failed to initialize WAF: invalid WAF config from string: failed to readfile: open coraza/crs-setup.conf: file does not exist

If I try to load it via - Include /coraza/crs-setup.conf I get:

Failed to initialize WAF: invalid WAF config from string: failed to readfile: read /coraza/crs-setup.conf: invalid name

Any idea?

@jcchavezs
Copy link
Owner Author

@tiran133 try Include crs-setup.conf

@tiran133
Copy link

Unfortunately not.
Still getting

Failed to initialize WAF: invalid WAF config from string: failed to readfile: open crs-setup.conf: file does not exist

Not sure what's going, but I tried all sorts of combinations to include the file, but it seems that the folder is not mounted.

@jcchavezs
Copy link
Owner Author

jcchavezs commented Oct 29, 2024 via email

@tiran133
Copy link

tiran133 commented Oct 29, 2024

Well the implementation is here it looks ok to me, I guess, but I'm not a go expert so not sure.

https://github.com/juliens/traefik/blob/ac0c880b1ffbe7d888a67586397976856cd7fc34/pkg/plugins/middlewarewasm.go#L89

For now, I gave up, and I will use the example file Include @crs-setup.conf.example and overwrite/add everything I need
through the middleware directives: key

@jcchavezs
Copy link
Owner Author

jcchavezs commented Oct 29, 2024 via email

jcchavezs added a commit that referenced this issue Oct 29, 2024
fix: fallsback on OS FS when not loading CRS (#17)
@jcchavezs
Copy link
Owner Author

Done, check 0.3.0

@tiran133
Copy link

tiran133 commented Oct 29, 2024

Great! Thank you for your fast reply!

Can you tag the traefik plugin too?
https://github.com/jcchavezs/coraza-http-wasm-traefik

EDIT:

Just compiled to locally and used the 'localPlugins' for traefik. Still getting the same error.

Failed to initialize WAF: invalid WAF config from string: failed to readfile: open crs-setup.conf: file does not exist

Any combination of mounts and what not, it will not work for me.

Thank you anyway!

@jcchavezs
Copy link
Owner Author

jcchavezs commented Oct 29, 2024 via email

@tiran133
Copy link

Thank you.

It is still not working for me. 😮‍💨

@jcchavezs
Copy link
Owner Author

I believe the problem comes from corazawaf/coraza#1208. I am testing the fix.

@jcchavezs jcchavezs reopened this Nov 13, 2024
@jcchavezs
Copy link
Owner Author

jcchavezs commented Nov 13, 2024

I reopened this issue because I could not find an easy fix for it. I suspect the failure comes from the mounting functionality provided by traefik. When I mount a folder e.g. /etc/coraza/testdata I am not able to access such folder. Creating a wasm function with

package main

import httpwasm "github.com/http-wasm/http-wasm-guest-tinygo/handler"

func main() {
	readDir(httpwasm.Host, ".")
	readDir(httpwasm.Host, "/")
	readDir(httpwasm.Host, "./etc")
	readDir(httpwasm.Host, "/etc")
	readDir(httpwasm.Host, "/etc/my-file")
}

func readDir(host api.Host, dir string) {
	dirEntries, err := os.ReadDir(dir)
	if err == nil {
		host.Log(api.LogLevelError, "=> reading dir"+dir)
		for _, f := range dirEntries {
			host.Log(api.LogLevelError, "reading file"+f.Name())
		}
	} else {
		host.Log(api.LogLevelError, "error reading dir "+err.Error())
	}
}

Fails all the time e2e_traefik_local-1 | 2024-11-13T14:49:22Z ERR github.com/traefik/traefik/v3/pkg/logs/wasm.go:31 > error reading dir open /etc/coraza/testdata: file does not exist

Ping @juliens

@jcchavezs
Copy link
Owner Author

Traefik merged a fix for this traefik/traefik#11321. Let's see when they cut a release.

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.

3 participants