I wanted to check out the status of WebAssembly and see how easy it is to create an Envoy filter. This is what I managed to piece together in August 2021.
The Envoy filter is built using Rust (which I'm new to!) and added to a vanilla version of Envoy v1.19.x.
I followed guidance from these two posts, but more useful links posted at the bottom:
- https://antweiss.com/blog/extending-envoy-with-wasm-and-rust/
- https://blog.red-badger.com/extending-istio-with-rust-and-webassembly
There is a Docker Compose file which starts up a provider service behind envoy and a consumer service to consume from it.
The provider service checks for an auth token - the aim is to move this to the filter in case you see this before I get that done
Use the Makefile to start it up
digraph G { compound=true; rankdir=LR pad="0.2,0.5"
subgraph cluster1 {
style=filled;
color=lightgrey;
node [style=filled,color=white];
wasmFilter [shape=box, label="WASM Filter"];
label=<Envoy<BR /><FONT POINT-SIZE="10">:8200</FONT>>;
}
consumer [shape=box, label=<Consumer<BR /><FONT POINT-SIZE="10">:8100</FONT>>];
provider [shape=box, label=<Provider<BR /><FONT POINT-SIZE="10">:8300</FONT>>];
consumer -> wasmFilter [lhead=cluster1];
wasmFilter -> provider [ltail=cluster1];
}
The filter currently just adds two headers to the requests it handles:
Request Header called 'filter-added'
Response Header called 'filter-added'
Run
# build the WASM filter in Rust
make build
# Deploy the demo
make start
# Successful request (default role = admin)
http localhost:8100/
curl localhost:8100/
# Unsuccessful request
http localhost:8100/ role==somethingelse
curl localhost:8100/?role=somethingelse