Repository navigation
Description
Summary
Two lib/ sops writers repeat the non-atomic redirect pattern that #6536 (dns save.sh) and #6554 (talos save-secrets.sh) were filed for, in places those issues do not cover:
lib/sops_encrypt.sh:16— the genericsops_encrypthelper writes ciphertext withsops --encrypt <(cat -) >"$output_file". The shell truncates$output_filebeforesopsruns, so any encryption failure (missing/expired age key, sops error, interruption) destroys the previous ciphertext. Worse, the failure is masked: the file has noset -e, and line 17 unconditionally echoesEncrypted output saved to $output_file; the function's return status is that echo's0. Both invocation forms are affected — running it as a script (lib/sops_encrypt.sh:28) and sourcing it as a function.lib/bitwarden-to-sops.sh:370— the first-run init path (if [ ! -f "$TARGET_FILE" ], :359) creates a brand-new sops file withsops -e ... >"$TARGET_FILE". This script does run underset -euo pipefail(:15), so a failedsopsexits non-zero — but the redirect has already created a zero-byte file at the target path. Every later run then takes the "file exists" branch (:374) and runssops set(:378) against that empty, unencrypted placeholder instead of retrying init, so one transient failure permanently wedges the target until a human deletes the empty file by hand.
The hardened oracle already exists in the same directory: lib/bws-to-sops.sh:144-152 encrypts to a mktemp file beside the target, round-trip-verifies it with sops -d, and only then mvs it over the target.
Evidence (verified this run, laptop primary at origin/main 9c06d0c)
Probe ~/git/fleet/probe-sops-lib-atomic drives the real lib/sops_encrypt.sh with a stub sops on PATH and a pre-existing out.enc holding a sentinel:
- Failing stub (
sopsexits 1), script form: exit 0, outputEncrypted output saved to out.enc, andout.encgoes from the sentinel to 0 bytes. - Failing stub, sourced-function form: function return 0, same success message, target 0 bytes.
- Control (succeeding stub emitting its input): exit 0, target replaced with the new content (10 bytes) — the happy path works; only the failure path destroys data and lies about it.
The bitwarden-to-sops site is verified by code read at the same commit (lines above): the redirect creates the target before sops runs, set -e stops the script but cannot un-create the file, and the [ ! -f ... ] branch test is what routes every subsequent run to the sops set update path.
Dedup: title/keyword searches for sops_encrypt, bitwarden-to-sops, and sops-truncation return no issue covering either lib/ site; #6536 covers infra/dns/save.sh only and #6554 covers infra/talos/01b.us/save-secrets.sh only (its body names dns as the sole related item).
Why it matters
sops_encrypt is the shared helper anything in lib/ (or any operator following the repo's own tooling) reaches for to persist an encrypted file; its contract is "pipe secrets in, get an encrypted file out". Today a transient sops failure both destroys the previous ciphertext and reports success, so the loss surfaces only when the file is next decrypted — the same failure shape as #6536/#6554, with the masking defect of #6554 added. The bitwarden-to-sops variant turns one transient failure into a stuck target file that misroutes all future runs.
Acceptance criteria
sops_encryptencrypts to a temporary file in the target's directory and atomically renames it over the output only aftersopsexits 0 (and the temp file is non-empty); a failed encryption leaves any previous output byte-identical.sops_encryptpropagates failure: non-zero return/exit on sops failure, and the "Encrypted output saved" message is printed only on actual success.bitwarden-to-sops.sh's init path uses the same temp-then-rename shape, so a failed first encryption leaves no file at$TARGET_FILEand the next run retries the init branch.- Regression coverage (stub-sops probe or test): failing sops → previous output unchanged + non-zero status for both the script and sourced forms of
sops_encrypt; failing init in bitwarden-to-sops → no target file created; succeeding sops → new ciphertext in place for both.
Distinct from
- Issue dns(save.sh): encrypting the tfstate of record is not atomic — a failed sops -e truncates terraform.tfstate.enc to zero bytes #6536 (
infra/dns/save.shtfstate encryption), issue talos(save-secrets.sh): a failed sops encryption truncates secrets.enc to zero bytes and the script still exits 0 #6554 (infra/talos/01b.us/save-secrets.sh) — same pattern, different files; neither lists theselib/sites. - Issue bws.yaml mirror freshness check: periodic bws-to-sops dry-run diff #5451 (bws-to-sops mirror freshness) — that script is the hardened oracle here, not a defect site.
Activity
developing-today commentedon Nov 6, 2026
CODE-1991
dezren39 commentedon Nov 6, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 6, 2026
Picked up — task 11218, issue #6555 (triage, direct lane).
Lane code-r claimed task 11218 and will work the triage directly (§1b assigned_lane=direct). Re-verified fresh via
gh: issue #6555 is OPEN with no hard-stop labels. Next: verify the cited code on the laptop primary at origin/main (lib/sops_encrypt.sh,lib/bitwarden-to-sops.sh, oraclelib/bws-to-sops.sh) and post a verdict.16 remaining items
dezren39 commentedon Nov 6, 2026
🤖 Agent note · picked up
Merge pull request #6565 from developing-today/queue/11219-6555-sops-…
dezren39 commentedon Nov 6, 2026
🤖 Agent note · done
bash lib/sops-atomic-writers.test.sh23/23 PASS, same suite against original HEAD scripts 7 FAILs (regression proven),bash -nOK. The scripts-test CI run 42254121734 stayed QUEUED for 30+ minutes with no runner pickup (infra queueing, not a failure); merged under the standing merge authority (verified fix, tests pass) — CI runs on main post-merge.