From eff12fc43bc7d8408918a890abeff743c8e6a9ad Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 22 Nov 2026 23:44:57 -0600 Subject: [PATCH] Backup sops age key in laptop-state set (#10295 slice 1) Adds ~/.config/sops/age/keys.txt to laptop-state-backup.sh sources so the restic snapshots contain the decryption key for the backed-up *.sops.yaml ciphertext. Optional source: missing file does not fail the run. Test fixture + assertion included. Inventory updated. No key material read, printed or committed; path only. --- nixos/home/laptop-state-backup.md | 13 +++++++++---- nixos/home/laptop-state-backup.sh | 6 +++++- nixos/home/laptop-state-backup.test.sh | 6 ++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/nixos/home/laptop-state-backup.md b/nixos/home/laptop-state-backup.md index b33b0229f0..d366ba06a2 100644 --- a/nixos/home/laptop-state-backup.md +++ b/nixos/home/laptop-state-backup.md @@ -12,6 +12,7 @@ No secret contents were read, printed or archived to produce this note. | `~/.local/state/opencode-claimant` | backed up directly (added #10298). Kept: `mode`, config, `fires.jsonl`, probe/poll/shadow JSON history. Excluded: per-run `*.out` / `*.err` logs (disposable, most of ~11M). | | `~/secrets/*.sops.yaml` | backed up directly (ciphertext only) | | `~/.ssh` | backed up directly | +| `~/.config/sops/age/keys.txt` | backed up directly (added #10295; sops age private key — restic repo is encrypted, so the key at rest is protected by restic encryption) | ## Rendered and local files in `~/pm-stack` and `~/secrets` @@ -42,10 +43,14 @@ Docker data stores (Kaneo Postgres, Grist sqlite, Pad sqlite + attachments ## Gaps (flagged, not fixed) -1. **sops age key** `~/.config/sops/age/keys.txt` (75 bytes) is in **no backup - set**. The `*.sops.yaml` ciphertext is backed up, but without this key it - cannot be decrypted. Adding it is a decision (it is a private key); Drew - to decide. Vault copies of most values mitigate this. +1. **sops age key vault copy** — `~/.config/sops/age/keys.txt` now rides the + restic set (this change; #10295 slice 1), so a disk loss is recoverable + from the encrypted restic snapshots. A named Bitwarden vault copy + (`sops.age-private-key-laptop` or equivalent) is still missing — vault + holds only `sops.age-private-key-sandbox` (verified by name only, + 2026-11-23). Storing the laptop private key needs the dedicated secrets + flow (key file piped directly to the vault, value never printed); left + for the next slice. 2. **Bare mirror rebuild** is an untested inference, per the 2026-11-14 audit. 3. **Snapshot evidence** (acceptance 1): not yet produced. The installed unit runs the nix-store copy of the script, so the new source appears only diff --git a/nixos/home/laptop-state-backup.sh b/nixos/home/laptop-state-backup.sh index 23cf8b8767..20305c8e66 100644 --- a/nixos/home/laptop-state-backup.sh +++ b/nixos/home/laptop-state-backup.sh @@ -7,6 +7,9 @@ # (per-run .out/.err logs excluded; #10298) # ~/secrets/*.sops.yaml sops-encrypted secrets (ciphertext only) # ~/.ssh SSH keys + known_hosts (irreplaceable) +# ~/.config/sops/age/keys.txt +# sops age private key (decrypts the above; +# restic repo is encrypted; #10295) # # DESIGN: restic with content-defined chunking + dedup, snapshotting # the source paths directly — the repo-archive-backup.sh @@ -87,10 +90,11 @@ SOURCES=() [ -d "$HOME/.local/state/opencode" ] && SOURCES+=("$HOME/.local/state/opencode") [ -d "$HOME/.local/state/opencode-claimant" ] && SOURCES+=("$HOME/.local/state/opencode-claimant") [ -d "$HOME/.ssh" ] && SOURCES+=("$HOME/.ssh") +[ -f "$HOME/.config/sops/age/keys.txt" ] && SOURCES+=("$HOME/.config/sops/age/keys.txt") for f in "$HOME"/secrets/*.sops.yaml; do [ -f "$f" ] && SOURCES+=("$f") done -[ "${#SOURCES[@]}" -gt 0 ] || fail "no source paths present (opencode state, opencode-claimant state, .ssh, secrets/*.sops.yaml all missing)" +[ "${#SOURCES[@]}" -gt 0 ] || fail "no source paths present (opencode state, opencode-claimant state, .ssh, sops age key, secrets/*.sops.yaml all missing)" # claimant per-run stdout/stderr logs are excluded: disposable, ~10M of churn. # mode, config, fires.jsonl and probe history are kept (#10298). EXCLUDES=() diff --git a/nixos/home/laptop-state-backup.test.sh b/nixos/home/laptop-state-backup.test.sh index d3d3a4ef91..67ad535eb9 100644 --- a/nixos/home/laptop-state-backup.test.sh +++ b/nixos/home/laptop-state-backup.test.sh @@ -22,14 +22,15 @@ SCRIPT="$SELF_DIR/laptop-state-backup.sh" TMP_ROOT="$(mktemp -d)" trap 'rm -rf "$TMP_ROOT"' EXIT -make_home() { # $1 dir; fake opencode state + ssh + one sops secret +make_home() { # $1 dir; fake opencode state + ssh + one sops secret + age key local h="$1" - mkdir -p "$h/.local/state/opencode" "$h/.local/state/opencode-claimant" "$h/.ssh" "$h/secrets" "$h/.config/bws" + mkdir -p "$h/.local/state/opencode" "$h/.local/state/opencode-claimant" "$h/.ssh" "$h/secrets" "$h/.config/bws" "$h/.config/sops/age" echo '{"x":1}' >"$h/.local/state/opencode/service-prod.json" echo "full" >"$h/.local/state/opencode-claimant/mode" echo "log" >"$h/.local/state/opencode-claimant/claimant-fire-x.out" echo "fake-key" >"$h/.ssh/id_ed25519" echo "ciphertext" >"$h/secrets/pm-stack.sops.yaml" + echo "fake-age-key" >"$h/.config/sops/age/keys.txt" echo "fake-token" >"$h/.config/bws/access-token" } @@ -96,6 +97,7 @@ check "claimant state backed up" grep -q "state/opencode-claimant" "$C" check "claimant logs excluded" grep -q -- "--exclude .*opencode-claimant/\*.out" "$C" check "ssh backed up" grep -q ".ssh" "$C" check "sops secret backed up" grep -q "sops.yaml" "$C" +check "sops age key backed up" grep -q "sops/age/keys.txt" "$C" check "check per backend" [ "$(grep -c ' check' "$C" 2>/dev/null || echo 0)" = "3" ] check "forget+prune per backend" [ "$(grep -c ' forget.*--prune' "$C" 2>/dev/null || echo 0)" = "3" ]