netx

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: AGPL-3.0 Imports: 32 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

Overview

Package netx opens the networks komando reaches targets through (docs/design/network.md). WireGuard and SOCKS run inside komando's own process, only for the connections that need them. Kinds that need an outside client (Tailscale, the openconnect family, OpenVPN) run as a background session that later commands reuse; most of them hand komando a local SOCKS port, so several VPNs work at once without touching the computer's routes. OpenVPN (OS mode) does change routes.

Index

Constants

This section is empty.

Variables

View Source
var ErrNeedsSudo = errors.New("the VPN runs as root and stopping it needs sudo")

ErrNeedsSudo means an OS-mode session runs as root and sudo wants a password; a person must run `komando vpn down` in a terminal.

View Source
var Kinds = map[string]Kind{
	"wireguard":     {Desc: "WireGuard, run inside komando (no admin rights, many at once)"},
	"socks":         {Desc: "a SOCKS5 proxy that is already running (`komando tunnel start HOST -D`, a company proxy)"},
	"system":        {Desc: "a VPN set up in your computer's settings; --service lets `vpn up` connect it"},
	"l2tp":          {Desc: "L2TP/IPsec with a pre-shared key, run inside komando (no admin rights)", Session: true},
	"ipsec":         {Desc: "Cisco-style IPsec (IKEv1, group name and XAUTH login), run inside komando", Session: true},
	"ikev2":         {Desc: "IKEv2/IPsec (pre-shared key or EAP login with a server certificate), run inside komando", Session: true},
	"tailscale":     {Desc: "Tailscale or Headscale, run inside komando (no tailscaled, no admin rights)", Session: true},
	"globalprotect": {Desc: "Palo Alto GlobalProtect", Session: true, Client: []string{"openconnect", "ocproxy"}, Protocol: "gp"},
	"fortinet":      {Desc: "Fortinet SSL VPN (FortiClient)", Session: true, Client: []string{"openconnect", "ocproxy"}, Protocol: "fortinet"},
	"anyconnect":    {Desc: "Cisco AnyConnect / ocserv, run inside komando (no openconnect)", Session: true},
	"pulse":         {Desc: "Pulse Secure / Ivanti Connect Secure", Session: true, Client: []string{"openconnect", "ocproxy"}, Protocol: "pulse"},
	"f5":            {Desc: "F5 BIG-IP SSL VPN", Session: true, Client: []string{"openconnect", "ocproxy"}, Protocol: "f5"},
	"openvpn":       {Desc: "OpenVPN, also Pritunl profiles, run inside komando (no openvpn program, Docker or admin rights)", Session: true},
}

Kinds are the VPN kinds komando knows.

View Source
var SessionSecret string

SessionSecret is what a person gave for this session: a typed OpenVPN password, or the cookie of a VPN login done at the terminal. It reaches `komando vpn serve` on its stdin, never on a command line.

View Source
var StartSession func(ctx context.Context, name string) error

StartSession is set by the CLI: it brings up a session for a VPN that can connect without a human (no MFA). Open calls it on demand.

Functions

func Alive

func Alive(pid int) bool

Alive reports whether a process exists.

func BuiltinSSL

func BuiltinSSL(kind string) bool

BuiltinSSL reports whether komando speaks the kind itself.

func Clashes

func Clashes(before, after []Route) []string

Clashes compares the routes before and after a VPN connected. A new route that overlaps one another interface already had means two networks claim the same addresses: one of them will not be reachable.

func Down

func Down(v *store.Vpn, err error) error

Down is the error for a VPN that cannot be used right now. The hint says what to do for its kind.

func DownHint

func DownHint(v *store.Vpn) string

DownHint is what to do when v does not answer.

func KindNames

func KindNames() []string

KindNames lists the kinds, sorted.

func LiveSession

func LiveSession(v *store.Vpn) *store.VpnSession

LiveSession returns the VPN's background session if it is running and not idle for longer than the vpn_idle setting. An idle one is stopped.

func Lock

func Lock(name string) (unlock func(), err error)

Lock holds the per-VPN lock that starting and stopping a session take, so a stale stop can never hit a session another process just started.

func LoginRequired

func LoginRequired(v *store.Vpn) error

LoginRequired is the error for a VPN that needs a human to log in.

func ReapIdle

func ReapIdle()

ReapIdle closes sessions unused for longer than vpn_idle. It runs at the start of every komando command, so sessions do not stay up forever.

func SSLVPNLogin

func SSLVPNLogin(ctx context.Context, v *store.Vpn, prompt func(label string, secret bool) (string, error)) (string, error)

SSLVPNLogin logs in at the terminal and returns the session cookie.

func SecretHint

func SecretHint(ref string) string

SecretHint says how to provide a secret reference that does not resolve.

func SessionAlive

func SessionAlive(s *store.VpnSession) bool

SessionAlive reports whether a session's process or container runs.

func StopSession

func StopSession(s *store.VpnSession) error

StopSession ends a session's process or container (through sudo for OS-mode ones). A session that is no longer running is already stopped. It reports an error when it could not stop it; the caller keeps the session then.

func StripWGKeys

func StripWGKeys(text string) (clean, private, psk string, err error)

StripWGKeys removes PrivateKey and PresharedKey lines from a wg-quick file, returning the rest and the keys, so only the vault holds them. komando supports one preshared key per VPN.

func TailscaleDir

func TailscaleDir(v *store.Vpn) string

TailscaleDir is where the VPN's node keys and state are kept.

func TailscaleLogin

func TailscaleLogin(ctx context.Context, v *store.Vpn, show func(url string)) error

TailscaleLogin logs the node in through the browser: show gets the login page. It returns once the node is connected; its state is kept, so later sessions start without a login until the key expires.

func Terminate

func Terminate(pid int) error

Terminate asks one process to stop. It refuses every pid that is not a single other process: kill(-1) would signal every program of the user, kill(0) the whole process group, kill(1) init.

Types

type Dialer

type Dialer func(ctx context.Context, network, addr string) (net.Conn, error)

Dialer opens a TCP connection through a network.

func Open

func Open(ctx context.Context, v *store.Vpn, timeout time.Duration) (Dialer, io.Closer, error)

Open starts v (or reuses its background session) and returns a dialer through it. Close the closer when done.

func OpenDirect

func OpenDirect(ctx context.Context, v *store.Vpn, timeout time.Duration) (Dialer, io.Closer, error)

OpenDirect opens an in-process kind (wireguard, socks, system) without looking for a session. `komando vpn serve` uses it.

func StartWG

func StartWG(c *WGConfig) (Dialer, io.Closer, error)

StartWG brings up a userspace WireGuard device for c and returns a dialer into its network.

type Kind

type Kind struct {
	Desc     string
	Session  bool
	Client   []string
	Protocol string // openconnect --protocol
}

Kind describes a VPN kind. Session kinds run a client in the background (`komando vpn up`), reused by later commands; Client names the program that must be installed for it.

type Route

type Route struct {
	Prefix netip.Prefix
	Iface  string
}

Route is one IPv4 entry of the computer's routing table.

func Routes

func Routes() ([]Route, error)

Routes reads the computer's IPv4 routes (netstat on macOS, ip on Linux). Only VPNs that change the computer's network (OpenVPN --os-mode, system VPNs) need it: the in-process and container kinds never add routes.

type WGConfig

type WGConfig struct {
	PrivateKey string
	Addresses  []netip.Addr
	DNS        []netip.Addr
	MTU        int
	Peers      []WGPeer
}

WGConfig is a wg-quick file ([Interface] and [Peer] sections).

func ParseWG

func ParseWG(text string) (*WGConfig, error)

ParseWG reads a wg-quick file. Keys stay base64, as in the file.

func (*WGConfig) UAPI

func (c *WGConfig) UAPI() (string, error)

UAPI turns the config into WireGuard's configuration protocol. Endpoints are resolved here, since the protocol takes IP:port.

type WGPeer

type WGPeer struct {
	PublicKey    string
	PresharedKey string
	Endpoint     string
	AllowedIPs   []netip.Prefix
	Keepalive    int
}

Jump to

Keyboard shortcuts

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