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 ¶
const ( ArgMethod = "method" ArgPath = "path" ArgVersion = "version" ArgHeaders = "headers" ArgBody = "body" ArgIP = "ip" ArgHTTPS = "https" )
Message arguments.
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.
const ( ActionAllow = "allow" ActionDeny = "deny" )
Values of VarAction.
const MessageName = "inkwall-request"
MessageName is the spoe-message the agent inspects.
Variables ¶
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
// 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.