wireguard

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package wireguard generates per-node WireGuard configuration for a cluster mesh. The server is the topology brain: given each node's public key, mesh IP, and (optional) public endpoint, it emits a wg0.conf for a target node with one Peer per other node, AllowedIPs pinned to each peer's /32 (so a node can only impersonate its own mesh IP), and a keepalive so NAT-bound nodes hold the tunnel open. The node's private key never reaches the server; the emitted config carries the PrivateKeyPlaceholder token, which the agent substitutes from its local key file at apply time.

Index

Constants

View Source
const PrivateKeyPlaceholder = "__LATTICE_WG_PRIVATE_KEY__"

PrivateKeyPlaceholder is replaced by the agent with the node's local private key when the config is applied. It is safe to display in an approval diff.

Variables

View Source
var ErrCustomTopology = errors.New("custom topology is not implemented; use mesh or hub-and-spoke")

ErrCustomTopology marks the not-yet-implemented explicit-edge mode. It fails closed rather than silently degrading to mesh, which would quietly widen a deliberately restricted topology.

Functions

func BuildMesh

func BuildMesh(nodes []model.Node, target model.Node, listenPort int) (Interface, []Peer, error)

BuildMesh computes the interface and peer list for target from the cluster's nodes. Nodes without a public key or mesh IP, and the target itself, are skipped. listenPort overrides the target's reported port when > 0.

func BuildTopology added in v0.2.1

func BuildTopology(
	network model.WGNetwork,
	memberships []model.WGMembership,
	nodes []model.Node,
	targetNodeID string,
) (Interface, []Peer, error)

BuildTopology computes the interface and peers for one member of a network. nodes supplies the public keys and fallback endpoints; memberships define the topology roles and addresses.

func GenerateConfig

func GenerateConfig(iface Interface, peers []Peer) (string, error)

GenerateConfig renders a wg0.conf. It validates keys and the interface name so attacker-influenced metadata cannot break out of the config structure.

func MeshFromNodes added in v0.2.1

func MeshFromNodes(nodes []model.Node, listenPort int) (model.WGNetwork, []model.WGMembership)

MeshFromNodes converts the existing implicit fleet mesh — the one encoded in Node.WireGuard* fields — into a named network plus memberships. It is the migration bridge: BuildTopology over its output must render identically to BuildMesh over the same nodes.

func ValidateEndpoint

func ValidateEndpoint(endpoint string) error

func ValidatePublicKey

func ValidatePublicKey(key string) bool

Types

type Interface

type Interface struct {
	Name       string
	Address    string // mesh address, e.g. 10.66.0.1/24
	ListenPort int
	MTU        int      // rendered only when > 0
	DNS        []string // resolver IPs; rendered only when non-empty
}

Interface is the Interface section for the target node.

type Peer

type Peer struct {
	Name       string // comment only
	PublicKey  string
	AllowedIPs string // typically <mesh-ip>/32
	Endpoint   string // host:port, empty for dial-out-only nodes
	Keepalive  int
}

Peer is one Peer section.

Jump to

Keyboard shortcuts

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