Skip to content

Commit 310ebc2

Browse files
committed
fix: fourth audit — nix build log, signing key validation, idempotent publish, hw-config tmp cleanup
1 parent fa7532b commit 310ebc2

2 files changed

Lines changed: 31 additions & 12 deletions

File tree

scripts/enroll.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ ok "Preflight passed ($(elapsed))"
145145

146146
step 1 "Hardware configuration"
147147

148+
rm -f "${HW_CONFIG}.tmp" # clean up any stale temp from a previous interrupted run
149+
148150
if [[ -f "${HW_CONFIG}" ]]; then
149151
ok "hardware-configuration.nix already present"
150152
else
@@ -354,6 +356,9 @@ else
354356
fi
355357

356358
SIGNING_PUBKEY=$(grep -v '^untrusted comment' "${MINISIGN_PUB}" | head -1)
359+
[[ -n "${SIGNING_PUBKEY}" ]] || \
360+
die "minisign public key file is empty or malformed: ${MINISIGN_PUB}
361+
Delete and re-run: rm -f ${MINISIGN_PUB} ${MINISIGN_SEC} && sudo bash scripts/enroll.sh"
357362
info "Signing public key: ${SIGNING_PUBKEY}"
358363

359364
# Write nix-cache-info and sign it. nginx serves the .minisig file alongside
@@ -380,13 +385,14 @@ ok "enroll.nix written — no Nix file patching needed ($(elapsed))"
380385
step 10 "Build NixOS closure + push to harmonia cache"
381386

382387
info "Building builder-aarch64 system closure..."
388+
BUILD_LOG="/tmp/sourceos-enroll-nix-build-$(date +%s).log"
383389
CLOSURE=$(nix build "${REPO_ROOT}#nixosConfigurations.${HOST}.config.system.build.toplevel" \
384-
--no-link --print-out-paths 2>/dev/null)
385-
# nix build returns empty stdout on failure (errors go to stderr). Verify both that
386-
# CLOSURE is non-empty and that the path actually exists in the Nix store.
390+
--no-link --print-out-paths 2>"${BUILD_LOG}")
391+
# nix build emits errors only to stderr (captured to BUILD_LOG above).
392+
# Verify stdout produced a non-empty, existing store path.
387393
[[ -n "${CLOSURE}" && -e "${CLOSURE}" ]] || \
388-
die "nix build failed — retry with:
389-
nix build ${REPO_ROOT}#nixosConfigurations.${HOST}.config.system.build.toplevel --no-link --show-trace"
394+
die "nix build failed. Build log: ${BUILD_LOG}
395+
For full trace: nix build ${REPO_ROOT}#nixosConfigurations.${HOST}.config.system.build.toplevel --no-link --show-trace"
390396
ok "Built: ${CLOSURE}"
391397

392398
# Harmonia must be running before we can push (it starts after pass-2 rebuild).

scripts/katello-sourceos-setup.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,26 @@ $HAMMER content-view add-repository --organization "${ORG}" \
7878
--repository "sourceos-closures-aarch64" \
7979
2>/dev/null || echo " sourceos-closures-aarch64 already in view"
8080

81-
# Publish version 1.0 to Library
82-
echo "--- publishing content view (this may take a minute)"
83-
$HAMMER content-view publish --organization "${ORG}" \
84-
--name "sourceos-builder-aarch64" \
85-
--description "Initial publish — dev channel bootstrap"
86-
87-
# Promote to dev lifecycle environment
81+
# Publish version 1.0 to Library — skip if any version already exists.
82+
# Re-running katello-sourceos-setup.sh (e.g. during enroll.sh retry) must not
83+
# create a new CV version: publishing is slow (1-2 min) and the extra versions
84+
# are noise that complicates CV_VERSION selection in subsequent steps.
85+
echo "--- checking content view publish state"
86+
EXISTING_CV_VERSIONS=$($HAMMER --output json content-view version list \
87+
--organization "${ORG}" \
88+
--content-view "sourceos-builder-aarch64" 2>/dev/null | \
89+
python3 -c "import json,sys; print(len(json.load(sys.stdin)))" 2>/dev/null || echo "0")
90+
91+
if [[ "${EXISTING_CV_VERSIONS}" -eq 0 ]]; then
92+
echo "--- publishing content view (this may take a minute)"
93+
$HAMMER content-view publish --organization "${ORG}" \
94+
--name "sourceos-builder-aarch64" \
95+
--description "Initial publish — dev channel bootstrap"
96+
else
97+
echo " content view already has ${EXISTING_CV_VERSIONS} version(s) — skipping publish"
98+
fi
99+
100+
# Promote to dev lifecycle environment (idempotent — hammer returns 0 if already promoted)
88101
echo "--- promoting to dev"
89102
CV_VERSION=$($HAMMER --output json content-view version list \
90103
--organization "${ORG}" \

0 commit comments

Comments
 (0)