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

chore: adds kong example. #144

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

chore: adds kong example. #144

wants to merge 6 commits into from

Conversation

jcchavezs
Copy link
Member

@jcchavezs jcchavezs commented Feb 4, 2023

This PR attempts to run kong with coraza-proxy-wasm enabled, kind of following https://github.com/Kong/proxy-wasm-hello-world

Limitations:

  • Kong proxy wasm runtime does not support host calls relative to metrics (e.g. DefineCounterMetric)
  • Some rules that attempt to modify the response body are failing as the response body has been already sent (to confirm)

Things to sort out:

  • Verify if at least this can pass the e2e test
  • Turn into docker compose
  • Get someone from Kong involved

@jcchavezs jcchavezs requested a review from anuraaga as a code owner February 4, 2023 19:01
@@ -172,6 +172,9 @@ func Build() error {
if os.Getenv("MEMSTATS") == "true" {
buildTags = append(buildTags, "memstats")
}
if os.Getenv("METRICS") == "false" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefineCountMetric isn't supported by kong yet.

Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the folder to examples and move the current one to an envoy subfolder

@@ -0,0 +1,30 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a docker-compose instead like the other example

@jcchavezs
Copy link
Member Author

jcchavezs commented Feb 6, 2023 via email

@jcchavezs jcchavezs marked this pull request as draft February 6, 2023 10:25
@hishamhm
Copy link

hishamhm commented Feb 6, 2023

@jcchavezs Hi! Hisham from Kong's WasmX team here — it's really cool that you're giving this a go! A lot has happened on our end since the tech preview container we released at Kong Summit 2022; we want to make some more updates public in the near future, but AFAIK there's no confirmed ETA yet.

I just looked at your PR diff and haven't actually played with it, but it looks like with these changes you succeeded loading your filter into the gateway using the tech preview container, right? Nice!

Verify if at least this can pass the e2e test

Very curious about this! I briefly looked at e2e/e2e-example.sh — given a Kong instance configured with the same ports and filter settings, in principle if all goes well that script should be able to run unmodified, right?

Get someone from Kong involved

You can get this box checked :)

@jcchavezs
Copy link
Member Author

Thanks for showing up @hishamhm

we want to make some more updates public in the near future, but AFAIK there's no confirmed ETA yet.

Any chance you can run a kong example with the e2e enabled with your internal image?

I just looked at your PR diff and haven't actually played with it, but it looks like with these changes you succeeded loading your filter into the gateway using the tech preview container, right? Nice!

Yes, I think we can do better at providing examples when the config string is complex (e.g. in our case it is a JSON where strings hold quotes inside).

Very curious about this! I briefly looked at e2e/e2e-example.sh — given a Kong instance configured with the same ports and filter settings, in principle if all goes well that script should be able to run unmodified, right?

Yeah I will try that one once I have some time.

You can get this box checked :)

Awesome, thanks. Are you in any slack? would be cool to have a few words.

@jcchavezs
Copy link
Member Author

jcchavezs commented Feb 13, 2023

@hishamhm I am having an issue by using kong in docker-compose. Basically kong can contact upstream, see https://github.com/corazawaf/coraza-proxy-wasm/pull/144/files#diff-c237865426ae84633a58c9aad1bd2ccb628bf43cff4ecbb262561aa534d8449dR24. Any clue?

@hishamhm
Copy link

hishamhm commented Mar 2, 2023

@jcchavezs hi, I was away on vacation, but I'm back now and I'll take a look at this as soon as I can!

@jcchavezs
Copy link
Member Author

Friendly ping @hishamhm

@hishamhm
Copy link

@jcchavezs Hi José — I gave this branch a try. It's been a long time since I last used Docker Compose, and I'm unfamiliar with Mage, so I hacked my way around them until I got something running in the Kong logs.

Here's a gist with all of my quick-and-dirty tweaks.

At first glance, it seemed to me that the problem with the configuration wasn't actually Kong-specific?... In your service-provisioner.sh script, were you able to talk to your httpbin upstream directly, without going through Kong? I tweaked it a bit so that http to httpbin worked directly, then I tried going at it through Kong. I also simplified the docker-compose configuration by replacing the Postgres database with a database-less Kong configuration, specifying the route, service and plugin directly in the declarative config file. I managed to get the request through, and the error messages indicate that the filter did run:

kong-kong-1                 | 172.18.0.4 - - [14/Mar/2023:21:11:41 +0000] "GET / HTTP/1.1" 200 17781 "-" "HTTPie/0.9.2"
kong-kong-1                 | 2023/03/14 21:11:41 [warn] 2162#0: *2370 failed to get source address: error status returned by host: not found, client: 172.18.0.4, server: kong, request: "GET / HTTP/1.1", host: "kong:8000"
kong-kong-1                 | 2023/03/14 21:11:41 [warn] 2162#0: *2370 failed to get destination address: error status returned by host: not found, client: 172.18.0.4, server: kong, request: "GET / HTTP/1.1", host: "kong:8000"
kong-kong-1                 | 2023/03/14 21:11:41 [crit] 2162#0: *2370 /%!(EXTRA T=GET, T=HTTP/2.0), client: 172.18.0.4, server: kong, request: "GET / HTTP/1.1", host: "kong:8000"
kong-kong-1                 | 2023/03/14 21:11:41 [crit] 2162#0: *2370 failed to get request headers: error status returned by host: not found, client: 172.18.0.4, server: kong, request: "GET / HTTP/1.1", host: "kong:8000"
kong-httpbin-1              | time="2023-03-14T21:11:41.6085" status=200 method="GET" uri="/" size_bytes=11133 duration_ms=0.30 user_agent="HTTPie/0.9.2" client_ip=172.18.0.4
kong-kong-1                 | 2023/03/14 21:11:41 [crit] 2162#0: *2370 [client ""] Coraza: Warning. Inbound Anomaly Score Exceeded (Total Score: 0) [file "@owasp_crs/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "0"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 0)"] [data ""] [severity "emergency"] [ver "OWASP_CRS/4.0.0-rc1"] [maturity "0"] [accuracy "0"] [tag "anomaly-evaluation"] [hostname ""] [uri "/"] [unique_id "mFPOhCJCcgpsAymuCZd"]
kong-kong-1                 |  while reading response header from upstream, client: 172.18.0.4, server: kong, request: "GET / HTTP/1.1", upstream: "http://172.18.0.2:8080/", host: "kong:8000"
kong-kong-1                 | 2023/03/14 21:11:41 [error] 2162#0: *2370 [wasm] trap in proxy_on_response_headers: response already sent <module: "main", vm: "main", runtime: "wasmer"> while reading response header from upstream, client: 172.18.0.4, server: kong, request: "GET / HTTP/1.1", upstream: "http://172.18.0.2:8080/", host: "kong:8000"
kong-kong-1                 | 172.18.0.4 - - [14/Mar/2023:21:11:41 +0000] "GET / HTTP/1.1" 500 46 "-" "HTTPie/0.9.2"
kong-service-provisioner-1  | {
kong-service-provisioner-1  |   "message":"An unexpected error occurred"
kong-service-provisioner-1 exited with code 0

These errors such as failed to get source address: error status returned by host: not found are probably caused by the Kong image being too old and missing proper support for those properties — I haven't tried it yet with a more recent build.

I assume you already ran the filter on Kong without the docker-compose environment — did you get it running further than what the logs above show?

@jcchavezs
Copy link
Member Author

Thanks a lot @hishamhm, indeed your changes improved the experience however as you point out, proxy wasm fails to get headers. Is there any chance we can try this with a more recent image? It would be cool to at least try rules in phase 1 (those about URI and request headers). If now, do you have a date when those are available? Wasmio 2023 is next week and it could be really cool to have this at least in a PoC.

@hishamhm
Copy link

Wasmio 2023 is next week and it could be really cool to have this at least in a PoC.

@jcchavezs I don't think we'll have a new public snapshot ready by then, but @casimiro from our team will be at the conference. If you or anyone from your team happen to be there, make sure to get in touch!

@jcchavezs
Copy link
Member Author

@s3rj1k
Copy link

s3rj1k commented Jul 1, 2024

@jcchavezs Are go changes planned to be merged into main? (Bare-minimal to make it work with Kong)

@jcchavezs
Copy link
Member Author

jcchavezs commented Jul 1, 2024 via email

@thibaultcha
Copy link

Btw, we now support metrics in ngx_wasm_module since last week. An upcoming release of Kong Gateway will include the latest ngx_wasm_module (no timeline yet, probably later this month or next).

@s3rj1k
Copy link

s3rj1k commented Jul 1, 2024

@thibaultcha Do we have some documentation for quick start with corza-wasm+ngx_wasm_module ?

@thibaultcha
Copy link

thibaultcha commented Jul 1, 2024

@s3rj1k Not that I know of. We have lots of documentation for ngx_wasm_module, and I'm sure coraza-wasm has its own documentation which should be more than enough.

@s3rj1k
Copy link

s3rj1k commented Jul 1, 2024

Not that I know of

I mean do you test that integration somehow in Kong? Maybe some Dockerfile? Or it just was some manual one-shot test from Kong side? (Not being negative here, just trying to understand maybe we already have some work done)

@thibaultcha
Copy link

We do not have a continuous integration suite for each Proxy-Wasm filter, I don't think that would be very sustainable... All of our tests for existing Proxy-Wasm filters (coraza-wasm or others) are one-off.

@s3rj1k
Copy link

s3rj1k commented Jul 1, 2024

are one-off

I see, thanks, so in case I would want to test this it should work on Kong/ngx_wasm_module HEAD + this PR?
cc @jcchavezs

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 this pull request may close these issues.

5 participants