Documentation
¶
Overview ¶
Package holt implements a reverse HTTP tunnel over a single bidirectional protobuf 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 module ships both halves:
- hub: the server side — accept Attach streams, keep a registry of live tunnels, dial "through" any peer with a RoundTripper.
- dial: the client side — a persistent attach loop that serves a handler over the tunnel and redials with backoff.
This package holds what both halves share: the frame-level net.Conn adapter, the handshake, and the GoAway vocabulary.
Index ¶
- Constants
- func ClientHandshake(stream FrameStream, peerVersion string) error
- func GoAwayReason(err error) string
- func ServerHandshake(stream FrameStream) (*holtv1.Hello, error)
- func TerminalReason(reason string) bool
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LastError() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(p []byte) (int, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SendGoAway(reason string) error
- func (c *Conn) SetDeadline(time.Time) error
- func (c *Conn) SetReadDeadline(time.Time) error
- func (c *Conn) SetWriteDeadline(time.Time) error
- func (c *Conn) Write(p []byte) (int, error)
- type ConnOption
- type FrameStream
- type GoAwayError
Constants ¶
const ( ReasonSuperseded = "superseded" ReasonTokenRevoked = "token-revoked" ReasonShuttingDown = "shutting-down" ReasonPeerStopping = "peer-stopping" // ReasonClosed is an operator-initiated close (e.g. an admin // "kill"): terminal, so the peer stops redialing until it is // restarted or re-enrolled. ReasonClosed = "closed" )
Well-known GoAway reasons. Superseded, credential revocation, and deliberate stop are terminal for the peer (no redial); everything else means "redial with backoff".
const MaxDataFrame = 32 * 1024
MaxDataFrame caps one TunnelFrame data payload — keeps inner HTTP/2 stream interleaving granular and stays far under gRPC's 4 MiB message ceiling.
const ProtocolVersion = 1
ProtocolVersion is the tunnel framing version spoken by this module, offered in Hello and confirmed in Welcome.
Variables ¶
This section is empty.
Functions ¶
func ClientHandshake ¶
func ClientHandshake(stream FrameStream, peerVersion string) error
ClientHandshake sends Hello and requires Welcome as the first reply. Called by the dial side on a fresh stream.
func GoAwayReason ¶
GoAwayReason returns the GoAway reason carried by err, or "" when err is not a GoAway.
func ServerHandshake ¶
func ServerHandshake(stream FrameStream) (*holtv1.Hello, error)
ServerHandshake requires Hello as the first frame and answers Welcome. Called by the hub on a fresh stream. Returns the peer's Hello for observability.
func TerminalReason ¶
TerminalReason reports whether a GoAway reason tells the peer to stop redialing.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn adapts an Attach stream to a net.Conn carrying raw bytes as TunnelFrame data frames. Read is single-reader — the HTTP/2 session on top owns it — and writes are serialised internally because streams do not allow concurrent sends.
Close seals the adapter: it waits out any in-flight write, then makes every later I/O attempt fail locally with net.ErrClosed instead of reaching the stream. Hub handlers rely on this — the HTTP/2 transport's background goroutines (ping, resets) outlive the stream handler, and a late write to a finished handler's stream panics inside connect.
func NewConn ¶
func NewConn(stream FrameStream, opts ...ConnOption) *Conn
NewConn wraps an attached (post-handshake) stream.
func (*Conn) Close ¶
Close seals the adapter (see the type comment) and runs the configured close func once.
func (*Conn) LastError ¶
LastError returns the first terminal read error; a GoAway from the far end surfaces here with its reason intact.
func (*Conn) Read ¶
Read returns buffered tunnel bytes, receiving the next data frame when the buffer is empty. A GoAway ends the stream with io.EOF after recording the reason (see LastError).
func (*Conn) RemoteAddr ¶
func (*Conn) SendGoAway ¶
SendGoAway emits a GoAway frame under the write mutex so it can never interleave with a data frame.
func (*Conn) SetDeadline ¶
Deadlines are accepted but not enforced: liveness comes from the HTTP/2 session's PING on top and the stream's own context.
type ConnOption ¶
type ConnOption func(*Conn)
ConnOption configures a Conn.
func WithCloseFunc ¶
func WithCloseFunc(fn func() error) ConnOption
WithCloseFunc runs fn once when the Conn is closed — the dial side passes the stream's CloseSend so the hub sees a clean EOF.
func WithSides ¶
func WithSides(local, remote string) ConnOption
WithSides labels LocalAddr/RemoteAddr for logs ("hub"/"peer").
type FrameStream ¶
type FrameStream interface {
Send(*holtv1.TunnelFrame) error
Recv() (*holtv1.TunnelFrame, error)
}
FrameStream is the frame-level view of an Attach stream. The gRPC client stream (holtv1.Tunnel_AttachClient) satisfies it directly; the hub wraps connect's BidiStream (whose receive method is named Receive) with a one-line adapter.
type GoAwayError ¶
type GoAwayError struct{ Reason string }
GoAwayError carries the far end's GoAway reason.
func (GoAwayError) Error ¶
func (e GoAwayError) Error() string
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/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/jwtauth
Package jwtauth issues and verifies the HMAC-SHA256 JWTs peers present when attaching to the hub.
|
Package jwtauth issues and verifies the HMAC-SHA256 JWTs peers present when attaching to the hub. |
|
holt/internal/selfsigned
Package selfsigned generates and persists the hub's self-signed TLS certificate — used to encrypt the tunnel transport — and its JWT secret, as files in the config folder.
|
Package selfsigned generates and persists the hub's self-signed TLS certificate — used to encrypt the tunnel transport — and its JWT secret, as files in the config folder. |
|
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 bordered table.
|
Package style is the CLI's small output vocabulary: a success mark, a dim note, and a bordered table. |
|
holt/internal/token
Package token is the copy-paste enrollment token that carries everything a peer needs to join: the hub's tunnel address, the JWT that authenticates it, and the hub's self-signed cert to pin (so the TLS-encrypted tunnel is verified, not blindly trusted).
|
Package token is the copy-paste enrollment token that carries everything a peer needs to join: the hub's tunnel address, the JWT that authenticates it, and the hub's self-signed cert to pin (so the TLS-encrypted tunnel is verified, not blindly trusted). |
|
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. |
|
Package dial is the client half of the holt: a persistent attach loop that dials the hub, 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 the holt: a persistent attach loop that dials the hub, serves an http.Handler over the reverse tunnel, and redials with jittered backoff until the context ends or the hub sends a terminal GoAway. |
|
examples
|
|
|
authenticated
command
Command authenticated shows the identity seam: the hub derives each peer's ID from a bearer token (a stand-in for a JWT claim or mTLS SAN), so the RoundTripper is keyed by an authenticated identity the peer cannot spoof — the Attach handshake carries no identity at all.
|
Command authenticated shows the identity seam: the hub derives each peer's ID from a bearer token (a stand-in for a JWT claim or mTLS SAN), so the RoundTripper is keyed by an authenticated identity the peer cannot spoof — the Attach handshake carries no identity at all. |
|
certs
Package certs is a tiny demo PKI for the separated client/server holt examples.
|
Package certs is a tiny demo PKI for the separated client/server holt examples. |
|
client-server/client
command
Command client is a standalone holt peer.
|
Command client is a standalone holt peer. |
|
client-server/server
command
Command server is a standalone holt hub.
|
Command server is a standalone holt hub. |
|
echo
command
Command echo is the smallest end-to-end holt demo: it stands up a hub and a peer in one process, the peer serves an HTTP handler that only it could serve, and the hub reaches that handler by dialing back THROUGH the tunnel the peer opened.
|
Command echo is the smallest end-to-end holt demo: it stands up a hub and a peer in one process, the peer serves an HTTP handler that only it could serve, and the hub reaches that handler by dialing back THROUGH the tunnel the peer opened. |
|
encrypted/client
command
Command client is a holt peer that dials the hub over a PLAINTEXT transport but serves its handler over MUTUAL TLS INSIDE the tunnel.
|
Command client is a holt peer that dials the hub over a PLAINTEXT transport but serves its handler over MUTUAL TLS INSIDE the tunnel. |
|
encrypted/server
command
Command server is a holt hub whose OUTER gRPC hop is plaintext, but which runs MUTUAL TLS INSIDE each tunnel.
|
Command server is a holt hub whose OUTER gRPC hop is plaintext, but which runs MUTUAL TLS INSIDE each tunnel. |
|
grpc-tunnel/client
command
Command client is a holt peer that serves a real gRPC service over the tunnel — with server reflection, so grpcurl can call it through the hub without any .proto files.
|
Command client is a holt peer that serves a real gRPC service over the tunnel — with server reflection, so grpcurl can call it through the hub without any .proto files. |
|
grpc-tunnel/server
command
Command server is a holt hub that lets you call a peer's gRPC service through the tunnel with grpcurl.
|
Command server is a holt hub that lets you call a peer's gRPC service through the tunnel with grpcurl. |
|
join-token/client
command
Command client joins the hub using a COPY-PASTE TOKEN — no cert files, no shared filesystem.
|
Command client joins the hub using a COPY-PASTE TOKEN — no cert files, no shared filesystem. |
|
join-token/server
command
Command server is a mutual-TLS holt hub that hands out its client credential as a COPY-PASTE TOKEN instead of writing files.
|
Command server is a mutual-TLS holt hub that hands out its client credential as a COPY-PASTE TOKEN instead of writing files. |
|
transport-tls/client
command
Command client is a holt peer that dials the hub over MUTUAL TLS.
|
Command client is a holt peer that dials the hub over MUTUAL TLS. |
|
transport-tls/server
command
Command server is a holt hub that secures the OUTER gRPC connection with MUTUAL TLS.
|
Command server is a holt hub that secures the OUTER gRPC connection with MUTUAL TLS. |
|
Package hub is the server half of the holt: it accepts Attach streams from peers, keeps a registry of live tunnels keyed by peer ID, and lets the application dial "through" any attached peer with an ordinary http.RoundTripper.
|
Package hub is the server half of the holt: it accepts Attach streams from peers, keeps a registry of live tunnels keyed by peer ID, and lets the application dial "through" any attached peer with an ordinary http.RoundTripper. |
|
admin
Package admin implements the holt hub's Admin gRPC service over a *hub.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 *hub.Registry: list live tunnels, force one closed, and — when a Blocker is supplied — ban/unban a peer id. |
|
sqldir
Package sqldir is a SQL-backed hub.Directory: a shared peer-presence store so a fleet of hubs can each see who is attached where.
|
Package sqldir is a SQL-backed hub.Directory: a shared peer-presence store so a fleet of hubs can each see who is attached where. |