envoyproxy / gateway

Manages Envoy Proxy as a Standalone or Kubernetes-based Application Gateway
https://gateway.envoyproxy.io
Apache License 2.0
1.6k stars 349 forks source link

Support Lua Filters in EnvoyExtensionPolicy #4627

Open arkodg opened 4 days ago

arkodg commented 4 days ago

Description:

Describe the desired behavior, what scenario it enables and how it would be used.

Allow users to configure Lua filters using the EnvoyExtensionPolicy https://gateway.envoyproxy.io/docs/api/extension_types/#envoyextensionpolicyspec

relates to https://github.com/envoyproxy/gateway/issues/2025

[optional Relevant Links:]

Any extra documentation required to understand the issue.

zhaohuabing commented 3 days ago

+1 Lua support is essential for users migrating from the Nginx ecosystem.

arkodg commented 2 days ago

Here's a workaround until this is implemented using EnvoyPatchPolicy which needs to be enabled https://gateway.envoyproxy.io/docs/tasks/extensibility/envoy-patch-policy/

This patch assumes the Gateway installed is the same as the one from the Quickstart https://gateway.envoyproxy.io/docs/tasks/quickstart/

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyPatchPolicy
metadata:
  name: lua-header-patch-policy 
  namespace: default 
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: Gateway
    name: eg
  type: JSONPatch
  jsonPatches:
    - type: "type.googleapis.com/envoy.config.listener.v3.Listener"
      # The listener name is of the form <GatewayNamespace>/<GatewayName>/<GatewayListenerName>
      name: default/eg/http
      operation:
        op: add
        path: "/default_filter_chain/filters/0/typed_config/http_filters/0"
        value:
          name: "envoy.filters.http.lua"
          typed_config:
            "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
            inline_code: |
              function envoy_on_request(request_handle)
                print("Hello World")
              end

You will need to also enable info logging in the proxy if testing this example

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: envoyproxy-logging-config
spec:
  logging:
    level:
      default: info

Note if linking this to a HTTPS listener, the path prefix will need to be updated to /filter_chains/0 instead of default_filter_chain