keyaudit

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 12 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 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

View Source
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.

View Source
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 Blocking

func Blocking(state string) bool

Blocking reports whether a state makes the audit fail rather than warn.

func FingerprintOf added in v0.1.6

func FingerprintOf(line string) (string, error)

FingerprintOf fingerprints one authorized_keys-style public key line.

func LooksLikeDevbox added in v0.1.3

func LooksLikeDevbox(name, comment string) string

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

func Notes(row keysvc.Row) []string

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

func PublicFingerprint(sshDir, name string) (string, error)

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

func LooseKeysIn(sshDir, root string) []LooseKey

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) ByState

func (r Report) ByState(state string) []Finding

ByState returns the findings in one state.

func (Report) Counts

func (r Report) Counts() map[string]int

Counts is findings per state, for a one-line summary.

func (Report) Lines

func (r Report) Lines() []string

Lines renders the report as a grouped block, each finding carrying its fix.

func (Report) OK

func (r Report) OK() bool

OK is the verdict: no blocking findings, or under Strict, no findings at all.

func (Report) ReservedLines added in v0.1.6

func (r Report) ReservedLines() []string

ReservedLines renders the reservations as doctor's info block.

func (Report) ReservedProblems added in v0.1.6

func (r Report) ReservedProblems() []Reserved

ReservedProblems are the reservations that need attention.

func (Report) Summary

func (r Report) Summary() string

Summary is the counts as one line, worst state first ("" when nothing dangles).

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.

func (Reserved) Line added in v0.1.6

func (r Reserved) Line() string

Line renders a reservation for doctor and `key list`.

func (Reserved) Problem added in v0.1.6

func (r Reserved) Problem() bool

Problem reports whether the reservation needs attention.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service audits one ~/.ssh tree against its manifest and inventory.

func New

func New(m *manifest.Manifest, inv *inventory.Inventory, sshDir string) *Service

New builds an audit service.

func (*Service) Audit

func (s *Service) Audit(strict bool) (Report, error)

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").

Jump to

Keyboard shortcuts

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