store

package
v0.4.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: 9 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 store persists komando state (inventory, conns, keys, snippets, jobs, tunnels, settings) as JSON files under $KOMANDO_HOME (default ~/.komando).

Index

Constants

This section is empty.

Variables

View Source
var DryRun bool

DryRun makes Update apply fn to a copy that is never saved. The CLI sets it for --dry-run, so a command shows the result of its change (and its validation errors) without making it.

View Source
var ErrDryRun = errors.New("this command cannot preview its change; nothing was changed")

ErrDryRun is returned by writes that cannot be simulated (the vault).

Functions

func EnsureHome

func EnsureHome() error

EnsureHome creates the state directory tree.

func Home

func Home() string

func Lock added in v0.3.0

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

Lock takes an exclusive lock on the file name in the state directory and returns the function that releases it. komando processes running at the same time (parallel agents) wait for each other.

func Path

func Path(parts ...string) string

func Update

func Update(fn func(s *State) error) error

Update loads state under an exclusive file lock, applies fn and saves atomically. Safe for concurrent komando processes (parallel agents).

func WriteFileAtomic

func WriteFileAtomic(path string, b []byte, mode os.FileMode) (err error)

WriteFileAtomic replaces path with b: a temporary file next to it is written, flushed to disk and renamed into place, and the folder is flushed too, so after a crash or power loss path holds either the old content or the new, never an empty or half-written file. The temporary file is removed on any failure.

Types

type Conn added in v0.2.0

type Conn struct {
	Name        string            `json:"name"`
	Kind        string            `json:"kind"` // postgres | mysql | sqlite
	URL         string            `json:"url"`
	PasswordRef string            `json:"password_ref,omitempty"` // secret:<name>, env:<VAR> or file:<path>
	Via         string            `json:"via,omitempty"`          // host used to reach the resource
	Groups      []string          `json:"groups,omitempty"`
	Tags        []string          `json:"tags,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Options     map[string]string `json:"options,omitempty"` // kind-specific settings
	Protected   bool              `json:"protected,omitempty"`
	Notes       string            `json:"notes,omitempty"`
	// TrustedPlugin is the hash of the kubeconfig login program a person
	// trusted for this conn (import kubeconfig). Not an Option: only a
	// person's import sets it, never --option.
	TrustedPlugin string    `json:"trusted_plugin,omitempty"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

Conn is a non-SSH resource (database, cache, ...) reached directly or through an SSH host. The URL never holds a password; see PasswordRef.

type Host

type Host struct {
	Name        string `json:"name"`
	Address     string `json:"address"`
	Port        int    `json:"port,omitempty"`
	User        string `json:"user,omitempty"`
	Key         string `json:"key,omitempty"`          // name of a key in the keychain
	Identity    string `json:"identity,omitempty"`     // path to a private key file
	PasswordRef string `json:"password_ref,omitempty"` // secret:<name> or env:<VAR>
	SudoRef     string `json:"sudo_ref,omitempty"`     // sudo password ref (secret:/env:)
	Via         string `json:"via,omitempty"`          // the way there: host name(s), comma-separated chain
	// ProxyCommand is a program on this computer whose stdin and stdout
	// carry the SSH connection (OpenSSH ProxyCommand): aws ssm start-session,
	// gcloud compute start-iap-tunnel, cloudflared access ssh. %h %p %r %n.
	ProxyCommand string            `json:"proxy_command,omitempty"`
	OldJump      string            `json:"jump,omitempty"` // before v0.3; moved to Via on load
	Groups       []string          `json:"groups,omitempty"`
	Tags         []string          `json:"tags,omitempty"`
	Labels       map[string]string `json:"labels,omitempty"`
	Env          map[string]string `json:"env,omitempty"` // exported before every command
	Protected    bool              `json:"protected,omitempty"`
	Notes        string            `json:"notes,omitempty"`
	CreatedAt    time.Time         `json:"created_at"`
	UpdatedAt    time.Time         `json:"updated_at"`
}

func (*Host) EffectivePort

func (h *Host) EffectivePort() int

func (*Host) HasTag

func (h *Host) HasTag(t string) bool

func (*Host) InGroup

func (h *Host) InGroup(g string) bool

type Job

type Job struct {
	ID        string    `json:"id"`
	Host      string    `json:"host"`
	Command   string    `json:"command"`
	PID       int       `json:"pid"`
	RemoteDir string    `json:"remote_dir"`
	StartedAt time.Time `json:"started_at"`
}

type Key

type Key struct {
	Name          string    `json:"name"`
	Path          string    `json:"path"`
	Type          string    `json:"type,omitempty"`
	PublicKey     string    `json:"public_key,omitempty"`
	Fingerprint   string    `json:"fingerprint,omitempty"`
	PassphraseRef string    `json:"passphrase_ref,omitempty"`
	Managed       bool      `json:"managed"` // generated/stored by komando
	CreatedAt     time.Time `json:"created_at"`
}

type Settings

type Settings struct {
	HostKeyPolicy    string   `json:"host_key_policy"` // accept-new | strict | off
	DefaultUser      string   `json:"default_user,omitempty"`
	DefaultTimeout   string   `json:"default_timeout"`
	ConnectTimeout   string   `json:"connect_timeout"`
	Parallel         int      `json:"parallel"`
	MaxOutputBytes   int      `json:"max_output_bytes"`
	ExtraDenyPattern []string `json:"extra_deny_patterns,omitempty"`
	Audit            bool     `json:"audit"`
	AuditSQL         string   `json:"audit_sql"`               // full | hash | off: how SQL text is kept in the audit log
	VpnIdle          string   `json:"vpn_idle"`                // a VPN session unused this long is disconnected
	ApprovalCode     bool     `json:"approval_code,omitempty"` // the approval window asks for a TOTP code
	AuditSyslog      string   `json:"audit_syslog,omitempty"`  // also send audit records to this log server (udp://, tcp://, tls://)
}

func DefaultSettings

func DefaultSettings() Settings

type Snippet

type Snippet struct {
	Name        string `json:"name"`
	Command     string `json:"command"`
	Description string `json:"description,omitempty"`
	Sudo        bool   `json:"sudo,omitempty"`
	// ReadOnly snippets skip the protected-host check. Everything else counts
	// as a change, so snippets saved before this field existed are treated
	// as changes too.
	ReadOnly  bool      `json:"read_only,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

type State

type State struct {
	Hosts    map[string]*Host       `json:"hosts"`
	Conns    map[string]*Conn       `json:"conns,omitempty"`
	Vpns     map[string]*Vpn        `json:"vpns,omitempty"`
	Sessions map[string]*VpnSession `json:"vpn_sessions,omitempty"`
	Keys     map[string]*Key        `json:"keys"`
	Snippets map[string]*Snippet    `json:"snippets"`
	Jobs     map[string]*Job        `json:"jobs"`
	Tunnels  map[string]*Tunnel     `json:"tunnels"`
	Settings Settings               `json:"settings"`
}

func Load

func Load() (*State, error)

Load reads state. Callers that mutate must use Update for locking.

func (*State) FindName added in v0.2.0

func (s *State) FindName(name string) (kind, existing string, found bool)

FindName finds the host or conn whose name equals name, ignoring case, so "Web1" and "web1" cannot both exist. existing is the name as stored.

func (*State) NameTaken added in v0.2.0

func (s *State) NameTaken(name string) (kind string, taken bool)

NameTaken reports whether a host or conn already uses name. Hosts and conns share one namespace so selectors stay unambiguous.

func (*State) SortedConns added in v0.2.0

func (s *State) SortedConns() []*Conn

func (*State) SortedHosts

func (s *State) SortedHosts() []*Host

func (*State) SortedVpns added in v0.2.0

func (s *State) SortedVpns() []*Vpn

type Tunnel

type Tunnel struct {
	ID        string    `json:"id"`
	Host      string    `json:"host"`
	Via       string    `json:"via,omitempty"`  // the --via chain when forwarding to a conn
	Conn      string    `json:"conn,omitempty"` // the conn this tunnel leads to
	Kind      string    `json:"kind"`           // local | remote | dynamic
	Spec      string    `json:"spec"`
	PID       int       `json:"pid"`
	LogFile   string    `json:"log_file"`
	StartedAt time.Time `json:"started_at"`
}

type Vpn added in v0.2.0

type Vpn struct {
	Name      string            `json:"name"`
	Kind      string            `json:"kind"`                 // see netx.Kinds
	Config    string            `json:"config,omitempty"`     // wireguard: the wg-quick file without its keys
	ConfigRef string            `json:"config_ref,omitempty"` // openvpn: the whole .ovpn, kept in the vault (it may hold keys)
	Address   string            `json:"address,omitempty"`    // socks: host:port of the proxy
	Portal    string            `json:"portal,omitempty"`     // openconnect kinds: the VPN server or portal
	Service   string            `json:"service,omitempty"`    // system: the OS VPN's name, to connect it with `vpn up`
	Server    string            `json:"server,omitempty"`     // tailscale: a Headscale login server; l2tp, ipsec, ikev2: the VPN server
	User      string            `json:"user,omitempty"`       // user name, if the VPN wants one
	KeyRef    string            `json:"key_ref,omitempty"`    // password, private key or auth key, as secret:/env:/file:
	PSKRef    string            `json:"psk_ref,omitempty"`    // wireguard, l2tp, ipsec, ikev2: preshared key, if any
	LocalID   string            `json:"id,omitempty"`         // ipsec: the group name; ikev2: our identity
	RemoteID  string            `json:"remote_id,omitempty"`  // ikev2: the server's identity (default: --server)
	CA        string            `json:"ca,omitempty"`         // ikev2: PEM of the CA that signed the server certificate
	MFA       bool              `json:"mfa,omitempty"`        // a human must log in (`vpn up`); never automated
	OSMode    bool              `json:"os_mode,omitempty"`    // openvpn: run on the computer itself (sudo, changes routes)
	Check     string            `json:"check,omitempty"`      // host:port that answers only through the VPN
	Groups    []string          `json:"groups,omitempty"`
	Tags      []string          `json:"tags,omitempty"`
	Labels    map[string]string `json:"labels,omitempty"`
	Notes     string            `json:"notes,omitempty"`
	CreatedAt time.Time         `json:"created_at"`
	UpdatedAt time.Time         `json:"updated_at"`
}

Vpn is a network komando opens inside its own process to reach targets (docs/design/network.md). Keys live in the vault, referenced by KeyRef.

type VpnSession added in v0.2.0

type VpnSession struct {
	Vpn       string    `json:"vpn"`
	PID       int       `json:"pid"`
	Socks     string    `json:"socks,omitempty"`      // local SOCKS5 address; empty when the OS routes the traffic
	Container string    `json:"container,omitempty"`  // the Docker container ID holding the VPN (openvpn)
	SocksUser string    `json:"socks_user,omitempty"` // login for the container's SOCKS port, random per session
	SocksPass string    `json:"socks_pass,omitempty"`
	Exe       string    `json:"exe,omitempty"`  // the program the pid must still be, so a reused pid is never signalled
	Sudo      bool      `json:"sudo,omitempty"` // the process runs as root (OS mode)
	LogFile   string    `json:"log_file,omitempty"`
	StartedAt time.Time `json:"started_at"`
	LastUsed  time.Time `json:"last_used"`
}

VpnSession is a VPN kept up in the background between commands.

Jump to

Keyboard shortcuts

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