Documentation
¶
Overview ¶
Package netx opens the networks komando reaches targets through (docs/features/vpn.md). WireGuard, SOCKS, HTTP proxies, L2TP, IPsec, IKEv2, Tailscale, OpenVPN and AnyConnect run inside komando, in user space, so the computer's routes are not changed. Only the openconnect family (globalprotect, fortinet, pulse, f5) uses an outside client when openconnect is installed; without it komando uses its own experimental client. A "system" VPN is one set up in the computer's own settings and does change routes. Session kinds run as a background session that later commands reuse.
Index ¶
- Variables
- func Alive(pid int) bool
- func BuiltinSSL(kind string) bool
- func BuiltinSSLFor(v *store.Vpn) bool
- func Clashes(before, after []Route) []string
- func Down(v *store.Vpn, err error) error
- func DownHint(v *store.Vpn) string
- func EditKeyUsers(pid int, procStart string, fn func(users []string) []string) error
- func ForgetTailscale(v *store.Vpn) error
- func KindNames() []string
- func LiveSession(ctx context.Context, v *store.Vpn) *store.VpnSession
- func Lock(name string) (unlock func(), err error)
- func LoginRequired(v *store.Vpn) error
- func ProcessStart(pid int) string
- func ProxyURL(address string) (*url.URL, error)
- func ReapIdle()
- func RecordStart(pid int) (string, error)
- func ReleaseKey(pub string, pid int) error
- func SSLVPNLogin(ctx context.Context, v *store.Vpn, ...) (string, error)
- func SecretHint(ref string) string
- func SessionAlive(s *store.VpnSession) bool
- func StopSession(s *store.VpnSession) error
- func StripWGKeys(text string) (clean, private, psk string, err error)
- func TailscaleDir(v *store.Vpn) string
- func TailscaleLogin(ctx context.Context, v *store.Vpn, show func(url string)) error
- func Terminate(pid int) error
- func WGPublicKey(private string) (string, error)
- type Dialer
- type KeyHolder
- type Kind
- type Route
- type WGConfig
- type WGPeer
- type WGStats
Constants ¶
This section is empty.
Variables ¶
var KeyLockDir = func() (string, error) { d, err := os.UserCacheDir() if err != nil { return "", err } return filepath.Join(d, "komando", "wireguard"), nil }
KeyLockDir is the per-user folder of key locks; tests point it elsewhere.
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 TARGET -D`, a company proxy)"}, "proxy": {Desc: "an HTTP proxy (CONNECT), such as a company proxy: every connection is tunneled through it"}, "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.
var LockBusy func(name string)
LockBusy, when set, is told that Lock has to wait for another komando that is starting or stopping the same VPN.
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.
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.
var WriteFor func(ctx context.Context) store.Write
WriteFor is set by the CLI: how the runtime record (a session's last use, a dead session gone) changes for the command ctx belongs to: store.Preview() under its --dry-run, so a preview writes nothing. Nil: store.Save().
Functions ¶
func BuiltinSSL ¶
BuiltinSSL reports whether komando speaks the kind itself.
func BuiltinSSLFor ¶ added in v0.12.0
BuiltinSSLFor is BuiltinSSL for one VPN: a GlobalProtect VPN without a user signs in through a browser, which only komando's own client does, so it never goes to openconnect.
func Clashes ¶
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 ¶
Down is the error for a VPN that cannot be used right now. The hint says what to do for its kind.
func EditKeyUsers ¶ added in v0.17.0
EditKeyUsers changes the Users of the key record the process pid (started at procStart) holds; nothing when it holds none.
func ForgetTailscale ¶ added in v0.13.0
ForgetTailscale removes a VPN's node state and folder (vpn rm).
func LiveSession ¶
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. It marks the session used, unless the command of ctx only previews (WriteFor).
func Lock ¶
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 ¶
LoginRequired is the error for a VPN that needs a human to log in.
func ProcessStart ¶ added in v0.15.0
ProcessStart is when pid started, in clock ticks after the system booted (field 22 of /proc/PID/stat); "" when there is no such process.
func ProxyURL ¶ added in v0.7.0
ProxyURL reads a proxy VPN's --address: host:port (plain HTTP to the proxy) or an http:// or https:// URL.
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 RecordStart ¶ added in v0.15.0
RecordStart is ProcessStart for a process komando just started, as its session records it: an error where this system reads start times but cannot read this one (the process already ended).
func ReleaseKey ¶ added in v0.17.0
ReleaseKey removes the record of pub while it is still pid's.
func SSLVPNLogin ¶
func SSLVPNLogin(ctx context.Context, v *store.Vpn, prompt func(label string, secret bool) (string, error), browser func(context.Context, sslvpn.BrowserPage) (string, error), notices io.Writer) (string, error)
SSLVPNLogin logs in at the terminal and returns the session cookie. browser shows a sign-in page to the person (GlobalProtect with SAML); nil, like a nil prompt, means nobody is there. notices gets what the browser sign-in tells the person (the stderr of the command that logs in); nil writes them nowhere.
func SecretHint ¶
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 runs: the pid is alive, runs the session's program, and started when the session's process did. A pid the system gave to another process later (after a crash, or named by an old copy of runtime.json put back) is not the session's, even when it runs the same program: its SOCKS port and login must not go to it, and it must not be signalled.
func StopSession ¶
func StopSession(s *store.VpnSession) error
StopSession ends a session's process. 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 ¶
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 ¶
TailscaleDir is tsnet's folder for the VPN (no keys: see sealedTSState).
func TailscaleLogin ¶
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 ¶
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.
func WGPublicKey ¶ added in v0.17.0
WGPublicKey derives the base64 public key of a base64 private key.
Types ¶
type Dialer ¶
Dialer opens a TCP connection through a network.
func Open ¶
Open starts v (or reuses its background session) and returns a dialer through it. Close the closer when done.
type KeyHolder ¶ added in v0.17.0
type KeyHolder struct {
PublicKey string `json:"public_key"`
PID int `json:"pid"`
ProcStart string `json:"proc_start,omitempty"` // ProcessStart of PID: a reused pid is another process
Socks string `json:"socks,omitempty"`
Home string `json:"home"`
Vpn string `json:"vpn"`
// Users are the VPN entries of Home that use this session (the same
// key); the last one's `vpn down` stops it.
Users []string `json:"users,omitempty"`
}
KeyHolder is the komando process that runs a WireGuard session for one interface key, as the key lock records it. It never holds the private key.
func ClaimKey ¶ added in v0.17.0
ClaimKey records h as the holder of h.PublicKey. When another live process holds it, nothing is written and that holder is returned. A record whose process has ended is taken over.
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 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).