Documentation
¶
Overview ¶
Package holt implements a reverse HTTP tunnel over a WebSocket carrying a bidirectional protobuf frame stream: a peer that can only dial OUT attaches to a hub, then serves an ordinary http.Handler back through the attached stream. The hub gets an http.RoundTripper per peer and a presence signal for free. The carrier is a WebSocket so the tunnel passes through CDN public hostnames, access proxies, and HTTP/1.1-only edges that cannot proxy gRPC.
This package is the front door for both halves: NewServer assembles a hub from options and serves it; NewClient wires a peer that attaches to one and serves a handler back through the tunnel. Everything needed to configure the two constructors lives here.
The optional surface lives under pkg/ for applications that want the pieces directly: pkg/registry (the operator surface — Server.Registry returns one), pkg/attach (the WebSocket attach handler, for mounting on your own router), pkg/revproxy (the data-plane reverse proxy), pkg/dial (the raw attach loop), pkg/directory and pkg/blocklist (peer presence and the denylist, each with SQLite and Postgres flavours), pkg/jwtauth and pkg/token (the JWT identity scheme and its join token), and pkg/peername (peer-id validation). Only the assembly guts and the wire protocol are internal.
Index ¶
- Constants
- type Client
- type ClientOption
- func WithBearerToken(token string) ClientOption
- func WithHTTPClient(httpClient *http.Client) ClientOption
- func WithHeader(key, value string) ClientOption
- func WithKeepalive(every time.Duration) ClientOption
- func WithTunnelTLS(cfg *tls.Config) ClientOption
- func WithVersion(version string) ClientOption
- type EndpointOption
- type ErrorHook
- type HandlerOption
- type Identity
- type Middleware
- type Option
- type Proxy
- type ProxyOption
- type RequestEvent
- type RequestHook
- type Resolver
- type Routing
- type Server
- type SharedOption
- type Tunnel
- type TunnelOption
- type WatchOption
Constants ¶
const ( RoutingHeader = revproxy.RoutingHeader RoutingSubdomain = revproxy.RoutingSubdomain RoutingBoth = revproxy.RoutingBoth )
The routing strategies.
const ( DefaultTunnelAddr = server.DefaultTunnelAddr DefaultProxyAddr = server.DefaultProxyAddr )
The addresses NewServer serves on when WithTunnel / WithProxy are not given — holt's canonical loopback ports.
const DevPeerHeader = tunnel.DevPeerHeader
DevPeerHeader is how a peer names itself under the development identity — the default when a tunnel has no identity configured. The claim is not verified.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.29.0
Client is the assembled peer: a persistent attach loop that dials the hub and serves an http.Handler back through the tunnel, redialing with jittered backoff. It is NewServer's counterpart for the client side.
c := holt.NewClient("wss://hub.example.com", handler,
holt.WithBearerToken(token),
)
err := c.Run(ctx) // attaches, serves, redials; cancel ctx to stop
func NewClient ¶ added in v0.29.0
func NewClient(hubURL string, handler http.Handler, opts ...ClientOption) *Client
NewClient wires a peer that attaches to the hub's tunnel endpoint at hubURL — ws:// or wss:// (http/https are accepted as aliases) — and serves handler over the tunnel, as if it were a normal HTTP server. Nothing dials until Run.
type ClientOption ¶ added in v0.29.0
ClientOption configures a Client; every SharedOption is one too.
func WithBearerToken ¶ added in v0.29.0
func WithBearerToken(token string) ClientOption
WithBearerToken sends token as the Authorization bearer on the attach request — the counterpart of the server's WithAuthBearer.
func WithHTTPClient ¶ added in v0.29.0
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient overrides the client used for the upgrade request (custom roots, proxies). Default http.DefaultClient.
func WithHeader ¶ added in v0.29.0
func WithHeader(key, value string) ClientOption
WithHeader adds a header to the WebSocket upgrade request — whatever the edge in front of the hub wants (e.g. CF-Access-Client-Id / CF-Access-Client-Secret). Repeatable.
func WithKeepalive ¶ added in v0.29.0
func WithKeepalive(every time.Duration) ClientOption
WithKeepalive paces WebSocket-level pings so proxies with idle timeouts keep a quiet tunnel open. A negative value disables them (the inner HTTP/2 PING remains).
func WithTunnelTLS ¶ added in v0.29.0
func WithTunnelTLS(cfg *tls.Config) ClientOption
WithTunnelTLS encrypts the payload end-to-end INSIDE the tunnel: after the plaintext holt handshake the peer runs a TLS server over the stream and serves the handler over HTTPS. The hub must dial with a matching client config (WithPeerTLS). Independent of any TLS on the outer WebSocket hop.
func WithVersion ¶ added in v0.29.0
func WithVersion(version string) ClientOption
WithVersion sets the peer build version sent in Hello (observability).
type EndpointOption ¶ added in v0.29.0
type EndpointOption interface {
TunnelOption
ProxyOption
}
EndpointOption configures either endpoint kind: it is accepted by both NewTunnel and NewProxy.
func WithListener ¶ added in v0.29.0
func WithListener(lis net.Listener) EndpointOption
WithListener serves the endpoint on a listener the caller bound — a tls.Listener for wss, a systemd socket, ":0" in a test — instead of binding the endpoint's address. The listener is closed when Run returns.
func WithMiddleware ¶ added in v0.29.0
func WithMiddleware(middleware ...Middleware) EndpointOption
WithMiddleware wraps the endpoint's handler, first-listed outermost. Repeatable; later calls append.
type ErrorHook ¶ added in v0.29.0
ErrorHook observes requests the proxy could not serve, with a low-cardinality reason.
type HandlerOption ¶ added in v0.29.0
type HandlerOption = attach.HandlerOption
HandlerOption configures the attach handler; pass them through WithHandlerOptions.
func WithPeerTLS ¶ added in v0.29.0
func WithPeerTLS(cfg *tls.Config) HandlerOption
WithPeerTLS makes the hub run TLS INSIDE each tunnel with this client config after the plaintext holt handshake — pairing with the peer's WithTunnelTLS, so the payload stays encrypted end-to-end even across a plaintext or TLS-terminated transport.
func WithTracerProvider ¶ added in v0.29.0
func WithTracerProvider(tp trace.TracerProvider) HandlerOption
WithTracerProvider sets the OTel tracer provider for attach spans. Default: the global provider.
type Identity ¶ added in v0.29.0
Identity extracts the peer ID from an attach request's context. The surrounding middleware establishes it (JWT claims, mTLS SAN, a header); returning ("", err) rejects the attach.
type Middleware ¶ added in v0.29.0
type Middleware = utils.Middleware
Middleware wraps an endpoint's handler — auth on the tunnel, instrumentation on the proxy, anything http.
type Option ¶ added in v0.29.0
Option configures a Server; every SharedOption is one too.
func WithGrace ¶ added in v0.29.0
WithGrace bounds how long Run waits for in-flight work when draining. Default 5s.
func WithProxy ¶ added in v0.29.0
WithProxy serves the given proxy endpoint instead of the default one on DefaultProxyAddr (see NewProxy). Nil disables the proxy entirely, for a tunnel-only process.
func WithRegistry ¶ added in v0.29.0
WithRegistry supplies the registry instead of the default NewRegistry(logger) — the way to set a hub id, a shared presence Directory, or a MeterProvider.
func WithTunnel ¶ added in v0.29.0
WithTunnel serves the given tunnel endpoint instead of the default one on DefaultTunnelAddr (see NewTunnel). Nil disables the tunnel entirely, for a proxy-only process.
type Proxy ¶ added in v0.29.0
Proxy is the endpoint that reaches peers through their tunnels. Build it with NewProxy.
func NewProxy ¶ added in v0.29.0
func NewProxy(addr string, opts ...ProxyOption) *Proxy
NewProxy declares the peer-reaching reverse proxy on addr. By default it routes on the x-tunnel-peer header; WithRouting adds subdomain routing, WithResolvers custom resolution, WithErrorHook observability.
type ProxyOption ¶ added in v0.29.0
ProxyOption configures a Proxy; every EndpointOption is one too.
func WithErrorHook ¶ added in v0.29.0
func WithErrorHook(hook ErrorHook) ProxyOption
WithErrorHook observes requests the proxy could not serve.
func WithRequestCapture ¶ added in v0.43.0
func WithRequestCapture(limit int) ProxyOption
WithRequestCapture adds the payload to what WithRequestHook reports: the headers (credential values redacted) and up to limit bytes of each body. Off by default; nothing is stored either way.
func WithResolvers ¶ added in v0.29.0
func WithResolvers(resolvers ...Resolver) ProxyOption
WithResolvers appends custom resolvers to the proxy's chain, tried after the ones WithRouting names (or instead of the header default when no strategy is configured). Repeatable.
func WithRouting ¶ added in v0.29.0
func WithRouting(routing Routing, domain string) ProxyOption
WithRouting sets how the proxy picks the target peer; domain is the base domain for the subdomain strategies. An unusable pair (unknown strategy, missing or unused domain) fails Server.Run before anything binds.
type RequestEvent ¶ added in v0.36.0
RequestEvent is one request crossing a tunnel: what it was, what came back, how long it took, and (on the hub) which peer it went to.
type RequestHook ¶ added in v0.36.0
RequestHook receives one RequestEvent per request, after the response. It runs on the request's goroutine, so keep it cheap.
type Resolver ¶ added in v0.29.0
Resolver maps an inbound proxy request to the peer it targets, or "" when the request names none. The proxy tries its resolvers in order and the first peer named wins — implement this to route on anything the built-in strategies do not cover.
type Server ¶ added in v0.29.0
Server is the assembled hub: a Registry, a Tunnel endpoint peers attach to, and (optionally) a Proxy endpoint that reaches them. It is the one-call counterpart of NewClient for the server side.
srv := holt.NewServer(
holt.WithLogger(logger),
holt.WithTunnel(holt.NewTunnel(":7200",
holt.WithAuthBearer(peerForToken), // token → peer id
)),
holt.WithProxy(holt.NewProxy(":7202")), // reach peers: x-tunnel-peer
)
err := srv.Run(ctx) // binds, serves, blocks; cancel ctx to drain
Zero configuration works: holt.NewServer().Run(ctx) serves a tunnel on 127.0.0.1:7200 and a proxy on 127.0.0.1:7202 with the development identity — peers name themselves with the x-holt-peer header (or get a generated name) and nothing verifies the claim. That identity is loopback-only by construction: a tunnel bound to anything other than a loopback address with no identity configured refuses to start, so the trusting default cannot reach a network.
The operator surface stays reachable through Registry: roster, stop, watch.
type SharedOption ¶ added in v0.29.0
type SharedOption interface {
Option
ClientOption
}
SharedOption configures either half: it is accepted by both NewServer and NewClient.
func WithLogger ¶ added in v0.29.0
func WithLogger(logger *zap.Logger) SharedOption
WithLogger sets the logger. Default: no logging.
type Tunnel ¶ added in v0.29.0
Tunnel is the endpoint peers attach to. Build it with NewTunnel.
func NewTunnel ¶ added in v0.29.0
func NewTunnel(addr string, opts ...TunnelOption) *Tunnel
NewTunnel declares the attach endpoint on addr. Give it an identity — WithAuthBearer for bearer tokens, or WithMiddleware + WithIdentity for any other scheme — because the peer id is the registry key and should come from something verified. Without one, the development identity applies: peers name themselves with the x-holt-peer header (or get a generated name), nothing verifies the claim, and Run says so in the log. Loopback development only.
type TunnelOption ¶ added in v0.29.0
TunnelOption configures a Tunnel; every EndpointOption is one too.
func WithAuthBearer ¶ added in v0.29.0
func WithAuthBearer(verify func(ctx context.Context, token string) (peer string, err error)) TunnelOption
WithAuthBearer authenticates attaches with a Bearer token: the middleware extracts Authorization, asks verify for the peer id it proves, answers 401 when it refuses, and wires the identity so the registry keys the tunnel by that id. It is WithMiddleware + WithIdentity fused for the most common scheme; bring your own pair for anything else.
func WithHandlerOptions ¶ added in v0.29.0
func WithHandlerOptions(opts ...HandlerOption) TunnelOption
WithHandlerOptions passes options through to the attach handler — WithPeerTLS for inner TLS, WithTracerProvider for tracing.
func WithIdentity ¶ added in v0.29.0
func WithIdentity(identity Identity) TunnelOption
WithIdentity sets how the peer id is derived from the attach request's context, after the middleware authenticated it and stamped whatever the func reads.
type WatchOption ¶ added in v0.36.0
type WatchOption interface {
ProxyOption
ClientOption
}
WatchOption configures a live request view. It fits either end: on NewProxy the hub reports every request it carried for every peer, on NewClient the peer reports the ones its own handler served.
func WithRequestHook ¶ added in v0.36.0
func WithRequestHook(hook RequestHook) WatchOption
WithRequestHook reports every request as it completes — the live view the CLI prints, available to anything embedding either half. Nothing is stored; what the hook does with the event is yours. The hub's duration includes the tunnel hop, the peer's does not.
Directories
¶
| Path | Synopsis |
|---|---|
|
api
|
|
|
cmd
|
|
|
holt
command
Command holt is the operator CLI for a reverse-tunnel hub: run the hub, enroll peers, and manage live tunnels.
|
Command holt is the operator CLI for a reverse-tunnel hub: run the hub, enroll peers, and manage live tunnels. |
|
holt/internal/admin
Package admin implements the holt hub's Admin gRPC service over a *registry.Registry: list live tunnels, force one closed, and — when a Blocker is supplied — ban/unban a peer id.
|
Package admin implements the holt hub's Admin gRPC service over a *registry.Registry: list live tunnels, force one closed, and — when a Blocker is supplied — ban/unban a peer id. |
|
holt/internal/capture
Package capture runs short-lived capture endpoints inside the hub process.
|
Package capture runs short-lived capture endpoints inside the hub process. |
|
holt/internal/clog
Package clog builds the CLI logger.
|
Package clog builds the CLI logger. |
|
holt/internal/config
Package config loads the operator CLI's connection profiles, used by the admin commands to reach a remote hub (e.g.
|
Package config loads the operator CLI's connection profiles, used by the admin commands to reach a remote hub (e.g. |
|
holt/internal/httpsrv
Package httpsrv is the listener plumbing behind the hub's four endpoints (tunnel, admin, proxy, metrics).
|
Package httpsrv is the listener plumbing behind the hub's four endpoints (tunnel, admin, proxy, metrics). |
|
holt/internal/hubapi
Package hubapi is the hub's own HTTP surface on the admin listener, alongside the Admin gRPC service: the enroll endpoint that mints join tokens, and — with --ui — the web console with its config and rotate-secret endpoints.
|
Package hubapi is the hub's own HTTP surface on the admin listener, alongside the Admin gRPC service: the enroll endpoint that mints join tokens, and — with --ui — the web console with its config and rotate-secret endpoints. |
|
holt/internal/hubmetrics
Package hubmetrics holds the OTel instruments the hub CLI records outside the library: refused attaches, and build info.
|
Package hubmetrics holds the OTel instruments the hub CLI records outside the library: refused attaches, and build info. |
|
holt/internal/hubsecret
Package hubsecret manages the hub's JWT signing secret: a 32-byte random value the hub signs peer JWTs with, and enroll (local mode) reads to mint tokens.
|
Package hubsecret manages the hub's JWT signing secret: a 32-byte random value the hub signs peer JWTs with, and enroll (local mode) reads to mint tokens. |
|
holt/internal/store
Package store is the hub's durable non-secret state: a single SQLite database under the config directory (~/.holt/holt.db).
|
Package store is the hub's durable non-secret state: a single SQLite database under the config directory (~/.holt/holt.db). |
|
holt/internal/style
Package style is the CLI's small output vocabulary: a success mark, a dim note, and a plain column list.
|
Package style is the CLI's small output vocabulary: a success mark, a dim note, and a plain column list. |
|
holt/internal/webui
Package webui owns the hub's embedded web console.
|
Package webui owns the hub's embedded web console. |
|
starter-client
command
Command starter-client is a minimal, self-contained holt peer — a template to copy when writing your own client.
|
Command starter-client is a minimal, self-contained holt peer — a template to copy when writing your own client. |
|
examples
|
|
|
authenticated/client
command
Command client is a standalone holt peer.
|
Command client is a standalone holt peer. |
|
authenticated/server
command
Command server is a standalone holt hub with a real identity: it accepts reverse tunnels from peers on one port and reaches those peers on another by dialing back THROUGH their tunnels.
|
Command server is a standalone holt hub with a real identity: it accepts reverse tunnels from peers on one port and reaches those peers on another by dialing back THROUGH their tunnels. |
|
echo/client
command
Command client is the peer half of the echo example: it dials the hub and serves an HTTP handler back over the reverse tunnel, while listening on nothing itself.
|
Command client is the peer half of the echo example: it dials the hub and serves an HTTP handler back over the reverse tunnel, while listening on nothing itself. |
|
echo/server
command
Command server is the hub half of the echo example, with zero configuration: holt.NewServer() serves the tunnel on 127.0.0.1:7200 and a proxy on :7202.
|
Command server is the hub half of the echo example, with zero configuration: holt.NewServer() serves the tunnel on 127.0.0.1:7200 and a proxy on :7202. |
|
internal
|
|
|
proxy
Package proxy declares the endpoint that reaches peers through their tunnels: where it serves and how it routes.
|
Package proxy declares the endpoint that reaches peers through their tunnels: where it serves and how it routes. |
|
server
Package server assembles the hub half: a registry, a tunnel endpoint peers attach to, and (optionally) a proxy endpoint that reaches them, served together under one lifecycle.
|
Package server assembles the hub half: a registry, a tunnel endpoint peers attach to, and (optionally) a proxy endpoint that reaches them, served together under one lifecycle. |
|
tunnel
Package tunnel declares the endpoint peers attach to: where it serves, how the peer id is derived, and what passes through to the attach handler.
|
Package tunnel declares the endpoint peers attach to: where it serves, how the peer id is derived, and what passes through to the attach handler. |
|
utils
Package utils holds the plumbing the Tunnel and Proxy endpoint declarations share.
|
Package utils holds the plumbing the Tunnel and Proxy endpoint declarations share. |
|
wire
Package wire holds what the hub and dial halves of the tunnel share: the frame-level net.Conn adapter, the handshake, and the GoAway vocabulary.
|
Package wire holds what the hub and dial halves of the tunnel share: the frame-level net.Conn adapter, the handshake, and the GoAway vocabulary. |
|
pkg
|
|
|
attach
Package attach is the hub's tunnel front door: an http.Handler that accepts a peer's WebSocket upgrade, runs the holt handshake, and registers the resulting tunnel in the registry.
|
Package attach is the hub's tunnel front door: an http.Handler that accepts a peer's WebSocket upgrade, runs the holt handshake, and registers the resulting tunnel in the registry. |
|
blocklist
Package blocklist is the hub's identity denylist: the peer ids refused at attach time, durable across restarts.
|
Package blocklist is the hub's identity denylist: the peer ids refused at attach time, durable across restarts. |
|
blocklist/postgres
Package postgres is the PostgreSQL flavour of the SQL-backed denylist.
|
Package postgres is the PostgreSQL flavour of the SQL-backed denylist. |
|
blocklist/sqlite
Package sqlite is the SQLite flavour of the SQL-backed denylist.
|
Package sqlite is the SQLite flavour of the SQL-backed denylist. |
|
dial
Package dial is the client half of holt: a persistent attach loop that dials the hub over a WebSocket, serves an http.Handler over the reverse tunnel, and redials with jittered backoff until the context ends or the hub sends a terminal GoAway.
|
Package dial is the client half of holt: a persistent attach loop that dials the hub over a WebSocket, serves an http.Handler over the reverse tunnel, and redials with jittered backoff until the context ends or the hub sends a terminal GoAway. |
|
directory
Package directory defines peer presence: which peer is attached to which hub, since when.
|
Package directory defines peer presence: which peer is attached to which hub, since when. |
|
directory/postgres
Package postgres is the PostgreSQL flavour of the SQL-backed presence directory.
|
Package postgres is the PostgreSQL flavour of the SQL-backed presence directory. |
|
directory/sqldir
Package sqldir is a SQL-backed directory.Directory for SQLite and PostgreSQL, sharing peer presence across a fleet of hubs.
|
Package sqldir is a SQL-backed directory.Directory for SQLite and PostgreSQL, sharing peer presence across a fleet of hubs. |
|
directory/sqlite
Package sqlite is the SQLite flavour of the SQL-backed presence directory.
|
Package sqlite is the SQLite flavour of the SQL-backed presence directory. |
|
jwtauth
Package jwtauth is the hub's attach-time authentication: it issues and verifies the HMAC-SHA256 JWTs peers present, holds the signing secret so it can be rotated live (Secret), and enforces the whole check in front of the tunnel handler (Guard).
|
Package jwtauth is the hub's attach-time authentication: it issues and verifies the HMAC-SHA256 JWTs peers present, holds the signing secret so it can be rotated live (Secret), and enforces the whole check in front of the tunnel handler (Guard). |
|
peername
Package peername validates peer identities.
|
Package peername validates peer identities. |
|
registry
Package registry keeps the hub's live tunnels keyed by peer ID and lets the application dial "through" any attached peer with an ordinary http.RoundTripper.
|
Package registry keeps the hub's live tunnels keyed by peer ID and lets the application dial "through" any attached peer with an ordinary http.RoundTripper. |
|
reqlog
Package reqlog is the live view of requests crossing a tunnel.
|
Package reqlog is the live view of requests crossing a tunnel. |
|
revproxy
Package proxy is the hub's data plane: an http.Handler that picks the peer a request targets — by x-tunnel-peer header, or by subdomain of a base domain — and dials it through that peer's tunnel.
|
Package proxy is the hub's data plane: an http.Handler that picks the peer a request targets — by x-tunnel-peer header, or by subdomain of a base domain — and dials it through that peer's tunnel. |
|
token
Package token is the copy-paste enrollment token: the JWT that authenticates a peer, with the hub's tunnel URL in the audience claim.
|
Package token is the copy-paste enrollment token: the JWT that authenticates a peer, with the hub's tunnel URL in the audience claim. |
|
tunneltype
Package tunneltype names what a peer carries over its tunnel.
|
Package tunneltype names what a peer carries over its tunnel. |