Documentation
¶
Overview ¶
Package vault stores secrets (passwords, key passphrases, tokens) encrypted with AES-256-GCM, each bound to its name. The key is derived with scrypt from $KOMANDO_VAULT_PASS when set (N=2^17, r=8, p=1: the OWASP minimum), otherwise from the sealed store's key (sealed.go).
Index ¶
- Constants
- Variables
- func Copy(w store.Write, from, to string, overwrite bool) error
- func Create(w store.Write, name, value string) error
- func Delete(w store.Write, name string) error
- func DeleteMany(w store.Write, names []string) error
- func Get(name string) (string, error)
- func Handoff() string
- func KeyToFile() error
- func KeyToKeychain() (string, error)
- func KeychainTool() (string, error)
- func Opens(oldPass string) error
- func PassOnStdin(c *exec.Cmd)
- func Passphrase() string
- func ReadPassStdin(r io.Reader) error
- func RefHelp() string
- func Rename(w store.Write, from, to string, overwrite bool) error
- func RenameMany(w store.Write, pairs map[string]string) error
- func Resolve(ref string) (string, error)
- func SelfEnv() []string
- func Set(w store.Write, name, value string) error
- func StripUnlock(env []string) []string
- func TakeUnlockEnv()
- func TicketMAC(msg []byte) ([]byte, error)
- func ValidRef(ref string) bool
- type Info
- type KeyChange
- type Strength
Constants ¶
const MinPassphrase = 15
MinPassphrase is the shortest passphrase doctor accepts without a warning.
const PassStdinFlag = "--vault-pass-stdin"
PassStdinFlag tells a komando process started with PassOnStdin to read the vault passphrase from stdin.
Variables ¶
var ( ErrLocked = errors.New("the vault is locked with a passphrase; set KOMANDO_VAULT_PASS") ErrKey = errors.New("the vault's key cannot be used") ErrDecrypt = errors.New("cannot decrypt secret") )
The vault cannot be opened: no passphrase given for a passphrase vault (ErrLocked), its key file is missing or broken (ErrKey), or a secret does not decrypt with the key or passphrase given (ErrDecrypt).
var AgentCall func() bool
AgentCall reports that an AI agent makes this call; the cli sets it.
var ErrExists = errors.New("secret already exists")
ErrExists is returned by Create when the name is taken, and by Copy and Rename when the new name is taken and overwrite is false.
var ErrKeychainTaken = errors.New("another vault's key is already in the keychain for this komando folder")
ErrKeychainTaken: the keychain already holds another key under this komando folder's name, most likely the only key of a vault that was moved aside, so komando does not replace it.
var ErrNoPassphrase = errors.New("the vault has no passphrase")
ErrNoPassphrase: the vault has no passphrase to take away.
var ErrNotFound = errors.New("secret not found")
var ErrShortPassphrase = fmt.Errorf("a vault passphrase needs %d or more characters", MinPassphrase)
ErrShortPassphrase: a new passphrase must have MinPassphrase characters.
var ErrWrongKey = errors.New("the key does not open the vault")
ErrWrongKey: a key that does not open the vault (a wrong KOMANDO_VAULT_PASS, say).
var OnResolve func(value string)
OnResolve, when set, gets every value Resolve read. komando's CLI sets it to hide the value in its output: a value from env:, file:, op://, a cloud secret manager... is in no list komando keeps.
var PassphraseN = 1 << 17
PassphraseN is the scrypt cost for passphrase vaults (OWASP Password Storage Cheat Sheet: N=2^17, r=8, p=1). Tests lower it.
var RefGuard func(kind, name string) error
RefGuard, when set, is asked before Resolve reads a vault secret (kind "secret"), a file on this computer (kind "file") or an environment variable (kind "env") for a reference. komando's CLI sets it, so a reference, which komando sends to a server as a password, never reads a secret komando keeps for itself, and an AI agent cannot point one at secrets it must not have.
var Refs = []string{
"secret:NAME (komando's vault)",
"env:VAR",
"file:PATH",
"op://VAULT/ITEM/FIELD (1Password Connect)",
"bw://ITEM/FIELD (Bitwarden, Vaultwarden)",
"kdbx:FILE#GROUP/ENTRY[#FIELD] (KeePass, KeePassXC)",
"vault:PATH#FIELD (HashiCorp Vault or OpenBao, KV)",
"aws-sm:NAME[#JSON_KEY] (AWS Secrets Manager)",
"gcp-sm:NAME[@PROJECT] (Google Secret Manager)",
"azure-kv:VAULT/NAME[#JSON_KEY] (Azure Key Vault)",
}
Refs are the kinds of secret reference komando understands, with an example each, for help texts and errors.
var UnlockVars = []string{"KOMANDO_KDBX_PASSWORD", "KOMANDO_KDBX_KEYFILE", "KOMANDO_BW_PASSWORD",
"KOMANDO_BW_CLIENT_SECRET", "OP_CONNECT_TOKEN", "VAULT_TOKEN", "BAO_TOKEN"}
UnlockVars are the variables, besides KOMANDO_VAULT_PASS, that unlock the secret stores komando reads (KeePass, Bitwarden, 1Password Connect, HashiCorp Vault / OpenBao).
Functions ¶
func Copy ¶ added in v0.3.0
Copy stores the value of from under the name to as well. The value is decrypted and sealed again inside the vault (each value is bound to its name) and never leaves this package.
func Create ¶ added in v0.15.0
Create stores value under name only when name is free, else ErrExists. The check and the write are one write step of the store, so of several komando processes creating one name at once exactly one wins.
func DeleteMany ¶ added in v0.13.0
DeleteMany removes several secrets in one change of the vault: all of them, or none when one is missing (an error that matches ErrNotFound and ends with ": NAME").
func Handoff ¶ added in v0.13.0
func Handoff() string
Handoff is what a background komando process needs to open the secret stores: the passphrase alone, or with the UnlockVars TakeUnlockEnv took, handoffMark and one "NAME base64" line each. ReadPassStdin reads either.
func KeyToFile ¶ added in v0.3.0
func KeyToFile() error
KeyToFile moves the store key back from the keychain into a key file.
func KeyToKeychain ¶ added in v0.3.0
KeyToKeychain gives the vault a new key, kept in the keychain, and removes store.key. It never replaces a key the keychain already holds for this komando folder (ErrKeychainTaken): that one may be the only key of a vault moved aside, even when it is this store's own old key. The new key of a move that stopped part way is fine. When keychainHas cannot tell (on Linux, a locked default collection among other things) it stores nothing and asks for the keychain to be unlocked first.
func KeychainTool ¶ added in v0.3.0
KeychainTool says which tool keeps the key here, or why there is none.
func Opens ¶ added in v0.7.0
Opens checks, without changing anything, that every secret decrypts with the vault's current key (see ChangeKey for oldPass). An error that matches ErrWrongKey means one did not.
func PassOnStdin ¶ added in v0.7.0
PassOnStdin readies c, a background komando process that needs the vault (`tunnel serve`, `vpn serve`): its environment is komando's own, without KOMANDO_VAULT_PASS, and the passphrase, when there is one, goes to it on stdin, with PassStdinFlag added to its arguments. It comes last: after what c.Stdin already holds (vpn serve's own lines), up to the end.
func Passphrase ¶ added in v0.2.0
func Passphrase() string
Passphrase returns $KOMANDO_VAULT_PASS and removes it from this process's environment, so programs komando starts (kubectl, credential plugins, VPN clients, docker) never inherit it.
func ReadPassStdin ¶ added in v0.7.0
ReadPassStdin reads the passphrase PassOnStdin sends, up to the end of r, and uses it for the vault from now on.
func Rename ¶ added in v0.3.0
Rename moves the value of from to the name to, in one change of the vault.
func RenameMany ¶ added in v0.7.0
RenameMany moves the values of several secrets to new names (pairs maps old to new) in one change of the vault: every secret moves, or none does. Values are decrypted and sealed again inside this package and never leave it, as in Rename.
A new name may not exist yet, and may not be a name that moves too: a swap (a→b, b→a) or a chain (a→b, b→c) is refused, because a reference the caller does not rewrite (a {{secret:b}} already in a file on a server) would then quietly get another secret's value. Two old names may not share a new one, and the approval code's secret never moves.
func Resolve ¶
Resolve turns a reference into a value:
secret:<name> -> komando's vault env:<VAR> -> environment variable file:<path> -> file contents (trailing newline trimmed) op://v/item/field -> 1Password Connect (OP_CONNECT_HOST, OP_CONNECT_TOKEN) bw://item/field -> Bitwarden or Vaultwarden, decrypted here (KOMANDO_BW_*) kdbx:file#group/entry[#field] -> a KeePass file (KOMANDO_KDBX_PASSWORD / KOMANDO_KDBX_KEYFILE) vault:path#field -> HashiCorp Vault / OpenBao KV (VAULT_ADDR and a token, as the CLI uses them) aws-sm:name[#key] -> AWS Secrets Manager (the usual AWS credentials; a JSON key when given) gcp-sm:name[@project]-> Google Secret Manager, latest version (application-default credentials) azure-kv:vault/name[/version][#key] -> Azure Key Vault (a service principal, the Azure CLI's token or a managed identity)
komando talks to those services itself (internal/cloud); the login stays with the person and komando never stores the values.
func SelfEnv ¶ added in v0.2.0
func SelfEnv() []string
SelfEnv is the environment for komando processes started by komando that need the vault: a command the menu runs. A background process that runs for long gets the passphrase on stdin instead (PassOnStdin): its environment stays in view for as long as it runs (`ps eww`, /proc/PID/environ), to every program of the user.
func StripUnlock ¶ added in v0.14.0
StripUnlock is env (KEY=value lines) without KOMANDO_VAULT_PASS and the UnlockVars: the environment of a program a call starts. TakeUnlockEnv cleans only the process's own environment; an app hands each call an environment of its own, which may still hold them. It is never nil, also for no env: an exec.Cmd whose Env is nil inherits the process's whole environment, unlock values and all.
func TakeUnlockEnv ¶ added in v0.13.0
func TakeUnlockEnv()
TakeUnlockEnv takes KOMANDO_VAULT_PASS and the UnlockVars out of this process's environment when komando starts, so no program it starts (ssh, kubectl, a VPN client, a dump tool, a background tunnel) inherits them: a long-running one would show them for hours (`ps eww`, /proc/PID/environ). komando reads them from memory (cloud.UnlockEnv); its own background processes get them on stdin (PassOnStdin).
Types ¶
type KeyChange ¶ added in v0.7.0
type KeyChange struct {
From string `json:"from"` // keyfile | passphrase | keychain; "" when there was no vault
To string `json:"to"` // passphrase | keyfile
Secrets int `json:"secrets"` // how many were sealed again
Removed string `json:"removed,omitempty"` // the old key that was removed: store.key | keychain
Left string `json:"left,omitempty"` // the old key that could not be removed, and why
}
KeyChange is what ChangeKey did.
func ChangeKey ¶ added in v0.7.0
ChangeKey seals every secret again under a new key: the passphrase newPass, or, when it is "", a new random key (sealed_keys.go). oldPass is the current passphrase when KOMANDO_VAULT_PASS does not hold it, otherwise "". A preview (a dry run) stops with store.ErrDryRun.
type Strength ¶ added in v0.2.0
type Strength struct {
Mode string `json:"mode"`
ScryptN int `json:"scrypt_n"`
ShortPass bool `json:"short_passphrase,omitempty"`
OldKDF bool `json:"old_kdf,omitempty"`
NoVaultYet bool `json:"no_vault_yet,omitempty"`
}
Strength describes the vault's protection for `komando doctor`: the mode, the scrypt cost and, for a passphrase, whether it is long enough (NIST SP 800-63B asks for 15 characters when it is the only factor).