snapshots

package
v0.1.1 Latest Latest
Warning

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

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

Constants

This section is empty.

Variables

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

func Archivable(name string) bool

Archivable reports whether a file of this name may go into a snapshot: the allowlist of files known to hold nothing secret.

func CleanTempArtifacts

func CleanTempArtifacts(sshDir string) []string

CleanTempArtifacts sweeps the crash residue FindTempArtifacts 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

func CurrentFiles(sshDir string) (map[string]string, error)

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

func Files(tarball string) (map[string]string, error)

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 Find

func Find(snapshotsDir, id string) (string, error)

Find is the snapshot a restore of id would use, as a path.

func FindTempArtifacts

func FindTempArtifacts(sshDir string) []string

FindTempArtifacts lists crash residue without removing it: leftover .<name>.*.tmp files anywhere under sshDir, plus any stray profiles/<p>/.staging or profiles/<p>/.mint-* dir. Paths are absolute and in removal order; CleanTempArtifacts is this plus the deletion, so a preview (`clean --dry-run`) reports exactly what the sweep would take.

func HoldsKeyMaterial

func HoldsKeyMaterial(tarball string) bool

HoldsKeyMaterial reports whether a snapshot predates the exclusion of private keys, so callers can warn that it is a plaintext key archive.

func List

func List(snapshotsDir string) []string

List returns snapshots oldest->newest (by creation time, then name). Mirrors fs.list_snapshots + _snap_sort_key.

func Prune

func Prune(snapshotsDir string, keep int) int

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

func Restore(tarball, sshDir string) error

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

func RestoreByID(sshDir, snapshotsDir string, retain int, id string) (string, error)

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.

func Snapshot

func Snapshot(sshDir, snapshotsDir string, retain int, stamp string) (string, error)

Snapshot tars the archivable part of sshDir into snapshotsDir (owner-only) and prunes to the last retain. Private keys are deliberately excluded; see the package doc. Returns the snapshot path, or "" if sshDir does not exist. stamp "" uses the current time.

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

func RestoreByIDIn(p paths.Paths, retain int, id string) (Result, error)

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

func RestoreInto(sshDir, snapshotsDir, devRoot, id string) (Result, error)

RestoreInto restores the snapshot id from snapshotsDir over sshDir, as RestoreByIDIn does but without its pre-restore snapshot. A preview runs it against a copy of ~/.ssh, where there is nothing to snapshot into.

Jump to

Keyboard shortcuts

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