Distributing WebAssembly Modules

The following information describes an experimental feature, which is intended for evaluation purposes only.

Istio provides the ability to extend proxy functionality using WebAssembly (Wasm). One of the key advantages of Wasm extensibility is that extensions can be loaded dynamically at runtime. But first these extensions must be distributed to the proxy. Starting in version 1.9, Istio makes this possible by allowing the Istio agent to dynamically download Wasm modules.

Configure an HTTP Filter with a Remote Wasm Module

Here we will walk through an example of adding a basic auth extension to our mesh. We will configure Istio to pull a basic auth module from a remote URI and load it with configuration to run the module on calls to the /productpage path.

To configure a WebAssembly filter with a remote Wasm module, two EnvoyFilter resources will be installed: one injects the HTTP filter, and the other provides configuration for the filter to use the remote Wasm module.

With the first EnvoyFilter, an HTTP filter will be injected into gateway proxies. It is configured to request the extension configuration named istio.basic_auth from ads (i.e. Aggregated Discovery Service), which is the same configuration source that Istiod uses to provide all other configuration resources. Within the configuration source, the initial fetch timeout is set to 0s, which means that when the Envoy proxy processes a listener update with this filter, it will wait indefinitely for the first extension configuration update before accepting requests with this listener.

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: EnvoyFilter
  3. metadata:
  4. name: basic-auth
  5. namespace: istio-system
  6. spec:
  7. configPatches:
  8. - applyTo: HTTP_FILTER
  9. match:
  10. context: GATEWAY
  11. listener:
  12. filterChain:
  13. filter:
  14. name: envoy.http_connection_manager
  15. patch:
  16. operation: INSERT_BEFORE
  17. value:
  18. name: istio.basic_auth
  19. config_discovery:
  20. config_source:
  21. ads: {}
  22. initial_fetch_timeout: 0s # wait indefinitely to prevent bad Wasm fetch
  23. type_urls: [ "type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm"]

The second EnvoyFilter provides configuration for the filter, which is an EXTENSION_CONFIG patch and will be distributed to the proxy as an Envoy Extension Configuration Discovery Service (ECDS) resource. Once this update reaches the Istio agent, the agent will download the Wasm module and store it in the local file system. If the download fails, the agent will reject the ECDS update to prevent invalid Wasm filter configuration from reaching the Envoy proxy. Because of this protection, with the initial fetch timeout being set to 0, the listener update will not become effective and invalid Wasm filter will not disturb the traffic. The important parts of this configuration are:

  • Wasm vm configuration which points to a remote Wasm module.
  • Wasm extension configuration, which is a JSON string that is consumed by the Wasm extension.
  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: EnvoyFilter
  3. metadata:
  4. name: basic-auth-config
  5. namespace: istio-system
  6. spec:
  7. configPatches:
  8. - applyTo: EXTENSION_CONFIG
  9. match:
  10. context: GATEWAY
  11. patch:
  12. operation: ADD
  13. value:
  14. name: istio.basic_auth
  15. typed_config:
  16. "@type": type.googleapis.com/udpa.type.v1.TypedStruct
  17. type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
  18. value:
  19. config:
  20. vm_config:
  21. vm_id: basic-auth
  22. runtime: envoy.wasm.runtime.v8
  23. code:
  24. remote:
  25. http_uri:
  26. uri: https://github.com/istio-ecosystem/wasm-extensions/releases/download/1.11.0/basic-auth.wasm
  27. # Optional: specifying sha256 checksum will let istio agent verify the checksum of downloaded artifacts.
  28. # It is **highly** recommended to provide the checksum, since missing checksum will cause the Wasm module to be downloaded repeatedly.
  29. # To compute the sha256 checksum of a Wasm module, download the module and run `sha256sum` command with it.
  30. # sha256: <WASM-MODULE-SHA>
  31. # The configuration for the Wasm extension itself
  32. configuration:
  33. '@type': type.googleapis.com/google.protobuf.StringValue
  34. value: |
  35. {
  36. "basic_auth_rules": [
  37. {
  38. "prefix": "/productpage",
  39. "request_methods":[ "GET", "POST" ],
  40. "credentials":[ "ok:test", "YWRtaW4zOmFkbWluMw==" ]
  41. }
  42. ]
  43. }

The Istio agent will only intercept and download remote Wasm modules configured via ECDS resources. This feature is enabled by default. To disable ECDS interception and Wasm downloading in the Istio agent, set the ISTIO_AGENT_ENABLE_WASM_REMOTE_LOAD_CONVERSION environment variable to false. For example, to set it globally:

  1. meshConfig:
  2. defaultConfig:
  3. proxyMetadata:
  4. ISTIO_AGENT_ENABLE_WASM_REMOTE_LOAD_CONVERSION: "false"

There are several known limitations with this module distribution mechanism, which will be addressed in future releases:

  • Envoy’s extension configuration discovery service only supports HTTP filters.
  • Modules can only be downloaded through HTTP/HTTPS.

Monitor Wasm Module Distribution

There are several stats which track the distribution status of remote Wasm modules.

The following stats are collected by Istio agent:

  • istio_agent_wasm_cache_lookup_count: number of Wasm remote fetch cache lookups.
  • istio_agent_wasm_cache_entries: number of Wasm config conversions and results, including success, no remote load, marshal failure, remote fetch failure, and miss remote fetch hint.
  • istio_agent_wasm_config_conversion_duration_bucket: Total time in milliseconds istio-agent spends on config conversion for Wasm modules.
  • istio_agent_wasm_remote_fetch_count: number of Wasm remote fetches and results, including success, download failure, and checksum mismatch.

If a Wasm filter configuration is rejected, either due to download failure or other reasons, istiod will also emit pilot_total_xds_rejects with the type label type.googleapis.com/envoy.config.core.v3.TypedExtensionConfig.

Develop a Wasm Extension

To learn more about Wasm module development, please refer to the guides provided in the istio-ecosystem/wasm-extensions repository, which is maintained by the Istio community and used to develop Istio’s Telemetry Wasm extension: