bridge

package
v0.2.2-dev.6 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 34 Imported by: 0 modules, 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

Index

Constants

View Source
const (
	CertificateHeader = "X-Mistgate-Bridge-Certificate"
	SignatureHeader   = "X-Mistgate-Bridge-Signature"
	RelayIDHeader     = "X-Mistgate-Relay-ID"
	// ClientHeader carries the address of the person a subscription host hands to the panel (ServeConfig.PassClient); it is
	// on the answers to a proven exit only.
	ClientHeader     = "X-Mistgate-Bridge-Client"
	ErrorHeader      = "X-Mistgate-Bridge-Error"
	ProtocolHeader   = "X-Mistgate-Bridge-Version"
	StreamHeader     = "X-Mistgate-Bridge-Stream"
	StreamKindHeader = "X-Mistgate-Bridge-Kind"
	TargetHeader     = "X-Mistgate-Bridge-Target"
	PairIDHeader     = "X-Mistgate-Bridge-Pair-ID"
	StreamKindPanel  = "panel"
)
View Source
const (
	DefaultPoolSize          = 2
	MinPoolSize              = 2
	MaxPoolSize              = 4
	PendingWorkersPerConn    = 4
	MaxPendingWorkersPerConn = 24
	DialRetryMin             = time.Second
	DialRetryMax             = time.Minute
	DialRetryResetAfter      = 30 * time.Second
	BridgePingInterval       = 15 * time.Second
	BridgePingTimeout        = 10 * time.Second

	BridgeConnectionAge       = time.Hour
	BridgeConnectionAgeJitter = BridgeConnectionAge / 5
	BridgeDrainTimeout        = 10 * time.Minute
	BridgeConnectionBytes     = uint64(1 << 30)
	BridgeRotateCheck         = time.Second
	BridgeDialTimeout         = 15 * time.Second
	BridgeTargetDialTimeout   = 5 * time.Second
	BridgeKeepAlive           = 30 * time.Second
)
View Source
const (
	MaxStreamsPerExit       = 4096
	MaxStreamsPerEntry      = 8192
	MaxPeopleConnsPerExit   = 2 * MaxPoolSize // the pool plus the connections that serve out their time
	MaxPanelConnsPerExit    = 2               // the control link's own TLS connection, plus the one a replacing link opens while the old one dies
	MaxConnectionsPerExit   = MaxPeopleConnsPerExit + MaxPanelConnsPerExit
	AcceptQueueSize         = 1024 // a burst of people arrives faster than the listener hands them out
	PendingStreamsPerExit   = 256
	MaxPendingClients       = 4096
	MaxClientsPerEntry      = 8192
	ClientWaitForStream     = time.Second
	BridgeStreamIdleTimeout = 2 * time.Minute
	BridgeRequestIdle       = 30 * time.Second
	BridgePairTimeout       = 5 * time.Second
	BridgePanelDialTimeout  = BridgeTargetDialTimeout
	BridgeProgressTimeout   = 30 * time.Second
	// The control link's byte budget: a bucket that holds ControlBudgetBytes and refills at ControlBudgetPerSecond. A busy exit's
	// session carries a few KiB per second for days, so a total per stream would cut it every hour or two; the bucket only stops an
	// exit that pumps data at the panel (2 Mbit/s sustained, a 64 MiB burst).
	ControlBudgetBytes     = uint64(64 << 20)
	ControlBudgetPerSecond = uint64(256 << 10)
)
View Source
const LocalTargetNetwork = "panel"

LocalTargetNetwork is the network of a target the exit reaches through its local dial (SetLocalDial) rather than a port of its own: the panel's listener of a subscription host's connections lives in its process.

View Source
const PanelPeerID = "panel"

PanelPeerID is the exit id of the panel at a subscription host's Entry.

View Source
const PanelURIHost = "panel"

PanelURIHost is the host of the panel's URI, spiffe://panel/<id> (internal/panel/fleet/ca.go issues it).

Variables

View Source
var (
	ErrNoPair       = errors.New("no bridge pair in time")           // the exit has no free pair (down, or all busy)
	ErrEntryBusy    = errors.New("bridge entry carries its maximum") // the entry's client limits
	ErrExitNotKnown = errors.New("bridge exit not served")           // exitID is not one of the entry's exits
)

