<p>I want to configure an EnvoyFilter to run only on Gateway and Sidecar-Inbound. Gateway and the Apps are in different namespaces.</p>
<p>If I specify the context as ANY, it will apply to Gateway, Sidecar-inbound and sidecar-outbound. However, I want it to apply only to Gateway and Sidecar-Inbound. how can I do that?</p>
<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:  
  name: filter-0-mydebugger
  namespace: istio-system
spec:
  configPatches:
  - applyTo: HTTP_FILTER
    match:
      context: GATEWAY # AND SIDECAR-INBOUND HOW?
      listener:
        filterChain:
          filter:
            name: envoy.http_connection_manager
            subFilter:
              name: envoy.router
    patch:
      operation: INSERT_BEFORE
      value:
        name: envoy.lua.mydebugger
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
          inlineCode: |
            function envoy_on_request(request_handle)              
              request_handle:logInfo(&quot;HelloWorld&quot;)             
            end
</code></pre>
<p>If you see, I have set the context to GATEWAY. How can I specify multiple matches - Gateway and Sidecar-Inbound? (Without having to repeat/duplicate the patch section)</p>

Jerald Baker
<p>The <code>context</code> is an <a href="https://istio.io/latest/docs/reference/config/networking/envoy-filter/#EnvoyFilter-PatchContext" rel="nofollow noreferrer">enum</a> so you can't do something like <code>[GATEWAY, SIDECAR_INBOUND]</code>. Therefore, unfortunately you will need to create another element inside <code>configPatches</code> with an <code>applyTo</code>, <code>match</code>, and <code>patch</code>.</p>
<p>However, with yaml you can use anchors(<code>&amp;</code>) and references(<code>*</code>) to reuse blocks of code which makes the duplication easier.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:  
  name: filter-0-mydebugger
  namespace: istio-system
spec:
  configPatches:
  - applyTo: HTTP_FILTER
    match: &amp;mymatch # create an anchor for reuse
      context: GATEWAY 
      listener:
        filterChain:
          filter:
            name: envoy.http_connection_manager
            subFilter:
              name: envoy.router
    patch: &amp;mypatch # create an anchor for reuse
      operation: INSERT_BEFORE
      value:
        name: envoy.lua.mydebugger
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
          inlineCode: |
            function envoy_on_request(request_handle)              
              request_handle:logInfo(&quot;HelloWorld&quot;)             
            end
  - applyTo: HTTP_FILTER
    match:
      &lt;&lt;: *mymatch # reuse the match
      context: SIDECAR_INBOUND # ... but override the context
    patch: *mypatch # reuse the patch without any overriding
</code></pre>
