keyaudit

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT 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 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.

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

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"`
}

LooseKey is a key-shaped file directly in ~/.ssh.

func LooseKeys added in v0.1.3

func LooseKeys(sshDir string) []LooseKey

LooseKeys 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.

type Report

type Report struct {
	Findings []Finding
	// 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) Summary

func (r Report) Summary() string

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

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.

Jump to

Keyboard shortcuts

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