spoe

package
v0.5.0 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: 22 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 spoe implements an SPOE agent (an SPOA): the adapter HAProxy's Stream Processing Offload Engine calls over SPOP, its binary protocol (doc/SPOE.txt in HAProxy).

HAProxy opens a few connections to the agent and starts each with a HELLO handshake, which settles the protocol version (2.0), the maximum frame size and pipelining. A HELLO with healthcheck set (option spop-check) is answered, and the connection closed. HAProxy then sends one NOTIFY frame per event that has messages: the agent answers each with an ACK carrying actions, here set-var actions in the transaction scope that HAProxy's rules act on. With pipelining, several NOTIFY frames are in flight on a connection and are answered in any order.

The agent reads the message named MessageName, whose arguments describe the request: method, path (pathq: path and query), version, headers (req.hdrs_bin), body (req.body), ip (src) and https (ssl_fc). It answers with the variables action ("allow" or "deny"), status (the status to deny with) and request_id, under the prefix of the spoe-agent section (txn. inkwall.action with option var-prefix inkwall). The variables are set on every answer, so an unset action means HAProxy didn't get one: the agent is down, or timed out. HAProxy then sets no variable at all, and its rules decide (the failure mode): a rule that denies when action is unset fails closed.

A denied gRPC call (by its Content-Type) also gets grpc_status, grpc_message and grpc_content_type, for HAProxy to answer it as a gRPC server would: HTTP 200 with the gRPC status in the headers.

The operator's probe (package haproxyprobe), a request whose X-Inkwall-Probe header has a valid MAC under the bundle's probe key, is answered uninspected with the variable probe, which the route's rules return: it tells the operator that HAProxy runs the filter on that route.

A NOTIFY without the message, or with arguments the agent can't read, gets action deny with status 400: only a misconfigured HAProxy sends one, and the request is not let through.

The body is inspected as HAProxy buffered it (option http-buffer-request). HAProxy buffers at most its buffer size (tune.bufsize), and sends no body without that option. A body shorter than its Content-Length was cut, and counts as truncated (body.onOversize decides). A body without Content-Length (chunked, or HTTP/2) counts as complete only when its frame is well under half the maximum frame size: HAProxy's buffer, of which the frame size is 4 bytes less, holds at least half its size of a request before it is full, whatever tune.maxrewrite is.

The client address is src, HAProxy's client (the PROXY protocol's, if HAProxy accepts it), resolved through the trusted proxies with the request's X-Forwarded-For.

Index

Constants

View Source
const (
	ArgMethod  = "method"
	ArgPath    = "path"
	ArgVersion = "version"
	ArgHeaders = "headers"
	ArgBody    = "body"
	ArgIP      = "ip"
	ArgHTTPS   = "https"
)

Message arguments.

View Source
const (
	VarAction    = "action"
	VarStatus    = "status"
	VarRequestID = "request_id"
	// VarGRPCStatus, VarGRPCMessage and VarGRPCContentType are set only
	// to deny a gRPC call (by its Content-Type): its gRPC status, the
	// grpc-message and the Content-Type to answer it with, trailers-only,
	// as the other adapters answer one.
	VarGRPCStatus      = "grpc_status"
	VarGRPCMessage     = "grpc_message"
	VarGRPCContentType = "grpc_content_type"
	// VarProbe is set only to answer the operator's probe
	// (haproxyprobe): the answer, which the route's rules return with
	// status 299. The probe is denied as well.
	VarProbe = "probe"
)

Variables the agent sets, in the transaction scope.

View Source
const (
	ActionAllow = "allow"
	ActionDeny  = "deny"
)

Values of VarAction.

View Source
const MessageName = "inkwall-request"

MessageName is the spoe-message the agent inspects.

Variables

View Source
var ErrServerClosed = errors.New("spoe: server closed")

ErrServerClosed is returned by Serve after Shutdown.

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 src and X-Forwarded-For.
	// Nil trusts no proxies: the client is src.
	ClientIP *clientip.Resolver
	// ReadTimeout bounds reading one frame once it has begun. Zero: no
	// limit. A connection may stay idle between frames.
	ReadTimeout time.Duration
	// Logger receives one security event per denied or logged request.
	// Nil uses slog.Default().
	Logger *slog.Logger
	// Metrics counts the messages and connections the agent can't read
	// (nil: none).
	Metrics *telemetry.Metrics
	// Events records each security event for the operator (nil: logged
	// only).
	Events *events.Recorder
	// ProbeKey returns the key of the operator's probe (the bundle's), or
	// nil: no probes are answered. Nil: none.
	ProbeKey func() []byte
}

Config configures a Server.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is an SPOE agent.

func New

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

New returns a Server that inspects requests with p.

func (*Server) Serve

func (s *Server) Serve(ln net.Listener) error

Serve accepts HAProxy's connections on ln until Shutdown.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops accepting connections, lets the NOTIFY frames being answered finish, says goodbye to HAProxy with AGENT-DISCONNECT and closes the connections. When ctx ends first, the connections are closed at once.

Jump to

Keyboard shortcuts

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