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

API: EnvoyExtensionPolicy #2570

Merged
merged 8 commits into from
Mar 16, 2024
Merged

Conversation

guydc
Copy link
Contributor

@guydc guydc commented Feb 6, 2024

What this PR does / why we need it:

This PR introduces a new policy type, EnvoyExtensionPolicy, that can be used to add multiple HTTP and Network extension filters (such as lua, wasm, golang, ext-proc), and define their order of execution.

Relates to #2546, #2025, #2877

Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.57%. Comparing base (23fa358) to head (b0dea04).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2570   +/-   ##
=======================================
  Coverage   64.57%   64.57%           
=======================================
  Files         122      122           
  Lines       21115    21115           
=======================================
  Hits        13636    13636           
  Misses       6632     6632           
  Partials      847      847           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guydc guydc force-pushed the api-extension-policy branch from 43f07ce to 1389569 Compare February 6, 2024 22:52
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Accepted")].reason`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// TrafficExtensionPolicy allows the user to configure various traffic extensibility options for the Gateway.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer EnvoyExtensionPolicy since these extensions are specific to envoy or ExtensionPolicy if these extensions are common across proxy implementations

@guydc
Copy link
Contributor Author

guydc commented Feb 7, 2024

In yesterday's community meeting, @arkodg raised the following requirements:

  • Users may need to attach multiple policies in order to configure multiple extension filters (a common use case for WASM, LUA)
  • Users may need to control the logical phase of filter execution (e.g. before auth, before rate limit, ... )
  • Users may need to control the order of execution of extension filters amongst themselves (within a specific phase)

Istio's implementation for WASM plugins uses phase and priority to achieve this. Envoy Gateway can follow similar principles. The definition of such phases can have an impact on #2571, for example limiting the level of flexibility that users will have when re-arranging the Envoy Gateway built-in extensions.

@envoyproxy/gateway-maintainers - WDYT? Should we follow the istio pattern and implement phases and priorities for user-defined extensions?

@guydc guydc changed the title [WIP] API: TrafficExtensionPolicy API: TrafficExtensionPolicy Feb 9, 2024
@guydc guydc marked this pull request as ready for review February 9, 2024 23:19
@guydc guydc requested a review from a team as a code owner February 9, 2024 23:19
type EnvoyExtensionPhase string

const (
AuthzEnvoyExtensionPhase EnvoyExtensionPhase = "AUTHZ"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to be consistent with other enums defined in the various EnvoyGateway CRDs, the enum values should not be all-caps.

	AuthzEnvoyExtensionPhase     EnvoyExtensionPhase = "AuthZ"
        AuthnEnvoyExtensionPhase     EnvoyExtensionPhase = "AuthN"
 	RateLimitEnvoyExtensionPhase EnvoyExtensionPhase = "RateLimit"

api/v1alpha1/envoyextensionypolicy_types.go Outdated Show resolved Hide resolved
type NetworkEnvoyExtension struct {
}

type ExtensionMetadata map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need to be an aliased type?

Similar definitions in the APIs don't define an aliased type for map[string]string. See KubernetesPodSpec for example.

api/v1alpha1/ext_proc_types.go Outdated Show resolved Hide resolved
api/v1alpha1/ext_proc_types.go Outdated Show resolved Hide resolved
// Default: no metadata context is sent or received
MetadataOptions *ExtProcMetadataOptions `json:"metadataOptions,omitempty"`
// The timeout for a response to be returned from the external processor
// Default: 200ms
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a +kubebuilder:default comment for MessageTimeout.

)

// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=sp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shortName is the same as the shortName defined for the SecurityPolicy resource.

Consider removing the short name, or changing it to ep.

api/v1alpha1/ext_proc_types.go Outdated Show resolved Hide resolved
api/v1alpha1/ext_proc_types.go Outdated Show resolved Hide resolved
api/v1alpha1/ext_proc_types.go Outdated Show resolved Hide resolved
@guydc guydc changed the title API: TrafficExtensionPolicy API: EnvoyExtensionPolicy Feb 12, 2024
@guydc guydc marked this pull request as draft February 14, 2024 21:55
@Xunzhuo Xunzhuo mentioned this pull request Mar 11, 2024
@guydc guydc force-pushed the api-extension-policy branch from ac5628c to f34cfbe Compare March 14, 2024 22:15
@guydc
Copy link
Contributor Author

guydc commented Mar 14, 2024

Incorporated points from the discussion in today's community meeting:

  • Filter Ordering in EnvoyProxy
  • Disablement of Extensibility by default, enablement in EnvoyGateway
  • Remove distinction between HTTP/Network in the interface
  • Allow route attachment

@guydc guydc force-pushed the api-extension-policy branch from f34cfbe to b657fc8 Compare March 14, 2024 22:23
@arkodg
Copy link
Contributor

arkodg commented Mar 14, 2024

@zhaohuabing lets pause on #2877 until this API is done, and the WASM API can be incorporated as a field within this API

Spec EnvoyExtensionPolicySpec `json:"spec"`

// Status defines the current status of EnvoyExtensionPolicy.
Status EnvoyExtensionPolicyStatus `json:"status,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably PolicyStatus here

Signed-off-by: Guy Daich <guy.daich@sap.com>
@guydc guydc force-pushed the api-extension-policy branch from b657fc8 to 04b7280 Compare March 14, 2024 22:43
// Fault-Injection, Local-Rate-Limit, Global-Rate-Limit
//
// +optional
FilterOrdering []EnvoyFilterName `json:"filterOrdering,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest keep filter ordering out of scope of this API, and solving it separately in #2571

@guydc guydc marked this pull request as ready for review March 14, 2024 22:57
guydc added 2 commits March 14, 2024 18:11
Signed-off-by: Guy Daich <guy.daich@sap.com>
Signed-off-by: Guy Daich <guy.daich@sap.com>
Copy link
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the spec support defining extensions as a list?

Unlike "normal" filters(Rate Limit, CORS, Basic Auth, OAuth2, JWT, etc), where typically only one filter per HTTPRoute is needed, users often require multiple custom Envoy extensions(wasm, lua, golang, ext auth?, etc.) of the same type for different purposes. For example, they might use a wasm filter for WAF and another for auth on the same HTTPRoute.

The current spec only supports defining a single extension per HTTPRoute, and it would block those use cases.

We may need to make it a list, like the below yaml snippet shows:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: EnvoyExtensionPolicy
metadata:
  name: my-extensions
spec:
  targetRef:
    kind: HTTPRoute
    name: backend
  wasm:
    - name: wasm_plugin_waf
     ...
    - name: my_plugin_auth
      ...
  ExtProc:
    - name: exproc_plugin_1 
      ....
    - name: exproc_plugin_2     
  Lua:
    - name: lua_plugin_1 
      ....
    - name: lua_plugin_2 
.....        

@guydc
Copy link
Contributor Author

guydc commented Mar 15, 2024

Should the spec support defining extensions as a list?

+1

I think that's a reasonable ask, when considering that we allow something similar with envoy patches and it is indeed a very common use case. Maybe we can even avoid dealing with priority and multi-attachment in the first phases for this policy, if we support this + route attachment in the initial iteration.

// ExtProc defines the configuration for the external processor extension.
//
// +optional
ExtProc *ExtProc `json:"extProc,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per huabing's point, should we make this a list ?

guydc added 3 commits March 15, 2024 13:35
Signed-off-by: Guy Daich <guy.daich@sap.com>
Signed-off-by: Guy Daich <guy.daich@sap.com>
@guydc
Copy link
Contributor Author

guydc commented Mar 15, 2024

To make things a bit simpler, I removed ext-proc from this PR. After the top-level resource is added, @zhaohuabing and I can work on ext-proc/wasm in parallel.

// EnvoyExtensionPolicySpec defines the desired state of EnvoyExtensionPolicy.
type EnvoyExtensionPolicySpec struct {
// +kubebuilder:validation:XValidation:rule="self.group == 'gateway.networking.k8s.io'", message="this policy can only have a targetRef.group of gateway.networking.k8s.io"
// +kubebuilder:validation:XValidation:rule="self.kind in ['Gateway']", message="this policy can only have a targetRef.kind of Gateway"
Copy link
Contributor

@arkodg arkodg Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should target Gateway and Route

@@ -151,6 +151,10 @@ type ExtensionAPISettings struct {
// EnableEnvoyPatchPolicy enables Envoy Gateway to
// reconcile and implement the EnvoyPatchPolicy resources.
EnableEnvoyPatchPolicy bool `json:"enableEnvoyPatchPolicy"`

// EnableEnvoyExtensionPolicy enables Envoy Gateway to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@envoyproxy/gateway-maintainers @envoyproxy/gateway-reviewers thoughts on this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine to remove all these, it will not happen unless you create a CR.


## Overview

This design document introduces the `EnvoyExtensionPolicy` API allowing system administrators to configure traffic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we incorporate some of these below points in this doc

  • there are now 2 kinds of extensibility today
    • extending EG API by configuring xDS directly using EnvoyPatchPolicy & ExtensionManager
    • the other kind, highlighted in this doc that extends and adds newer functionality on top of what Envoy offers

Also a note around how users have been using EnvoyPatchPolicy & ExtensionManager to directly configure this extensions, but this API provides a safer and more scoped API

guydc added 2 commits March 15, 2024 15:29
Signed-off-by: Guy Daich <guy.daich@sap.com>
Signed-off-by: Guy Daich <guy.daich@sap.com>
@guydc
Copy link
Contributor Author

guydc commented Mar 15, 2024

/retest

Copy link
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@arkodg arkodg requested review from a team March 15, 2024 22:01
@zirain zirain merged commit df051fa into envoyproxy:main Mar 16, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants