Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 6f78c25

Browse files
authored
Merge branch 'intel:main' into main
2 parents f66b5af + bf0e3b6 commit 6f78c25

File tree

5 files changed

+181
-1
lines changed

5 files changed

+181
-1
lines changed

.github/workflows/build-wasm-plugin.yaml

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,86 @@ on:
66
- main
77
pull_request:
88
paths:
9+
- "e2e"
910
- "wasmplugin/**"
1011
- ".github/workflows/build-wasm-plugin.yaml"
1112

1213
jobs:
13-
build-wasm-plugin:
14+
build-wasm-plugin-dynamic:
1415
runs-on: ubuntu-20.04
1516
steps:
1617
- name: Set up QEMU
1718
uses: docker/setup-qemu-action@v1
19+
1820
- name: Set up Docker Buildx
1921
uses: docker/setup-buildx-action@v1
22+
# In this step, this action saves a list of existing images,
23+
# the cache is created without them in the post run.
24+
# It also restores the cache if it exists.
25+
2026
- name: Build and push
2127
uses: docker/build-push-action@v2
2228
with:
2329
context: "{{defaultContext}}:wasmplugin"
2430
push: false
2531
tags: intel/modsecurity-wasm-filter:latest
32+
33+
build-wasm-plugin-static:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: "Checkout"
37+
uses: actions/checkout@v3
38+
with:
39+
submodules: recursive
40+
41+
# In this step, this action saves a list of existing images,
42+
# the cache is created without them in the post run.
43+
# It also restores the cache if it exists.
44+
- uses: satackey/[email protected]
45+
# Ignore the failure of a step and avoid terminating the job.
46+
continue-on-error: true
47+
48+
- name: "Cache generated .wasm file"
49+
uses: actions/cache@v3
50+
with:
51+
path: |
52+
e2e/build/
53+
key: wasm-module-build-${{ github.sha }}
54+
55+
- name: "Build wasm module"
56+
shell: bash
57+
run: make -C e2e build-wasm-plugin-static extract-wasm-plugin-static
58+
59+
e2e-test-wasm-plugin-static:
60+
runs-on: ubuntu-latest
61+
needs: build-wasm-plugin-static
62+
steps:
63+
- name: "Checkout"
64+
uses: actions/checkout@v3
65+
with:
66+
fetch-depth: 0
67+
68+
- name: "Install func-e"
69+
shell: bash
70+
run: curl https://func-e.io/install.sh | bash -s -- -b /usr/local/bin
71+
72+
- name: "Restore the wasm files cache"
73+
uses: actions/cache@v3
74+
with:
75+
path: |
76+
e2e/build/
77+
key: wasm-module-build-${{ github.sha }}
78+
79+
- name: "Spin up envoy"
80+
shell: bash
81+
run: |
82+
func-e run -c e2e/envoy-config.yaml --log-level info --component-log-level wasm:debug &
83+
84+
- name: "Run local tests"
85+
env:
86+
HEALTH_URL: "http://localhost:8001"
87+
REQ_UNFILTERED: "http://localhost:8001/home"
88+
REQ_FILTERED: "http://localhost:8001/admin"
89+
shell: bash
90+
run: |
91+
./e2e/tests.sh

e2e/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/**

e2e/Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
IMAGE_NAME=intel/modsecurity-wasm-filter-static
2+
IMAGE_VERSION?=latest
3+
EXTRACT_CONTAINER_NAME=modsecurity-wasm-filter-static-extract
4+
5+
build-wasm-plugin-static:
6+
sed -i 's/envoy-wasm-modsecurity-dynamic/envoy-wasm-modsecurity/' ../wasmplugin/Dockerfile
7+
sed -i 's/envoy-wasm-modsecurity-dynamic/envoy-wasm-modsecurity/' ../wasmplugin/Makefile
8+
docker build --platform linux/amd64 -t $(IMAGE_NAME):$(IMAGE_VERSION) -f ../wasmplugin/Dockerfile ../wasmplugin
9+
# Go back to old state
10+
cd ../wasmplugin; git checkout .
11+
12+
extract-wasm-plugin-static:
13+
@docker rm -f $(EXTRACT_CONTAINER_NAME) || true
14+
@docker create --rm --name $(EXTRACT_CONTAINER_NAME) $(IMAGE_NAME):$(IMAGE_VERSION) /plugin.wasm
15+
@mkdir ./build
16+
@docker cp $(EXTRACT_CONTAINER_NAME):/plugin.wasm ./build/modsecurity-filter.wasm
17+
@docker rm -f $(EXTRACT_CONTAINER_NAME)
18+

e2e/envoy-config.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
static_resources:
2+
listeners:
3+
- address:
4+
socket_address:
5+
address: 0.0.0.0
6+
port_value: 8001
7+
filter_chains:
8+
- filters:
9+
- name: envoy.filters.network.http_connection_manager
10+
typed_config:
11+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
12+
stat_prefix: ingress_http
13+
codec_type: auto
14+
route_config:
15+
virtual_hosts:
16+
- name: local_route
17+
domains:
18+
- "*"
19+
routes:
20+
- match: { prefix: "/" }
21+
direct_response:
22+
status: 200
23+
http_filters:
24+
- name: envoy.filters.http.wasm
25+
typed_config:
26+
"@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
27+
config:
28+
name: "modsecurity-filter"
29+
root_id: ""
30+
configuration:
31+
"@type": "type.googleapis.com/google.protobuf.StringValue"
32+
value: |
33+
{
34+
"rules":"SecDebugLogLevel 5 \nSecDebugLog modsec.log \nSecRuleEngine On \nSecRule REQUEST_URI \"@streqr /admin\" \"id:101,phase:1,t:lowercase,deny\""
35+
}
36+
vm_config:
37+
runtime: "envoy.wasm.runtime.v8"
38+
vm_id: "modsecurity-filter-vm"
39+
code:
40+
local:
41+
filename: "./e2e/build/modsecurity-filter.wasm"
42+
- name: envoy.filters.http.router
43+
typed_config:
44+
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

e2e/tests.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
4+
step=1
5+
total_steps=3
6+
max_retries=10 #seconds for the server reachability timeout
7+
8+
# if env variables are in place, default values are overridden
9+
health_url="http://localhost:8001"
10+
[[ ! -z "$HEALTH_URL" ]] && health_url=$HEALTH_URL
11+
envoy_url_unfiltered="http://localhost:8001/home"
12+
[[ ! -z "$REQ_UNFILTERED" ]] && envoy_url_unfiltered=$REQ_UNFILTERED
13+
envoy_url_filtered="http://localhost:8001/admin"
14+
[[ ! -z "$REQ_FILTERED" ]] && envoy_url_filtered=$REQ_FILTERED
15+
16+
# Testing if the server is up
17+
echo "[$step/$total_steps] Testing application reachability"
18+
status_code="000"
19+
while [[ "$status_code" -eq "000" ]]; do
20+
status_code=$(curl --write-out "%{http_code}" --silent --output /dev/null $health_url)
21+
sleep 1
22+
echo -ne "[Wait] Waiting for response from $health_url. Timeout: ${max_retries}s \r"
23+
((max_retries-=1))
24+
if [[ "$max_retries" -eq 0 ]] ; then
25+
echo "[Fail] Timeout waiting for response from $health_url, make sure the server is running."
26+
exit 1
27+
fi
28+
done
29+
echo -e "\n[Ok] Got status code $status_code, expected 200. Ready to start."
30+
31+
# Testing envoy container reachability with an unfiltered request
32+
((step+=1))
33+
echo "[$step/$total_steps] Testing true negative request"
34+
status_code=$(curl --write-out "%{http_code}" --silent --output /dev/null $envoy_url_unfiltered)
35+
if [[ "$status_code" -ne 200 ]] ; then
36+
echo "[Fail] Unexpected response with code $status_code from $envoy_url_unfiltered"
37+
exit 1
38+
fi
39+
echo "[Ok] Got status code $status_code, expected 200"
40+
41+
# Testing filtered request
42+
((step+=1))
43+
echo "[$step/$total_steps] Testing true positive request"
44+
status_code=$(curl --write-out "%{http_code}" --silent --output /dev/null $envoy_url_filtered)
45+
if [[ "$status_code" -ne 403 ]] ; then
46+
echo "[Fail] Unexpected response with code $status_code from $envoy_url_filtered"
47+
exit 1
48+
fi
49+
echo "[Ok] Got status code $status_code, expected 403"
50+
51+
echo "[Done] All tests passed"

0 commit comments

Comments
 (0)