Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Lua Filters in EnvoyExtensionPolicy #4627

Closed
arkodg opened this issue Nov 4, 2024 · 7 comments · Fixed by #5270
Closed

Support Lua Filters in EnvoyExtensionPolicy #4627

arkodg opened this issue Nov 4, 2024 · 7 comments · Fixed by #5270
Assignees
Labels
area/api API-related issues
Milestone

Comments

@arkodg
Copy link
Contributor

arkodg commented Nov 4, 2024

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 #2025

[optional Relevant Links:]

Any extra documentation required to understand the issue.

@arkodg arkodg added triage help wanted Extra attention is needed area/api API-related issues labels Nov 4, 2024
@arkodg arkodg modified the milestones: v1.2.0, Backlog Nov 4, 2024
@arkodg arkodg added kind/decision A record of a decision made by the community. and removed triage help wanted Extra attention is needed labels Nov 4, 2024
@zhaohuabing
Copy link
Member

zhaohuabing commented Nov 5, 2024

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

@arkodg
Copy link
Contributor Author

arkodg commented Nov 5, 2024

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

@arkodg arkodg added help wanted Extra attention is needed and removed kind/decision A record of a decision made by the community. labels Nov 7, 2024
@arkodg arkodg modified the milestones: Backlog, v1.3.0-rc.1 Nov 21, 2024
@rudrakhp
Copy link
Member

rudrakhp commented Dec 1, 2024

Is this issue open for contributions? I could start with an API PR.

@arkodg
Copy link
Contributor Author

arkodg commented Dec 3, 2024

go for it @rudrakhp !

would be great to think about how the Lua config can be validated before pushing it to the proxy
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter

@arkodg arkodg removed the help wanted Extra attention is needed label Dec 3, 2024
@rudrakhp
Copy link
Member

rudrakhp commented Dec 3, 2024

@arkodg IMO we have two options here:

  1. Use a Go based Lua compiler to run the user provided script. We will need to mock the APIs defined in the Envoy documentation to ensure Lua run succeeds for a valid script. This will be more thorough but might be trickier to implement.
  2. Parse the script and validate basic assumptions (like it should contain one of envoy_on_response or envoy_on_request). Easier to implement but less thorough.

WDYT?

@arkodg
Copy link
Contributor Author

arkodg commented Dec 4, 2024

+1 for 1, the list of methods available on the stream handle doesnt seem very long
https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/lua_filter#stream-handle-api

Copy link

github-actions bot commented Jan 4, 2025

This issue has been automatically marked as stale because it has not had activity in the last 30 days.

@github-actions github-actions bot added the stale label Jan 4, 2025
@arkodg arkodg modified the milestones: v1.3.0-rc.1, Backlog Jan 21, 2025
@github-actions github-actions bot removed the stale label Jan 22, 2025
@arkodg arkodg removed this from the Backlog milestone Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/api API-related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants