Documentation
¶
Overview ¶
Package snapshots is the local reversible-backup layer for ~/.ssh. A snapshot is an owner-only ssh-<stamp>.tar.gz that the mutation guard writes before every mutating op, so a change can be rolled back.
Snapshots roll back configuration, not key material. They are plaintext archives written on ordinary operations and kept several deep, so including private keys would build a rolling unencrypted history of every key the user has ever held - a far larger exposure than the mistake being guarded against. Restoring therefore overwrites what the archive holds and removes nothing; key files are only ever destroyed by an explicit purge, which takes its own encrypted backup.
The same exclusion means a restore can split a keypair: the archive holds a .pub whose private half may since have been replaced on disk. A .pub is only written beside a private key it is proven to belong to; see foreignPub.
Index ¶
- Variables
- func Archivable(name string) bool
- func CleanTempArtifactsIn(sshDir, root string) []string
- func CurrentFiles(sshDir string) (map[string]string, error)
- func Files(tarball string) (map[string]string, error)
- func Find(snapshotsDir, id string) (string, error)
- func FindTempArtifactsIn(sshDir, root string) []string
- func HoldsKeyMaterial(tarball string) bool
- func List(snapshotsDir string) []string
- func Prune(snapshotsDir string, keep int) int
- func Restore(tarball, sshDir string) error
- func RestoreByID(sshDir, snapshotsDir string, retain int, id string) (string, error)
- func Snapshot(sshDir, snapshotsDir string, retain int, stamp string) (string, error)
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrHoldsKeyMaterial = errors.New("this snapshot predates key exclusion and holds private keys, so it is not opened; " +
"remove it once you no longer need it: authama ssh snapshots prune --keep 0")
ErrHoldsKeyMaterial refuses to open a snapshot written before private keys were excluded. Reading it to show a diff would put a private key on a page.
Functions ¶
func Archivable ¶
Archivable reports whether a file of this name may go into a snapshot: the allowlist of files known to hold nothing secret.
func CleanTempArtifactsIn ¶ added in v0.1.6
CleanTempArtifactsIn sweeps the crash residue FindTempArtifactsIn reports. Both .staging and .mint-* can hold a private key a crash left behind, so this is a leak sweep and not only tidiness. Returns the relative paths removed.
func CurrentFiles ¶
CurrentFiles returns what a snapshot of sshDir would hold now, in the same form as Files, so the two can be compared file by file.
func Files ¶
Files returns the text of every file a snapshot holds, keyed by its path below the ssh directory ("config", "profiles/work/config"). It refuses a snapshot that holds key material, and reads only the names a snapshot may hold, so a member it was never meant to contain is skipped, not shown.
func FindTempArtifactsIn ¶ added in v0.1.6
FindTempArtifactsIn lists crash residue without removing it: leftover .<name>.*.tmp files anywhere under sshDir, plus any stray <root>/<p>/.staging or <root>/<p>/.mint-* dir. Paths are absolute and in removal order; CleanTempArtifactsIn is this plus the deletion, so a preview (`clean --dry-run`) reports exactly what the sweep would take.
func HoldsKeyMaterial ¶
HoldsKeyMaterial reports whether a snapshot predates the exclusion of private keys, so callers can warn that it is a plaintext key archive.
func List ¶
List returns snapshots oldest->newest (by creation time, then name). Mirrors fs.list_snapshots + _snap_sort_key.
func Prune ¶
Prune keeps the keep most-recent snapshots and removes the rest, returning how many were removed. keep<=0 removes all. Mirrors facade.prune_snapshots.
func Restore ¶
Restore lays a snapshot back over sshDir. The caller snapshots the current tree first.
It overwrites the files the archive holds and deletes nothing else. Wiping the directory first, as an exact restore would, is no longer possible: snapshots exclude private keys, so it would destroy every key in the tree. For the same reason a .pub that does not belong to the private key now on disk is left as it is (see foreignPub); RestoreByIDIn reports which.
func RestoreByID ¶
RestoreByID restores ~/.ssh from a snapshot (latest if id is empty, else the last whose name contains id), snapshotting the current tree first so the restore is itself reversible, then re-asserting perms. Returns the chosen snapshot path. The advisory lock and the pre-restore snapshot are the CLI's mutation guard, upstream of this, so they are not duplicated here.
It does not admit the dev sandbox and does not report skipped .pub files; a caller holding a resolved layout uses RestoreByIDIn.
Types ¶
type Result ¶
type Result struct {
// Snapshot is the archive restored from.
Snapshot string
// Skipped lists the .pub files left as they were because they do not belong
// to the private key on disk, relative to the ssh dir.
Skipped []string
}
Result is the outcome of RestoreByIDIn.
func RestoreByIDIn ¶
RestoreByIDIn is RestoreByID for a resolved layout: it restores p.SSHDir from p.SnapshotsDir(), admits the sandbox's ssh dir when p is a dev layout, and reports the .pub files it did not overwrite.
func RestoreInto ¶
RestoreInto restores the snapshot id from snapshotsDir over sshDir, as RestoreByIDIn does but without its pre-restore snapshot, then re-asserts the permissions under the key root keyRoot. A preview runs it against a copy of ~/.ssh, where there is nothing to snapshot into.