Skip to content

feat(tools): nix run .#rekey, replacing the age key safely - #62

Merged
thatbagu merged 1 commit into
mainfrom
feat/rekey
Nov 21, 2026
Merged

thatbagu merged 1 commit into
mainfrom
feat/rekey

Conversation

@thatbagu

Copy link
Copy Markdown
Owner

The documented re-keying steps were manual and in a risky order. Push a re-encrypted secrets.yaml before every node has the new key, and their nightly upgrades (and the in-cluster nixlab-secrets job) can't decrypt it.

nix run .#rekey does it in two steps, and nothing is ever unable to decrypt:

  1. rekey:
    • adds a new key next to the old one, on every node first, then your workstation, then the cluster's copy (restarting nixlab-age-key on the masters)
    • re-encrypts secrets.yaml for the new key, and checks that it opens with the new key alone and no longer with the old one
    • tells you to back up the new key, commit and push.
  2. rekey --finish:
    • refuses until .sops.yaml and secrets.yaml are committed and pushed (the nodes build what's pushed)
    • then leaves only the new key on every node and in the cluster's copy
    • sets your workstation's old key aside in <keyfile>.retired-<date>.

Key files are swapped in atomically and stay read-only. If a node is unreachable, the first step stops before re-encrypting anything; rerun it later. The docs section is now three commands.

Test: tool-rekey runs the whole flow in the sandbox with real age, sops and git: a stubbed ssh stands in for the nodes, and a bare repository for the remote. It covers 15 steps: both keys work in between, the old key alone no longer opens the file, the finish is refused before the commit and before the push, one key is left everywhere afterwards, the old key is set aside, and a second run is a no-op.

It wasn't run against the live cluster: rotating the owner's real key unattended isn't mine to do.

🤖 Generated with Claude Code

The documented steps were manual and in a risky order: push a re-encrypted
secrets.yaml before every node had the new key, and their upgrades (and the
in-cluster secrets job) can't decrypt it. rekey does it in two steps:
the new key joins the old one on the workstation, every node and the
cluster's copy, and secrets.yaml is encrypted for it (checked to open with
the new key alone); --finish, refused until that's committed and pushed,
removes the old key everywhere and sets the workstation's copy aside.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thatbagu
thatbagu merged commit 3ceb072 into main Nov 21, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant