Skip to content

Commit 61f7926

Browse files
authored
feat(e2e): swaps e2e with the official Coraza ones, updates Go to 1.20 (#224)
1 parent 1722d44 commit 61f7926

File tree

12 files changed

+152
-198
lines changed

12 files changed

+152
-198
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ on:
1212
workflow_dispatch:
1313

1414
env:
15-
GO_VERSION: 1.19
15+
GO_VERSION: '1.20'
1616
TINYGO_VERSION: 0.28.1
1717
# Run e2e tests against latest two releases and latest dev
1818
ENVOY_IMAGES: >
19+
envoyproxy/envoy:v1.27-latest
1920
envoyproxy/envoy:v1.26-latest
20-
envoyproxy/envoy:v1.25-latest
2121
envoyproxy/envoy-dev:latest
2222
2323
jobs:
@@ -70,13 +70,8 @@ jobs:
7070
- name: Run unit tests
7171
run: go run mage.go coverage
7272

73-
- name: Run e2e tests against the example
74-
shell: bash
75-
run: >
76-
for image in $ENVOY_IMAGES; do
77-
echo "Running e2e with Envoy image $image"
78-
ENVOY_IMAGE=$image go run mage.go e2e
79-
done
73+
- name: Run e2e tests
74+
run: go run mage.go e2e
8075

8176
- name: Run regression tests (ftw)
8277
run: go run mage.go ftw

.github/workflows/nightly-coraza-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- cron: "0 4 * * *"
99

1010
env:
11-
GO_VERSION: 1.19
11+
GO_VERSION: '1.20'
1212
TINYGO_VERSION: 0.28.1
1313

1414
jobs:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ In order to monitor envoy logs while performing requests you can run:
163163

164164
### Manual requests
165165

166-
Run `./e2e/e2e-example.sh` in order to run the following requests against the just set up test environment, otherwise manually execute and tweak them to grasp the behaviour of the filter:
166+
List of requests that can be manually executed and tweaked to grasp the behaviour of the filter:
167167

168168
```bash
169169
# True positive requests:

e2e/Dockerfile.curl

Lines changed: 0 additions & 16 deletions
This file was deleted.

e2e/docker-compose.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
services:
22
httpbin:
3-
image: mccutchen/go-httpbin:v2.5.0
3+
image: mccutchen/go-httpbin:v2.9.0
4+
command: [ "/bin/go-httpbin", "-port", "8081" ]
5+
ports:
6+
- 8081:8081
47
envoy:
58
depends_on:
69
- httpbin
7-
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.23-latest}
10+
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.27-latest}
811
command:
912
- -c
1013
- /conf/envoy-config.yaml
1114
volumes:
1215
- ../build:/build
13-
- ../example:/conf # relying on envoy-config file from /example/
14-
tests:
15-
depends_on:
16-
- envoy
17-
build:
18-
context: .
19-
dockerfile: ./Dockerfile.curl
16+
- .:/conf
17+
ports:
18+
- 8080:8080

e2e/e2e-example.sh

Lines changed: 0 additions & 151 deletions
This file was deleted.

e2e/envoy-config.yaml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
stats_config:
2+
stats_tags:
3+
# Envoy extracts the first matching group as a value.
4+
# See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/metrics/v3/stats.proto#config-metrics-v3-statsconfig.
5+
- tag_name: phase
6+
regex: "(_phase=([a-z_]+))"
7+
- tag_name: rule_id
8+
regex: "(_ruleid=([0-9]+))"
9+
- tag_name: identifier
10+
regex: "(_identifier=([0-9a-z.:]+))"
11+
- tag_name: owner
12+
regex: "(_owner=([0-9a-z.:]+))"
13+
- tag_name: authority
14+
regex: "(_authority=([0-9a-z.:]+))"
15+
16+
static_resources:
17+
listeners:
18+
- address:
19+
socket_address:
20+
address: 0.0.0.0
21+
port_value: 8080
22+
filter_chains:
23+
- filters:
24+
- name: envoy.filters.network.http_connection_manager
25+
typed_config:
26+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
27+
stat_prefix: ingress_http
28+
codec_type: auto
29+
route_config:
30+
# A custom response header is added for e2e testing purposes. A local response, triggered by an interruption,
31+
# has to allow custom added headers like this. See https://github.com/corazawaf/coraza-proxy-wasm/pull/172
32+
response_headers_to_add:
33+
- header:
34+
key: "custom_header"
35+
value: "custom_value"
36+
virtual_hosts:
37+
- name: local_route
38+
domains:
39+
- "*"
40+
routes:
41+
- match:
42+
prefix: "/"
43+
route:
44+
cluster: local_server
45+
http_filters:
46+
- name: envoy.filters.http.wasm
47+
typed_config:
48+
"@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
49+
config:
50+
name: "coraza-filter"
51+
root_id: ""
52+
configuration:
53+
"@type": "type.googleapis.com/google.protobuf.StringValue"
54+
# See https://github.com/corazawaf/coraza/blob/main/http/e2e/cmd/httpe2e/main.go#L22 for e2e Coraza directives
55+
value: |
56+
{
57+
"directives_map": {
58+
"rs1": [
59+
"SecRuleEngine On",
60+
"SecRequestBodyAccess On",
61+
"SecResponseBodyAccess On",
62+
"SecResponseBodyMimeType application/json",
63+
"SecRule &REQUEST_HEADERS:coraza-e2e \"@eq 0\" \"id:100,phase:1,deny,status:424,log,msg:'Coraza E2E - Missing header'\"",
64+
"SecRule REQUEST_URI \"@streq /admin\" \"id:101,phase:1,t:lowercase,log,deny,status:403\"",
65+
"SecRule REQUEST_BODY \"@rx maliciouspayload\" \"id:102,phase:2,t:lowercase,log,deny,status:403\"",
66+
"SecRule RESPONSE_HEADERS:pass \"@rx leak\" \"id:103,phase:3,t:lowercase,log,deny,status:403\"",
67+
"SecRule RESPONSE_BODY \"@contains responsebodycode\" \"id:104,phase:4,t:lowercase,log,deny,status:403\"",
68+
"SecRule ARGS_NAMES|ARGS \"@detectXSS\" \"id:9411,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:htmlEntityDecode,t:jsDecode,t:cssDecode,t:removeNulls,log,deny,status:403\"",
69+
"SecRule ARGS_NAMES|ARGS \"@detectSQLi\" \"id:9421,phase:2,t:none,t:utf8toUnicode,t:urlDecodeUni,t:removeNulls,multiMatch,log,deny,status:403\"",
70+
"SecRule REQUEST_HEADERS:User-Agent \"@pm grabber masscan\" \"id:9131,phase:1,t:none,log,deny,status:403\""
71+
]
72+
},
73+
"default_directives": "rs1",
74+
"metric_labels": {
75+
"owner": "coraza",
76+
"identifier": "global"
77+
}
78+
}
79+
vm_config:
80+
runtime: "envoy.wasm.runtime.v8"
81+
vm_id: "my_vm_id"
82+
code:
83+
local:
84+
filename: "build/main.wasm"
85+
- name: envoy.filters.http.router
86+
typed_config:
87+
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
88+
89+
clusters:
90+
- name: local_server
91+
connect_timeout: 6000s
92+
type: STRICT_DNS
93+
lb_policy: ROUND_ROBIN
94+
load_assignment:
95+
cluster_name: local_server
96+
endpoints:
97+
- lb_endpoints:
98+
- endpoint:
99+
address:
100+
socket_address:
101+
address: httpbin
102+
port_value: 8081
103+
104+
admin:
105+
access_log_path: "/dev/null"
106+
address:
107+
socket_address:
108+
address: 0.0.0.0
109+
port_value: 8082

example/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
httpbin:
3-
image: mccutchen/go-httpbin:v2.5.0
3+
image: mccutchen/go-httpbin:v2.9.0
44
environment:
55
- MAX_BODY_SIZE=15728640 # 15 MiB
66
ports:
@@ -19,7 +19,7 @@ services:
1919
depends_on:
2020
- chown
2121
- httpbin
22-
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.23-latest}
22+
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.27-latest}
2323
command:
2424
- -c
2525
- /conf/envoy-config.yaml

ftw/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
httpbin:
3-
image: mccutchen/go-httpbin:v2.5.0
3+
image: mccutchen/go-httpbin:v2.9.0
44
chown:
55
image: alpine:3.16
66
command:
@@ -14,7 +14,7 @@ services:
1414
depends_on:
1515
- chown
1616
- httpbin
17-
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.23-latest}
17+
image: ${ENVOY_IMAGE:-envoyproxy/envoy:v1.27-latest}
1818
command:
1919
- -c
2020
- ${ENVOY_CONFIG:-/conf/envoy-config.yaml}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/corazawaf/coraza-proxy-wasm
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
github.com/corazawaf/coraza-wasilibs v0.0.0-20230620081031-05a5097dbea3

0 commit comments

Comments
 (0)