Documentation
¶
Overview ¶
Package store keeps komando state (inventory, conns, keys, snippets, jobs, tunnels, settings) in the sealed store under $KOMANDO_HOME (default ~/.komando).
Index ¶
- Constants
- Variables
- func AbortSeal()
- func AcceptOldCopy(want uint64) (from uint64, err error)
- func AppendAuditLines(lines [][]byte) error
- func AuditAfter(n int64) ([][]byte, error)
- func AuditCount() (int64, error)
- func BeginSeal() error
- func CheckWritable() error
- func Commits() uint64
- func CopyState() (have, kept uint64, guardedStore, old bool, err error)
- func DB(create bool) (*sealdb.DB, error)
- func DBPath() string
- func EndSeal()
- func EnsureHome() error
- func ErrNeedsSeal() error
- func FinishSeal() error
- func Home() string
- func IsMovedNote(path string) bool
- func LegacyKeyFiles() []string
- func Lock(name string) (unlock func(), err error)
- func ManagedKeyPath(name string) string
- func MasterKey() ([]byte, error)
- func MixedHome() bool
- func NeedsSeal() bool
- func OpenArchive(b []byte) ([]byte, error)
- func OpenRuntimeFile() ([]byte, error)
- func Path(parts ...string) string
- func ReadPrivateKey(k *Key) ([]byte, error)
- func Rekey(newMaster []byte, meta map[string]string, then func(tx *sealdb.Tx) error) error
- func RemoveManagedKey(k *Key) error
- func RemoveStore(name string) error
- func SealArchive(data []byte) ([]byte, error)
- func SealedKey(k *Key) bool
- func SetStoreMeta(meta map[string]string) error
- func StartBuilding()
- func StartGeneration() error
- func Update(fn func(s *State) error) error
- func UpdateRuntime(fn func(s *State) error) error
- func WriteFileAtomic(path string, b []byte, mode os.FileMode) (err error)
- func WriteManagedKey(name string, private, public []byte) (string, error)
- type Conn
- type GenerationKeep
- type Host
- type Job
- type Key
- type Rec
- type Runtime
- type RuntimePIDs
- type SSHLogin
- type Settings
- type Snippet
- type State
- type Tunnel
- type Vpn
- type VpnPID
- type VpnSession
- type WinRMOpts
Constants ¶
const ( KindHost = "host" KindConn = "conn" KindVpn = "vpn" KindKey = "key" KindRecipe = "recipe" )
Kinds of records, the record types in the store.
const MovedNote = "" /* 126-byte string literal not displayed */
MovedNote replaces each file of before once a folder is sealed (komando seal). It is not valid data for any of them, so a komando from before the sealed store stops with an error instead of starting with an empty folder (no protected servers, no deny rules, no pinned host keys).
const OSWindows = "windows"
OSWindows is Host.OS for a Windows server.
const StoreFile = "store.db"
StoreFile is the sealed store's file name in the home folder.
const TransportWinRM = "winrm"
TransportWinRM is Host.Transport for a server reached over WinRM.
Variables ¶
var AllowOldCopy bool
AllowOldCopy lets this process open an old copy (doctor and dry runs: they change nothing, and doctor must be able to say what is wrong).
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.
var ErrDryRun = errors.New("this command cannot preview its change; nothing was changed")
ErrDryRun is returned by writes that cannot be simulated (the vault).
var ErrKeychainSlow = errors.New("store: the keychain did not answer in time")
ErrKeychainSlow wraps a keychain that did not answer in time. Only this lets a command go on unchecked, and then only to read (the keychain gave the key a moment ago; a busy one must not stop all work, but nothing is changed on a store that was not checked); doctor warns about it.
var ErrNoStore = errors.New("store: no store yet")
ErrNoStore: a read of a fresh home, which has no store yet. Callers treat it as empty.
var ErrOldCopy = errors.New("store: an older copy than the keychain's")
ErrOldCopy: the store is older than the keychain says.
var ErrRuntimeOnly = errors.New("store: UpdateRuntime changed more than runtime data; use Update")
ErrRuntimeOnly: fn of UpdateRuntime changed the inventory, which UpdateRuntime does not save. A bug in the caller.
var KeySource func(meta map[string]string, create bool) (master []byte, newMeta map[string]string, err error)
KeySource gives the store's 32-byte master key. meta holds the store's readable settings (key_mode, salt, ...); with create, there is no store yet and KeySource picks the mode and returns the settings to keep. The vault package sets it (it owns the keychain, key file and passphrase).
Functions ¶
func AbortSeal ¶ added in v0.12.0
func AbortSeal()
AbortSeal sets a store that was being built aside, with its key file, under names of their own, and forgets its change count.
func AcceptOldCopy ¶ added in v0.12.0
AcceptOldCopy makes the keychain remember this store's number, so an old copy put back on purpose (a restore) is used from now on. want is the number the person saw and said yes to: another one is refused. For a person only: the caller checks.
func AppendAuditLines ¶ added in v0.12.0
AppendAuditLines adds audit records of before to a sealed store, as they are, in one write step.
func AuditAfter ¶ added in v0.12.0
AuditAfter gives the audit records after the first n, as written.
func AuditCount ¶ added in v0.12.0
AuditCount is how many audit records the store holds (the move keeps it in the archive, so an undo can carry the ones written after).
func BeginSeal ¶ added in v0.12.0
func BeginSeal() error
BeginSeal takes the file backend's locks for the whole move (the files of before are read under them); StartBuilding then turns this process to a store under a building name. EndSeal undoes both.
func CheckWritable ¶ added in v0.12.0
func CheckWritable() error
CheckWritable opens this home's store (making it on a fresh home) and checks the file can be written, so a command that changes something, and records it in the audit log, finds out before it runs.
func Commits ¶ added in v0.12.0
func Commits() uint64
Commits is how many write steps of this process changed the store.
func CopyState ¶ added in v0.12.0
CopyState says how this home's store compares with the keychain: guarded is false when its key is not in the keychain (no protection); slow when the keychain did not answer, so nothing was compared.
func DB ¶ added in v0.12.0
DB opens the sealed store of this home, once per process. With create, a home without store.db gets one, with a new key; without, it returns ErrNoStore, so a read makes no file and no key.
func DBPath ¶ added in v0.12.0
func DBPath() string
DBPath is the file of this home's sealed store (another one while a move builds it).
func ErrNeedsSeal ¶ added in v0.12.0
func ErrNeedsSeal() error
ErrNeedsSeal stops every command on a folder that NeedsSeal.
func FinishSeal ¶ added in v0.12.0
func FinishSeal() error
FinishSeal puts the built store in place: from now on every komando process uses it. The locks stay until EndSeal.
func IsMovedNote ¶ added in v0.12.0
IsMovedNote reports a file that holds MovedNote.
func LegacyKeyFiles ¶ added in v0.12.0
func LegacyKeyFiles() []string
LegacyKeyFiles are the private key files under keys/ (not the .pub).
func Lock ¶ added in v0.3.0
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 ManagedKeyPath ¶ added in v0.12.0
ManagedKeyPath is where a key komando makes under name is kept.
func MasterKey ¶ added in v0.12.0
MasterKey returns this home's sealed store master key, for keys made from it under other labels (the vault's entries). ErrNoStore when there is no store yet.
func MixedHome ¶ added in v0.12.0
func MixedHome() bool
MixedHome reports a home with store.db and files of before beside it (an older komando wrote there); doctor warns about it.
func NeedsSeal ¶ added in v0.12.0
func NeedsSeal() bool
NeedsSeal reports a folder of an earlier komando: it has files of before with data and no store.db. komando works only on the sealed store, so such a folder is moved with `komando seal` before any other use.
func OpenArchive ¶ added in v0.12.0
OpenArchive opens what SealArchive made.
func OpenRuntimeFile ¶ added in v0.12.0
OpenRuntimeFile gives runtime.json's content, opened when it is sealed (the undo puts it back plain).
func ReadPrivateKey ¶ added in v0.12.0
ReadPrivateKey returns the private key of k.
func Rekey ¶ added in v0.12.0
Never call Rekey from inside Update or UpdateRuntime: it takes the runtime lock, which they hold.
Rekey seals this home's store again under a new master key and keeps meta as its readable key settings, in one write step; then runs inside it, with the new key in force (the vault reseals its values there).
func RemoveManagedKey ¶ added in v0.12.0
RemoveManagedKey deletes a key komando made from the store. A key that is gone already is not an error.
func RemoveStore ¶ added in v0.12.0
RemoveStore takes a store away (a move that did not finish, or its undo): store.db is renamed to name, never deleted, and this process forgets it.
func SealArchive ¶ added in v0.12.0
SealArchive seals data with the store's archive key, for the archive of the files of before.
func SealedKey ¶ added in v0.12.0
SealedKey reports a key kept inside the sealed store, which has no file.
func SetStoreMeta ¶ added in v0.12.0
SetStoreMeta changes readable key settings of this home's store (a key moved between the keychain and a key file: the same key, kept elsewhere).
func StartBuilding ¶ added in v0.12.0
func StartBuilding()
StartBuilding turns this process to the store being built.
func StartGeneration ¶ added in v0.12.0
func StartGeneration() error
StartGeneration writes the keychain's number for a store whose key has just gone into the keychain (a new store, `secret keychain`), so a missing number is never normal.
func Update ¶
Update reads the inventory, applies fn and writes what changed, in one write step of the store. Safe for concurrent komando processes (parallel agents).
func UpdateRuntime ¶ added in v0.12.0
UpdateRuntime is Update for a change to runtime data only (Sessions, Logins, Jobs, Tunnels). It takes the runtime lock and not the inventory lock, and saves runtime.json only, so background processes do not wait for, or rewrite, the inventory. fn sees the whole state; a change to anything else stops it with ErrRuntimeOnly and nothing is saved.
Never call Update or UpdateRuntime from inside fn.
func WriteFileAtomic ¶
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"` // a name from driver.Kinds: postgres, redis, s3, kafka ...
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"`
Rec Rec `json:"-"`
}
Conn is a non-SSH resource (database, cache, ...) reached directly or through an SSH host. The URL never holds a password; see PasswordRef.
type GenerationKeep ¶ added in v0.12.0
type GenerationKeep struct {
Get func() (n uint64, ok bool, err error)
Set func(n uint64) error
Del func() // the store went aside (a failed move, an undo)
}
GenerationKeep reads and writes the number in the keychain.
var GenerationKeeper GenerationKeep
GenerationKeeper is set by the vault package (it owns the keychain).
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"`
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"`
// OS is "windows" for a Windows server: commands are PowerShell, not
// sh. Empty: Linux or another Unix (docs/design/windows.md).
OS string `json:"os,omitempty"`
// Transport is "winrm" for a Windows server reached over WinRM, with
// its settings in WinRMOpts. Empty: SSH.
Transport string `json:"transport,omitempty"`
WinRMOpts *WinRMOpts `json:"winrm,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Rec Rec `json:"-"`
}
func (*Host) EffectivePort ¶
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"`
// Ended is how the job ended (exited, killed, lost) the last time
// komando asked its server; empty while it ran or nobody asked yet
Ended string `json:"ended,omitempty"`
}
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"`
Rec Rec `json:"-"`
}
type Rec ¶ added in v0.12.0
Rec is a record's identity (docs/design/sync-security.md section 16): a random ID that stays when the record is renamed, and a version that goes up by one each time the record changes. The coming sealed store keys its rows by ID, and sync tells changes apart by version.
type Runtime ¶ added in v0.12.0
type Runtime struct {
Sessions map[string]*VpnSession `json:"vpn_sessions,omitempty"`
Logins map[string]*SSHLogin `json:"ssh_logins,omitempty"`
Jobs map[string]*Job `json:"jobs,omitempty"`
Tunnels map[string]*Tunnel `json:"tunnels,omitempty"`
}
Runtime is what komando's background work keeps between commands: VPN sessions, server logins, jobs and tunnels. It lives in runtime.json, apart from the inventory in store.db, so a VPN marking itself used does not rewrite the inventory, and the coming sealed store can seal it on its own (docs/design/sync-security.md section 16).
func ReadRuntime ¶ added in v0.12.0
ReadRuntime reads runtime.json alone, sealed or not, for a caller that needs only the running sessions and tunnels (the shell prompt).
type RuntimePIDs ¶ added in v0.12.0
type RuntimePIDs struct {
Vpns []VpnPID `json:"vpns,omitempty"`
Tunnels []int `json:"tunnels,omitempty"`
}
RuntimePIDs is what the shell prompt may know of a sealed home's runtime data without its key: the processes of running VPNs (with when each was last used) and tunnels. No names, logins or tokens.
func ReadRuntimePIDs ¶ added in v0.12.0
func ReadRuntimePIDs() (*RuntimePIDs, error)
ReadRuntimePIDs reads runtime.pids: on a sealed home, the only runtime data that opens without the store's key.
type SSHLogin ¶ added in v0.8.0
type SSHLogin struct {
Host string `json:"host"`
Target string `json:"target"` // user@address:port when it logged in: the login is used only while the host still points there
PID int `json:"pid"`
Exe string `json:"exe,omitempty"`
Socket string `json:"socket"`
Token string `json:"token"` // the socket's password, random per login
HostKey string `json:"host_key"` // the socket's own key (authorized_keys form), random per login
LogFile string `json:"log_file,omitempty"`
StartedAt time.Time `json:"started_at"`
Until time.Time `json:"until"`
}
SSHLogin is a server login a person made with `komando login HOST`, held by a background komando process (sshx/held.go) on a Unix socket only this user can open, and only for a client with Token.
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
LoginFor string `json:"login_for"` // how long `komando login HOST` keeps a server's login
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://)
MaskPersonal string `json:"mask_personal,omitempty"` // protected | all | off: where AI agents see personal data hidden
}
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. A snippet without it
// counts as a change.
ReadOnly bool `json:"read_only,omitempty"`
CreatedAt time.Time `json:"created_at"`
Rec Rec `json:"-"`
}
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"`
Keys map[string]*Key `json:"keys"`
Snippets map[string]*Snippet `json:"snippets"`
// Runtime data (VPN sessions, logins, jobs, tunnels) lives in its own
// file (runtime.go); a state.json of before may hold it here.
Runtime
Settings Settings `json:"settings"`
// contains filtered or unexported fields
}
func ReadOldState ¶ added in v0.12.0
ReadOldState reads the inventory of a folder of an earlier komando (state.json, and runtime.json beside it), for `komando seal`. It only reads: komando never writes these files any more. A folder without state.json reads as empty.
func (*State) FindName ¶ added in v0.2.0
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. Hosts and conns share one namespace so selectors stay unambiguous.
func (*State) SortedConns ¶ added in v0.2.0
func (*State) SortedHosts ¶
func (*State) SortedVpns ¶ added in v0.2.0
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"` // removed OpenVPN OS mode; kept only so `vpn up` refuses such a VPN
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"`
// Weaker logins a person allowed for this VPN (`vpn edit`, with a yes).
LegacyCrypto bool `json:"legacy_crypto,omitempty"` // l2tp, ipsec: also offer 3DES and DH groups 2 and 5
AllowPAP bool `json:"allow_pap,omitempty"` // l2tp: the server may pick PAP, which sends the password itself
Rec Rec `json:"-"`
}
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
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
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.
type WinRMOpts ¶ added in v0.9.0
type WinRMOpts struct {
Auth string `json:"auth,omitempty"` // ntlm (default) | basic
// TLS: "" checks the certificate (HTTPS, port 5986), skip-verify does
// not, off is plain HTTP (port 5985)
TLS string `json:"tls,omitempty"`
CA string `json:"ca,omitempty"` // secret:NAME holding the PEM of the CA that signed the server's certificate
}
WinRMOpts is how komando speaks WinRM to a server.