agent

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Overview

Package agent implements the tunnel agent: the client side of the vpc.apoxy.dev relay stack. It owns the shared UDP packet plane (Geneve data + QUIC control on one socket), the overlay datapath (in-process netstack with a SOCKS listener, or a kernel TUN device), and the relay session lifecycle (bootstrap, connection slots, key rotation, watchdog).

It is consumed by the `apoxy alpha tunnel run` command and embedded in-process by services that need a foot in the overlay themselves (e.g. the backplane's VTEP peer, which runs the agent in TUN mode so Envoy can reach overlay destinations by kernel route).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverRelays

func DiscoverRelays(ctx context.Context, vpc vpcclient.VpcV1alpha1Interface, network *vpcv1alpha1.VPCNetwork) (sets.Set[string], error)

DiscoverRelays lists ready relays whose network selector matches the given network and returns their dialable underlay addresses.

func HealthHandler

func HealthHandler(w http.ResponseWriter, r *http.Request)

HealthHandler returns 200 OK when at least one tunnel connection is active, 503 otherwise. This is used by external health checks.

Response codes:

  • 200 OK: At least one tunnel connection is active
  • 503 Service Unavailable: No active tunnel connections

Body is plain text with a short summary.

func MatchingRelays

func MatchingRelays(relays []vpcv1alpha1.Relay, network *vpcv1alpha1.VPCNetwork) []*vpcv1alpha1.Relay

MatchingRelays filters relays to the ready ones whose network selector matches the given network. A relay with a nil selector serves all networks (per RelaySpec). This is THE definition of "which relays serve a network" — both agent-side discovery (DiscoverRelays) and in-shard consumers that dial relays by other addresses (e.g. the backplane VTEP resolving underlay endpoints) must go through it so their views never diverge.

func NewRelayLister

func NewRelayLister(vpc vpcclient.VpcV1alpha1Interface, networkName string) func(context.Context) (sets.Set[string], error)

NewRelayLister returns a Config.RelayLister that re-fetches the VPCNetwork on every refresh, so relabeling it (which changes which relay selectors match) is picked up without an agent restart.

func Run

func Run(ctx context.Context, cfg Config) error

Run connects the agent to the relay fabric and blocks until ctx is canceled or the datapath fails: it bootstraps against the seed relay, starts the overlay router, and maintains MinConns concurrent relay sessions from the (optionally refreshed) relay pool.

Types

type Config

type Config struct {
	Agent            string            // agent identifier
	Network          string            // VPC network name
	Token            string            // tunnel auth token
	Labels           map[string]string // agent-declared labels for VPCService selection
	AdvertisedRoutes []string          // CIDRs reachable behind this agent, advertised to the relay
	Instance         string            // stable per-process instance UUID

	// SeedRelayAddr is the relay dialed for the bootstrap session (host:port).
	// Empty means Run picks one at random from SeedRelays; set it only for the
	// static single-relay case.
	SeedRelayAddr string
	// SeedRelays is the initial relay pool. Empty means just SeedRelayAddr.
	SeedRelays sets.Set[string]
	// RelayLister, when set, is polled to keep the relay pool current; relays
	// coming and going are picked up without a restart. Nil = static pool.
	RelayLister func(context.Context) (sets.Set[string], error)
	// MinConns is the number of concurrent relay connection slots. Values
	// below 1 are treated as 1. Ignored when ConnectAll is set.
	MinConns int
	// ConnectAll maintains one session per relay in the pool instead of
	// MinConns slots, tracking pool refreshes. Relay consumers (backplane
	// VTEP sessions) need this: relays do not federate routes, so reaching
	// agents homed on any relay requires a session to every relay.
	ConnectAll bool

	// TLSConfig is used for the QUIC control sessions. Nil means defaults.
	TLSConfig *tls.Config

	// SocksListenAddr is the SOCKS5 listen address for the netstack datapath.
	// Ignored in TUN mode.
	SocksListenAddr string
	// PcapPath writes a packet capture of the netstack datapath. Not
	// supported in TUN mode.
	PcapPath string
	// TunMode selects the kernel TUN datapath over the in-process netstack:
	// the agent creates a TUN device (TunIfaceName) and programs overlay
	// addresses/routes on it, so any process in the netns reaches the overlay
	// by kernel route. Linux only; requires NET_ADMIN and /dev/net/tun.
	TunMode bool
	// TunIfaceName names the TUN device created in TUN mode.
	TunIfaceName string
	// TunNetns, when non-empty, places the TUN device inside this named
	// network namespace (created and bind-mounted under /var/run/netns if
	// missing). Only sockets created in that namespace reach the overlay,
	// giving kernel-level isolation between tenants sharing the process.
	// Requires CAP_SYS_ADMIN. Ignored outside TUN mode.
	TunNetns string
}

Config holds the agent identity, credential, and datapath configuration for one Run. Agent, Network, Token, and a relay source (SeedRelayAddr or a non-empty SeedRelays) are required.

Jump to

Keyboard shortcuts

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