gateway icon indicating copy to clipboard operation
gateway copied to clipboard

feat(api): support statusOnError field in EnvoyExtensionPolicy ExtProc

Open dragon3 opened this issue 6 months ago • 2 comments

Description

When an ext_proc gRPC backend is unreachable (stream closed, connection refused, timeout, etc.) and failOpen: false, the Envoy ext_proc filter returns the default status_on_error HTTP status (500 Internal Server Error) to the downstream client. Envoy itself exposes the field as configurable via the ext_proc filter proto:

// If specified, the filter will use this status when an external processor returns an
// error or cannot be reached. The default status is `HTTP 500 Internal Server Error`.
type.v3.HttpStatus status_on_error = 24;

But Envoy Gateway's EnvoyExtensionPolicy.extProc API does not currently expose it, so operators have to use EnvoyPatchPolicy to override the default — fragile because patches are keyed on Envoy Gateway-generated listener/filter names.

Precedent: ExtAuth already supports this

SecurityPolicy.extAuth.statusOnError was added in #8432 (tracked via #5180, #6872, #5214) with this shape:

// Sets the HTTP status that is returned when the authorization service returns an error
// or cannot be reached. Defaults to 403 Forbidden.
// Only 4xx and 5xx status codes are supported.
//
// +optional
// +kubebuilder:validation:Enum=400;401;...;511
StatusOnError *int32 `json:"statusOnError,omitempty"`

Proposal

Add a StatusOnError *int32 field to ExtProc mirroring the ExtAuth one, with the same enum validation (4xx + 5xx) and defaulting to nil (preserving the current Envoy default of 500).

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
spec:
  targetRefs: [...]
  extProc:
  - backendRefs: [...]
    failOpen: false
    statusOnError: 503   # ← new

Use case (motivation)

In environments that run both hand-managed Envoy proxies (configured via static bootstrap) and Envoy Gateway-managed proxies side-by-side, the hand-managed proxies commonly set status_on_error: { code: ServiceUnavailable } (HTTP 503) on the ext_proc filter so that ext_proc failures fall into the gateway-error retry bucket and 5xx-class SLOs / alerting rules treat them consistently.

When an Envoy Gateway-managed proxy joins the same fleet, it can't match that behavior — the API has no knob for status_on_error, so its ext_proc failures emit HTTP 500 by default. Operators either accept the divergence (different status code → different retry semantics → split observability per proxy type) or maintain an EnvoyPatchPolicy alongside the EnvoyExtensionPolicy (sensitive to Envoy Gateway version changes). Exposing statusOnError directly unifies behavior across both proxy types and matches what ExtAuth already supports.

Related

  • #8432 — feat: support status_on_error field in external authorization (ExtAuth equivalent)
  • #5180 / #6872 / #5214 — earlier requests for the ExtAuth version

Workaround

EnvoyPatchPolicy to inject status_on_error directly into the generated xDS — works but is sensitive to Envoy Gateway version changes.

Implementation

Happy to implement and PR this — the change should be small (~50 LoC + tests) mirroring the ExtAuth implementation in #8432: add the field on the ExtProc struct, wire it through the xDS translator, add a CRD validation test and a translator testdata pair, plus a doc update. Will start once a maintainer ACKs the direction.

dragon3 avatar May 20 '26 09:05 dragon3

Quick update — I went ahead and put up a PR (#9044) anyway since the change ended up being a near-1:1 mirror of #8432 and I figured it'd be easier to discuss against concrete code than in the abstract. Happy to close/hold it if maintainers would prefer to ACK the direction first before reviewing.

The PR adds statusOnError on EnvoyExtensionPolicy.spec.extProc[] with the same 4xx/5xx enum validation as SecurityPolicy.spec.extAuth.statusOnError, wires it through the IR and xDS translator, and updates one gateway-api translator testdata pair + one xDS translator testdata pair, plus the release note and generated CRDs/docs.

dragon3 avatar May 20 '26 23:05 dragon3

cc @guydc

zirain avatar May 22 '26 02:05 zirain