ext_proc — body mutation, AI-friendly
Stream request and response bodies through an external gRPC service for transformation.
What ext_proc unlocks that nothing else does
envoy.filters.http.ext_authz can inspect requests and add headers, but
it cannot mutate response bodies. WASM and Lua can mutate bodies
locally, but they're constrained to the languages that compile to the
sandbox.
envoy.filters.http.ext_proc is the third option: a streaming gRPC
filter that hands every phase of a request and response — headers,
body chunks, trailers — to an external service, message by message,
in both directions. Your service mutates whatever it wants and streams
the result back.
The killer use cases the official site under-sells: PII redaction in responses, prompt rewriting for LLM gateways, content moderation, lossless body-included audit logging, and on-the-fly compression / transcoding.
Minimal envoy.yaml
http_filters:
- name: envoy.filters.http.ext_proc
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.ext_proc.v3.ExternalProcessor
grpc_service:
envoy_grpc: { cluster_name: ext_proc }
timeout: 2s
failure_mode_allow: false
processing_mode:
request_header_mode: SEND
response_header_mode: SEND
request_body_mode: NONE
response_body_mode: BUFFERED # buffer entire response
response_trailer_mode: SKIP
- name: envoy.filters.http.router
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
clusters:
- name: ext_proc
type: STRICT_DNS
typed_extension_protocol_options:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
"@type": type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicit_http_config: { http2_protocol_options: {} }
load_assignment:
cluster_name: ext_proc
endpoints:
- lb_endpoints:
- endpoint: { address: { socket_address: { address: ext-proc, port_value: 50051 }}}
A tiny Go ext_proc service (lowercase the body)
func (s *srv) Process(stream extprocv3.ExternalProcessor_ProcessServer) error {
for {
req, err := stream.Recv()
if err != nil { return err }
resp := &extprocv3.ProcessingResponse{}
switch v := req.Request.(type) {
case *extprocv3.ProcessingRequest_ResponseBody:
body := bytes.ToLower(v.ResponseBody.Body)
resp.Response = &extprocv3.ProcessingResponse_ResponseBody{
ResponseBody: &extprocv3.BodyResponse{
Response: &extprocv3.CommonResponse{
BodyMutation: &extprocv3.BodyMutation{
Mutation: &extprocv3.BodyMutation_Body{Body: body},
},
},
},
}
default:
resp.Response = &extprocv3.ProcessingResponse_RequestHeaders{
RequestHeaders: &extprocv3.HeadersResponse{},
}
}
if err := stream.Send(resp); err != nil { return err }
}
}
Three pitfalls
response_body_mode: BUFFERED means Envoy waits for the
entire body before the client sees a byte. Fine for small JSON. For
LLM-streamed responses or large downloads, use STREAMED and
emit BodyMutation per chunk — but your service must keep
state, and you cannot grow the body across a chunk boundary without
re-buffering.
A bad deploy of the processor will take production with it. Pair
ext_proc with health-checked endpoints, generous outlier detection
(Lesson 27), and either failure_mode_allow: true (open) or
a circuit breaker so the data plane survives if the processor doesn't.
ext_proc before ext_authz means your processor sees
unauthenticated traffic — anyone can spoof a request and watch your
processor handle it. Put ext_proc after auth filters so it only
sees verified traffic, with auth-added headers (x-jwt-sub,
etc.) already populated.
Hands-on: lowercase the world
-
Run the Go ext_proc above in one container, your Envoy in another (with the config above) on a shared docker network.
-
Hit an upstream that returns "HELLO WORLD":
curl -s localhost:10000/anything
The client sees "hello world". The upstream still emits caps; the mutation happens at Envoy.
-
Switch
response_body_modefromBUFFEREDtoSTREAMED. Have the upstream return a 1MB payload and watch intcpdump(or Envoy access logs with%DURATION%) — bytes arrive at the client incrementally instead of in one blob. -
Stop the processor. With
failure_mode_allow: falsethe next request returns 500. Flip totrueand confirm requests pass through unmodified.
When to reach for ext_proc
| You need… | ext_proc | WASM | Lua |
|---|---|---|---|
| Mutate response body | ✅ | ✅ (small) | ⚠ (single chunk) |
| Use Python / heavy ML libs | ✅ | ❌ | ❌ |
| Sub-millisecond per request | ❌ (network hop) | ✅ | ✅ |
| Share state across many Envoys | ✅ (centralised service) | ❌ | ❌ |
| No build / toolchain | ⚠ (need a service) | ❌ | ✅ |
ext_proc is the right answer when you're doing AI/ML mutation, when the logic needs to be in Python, or when the policy is updated independently from the proxy.
Which capability does ext_proc have that ext_authz does NOT?