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. Its response leg (#595) is let through when its response is kept, and that response is answered with the variable response_probe, which the route's response rules return: HAProxy sends the route's responses to the engine.
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.
With Config.Responses, the agent also inspects the responses of the requests whose policies inspect them, which HAProxy sends in the message ResponseMessageName: see responses.go.
Index ¶
Constants ¶
const ( // ArgStatus is the response's status (status). ArgStatus = "status" // ArgKey is the request's VarResponses. ArgKey = "key" // ArgFailure is the request's VarResponseFailure. ArgFailure = "failure" // ArgWhole is true when HAProxy waited for the whole body // (wait-for-body, which answers 504 itself when the body doesn't come // in time): the message ended, or the buffer filled, which the frame's // size tells. Without it, a body without Content-Length counts as // cut: nothing else tells it whole. ArgWhole = "whole" )
Arguments of ResponseMessageName, besides ArgHeaders (res.hdrs_bin) and ArgBody (res.body).
const ( // VarResponses is set on a request's answer when its response is to // be inspected: the key its response message sends back. VarResponses = "responses" // VarResponseFailure is set with VarResponses: FailureOpen or // FailureClosed, what a response without an answer gets. VarResponseFailure = "response_failure" // VarResponseAction is ActionAllow or ActionDeny, on every answer to // a response message. VarResponseAction = "response_action" // VarResponseStatus is the status to replace a denied response with: // 403 for a leak, 502 for a body that couldn't be inspected or a // response the agent can't inspect, 503 when inspecting it failed. VarResponseStatus = "response_status" // VarResponseProbe is set only to answer the response leg of the // operator's probe (#595): the answer, which the route's response // rules return with status 299, in place of the app's response. VarResponseProbe = "response_probe" )
Variables of responses, in the transaction scope.
const ( FailureOpen = "open" FailureClosed = "closed" )
Values of VarResponseFailure.
const ( DefaultMaxPendingResponses = 4096 DefaultMaxPendingResponseBytes = 64 << 20 // DefaultResponseTTL is above HAProxy's usual timeout server (30s in // examples/haproxy, 50s in the HAProxy Kubernetes Ingress Controller): // a state must outlive the slowest response it waits for. DefaultResponseTTL = time.Minute )
Bounds of the table, by default.
const ( ArgMethod = "method" ArgPath = "path" ArgVersion = "version" ArgHeaders = "headers" ArgBody = "body" ArgIP = "ip" ArgHTTPS = "https" // ArgResponses, optional, says whether HAProxy sends the request's // response (ResponseMessageName): false for a backend without the // response rules, so the agent keeps nothing for it. Unset: it may. ArgResponses = "responses" )
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.
const ResponseMessageName = "inkwall-response"
ResponseMessageName is the spoe-message describing a response.
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
// 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
// Responses keeps the inspection of each request whose policy
// inspects responses for its response, which HAProxy sends in the
// message ResponseMessageName (responses.go). Off, the agent keeps
// nothing, whatever the policies say: HAProxy must be configured to
// send the responses first.
Responses bool
// MaxPendingResponses and MaxPendingResponseBytes bound the requests
// kept for their responses: their number and an estimate of their
// memory (0: DefaultMaxPendingResponses, DefaultMaxPendingResponseBytes).
MaxPendingResponses int
MaxPendingResponseBytes int64
// ResponseTTL is how long a request is kept for its response (0:
// DefaultResponseTTL): above HAProxy's timeout server.
ResponseTTL time.Duration
}
Config configures a Server.