bundler

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 26 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 bundler makes and restores an age-encrypted backup. bundle tars {private keys + manifest + inventory + providers.json} (NEVER .env) and age-encrypts it with a SHA256 sidecar + a contents list; restore decrypts and lays the SAME keys back (same fingerprint). The cipher is behind a seam (Cipher) so tests inject a fake and the tar / lay-down / fingerprint guarantees are verifiable without age installed.

Plaintext never touches the disk. The tar is piped straight into age and the decrypted stream is read into memory and written to its final destination, so there is no staging copy in $TMPDIR - which is world-traversable, often on a different filesystem, and outlives a crash.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupBeforeDestroying

func BackupBeforeDestroying(p paths.Paths, out io.Writer, skip bool) error

BackupBeforeDestroying writes an age-encrypted bundle so an operation that destroys key material stays recoverable.

This used to be free: the pre-mutation snapshot tarred every private key, so anything destroyed could be dug back out of it. Snapshots no longer carry keys - deliberately, they were a rolling plaintext archive - which means the destructive paths need a real backup of their own. An encrypted bundle is the replacement, and no configured recipient is a hard stop rather than a shrug, because the alternative is losing a key with no way back.

func FinishRestore

func FinishRestore(p paths.Paths) error

FinishRestore re-asserts perms on the restored tree and config-home secrets, then re-renders the config. The bundle does not carry the rendered files, so without the render ~/.ssh has no category configs; a failure is returned rather than dropped.

func Prune

func Prune(dir string, keep int) []string

Prune removes all but the newest keep bundles in dir, taking their sidecars with them so no orphaned .sha256 is left to verify a missing file. Returns the base names removed.

func Sorted

func Sorted(dir string) []string

Sorted lists the bundles in dir, oldest first: the order Prune removes them in.

Types

type AgeCipher

type AgeCipher struct{}

AgeCipher shells out to age (X25519 + ChaCha20-Poly1305) over stdin/stdout.

func (AgeCipher) Decrypt

func (AgeCipher) Decrypt(dst io.Writer, src io.Reader, identityFile string) error

func (AgeCipher) Encrypt

func (AgeCipher) Encrypt(dst io.Writer, src io.Reader, recipient string) error

type BundleResult

type BundleResult struct {
	AgePath  string
	SHA256   string
	Contents []string
}

BundleResult summarizes a bundle run.

func (BundleResult) Format

func (r BundleResult) Format() string

Format renders the bundle summary (mirrors BundleResult.format).

type Bundler

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

Bundler makes/restores bundles.

func New

func New(sshDir, configDir string, cipher Cipher) *Bundler

New builds a Bundler.

func (*Bundler) Bundle

func (b *Bundler) Bundle(recipient, destDir, stamp string) (BundleResult, error)

Bundle tars the keys + config models, encrypts to dest/ssh-manager-<stamp>.age, and writes the .sha256 + .contents sidecars. The tar is piped directly into the cipher, so the plaintext archive exists only in memory.

func (*Bundler) Restore

func (b *Bundler) Restore(bundlePath, identityFile string, fingerprintOf func(string) (string, error)) (RestoreResult, error)

Restore decrypts bundlePath and lays the same keys back down (verifying the SHA256 sidecar first). fingerprintOf fingerprints each restored .pub.

The decrypted stream is read into memory and written straight to its final destination. Reading it whole before writing anything also means a corrupt or wrongly-keyed bundle is rejected before it has half-overwritten the tree.

type Cipher

type Cipher interface {
	Encrypt(dst io.Writer, src io.Reader, recipient string) error
	Decrypt(dst io.Writer, src io.Reader, identityFile string) error
}

Cipher transforms a stream. It is deliberately stream-shaped rather than file-shaped: a file-based cipher forces the caller to stage plaintext on disk.

type FP

type FP struct{ Name, Fingerprint string }

FP is one restored key's fingerprint (ordered by lay-down).

type RestoreResult

type RestoreResult struct {
	Restored     []string
	Fingerprints []FP
	// Skipped lists rendered files an older (or forged) bundle carried, which
	// restore does not lay down: the caller re-renders them from the manifest.
	Skipped []string
}

RestoreResult summarizes a restore run.

func (RestoreResult) Format

func (r RestoreResult) Format() string

Format renders the restore summary (mirrors RestoreResult.format).

Jump to

Keyboard shortcuts

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