From 512b9f5f1da6c56959ebb801d31a1887b1c341c3 Mon Sep 17 00:00:00 2001 From: cflmy Date: Sat, 21 Nov 2026 17:41:23 +0800 Subject: [PATCH] ci(security): fail the lane when evidence generation fails A green lane without a strict-evidence.json must not count as a gate. The EXIT trap now turns a generator failure into a lane failure. The self-hosted workflow exports the archive path in the run step (env written by GITHUB_ENV is not guaranteed in the env expression context), records the pinned image digest as an input, and verifies schema/outcome/tested_sha/non-root before uploading. Also define SOURCE_SHA before the VM overlay commands. --- .github/workflows/security-linux.yml | 29 ++++++++++++++++++++++++++-- docs/security-vm.md | 1 + tests/security/run-lane.sh | 10 +++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/security-linux.yml b/.github/workflows/security-linux.yml index c4161dc..90608ee 100644 --- a/.github/workflows/security-linux.yml +++ b/.github/workflows/security-linux.yml @@ -20,6 +20,11 @@ on: description: "Exact reviewed commit SHA" required: true type: string + runner_image_sha256: + description: "Pinned VM base-image digest (evidence, not a secret)" + required: false + default: "unrecorded" + type: string permissions: contents: read @@ -73,17 +78,37 @@ jobs: MARQDO_STRICT_EVIDENCE: ${{ runner.temp }}/strict-evidence.json MARQDO_STRICT_LANE_LOG: ${{ runner.temp }}/gc-lane.log MARQDO_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - MARQDO_SOURCE_ARCHIVE: ${{ runner.temp }}/marqdo-source-${{ env.TESTED_SHA }}.tar MARQDO_RUNNER_KIND: disposable-vm + MARQDO_RUNNER_IMAGE_SHA256: ${{ inputs.runner_image_sha256 || 'unrecorded' }} run: | set -euo pipefail + export MARQDO_SOURCE_ARCHIVE="$RUNNER_TEMP/marqdo-source-${TESTED_SHA}.tar" ./tests/security/run-lane.sh 2>&1 | tee "$MARQDO_STRICT_LANE_LOG" + - name: Verify strict evidence matches the tested SHA + if: success() + shell: bash + env: + MARQDO_STRICT_EVIDENCE: ${{ runner.temp }}/strict-evidence.json + run: | + set -euo pipefail + python3 - <<'PY' + import json, os + path = os.environ["MARQDO_STRICT_EVIDENCE"] + with open(path, encoding="utf-8") as handle: + evidence = json.load(handle) + assert evidence["schema"] == "marqdo.strict-evidence.v1", evidence + assert evidence["run"]["outcome"] == "PASS", evidence + assert evidence["tested_sha"] == os.environ["TESTED_SHA"], evidence + assert evidence["environment"]["uid"] != 0, evidence + print("strict evidence verified for", evidence["tested_sha"]) + PY + - name: Upload strict evidence if: always() uses: actions/upload-artifact@v4 with: - name: strict-evidence-${{ env.TESTED_SHA || github.sha }} + name: strict-evidence-${{ inputs.source_sha || github.sha }} path: | ${{ runner.temp }}/strict-evidence.json ${{ runner.temp }}/gc-lane.log diff --git a/docs/security-vm.md b/docs/security-vm.md index 90de2da..48a1bc2 100644 --- a/docs/security-vm.md +++ b/docs/security-vm.md @@ -34,6 +34,7 @@ URL. Download one dated release, verify it against Ubuntu's published `SHA256SUMS`, record the digest, and keep that file immutable: ```bash +export SOURCE_SHA="$(git rev-parse HEAD)" # reviewed commit, clean tree mkdir -p .tools/vm && cd .tools/vm # Replace with the reviewed dated release URL, never .../current/... curl -L -o ubuntu-base.img \ diff --git a/tests/security/run-lane.sh b/tests/security/run-lane.sh index 6974c20..18e0a03 100755 --- a/tests/security/run-lane.sh +++ b/tests/security/run-lane.sh @@ -23,14 +23,18 @@ finish_lane() { if [ "$status" -eq 0 ]; then outcome="PASS" fi - python3 tools/ci/strict-evidence.py \ + if ! python3 tools/ci/strict-evidence.py \ --repo "$repo" \ --out "$evidence" \ --outcome "$outcome" \ --started "$started_utc" \ --finished "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - --log "${MARQDO_STRICT_LANE_LOG:-}" \ - || echo "warning: could not write strict evidence" >&2 + --log "${MARQDO_STRICT_LANE_LOG:-}"; then + echo "error: strict evidence generation failed; a green lane without evidence is not a gate" >&2 + if [ "$status" -eq 0 ]; then + status=1 + fi + fi fi exit "$status" }