fix: third audit — PIPESTATUS regression, atomic hw-config, age-keygen stderr, env-example guard - #175
Merged
Merged
Conversation
…n errors, env-example guard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third audit findings
C1 — audit #2 introduced a critical regression in nixos-rebuild failure detection
The audit #2 fix replaced fragile log-pattern matching with
PIPESTATUS[0]capture — but left|| trueon thegrepat the end of each pipeline. This is broken.When
|| truetriggers (either because nixos-rebuild failed AND caused a non-zero pipeline exit, or because grep found no matching lines), bash executestrueas a simple command.trueis a pipeline-of-one and resets PIPESTATUS to[0]. Every subsequentNB1_EXIT=${PIPESTATUS[0]}reads0, always, regardless of nixos-rebuild's actual exit code. Proven with a live test:Fix: remove
|| true, bracket each nixos-rebuild pipeline withset +e/set -e. Withset +e, grep exiting 1 (no matching lines on a cached build) does not abort the script. PIPESTATUS is read before any subsequent command can reset it. Tested:This affects both pass-1 and pass-2.
H1 — Step 1:
nixos-generate-config > HW_CONFIGcreates an empty file on failureThe shell
>redirect creates (or truncates)HW_CONFIGto zero bytes beforenixos-generate-configruns. If the command then fails, an emptyhardware-configuration.nixremains on disk. On re-run,[[ -f "${HW_CONFIG}" ]]is true, the generation step is skipped, and pass-1 nixos-rebuild fails with a confusing Nix "empty file" import error — the operator sees nothing aboutnixos-generate-confighaving failed.Fix: write to
HW_CONFIG.tmp, check-s(non-empty), thenmvatomically. The.nixfile is only replaced if generation succeeded with non-empty output.M1 — Step 3:
age-keygen -o ... 2>/dev/nullsilences errorsIf
age-keygenfails (permissions, disk full, etc.), the operator sees no reason why. The script exits viaset -eat the subsequentchmod 600with a misleading "no such file" error. Removed2>/dev/null.M2 — Step 4: No guard before
cp "${COMPOSE_ENV_EXAMPLE}"If the prophet-platform clone is incomplete, or the compose layout changed,
cpfails with a raw shell error. Added an existence check with a diagnostic message before the copy.