Documentation
¶
Overview ¶
Package keyaudit is the one definition of what "dangling" means for a key.
A key can go wrong in seven ways, and each one used to be either undetected or detected differently by whoever happened to look. doctor called a tree clean while listing orphans; a key file with no .pub - the most dangling artifact possible - was skipped by the orphan check precisely because it had no .pub; nothing at all noticed a key the manifest declared but no host used, or an inventory record pointing at a profile that had been deleted. So doctor, `key list`, `show`, `clean` and the notifier all read their answer from here.
Everything is decided from the manifest, the inventory and os.Lstat. Private key material is never read - only public halves, and only to confirm they are public keys.
Index ¶
- Constants
- func Blocking(state string) bool
- func FingerprintOf(line string) (string, error)
- func LooksLikeDevbox(name, comment string) string
- func Notes(row keysvc.Row) []string
- func PublicFingerprint(sshDir, name string) (string, error)
- func Reservations(m *manifest.Manifest, planned map[string]manifest.ReservedKey) (map[string]manifest.ReservedKey, map[string]string)
- type Finding
- type LooseKey
- type Report
- type Reserved
- type Service
Constants ¶
const ( // Untracked: a key file under profiles/ that no manifest profile owns. The // tool made it and then lost track of it, or someone put it there. Untracked = "untracked" // Unwired: owned by a profile, referenced by no host, so it is never // rendered as an IdentityFile and never actually used by ssh. Unwired = "unwired" // Missing: the manifest references it, the filesystem does not have it. Missing = "missing" // HalfPair: a private key with no .pub, or a .pub with no private key. HalfPair = "half-pair" // Unrecorded: file and manifest agree, but no inventory record covers it, so // expiry and rotation are blind to it. Unrecorded = "unrecorded" // StaleInventory: a record whose path no manifest key owns any more - it // tracks the expiry of something that is gone. StaleInventory = "stale-inventory" // Loose: a key-shaped file directly under ~/.ssh that no Host block uses. // Reported and offered to `import`, never touched: the tool did not create // it, which is exactly why it is worth mentioning. Loose = "loose" )
The seven states a key can dangle in.
const ( ReservedKept = "kept" ReservedMissing = "missing" ReservedChanged = "changed" ReservedAdopted = "adopted" )
The states a reserved key can be in. Only ReservedKept is the expected one; the others are warnings, because the note no longer describes the file.
Variables ¶
This section is empty.
Functions ¶
func FingerprintOf ¶ added in v0.1.6
FingerprintOf fingerprints one authorized_keys-style public key line.
func LooksLikeDevbox ¶ added in v0.1.3
LooksLikeDevbox reports which word in a key's name or comment suggests a VM ("" when none does). Words are matched whole, on '-', '_', '.', '@' and space boundaries, so "vm" matches "docker-vm" but not "vmail".
func Notes ¶
Notes lists the states one manifest key is in, worst first. This is the per-key view `key list` and `show` mark each row with; the states are the same ones the audit reports, so a key never reads as fine in one command and dangling in another.
func PublicFingerprint ¶ added in v0.1.6
PublicFingerprint is the OpenSSH SHA256 fingerprint of ~/.ssh/<name>.pub, computed from the public half only (what `ssh-keygen -lf` prints).
func Reservations ¶ added in v0.1.6
func Reservations(m *manifest.Manifest, planned map[string]manifest.ReservedKey) (map[string]manifest.ReservedKey, map[string]string)
Reservations merges the manifest's reserved keys with planned ones; the manifest's entry wins, borrowing For from the plan when it has none. The second map gives each name's source.
Types ¶
type Finding ¶
type Finding struct {
State string
Subject string // "profile/key", a path relative to ~/.ssh, or a fingerprint
Detail string // what is actually wrong, in one clause
Fix string // the command that resolves it, if there is one
}
Finding is one dangling artifact.
type LooseKey ¶ added in v0.1.3
type LooseKey struct {
Name string `json:"name"`
Comment string `json:"comment,omitempty"`
Type string `json:"type,omitempty"`
// Devbox is set when the name or comment suggests a VM's key (devbox,
// docker, tunnel, vm, or a hypervisor's name); Hint says which.
Devbox bool `json:"devbox,omitempty"`
Hint string `json:"hint,omitempty"`
// CopyOf is the managed key (relative to ~/.ssh) whose public key this
// one's is - the original left behind by `vm adopt-key` without --move.
CopyOf string `json:"copy_of,omitempty"`
// Reserved is set (by MarkReserved) when the key is kept on purpose.
Reserved bool `json:"reserved,omitempty"`
ReservedFor string `json:"reserved_for,omitempty"`
ReservedNote string `json:"reserved_note,omitempty"`
}
LooseKey is a key-shaped file directly in ~/.ssh.
func LooseKeysIn ¶ added in v0.1.6
LooseKeysIn finds key-shaped files sitting directly in ~/.ssh: the pre-authama keys a user already had. Detection is by pairing (a file with a .pub sibling) or by a .pub that parses as a public key - never by reading private key material. root is the key root, whose keys mark a loose file as a leftover copy of one authama manages.
func MarkReserved ¶ added in v0.1.6
func MarkReserved(keys []LooseKey, res map[string]manifest.ReservedKey) []LooseKey
MarkReserved labels the loose keys that are reserved, for pickers and pages.
type Report ¶
type Report struct {
Findings []Finding
// Reserved are the keys kept on purpose (0.1.4). They are information, not
// findings: none of them makes the report fail, even under Strict.
Reserved []Reserved
// Strict escalates every state to blocking, for CI - where a warning nobody
// reads is the same as no check at all.
Strict bool
}
Report is everything the audit found.
func (Report) ReservedLines ¶ added in v0.1.6
ReservedLines renders the reservations as doctor's info block.
func (Report) ReservedProblems ¶ added in v0.1.6
ReservedProblems are the reservations that need attention.
type Reserved ¶ added in v0.1.6
type Reserved struct {
Name string `json:"name"`
For string `json:"for,omitempty"`
Note string `json:"note,omitempty"`
Since string `json:"since,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
// Source is "manifest" or "devbox <alias>" (authama.json).
Source string `json:"source"`
State string `json:"state"`
Detail string `json:"detail,omitempty"`
Fix string `json:"fix,omitempty"`
}
Reserved is one key kept on purpose: reserved in the manifest (`authama ssh key reserve`) or named as the key of a devbox in authama.json that has no VM yet. It is never a loose-key finding.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service audits one ~/.ssh tree against its manifest and inventory.
func (*Service) Audit ¶
Audit walks the manifest, the inventory and the tree, and returns every dangling artifact found. Findings are grouped by state in severity order and sorted within a state, so two runs over the same tree report identically.
func (*Service) WithPlanned ¶ added in v0.1.6
func (s *Service) WithPlanned(planned map[string]manifest.ReservedKey) *Service
WithPlanned adds reservations that come from outside the manifest: the keys of devboxes declared in authama.json without a VM yet. The map's For is expected to name the devbox ("devbox docker").