Configure Envoy Gateway Extensions
TOC
OverviewPrerequisitesConfigure a LuaFilter ExtensionConfigure a Wasm ExtensionConfigure a Dynamic Module WAF ExtensionPrepare a Helper ImageConfigure EnvoyProxyAttach the Coraza WAF FilterCheck Extension StatusCleanupOverview
Envoy Gateway supports traffic extension through EnvoyExtensionPolicy. You can attach an extension policy to a
Gateway or HTTPRoute to run custom logic in the Envoy data plane without changing application code.
This document describes three extension mechanisms:
Prerequisites
Before configuring extensions, make sure that you have completed the following tasks:
- Install or upgrade Envoy Gateway to a version that supports the required extension fields. Dynamic Module examples in this document require Envoy Gateway 1.8 or later.
- Configure EnvoyGatewayCtl
- Configure Gateway
- Configure Route
- Prepare a backend Service and an
HTTPRoutethat forwards traffic to that Service.
The examples in this document use the following resource names. Replace them with the names in your environment.
The extension artifact must be reachable by the Envoy data plane. For Wasm modules, use an HTTP or OCI source that the Envoy pods can access. For Dynamic Modules, make sure the shared object file is mounted into the Envoy container before Envoy starts.
Configure a LuaFilter Extension
Use LuaFilter for lightweight request or response handling. The following example attaches a Lua script to
example-route and adds the x-gwext-lua: enabled response header.
Apply the policy:
Verify that the route returns the response header:
Expected response header:
For more Lua configuration options, see the upstream Envoy Gateway Lua task.
Configure a Wasm Extension
Use Wasm when extension logic is packaged as a WebAssembly module. The following example loads the sample Wasm module
used by the upstream Envoy Gateway Wasm task from an HTTP endpoint and attaches it to example-route.
Apply the policy:
Verify that the Wasm filter runs. The test module used in this example adds the x-wasm-custom: FOO response header:
Expected response header:
The Wasm module URL in this example comes from the upstream Envoy Gateway Wasm task. To build and use your own Wasm
filter, follow the upstream task and replace url and sha256 with your own artifact details.
For more Wasm configuration options, see the upstream Envoy Gateway Wasm task.
Configure a Dynamic Module WAF Extension
Use Dynamic Module when you need to load a native Envoy extension from a shared object file. This example uses the Composer Dynamic Module with Coraza WAF rules. The WAF filter blocks suspicious requests, such as SQL injection payloads.
Dynamic Module configuration has two parts:
- Configure
EnvoyProxy.spec.dynamicModulesto allow Envoy to load the module. - Configure
EnvoyExtensionPolicy.spec.dynamicModuleto attach the module as an HTTP filter.
Prepare a Helper Image
The Composer module is provided as libcomposer.so. Prepare a helper image that contains the file and can run a shell
command in an init container.
Kubernetes 1.35 or later supports mounting an OCI image or artifact directly as an image volume. If all clusters that
run this configuration use Kubernetes 1.35 or later, you can mount the Composer artifact as an image volume instead of
copying the file in an init container.
This example uses an init container and a shared emptyDir volume for compatibility with older Kubernetes versions.
With this approach, the init container copies libcomposer.so from the helper image into the shared volume, and the
Envoy container loads the module from the same volume.
The following Dockerfile copies libcomposer.so from the Composer image into a normal Alpine-based image:
Build and push the helper image to a registry that the cluster can access:
Configure EnvoyProxy
Create or update the EnvoyProxy used by your Gateway. The following configuration uses an init container to copy
libcomposer.so into a shared emptyDir volume. The Envoy container mounts the same volume and loads the module from
/etc/envoy/dynamic-modules/libcomposer.so.
Apply the EnvoyProxy:
Make sure the Gateway references this EnvoyProxy:
Attach the Coraza WAF Filter
Create an EnvoyExtensionPolicy that attaches the Composer module to the Gateway and enables the Coraza WAF rules:
Apply the policy:
Verify a normal request:
Expected status:
Verify that the WAF blocks a SQL injection style request:
Expected status:
For more Dynamic Module configuration options, see the upstream Envoy Gateway Dynamic Modules task.
Check Extension Status
After applying an extension policy, check whether the policy is accepted:
If the policy is not accepted, check the Envoy Gateway controller logs and the generated Envoy pods:
For Dynamic Modules, also verify the following items:
Cleanup
Delete the extension policies when they are no longer needed:
If you created a dedicated EnvoyProxy for Dynamic Module testing, delete it after removing or updating the Gateway
that references it: