proxy

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 29 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 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

This section is empty.

Variables

This section is empty.

Functions

func Transport added in v0.5.0

func Transport(h2c bool, cas *x509.CertPool) *http.Transport

Transport returns the upstream's transport: HTTP/2 over TLS by ALPN, or over cleartext with h2c, and connections kept for reuse.

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
}

Config configures a Handler.

type Handler

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

Handler is an inspecting reverse proxy.

func New

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

New returns a Handler that inspects requests with p.

func (*Handler) CloseWebSockets added in v0.5.0

func (h *Handler) CloseWebSockets(ctx context.Context) error

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.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP inspects r, then denies it or forwards it to the upstream.

Jump to

Keyboard shortcuts

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