github编辑

Enable WASM filter per route

Configure a WASM filter at the Route level

提出问题

当我们采用 typed_per_filter_config 来实现 wasm per route 的时候,envoy 的日志会告诉我们 wasm filter 并不支持。

                route:
                  cluster: web_service
                typed_per_filter_config:
                  my_wasm_plugin:
                    "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
                    config:
                      name: "my_plugin"

          http_filters:
          - name: my_wasm_plugin
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm
              config:
                name: "my_wasm_plugin"
                root_id: "my_root_id"
                # if your wasm filter requires custom configuration you can add
                # as follows
                configuration:
                  "@type": "type.googleapis.com/google.protobuf.StringValue"
                  value: |
                    {}
                vm_config:
                  vm_id: "my_vm_id"
                  code:
                    local:
                      filename: "lib/envoy_filter_http_wasm_example.wasm"
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
  - name: listener_1
    address:

解决问题

为此,我们在 envoy 的 issues 中找到了好多相关的问题。其中下面这个 issue 里有提到如何解决这个问题。

Does this make sense? envoyproxy.io/docs/envoy/latest/intro/arch_overview/http/http_filters#route-based-filter-chainarrow-up-right

By that way, you can disable all wasm filters by default in the HCM and them enable specific some wasm filters on specific virtual host.

Considering that the wasm filter has no per route level config, you can use a hack way to enable the filter.

最后更新于