Errors of Attach and DialExit. Neither touches the connection when it returns one of these: the caller decides what the person gets (a subscription host sends it to the node's site).

Functions

func VerifyPanelProof

func VerifyPanelProof(hostNodeID string, exporter []byte, proof Proof, roots *x509.CertPool, now time.Time) error

VerifyPanelProof checks that the panel of this fleet calls subscription host hostNodeID over this connection: a certificate of the fleet CA with the one URI spiffe://panel/<id> and ClientAuth, and a signature over the connection's exporter in the panel's own domain (agentlink.PanelBridgeDigest). An agent's certificate or a bridge proof never passes.

func VerifyProof

func VerifyProof(entryNodeID string, exporter []byte, proof Proof, roots *x509.CertPool, allowed map[string]struct{}, now time.Time) (string, error)

VerifyProof checks fleet trust, the node id in the certificate, and the connection-bound signature.

Types

type Client

type Client struct {
	Conn net.Conn
	// RelayID is the exit's target for it.
	RelayID string
	// Idle is how long the stream may carry nothing before it is closed; 0 = BridgeStreamIdleTimeout.
	Idle time.Duration
	// Addr is the person's address, told to the exit when the entry passes it (ServeConfig.PassClient).
	Addr netip.AddrPort
}

Client is a connection a caller of Attach accepted itself (a subscription host takes them from a route of its front, not from a RelayListener the entry binds).

type DialIdentity

type DialIdentity struct {
	NodeID         string
	CertificateDER []byte
	PrivateKey     *ecdsa.PrivateKey
	// Panel: the panel calls a subscription host (its certificate is spiffe://panel/<id>); the proof is MakePanelProof.
	Panel bool
}

type DialSpec

type DialSpec struct {
	Dial         plugin.BridgeDial
	Error        string // A bridge-wide configuration error; no socket is opened when set.
	TargetErrors map[string]string
}

type DialState

type DialState struct {
	PeerNodeID string
	Conns      uint32 // panel pools count only connections with an authenticated pair
	Since      time.Time
	RTT        time.Duration
	Streams    uint64
	BytesIn    uint64
	BytesOut   uint64
	Error      string
}

type Dialer

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

func NewDialer

func NewDialer(identity func() DialIdentity) *Dialer

func (*Dialer) Close

func (d *Dialer) Close()

func (*Dialer) Connected

func (d *Dialer) Connected(peerNodeID string) bool

Connected reports whether a peer currently has a usable connection.

func (*Dialer) DialFleetPanel

func (d *Dialer) DialFleetPanel(ctx, lifetime context.Context, dial plugin.BridgeDial) (net.Conn, error)

DialFleetPanel opens one authenticated panel control pair without a relay run. ctx bounds dialing and the pair handshake only; lifetime, Dialer.Close or closing the returned conn ends the established pair.

func (*Dialer) DialPanel

func (d *Dialer) DialPanel(ctx context.Context, entryNodeID string) (net.Conn, error)

DialPanel opens one authenticated control stream through an already connected bridge. The entry chooses its panel target from its own configuration; this method does not accept a target address from the exit.

func (*Dialer) SetClock

func (d *Dialer) SetClock(now func() time.Time)

func (*Dialer) SetLocalDial

func (d *Dialer) SetLocalDial(dial LocalDial)

SetLocalDial sets the dial of LocalTargetNetwork targets. Call it once, before the first Sync.

func (*Dialer) States

func (d *Dialer) States() []DialState

func (*Dialer) Sync

func (d *Dialer) Sync(ctx context.Context, specs []DialSpec)

Sync replaces the exit's bridge targets and starts or stops their dial pools.

type Entry

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

func NewEntry

func NewEntry() *Entry

func (*Entry) Attach

func (e *Entry) Attach(ctx context.Context, exitID string, c Client) error

Attach hands c to a free pair of exit exitID, as a RelayListener does with a person it accepted, and blocks until the person's stream ends (nil). It returns ErrNoPair when no pair came within ClientWaitForStream, ErrEntryBusy over the entry's client limits, ErrExitNotKnown for an exit the entry does not serve, or ctx's error before the stream began; in each of these cases c is untouched. Once attached, c belongs to the stream, which closes it; ctx ending then cuts the stream.

func (*Entry) Close

func (e *Entry) Close()

func (*Entry) Connected

func (e *Entry) Connected(exitID string) bool

Connected says whether exit exitID holds a connection to this entry now (it may still have no free pair).

func (*Entry) DialExit

func (e *Entry) DialExit(ctx context.Context, exitID, relayID string, idle time.Duration) (net.Conn, error)

DialExit is the entry's own connection to exit exitID's target relayID, through a free pair, as a person's would be: a subscription host's agent reaches the panel this way. ctx bounds the wait for a pair only; the connection then lives until either side closes it or it carries nothing for idle (0 = BridgeStreamIdleTimeout).

func (*Entry) Handler

func (e *Entry) Handler(site http.Handler) http.Handler

Handler adds the private bridge route to a site without changing ordinary site responses.

func (*Entry) RelayCounters

func (e *Entry) RelayCounters() map[string]RelayCounters

func (*Entry) Serving

func (e *Entry) Serving() ServeConfig

Serving is the entry's current configuration (SetServe), for reports and tests.

func (*Entry) SetLogger

func (e *Entry) SetLogger(log *slog.Logger)

func (*Entry) SetServe

func (e *Entry) SetServe(cfg ServeConfig) error

func (*Entry) States

func (e *Entry) States() []PeerState

func (*Entry) StopListeners

func (e *Entry) StopListeners()

func (*Entry) SyncListeners

func (e *Entry) SyncListeners(relays []RelayListener) map[string]error

type LocalDial

type LocalDial func(ctx context.Context, target plugin.BridgeTarget, client netip.AddrPort) (net.Conn, error)

LocalDial opens a connection to target for a person the entry carries; client is the person's address, invalid when the entry does not pass it.

type PeerKind

type PeerKind uint8

PeerKind says whose proof an Entry accepts.

const (
	PeerAgents       PeerKind = iota // fleet agents, by node id (VerifyProof)
	PeerPanel                        // the fleet's panel (VerifyPanelProof): the entry is a subscription host
	PeerFleetControl                 // only an agent with the panel's current certificate, for a panel control pair
)

type PeerState

type PeerState struct {
	PeerNodeID string
	Conns      uint32
	Since      time.Time
	Streams    uint64
	BytesIn    uint64
	BytesOut   uint64
	Error      string
	// Clients is how many people the bridge carries now: pairs a person's connection was handed to and that have not ended.
	// Streams only counts up, and the waiting pairs are not people.
	Clients uint32
}

type Proof

type Proof struct {
	CertificateDER []byte
	Signature      []byte
}

Proof carries a node's certificate and a proof tied to one TLS connection.

func MakePanelProof

func MakePanelProof(hostNodeID string, exporter []byte, certificateDER []byte, key *ecdsa.PrivateKey) (Proof, error)

MakePanelProof is MakeProof in the panel's own domain (VerifyPanelProof).

func MakeProof

func MakeProof(entryNodeID string, exporter []byte, certificateDER []byte, key *ecdsa.PrivateKey) (Proof, error)

type RelayCounters

type RelayCounters struct {
	Bytes     uint64 // client to the exit's server
	BytesBack uint64 // exit's server to the client
}

type RelayListener

type RelayListener struct {
	RelayID    string
	ExitNodeID string
	Port       uint16
	Address    string // Only tests set an address; production listens on all local addresses.
}

type ServeConfig

type ServeConfig struct {
	EntryNodeID string
	Path        string
	ExitNodeIDs []string
	PanelVia    bool
	// PanelAddress is supplied only by the entry agent from its own enrollment configuration.
	PanelAddress string
	// PanelDial connects a fleet control pair to the panel's private listener. Its context bounds the dial, not the returned conn.
	PanelDial func(context.Context) (net.Conn, error)
	// AuthorizeAgent is required for PeerFleetControl. It reports whether serial (lowercase hexadecimal) is the panel's
	// current certificate for nodeID. It must read the latest local snapshot without blocking or calling back into Entry.
	AuthorizeAgent func(nodeID, serial string) bool
	Roots          *x509.CertPool
	Now            func() time.Time
	// Peer selects which identities and stream kinds may call the entry.
	Peer PeerKind
	// PassClient: the exit is told each person's address (ClientHeader on the pair's answers), so the panel sees whom a
	// subscription host carries. An agent's bridge never passes it.
	PassClient bool
}

Jump to

Keyboard shortcuts

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