extproc

package
v0.5.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 27 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package extproc implements the ext_proc adapter used by Envoy's external processing filter (envoy.service.ext_proc.v3), and so by Envoy Gateway.

Envoy opens one gRPC stream per HTTP request and sends the request headers, then the body if its processing mode asks for it. The adapter answers an allowed request with CONTINUE and a denied one with an immediate response carrying the verdict's status, or, for a gRPC call, its gRPC status (trailers-only). Later messages (the response headers and body, if the filter sends them) are answered with CONTINUE, unless the request's policy inspects responses.

A policy that inspects responses keeps the request's evaluation for the response (pipeline.Exchange). Its status and headers are inspected, and its body when the rules read its media type and Envoy sends it in one message (response_body_mode BUFFERED or BUFFERED_PARTIAL): Envoy holds the response headers meanwhile, so a denied response is replaced by an immediate response. A response body the engine doesn't read (an image, a stream) is let through at the headers, and the answer asks Envoy, through mode_override, not to send or buffer it. A body Envoy cut, or doesn't send in one piece, has its prefix inspected and is handled as oversized (responses.onOversize). On a route whose response bodies are inspected, the request's Accept-Encoding is removed, so the upstream sends bodies the rules can read; gzip and deflate bodies are decoded all the same.

The body is inspected when the policy asks for it and Envoy sends it in one message: request_body_mode BUFFERED or BUFFERED_PARTIAL. A body Envoy doesn't send that way (NONE, STREAMED, ...) goes uninspected, and is handled like a body over the policy's limit (body.onOversize). With BUFFERED_PARTIAL, a body Envoy cut at its buffer limit is handled the same way. Envoy sends a body without end_of_stream when it cut it, but also when trailers follow (HTTP/2), and then sends no trailers message: Envoy Gateway can't ask for them. Such a body counts as complete only when it is under the limit and as long as its Content-Length says: one without Content-Length may have been cut at a buffer the engine doesn't know, so it is handled as oversized.

An upgrade (a WebSocket handshake: a GET with an Upgrade header) that declares no body is decided on its headers, and answered with CONTINUE_AND_REPLACE, so Envoy stops sending the stream: what follows its headers is the upgraded connection's data, not a body (#276). Its response is inspected as any other, unless it is a 101: an upstream that ignores the Upgrade header answers with an ordinary response, which must not pass uninspected because the client asked for an upgrade.

In observability mode (detect mode) Envoy doesn't wait for the answers, and the adapter sends none. The body comes in chunks there (STREAMED, the only mode Envoy allows, whatever protocol_config says): they are gathered up to the limit, and the stream is closed once the request is decided, or its response when that is inspected. A stream that ends first is decided on what came.

The protocol the client spoke is Envoy's request.protocol attribute, if the filter sends it; HTTP/1.1 otherwise.

The client address comes from X-Forwarded-For, which Envoy sets before the filter runs, through the trusted proxies. Envoy is the direct peer: a Unix-socket peer counts as loopback, 127.0.0.1.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxBodyBytes is how much of a request body is inspected. Zero
	// disables body inspection.
	MaxBodyBytes int64
	// ClientIP resolves the client address from X-Forwarded-For. Envoy is
	// the direct peer, so its address must be trusted. Nil trusts no
	// proxies.
	ClientIP *clientip.Resolver
	// Logger receives one security event per denied or logged request.
	// Nil uses slog.Default().
	Logger *slog.Logger
	// JSONDenials answers a denied client that accepts application/json
	// with a JSON body (httpadapter.DenialBody); off: text.
	JSONDenials bool
	// ProbeKey returns the key of the operator's probe (the bundle's), or
	// nil: a request with a valid probe header is then answered by the
	// engine, uninspected (#372). Nil: no probe is answered.
	ProbeKey func() []byte
	// Metrics counts the requests the adapter can't read (nil: none).
	Metrics *telemetry.Metrics
	// Events records each security event for the operator (nil: logged
	// only).
	Events *events.Recorder
}

Config configures a Server.

type Server

type Server struct {
	extprocv3.UnimplementedExternalProcessorServer
	// contains filtered or unexported fields
}

Server answers Envoy's external processing streams.

func New

func New(p pipeline.Inspector, cfg Config) (*Server, error)

New returns a Server that inspects requests with p.

func (*Server) NewGRPCServer

func (s *Server) NewGRPCServer(opts ...grpc.ServerOption) *grpc.Server

NewGRPCServer returns a gRPC server that serves s. It accepts messages as large as the body limit and the headers.

func (*Server) Process

Process handles the stream of one HTTP request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL