Documentation
¶
Index ¶
- Constants
- Variables
- func VerifyPanelProof(hostNodeID string, exporter []byte, proof Proof, roots *x509.CertPool, ...) error
- func VerifyProof(entryNodeID string, exporter []byte, proof Proof, roots *x509.CertPool, ...) (string, error)
- type Client
- type DialIdentity
- type DialSpec
- type DialState
- type Dialer
- func (d *Dialer) Close()
- func (d *Dialer) Connected(peerNodeID string) bool
- func (d *Dialer) DialFleetPanel(ctx, lifetime context.Context, dial plugin.BridgeDial) (net.Conn, error)
- func (d *Dialer) DialPanel(ctx context.Context, entryNodeID string) (net.Conn, error)
- func (d *Dialer) SetClock(now func() time.Time)
- func (d *Dialer) SetLocalDial(dial LocalDial)
- func (d *Dialer) States() []DialState
- func (d *Dialer) Sync(ctx context.Context, specs []DialSpec)
- type Entry
- func (e *Entry) Attach(ctx context.Context, exitID string, c Client) error
- func (e *Entry) Close()
- func (e *Entry) Connected(exitID string) bool
- func (e *Entry) DialExit(ctx context.Context, exitID, relayID string, idle time.Duration) (net.Conn, error)
- func (e *Entry) Handler(site http.Handler) http.Handler
- func (e *Entry) RelayCounters() map[string]RelayCounters
- func (e *Entry) Serving() ServeConfig
- func (e *Entry) SetLogger(log *slog.Logger)
- func (e *Entry) SetServe(cfg ServeConfig) error
- func (e *Entry) States() []PeerState
- func (e *Entry) StopListeners()
- func (e *Entry) SyncListeners(relays []RelayListener) map[string]error
- type LocalDial
- type PeerKind
- type PeerState
- type Proof
- type RelayCounters
- type RelayListener
- type ServeConfig
Constants ¶
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" )
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 )
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) )
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.
const PanelPeerID = "panel"
PanelPeerID is the exit id of the panel at a subscription host's Entry.
const PanelURIHost = "panel"
PanelURIHost is the host of the panel's URI, spiffe://panel/<id> (internal/panel/fleet/ca.go issues it).
Variables ¶
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.
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 Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
func NewDialer ¶
func NewDialer(identity func() DialIdentity) *Dialer
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 ¶
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) SetLocalDial ¶
SetLocalDial sets the dial of LocalTargetNetwork targets. Call it once, before the first Sync.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
func (*Entry) Attach ¶
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) Connected ¶
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 ¶
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) SetServe ¶
func (e *Entry) SetServe(cfg ServeConfig) error
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 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 ¶
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).
type RelayCounters ¶
type RelayListener ¶
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
}