Skip to content

talos(save-secrets.sh): a failed sops encryption truncates secrets.enc to zero bytes and the script still exits 0 #6554

Closed

Description

@dezren39

Problem

infra/talos/01b.us/save-secrets.sh — the script that persists the Talos cluster's secrets to their only encrypted copy, secrets.enc — writes that copy non-atomically and masks the failure:

#!/usr/bin/env bash
tar czf - ./secrets | base64 >secrets.tmp
sops --encrypt secrets.tmp >secrets.enc
rm secrets.tmp
  • save-secrets.sh:3: the shell truncates secrets.enc before sops runs, so any encryption failure (missing/expired sops key, sops error, disk full, interruption) leaves the encrypted copy empty or partial.
  • The script has no set -e / pipefail at all (the house style in this repo's sibling scripts, e.g. infra/dns/*.sh and init-talos.sh itself, is set -Eexuo pipefail). After sops fails, rm secrets.tmp (line 4) still runs and succeeds, so the script exits 0 — the failure is silent.
  • The caller trusts that exit code: init-talos.sh (which runs under set -Eexuo pipefail) invokes ./save-secrets.sh at lines 14 and 148 and proceeds with cluster bootstrap on the assumption the secrets were saved.

Evidence

infra/talos/01b.us/save-secrets.sh @ 9c06d0c8a4 (full file, 4 lines, quoted above):

  • secrets.enc is 43,916 bytes and is the only persistent copy: .gitignore ignores secret* and excepts exactly !secrets.enc; the plaintext ./secrets directory is gitignored, and load-secrets.sh can only regenerate it from secrets.enc.
  • Verified this run on the laptop (probe ~/git/fleet/probe-talos-save, real save-secrets.sh copied verbatim — md5 identical to the repo file — stub sops on PATH):
    • Stub sops --encrypt exits 1: save-secrets.sh exits 0 and secrets.enc goes from 30 bytes to 0 bytes.
    • Control (stub sops --encrypt succeeds): exit 0, secrets.enc holds the new ciphertext, secrets.tmp removed.
    • Load path probed for contrast: a failing sops --decrypt in load-secrets.sh exits 2 via tar, so the load side is not silently masked in that shape — the defect is specific to the save side.

Why it matters

secrets/ holds the cluster's identity material (secrets.yaml from talosctl gen secrets, plus the generated controlplane/worker configs and talosconfig). secrets.enc is the sole durable, committed copy of it. Zeroing it on a transient sops failure destroys the cluster's secrets — a re-run of init-talos.sh would generate a new cluster identity rather than recover the old one — and because the script reports success, the operator only discovers the loss the next time load-secrets.sh is needed, possibly after the plaintext directory has been cleaned up. The intermediate secrets.tmp is also an unencrypted base64 tarball of the same secrets: it is removed on the happy path, but nothing guarantees its cleanup if the script is interrupted mid-run.

Related but distinct: #6536 covers the same non-atomic pattern in infra/dns/save.sh (different script, different state of record, and that script at least exits non-zero on failure). This issue is the Talos counterpart, with the additional failure-masking defect.

Acceptance criteria

  • save-secrets.sh encrypts to a temporary file in the same directory and atomically renames it over secrets.enc only after sops exits 0 and the temp file is non-empty; a failed encryption leaves the previous secrets.enc byte-identical.
  • The script fails loudly: set -Eeuo pipefail (house style) or equivalent explicit checks, so a tar or sops failure exits non-zero and init-talos.sh stops instead of proceeding.
  • Plaintext-bearing intermediates (secrets.tmp and any new temp ciphertext) are cleaned up on failure and on interruption (e.g. an EXIT trap), without touching the live secrets.enc.
  • A regression probe/test with a failing sops --encrypt stub shows secrets.enc unchanged and a non-zero exit; a succeeding stub shows the new ciphertext in place; load-secrets.sh still round-trips a saved secrets.enc.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    on Nov 6, 2026
  2. developing-today commented on Nov 6, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    area/infraInfrastructure, deployment, and operations
    app/talosinfra/talos cluster secrets workflow
    on Nov 6, 2026
  4. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: filed

  5. dezren39 commented on Nov 6, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Nov 6, 2026
  7. 20 remaining items

  8. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · fix proposed

  9. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    Agent note - parked on CI. Agent: repo queue worker, lane code-b (repo-worker-code). Session: cron repo-queue-worker-shift-b run 2026-11-09 03:40 CST; task 14344 (direct lane, lane row 5573). Fresh revalidation: issue #6554 OPEN, no hard-stop labels; fix PR #8000 already OPEN on branch fix/6554-talos-save-secrets-atomic. Checks QUEUED (fleet Actions stall; CodeRabbit NEUTRAL completed); Codex review failed on usage limits with no inline findings to disposition. Task parked 1200s; resume = merge PR #8000 when checks go green, then complete task 14344. agent-note:v1 agent=repo-worker-code lane=code-b state=parked task=14344

  10. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    work/assignedQueue worker lifecycle state
    and removed on Nov 9, 2026
  11. added a commit that references this issue on Nov 9, 2026
  12. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    Agent note - done. Agent: repo queue worker, lane code-n (repo-worker-code). Session: cron repo-queue-worker-shift-n run 2026-11-09 04:47 CST; task 14344 (direct, row 5573). Verified PR #8000 diff fresh (atomic rename, set -Eeuo pipefail, EXIT trap, non-empty guard; no Codex findings). Checks QUEUED since 07:23Z in the fleet Actions stall with no failures; merged under standing merge authority. PR #8000 MERGED 53ce254 2026-11-09T10:51:35Z; issue #6554 CLOSED. Task 14344 completing fixed_merged. agent-note:v1 agent=repo-worker-code lane=code-n state=done task=14344

  13. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/talosinfra/talos cluster secrets workflowarea/infraInfrastructure, deployment, and operationskind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions