package main // The sweep (novox/hq ADR 0415, issue 1017): ssh-client owns ~/.ssh, so it keeps it to what it knows. // Every path it does not know is moved, whole, into ~/.local/state/ssh-client/retired//, // keeping its path relative to ~/.ssh. Nothing is deleted. A key (private, public or a certificate), // at any depth and whatever its name, and authorized_keys are never moved (design 29 §3: moving one // can lock the operator out); a folder holding a key is gone into rather than moved whole. A socket // is ssh's own runtime and stays. The process sweeps when it starts and every KeyRound (main.go). import ( "encoding/json" "fmt" "io/fs" "os" "path/filepath" "regexp" "sort" "strings" "time" ) // Declared are the paths under ~/.ssh this module declares (module.json) or its own process makes // (keykeeper.go). A test checks the manifest against this list. var Declared = map[string]bool{ "config": true, "known_hosts": true, "config.d": true, "config.d/00-mesh": true, "config.d/10-forge": true, KeyFile: true, KeyFile + ".pub": true, "authorized_keys": true, "authorized_keys2": true, // sshd's second AuthorizedKeysFile by default: moving it can lock the operator out } // copyOf is a copy of authorized_keys or known_hosts (authorized_keys.revoked-*, known_hosts.old): it // carries key lines but is no key, and sshd and ssh never read it. var copyOf = regexp.MustCompile(`^(authorized_keys|known_hosts)[^/]+$`) // RetiredDir is where the sweep moves what it does not know, under the account's home. const RetiredDir = ".local/state/ssh-client/retired" // Moved is one path a sweep moved out of ~/.ssh. type Moved struct { From string `json:"from"` To string `json:"to"` } // Sweep is what one sweep did: what it moved, and what it left because it could not tell what it is. type Sweep struct { At string `json:"at"` Moved []Moved `json:"moved"` Left []string `json:"left,omitempty"` } // Sweep moves every path under ~/.ssh this module does not know into a retired folder named by now, // and writes beside that folder the list of what it moved (