Skip to content

Commit 9a92135

Browse files
committed
Polish vmod-wasm documentation
1 parent 8b1fcd5 commit 9a92135

7 files changed

Lines changed: 71 additions & 18 deletions

File tree

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Code Of Conduct
1+
# Code of Conduct
22

33
## Our Pledge
44

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ test: add VTC for bot detection edge case
122122
Stable release tags include the supported Varnish ABI line:
123123

124124
```shell
125-
git tag varnish9-v4.3.3
126-
git push origin varnish9-v4.3.3
125+
git tag varnish9-vX.Y.Z
126+
git push origin varnish9-vX.Y.Z
127127
```
128128

129-
The package version remains semantic (`4.3.3`); the tag prefix makes the Varnish
130-
support line explicit for release assets.
129+
The package version remains semantic (`X.Y.Z`); the tag prefix makes the
130+
Varnish support line explicit for release assets.
131131

132132
## Reporting Issues
133133

docs/ARCHITECTURE.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Overview
44

5-
vmod-wasm embeds the [Wasmtime](https://wasmtime.dev/) WebAssembly runtime into Varnish Cache as a VMOD (Varnish Module). It supports two execution models:
5+
vmod-wasm embeds the [Wasmtime](https://wasmtime.dev/) WebAssembly runtime into
6+
Varnish Cache as a VMOD (Varnish Module). It supports two execution models:
67

78
1. **Raw host-function modules** — Wasm modules that import/export C-ABI functions directly
89
2. **Proxy-Wasm ABI modules** — Standard filters using the [Proxy-Wasm ABI v0.2.1](https://github.com/proxy-wasm/spec)
@@ -127,7 +128,9 @@ mutating the module set used by older traffic.
127128

128129
### Store Pooling
129130

130-
Instead of creating a new Wasmtime instance per request, vmod-wasm pre-creates a pool of instances at VCL init time. This eliminates compilation latency from the request path.
131+
Instead of creating a new Wasmtime instance per request, vmod-wasm pre-creates
132+
a pool of instances at VCL init time. This eliminates compilation latency from
133+
the request path.
131134

132135
- Default pool size: 8 stores per module
133136
- Configurable with `wasm.set_store_pool_size(module, size)` after `wasm.load()`
@@ -142,7 +145,10 @@ and instance. The pool is an optimization, not a correctness dependency.
142145

143146
### Epoch-Based Time Limits
144147

145-
Unlike fuel-based metering (which adds per-instruction overhead), epoch interruption uses a background thread that increments a global epoch counter. When a Wasm execution exceeds its deadline, the next epoch check traps the execution.
148+
Unlike fuel-based metering, which adds per-instruction overhead, epoch
149+
interruption uses a background thread that increments a global epoch counter.
150+
When a Wasm execution exceeds its deadline, the next epoch check traps the
151+
execution.
146152

147153
- Zero overhead during normal execution
148154
- Background ticker thread (1ms resolution)

docs/COMPATIBILITY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
This document tracks the implementation status of the
66
[Proxy-Wasm ABI v0.2.1](https://github.com/proxy-wasm/spec) specification.
7+
Use it to check whether an existing HTTP Proxy-Wasm filter can run on Varnish
8+
without redesign. Unsupported gRPC, L4, and foreign-function surfaces are
9+
registered for SDK link compatibility only.
710

811
## Runtime Support
912

docs/CONFIGURATION.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
Complete reference for all vmod-wasm VCL functions and their parameters.
44

5+
Most production VCL only needs four groups:
6+
7+
- load modules with `wasm.load()`
8+
- set resource limits with `wasm.set_epoch_deadline()` and
9+
`wasm.set_memory_limit()`
10+
- restrict HTTP callouts with `wasm.set_allowed_upstreams()` and
11+
`wasm.set_http_call_limit()`
12+
- expose observability with `wasm.get_metrics_json()` and
13+
`wasm.get_stats_json()`
14+
515
## Support And Scope
616

717
The stable release line targets Varnish 9.x with Wasmtime C API 44.0.0.
@@ -255,14 +265,15 @@ Behavior when Wasm execution encounters an error.
255265

256266
Return all Proxy-Wasm metrics as a JSON string.
257267

258-
**Returns**: STRING (JSON object with metric names as keys and values as numbers)
268+
**Returns**: STRING (JSON object with metric names as keys and metric records
269+
as values)
259270

260271
**Example output**:
261272
```json
262273
{
263-
"edge_requests_total": 15234,
264-
"edge_blocked_total": 42,
265-
"edge_rate_limited_total": 7
274+
"edge_requests_total": {"type": "counter", "value": 15234},
275+
"edge_blocked_total": {"type": "counter", "value": 42},
276+
"edge_rate_limited_total": {"type": "counter", "value": 7}
266277
}
267278
```
268279

docs/PRODUCTION.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## Overview
44

55
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.
89

910
The stable release support target is Varnish 9.x on Linux `amd64` and `arm64`.
1011
GitHub binary bundles include the Wasmtime 44.0.0 runtime library used at build
@@ -35,6 +36,36 @@ Then verify linkage before traffic:
3536
ldd /usr/lib/varnish/vmods/libvmod_wasm.so | grep libwasmtime
3637
```
3738

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+
3869
## Resource Limits
3970

4071
### Epoch Deadline (Execution Time Limit)
@@ -194,6 +225,7 @@ sub vcl_deliver {
194225
`proxy_on_response_body` as they arrive — no buffering
195226
- Each chunk is forwarded to the client immediately after inspection
196227
- `end_of_stream=1` is set on the final chunk
228+
- Memory usage is O(chunk_size), not O(body_size)
197229

198230
## Module Lifecycle Management
199231

@@ -351,7 +383,6 @@ so budget for at least two loaded VCL generations during deployment.
351383
| Security filter (bot + rate limit) | 100ms | 8 MiB | 0 |
352384
| Auth validation (with callout) | 200ms | 8 MiB | 3 |
353385
| Complex transform (body inspection) | 500ms | 16 MiB | 5 |
354-
- Memory usage is O(chunk_size), not O(body_size)
355386

356387
## Upgrading Modules
357388

docs/SECURITY.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## Overview
44

5-
vmod-wasm isolates untrusted Wasm code within a sandboxed runtime.
6-
This document describes the security boundaries and controls.
5+
vmod-wasm isolates untrusted Wasm code within a sandboxed runtime. This
6+
document describes the security boundaries, defaults, and production controls
7+
that matter before you allow modules to process real traffic.
78

89
## Isolation Guarantees
910

@@ -15,7 +16,8 @@ This document describes the security boundaries and controls.
1516
### Execution Isolation
1617
- Epoch-based time limits prevent infinite loops and CPU exhaustion
1718
- Each request gets a fresh instance — no state leakage between requests
18-
- Wasm modules cannot access the filesystem, network, or system calls
19+
- Wasm modules cannot directly access the filesystem, network, or host system
20+
calls
1921
- All host interaction goes through explicitly defined host functions
2022

2123
### Network Isolation

0 commit comments

Comments
 (0)