EnvoyFilter not appending headers for Istio sidecars

1/20/2022

I am trying to add an header to all my requests being answered by my service, I am using Lua EnvoyFilter to do so. But the filter is not being applied to the sidecar-proxy, when I try to do configDump I dont find my filter nor the header in the resonses which I had added. I have manually labelled the pod & the deployment with app=gateway & the below is the filter I used, I can’t seem to find anything helpful in Istio doc nor in the envoy filter docs. Can anyone please help if I have missed something over here?

apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: response-interceptor
  namespace: gateway
spec:
  workloadSelector:
    labels:
      app: gateway
  configPatches:
    - applyTo: HTTP_FILTER
      match:
        context: SIDECAR_INBOUND
        listener:
          filterChain:
            filter:
              name: envoy.http_connection_manager
              subFilter:
                name: envoy.router
      patch:
        operation: INSERT_BEFORE
        value:
          name: envoy.lua
          typed_config:
            "@type": "type.googleapis.com/envoy.config.filter.http.lua.v2.Lua"
            inlineCode: |
              function envoy_on_response(response_handle)
                response_handle:headers():add("X-Custom-Namespace", "worked");
              end

Gateway over here is my service-name & is not the istio-ingress gateway.

-- Kush Trivedi
envoyproxy
istio
kubernetes

1 Answer

1/20/2022

Seems like an occasional error with EnvoyFilters on Minikube, after deleting & re-applying it magically started to work. https://github.com/istio/istio/issues/8261 https://github.com/istio/istio/issues/8616

-- Kush Trivedi
Source: StackOverflow