|
3 | 3 | ## Overview |
4 | 4 |
|
5 | 5 | vmod-wasm embeds a WebAssembly runtime (Wasmtime) into Varnish Cache, |
6 | | -enabling request/response processing via compiled Wasm modules. This |
7 | | -document covers production deployment considerations. |
| 6 | +enabling request/response processing via compiled Wasm modules. This guide is |
| 7 | +for operators deciding how to install, constrain, monitor, reload, and roll back |
| 8 | +Wasm filters in production. |
8 | 9 |
|
9 | 10 | The stable release support target is Varnish 9.x on Linux `amd64` and `arm64`. |
10 | 11 | GitHub binary bundles include the Wasmtime 44.0.0 runtime library used at build |
@@ -35,6 +36,36 @@ Then verify linkage before traffic: |
35 | 36 | ldd /usr/lib/varnish/vmods/libvmod_wasm.so | grep libwasmtime |
36 | 37 | ``` |
37 | 38 |
|
| 39 | +## Minimal Production Shape |
| 40 | + |
| 41 | +A production VCL should load modules only in `vcl_init`, set explicit runtime |
| 42 | +limits, fail closed for security decisions, and expose metrics on an internal |
| 43 | +path: |
| 44 | + |
| 45 | +```vcl |
| 46 | +import wasm; |
| 47 | +
|
| 48 | +sub vcl_init { |
| 49 | + wasm.load("edge", "/etc/varnish/wasm/edge_security_filter.wasm"); |
| 50 | + wasm.set_epoch_deadline(100); |
| 51 | + wasm.set_memory_limit(8388608); |
| 52 | + wasm.set_allowed_upstreams("auth.internal:8080"); |
| 53 | + wasm.set_http_call_limit(3); |
| 54 | + wasm.set_fail_mode("closed"); |
| 55 | +} |
| 56 | +
|
| 57 | +sub vcl_recv { |
| 58 | + if (req.url == "/__wasm_metrics" && req.http.X-Internal == "true") { |
| 59 | + return (synth(200, "Metrics")); |
| 60 | + } |
| 61 | +
|
| 62 | + set req.http.X-Wasm-Action = wasm.proxy_wasm_on_request("edge"); |
| 63 | + if (req.http.X-Wasm-Action != "0") { |
| 64 | + return (synth(403, "Blocked")); |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
38 | 69 | ## Resource Limits |
39 | 70 |
|
40 | 71 | ### Epoch Deadline (Execution Time Limit) |
@@ -194,6 +225,7 @@ sub vcl_deliver { |
194 | 225 | `proxy_on_response_body` as they arrive — no buffering |
195 | 226 | - Each chunk is forwarded to the client immediately after inspection |
196 | 227 | - `end_of_stream=1` is set on the final chunk |
| 228 | +- Memory usage is O(chunk_size), not O(body_size) |
197 | 229 |
|
198 | 230 | ## Module Lifecycle Management |
199 | 231 |
|
@@ -351,7 +383,6 @@ so budget for at least two loaded VCL generations during deployment. |
351 | 383 | | Security filter (bot + rate limit) | 100ms | 8 MiB | 0 | |
352 | 384 | | Auth validation (with callout) | 200ms | 8 MiB | 3 | |
353 | 385 | | Complex transform (body inspection) | 500ms | 16 MiB | 5 | |
354 | | -- Memory usage is O(chunk_size), not O(body_size) |
355 | 386 |
|
356 | 387 | ## Upgrading Modules |
357 | 388 |
|
|
0 commit comments