Skip to the content.

Middleware: built-in checks, Rhai scripts, WASM plugins and external processors

Conduit does most of what a gateway needs with built-in settings: IP filtering, rate limits, authentication, redirects. When that is not enough you write your own check, either as a Rhai script (a text file, no build step) or as a WebAssembly plugin (compiled from Rust, Go, C, AssemblyScript, …), or you ask a service of your own through external processing (ext_proc, a gRPC protocol of Envoy). All three are configured in the same list, middleware, and this page says how that list behaves and which tool to pick.

The middleware list

sites:
  - port: 8080
    proxy: http://127.0.0.1:4000
    middleware:
      - type: script          # Rhai
        path: ./scripts/block-bots.rhai
      - type: wasm            # WebAssembly
        path: ./plugins/api-key-check.wasm
        config:               # any JSON, handed to the script or plugin
          allowed_key: "secret-abc"
      - type: script
        path: ./scripts/tag-response.rhai
        phase: response       # runs on the upstream's answer instead of the request
      - type: ext_proc        # an external service over gRPC
        config:
          grpc: "grpc://127.0.0.1:50051"
Field Meaning
type "script" (Rhai), "wasm" or "ext_proc". An unknown value is a validation error; ipFilter, rateLimit, auth and headers are accepted but do nothing here, because those checks are the top-level settings of the same names.
path The .rhai text file or the .wasm binary module. Required for script and wasm; an ext_proc entry has none.
config Optional JSON for the script or plugin to read. For ext_proc it is the entry’s settings and is required (grpc at least): see the guide.
phase "request" (the default) or "response". It selects the phase of a script entry. A wasm entry has no phase: its on_request always runs on the request and its on_response, if it has one, on the response.

Which one

You want Use
Allow or deny by IP, credentials, JWT or an external auth service; limit the rate; redirect The built-in setting: the access checks fail closed, and all of them are cheaper than anything you write.
A small rule on headers or the path: block a bot, require a header, answer a path yourself A Rhai script: no build step, edit and reload.
Change the request headers that go upstream, read the client IP, take the logic from a language you already use, or run compiled code A WASM plugin.
Run on the upstream’s answer phase: response in Rhai, or on_response in WASM.
Logic that already lives in a service (a policy engine, an Envoy processor, a DLP scanner), needs state or a database, or must see or rewrite the request body An ext_proc processor: any language, one gRPC round trip per request, fails closed.

Limits differ: a script gets 500,000 operations per call and a plugin 10,000,000 units of fuel, and neither has network or file access; a processor is your own service and has whatever access you give it. The details are in the Rhai guide, the WASM guide and the ext_proc guide.