Documentation
¶
Overview ¶
Package proxy implements Inkwall's standalone mode: an HTTP reverse proxy that inspects each request and forwards allowed ones to an upstream.
It is used in front of services without a supported ingress, and it is the reference adapter: every other adapter must reach the same verdict for the same request.
Index ¶
Constants ¶
const DefaultMaxHeldResponseBytes = 64 << 20
DefaultMaxHeldResponseBytes bounds the response bodies the proxy holds at once for inspection (Config.MaxHeldResponseBytes).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Upstream is the service that allowed requests are forwarded to.
Upstream *url.URL
// MaxBodyBytes is how much of a request body is inspected. The rest is
// streamed to the upstream uninspected. Zero disables body inspection.
MaxBodyBytes int64
// ClientIP resolves the client address behind trusted proxies. 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
// Metrics counts the requests the proxy can't read, and its
// WebSockets (nil: none).
Metrics *telemetry.Metrics
// Events records each security event for the operator (nil: logged
// only).
Events *events.Recorder
// WebSocketMessages inspects the messages of the WebSockets it
// forwards (websocket.go), each up to MaxBodyBytes. It needs a policy
// from flags (a *pipeline.Pipeline).
WebSocketMessages pipeline.WebSocketMessages
// WebSocketIdleTimeout closes a WebSocket with 1001 (going away) when
// no bytes pass either way for this long (0: never).
WebSocketIdleTimeout time.Duration
// BodyReadTimeout bounds reading the part of a request body that is
// inspected, from when the engine starts reading it: a client that
// stalls in it gets 408. The rest streams to the upstream under the
// server's own limits (0: none but the server's).
BodyReadTimeout time.Duration
// ReadTimeout is the server's limit to read a whole request
// (http.Server.ReadTimeout), set again once BodyReadTimeout's part is
// read (0: none).
ReadTimeout time.Duration
// UpstreamH2C reaches an http:// upstream over HTTP/2 without TLS
// (prior knowledge), as a gRPC server needs; WebSocket upgrades, HTTP/1
// only, can't pass then. An https:// upstream gets HTTP/2 or HTTP/1.1,
// as ALPN settles.
UpstreamH2C bool
// UpstreamCAs verifies an https:// upstream's certificate (nil: the
// system's roots).
UpstreamCAs *x509.CertPool
// MaxHeldResponseBytes bounds the response bodies held at once for
// inspection, each up to its policy's limit (and one byte): past it,
// a response gets the failure mode, as an evaluation refused for
// overload (0: DefaultMaxHeldResponseBytes).
MaxHeldResponseBytes int64
}
Config configures a Handler.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is an inspecting reverse proxy.
func (*Handler) CloseWebSockets ¶ added in v0.5.0
CloseWebSockets sends 1001 (going away) to the open WebSockets, both ways, and waits until they are closed or ctx ends: the http.Server's Shutdown doesn't see them once hijacked.