From 54a025565f9a7f26d0d11430cedbf0bf2afbf326 Mon Sep 17 00:00:00 2001 From: mtriSE Date: Sat, 31 Oct 2026 12:22:57 +0700 Subject: [PATCH] ci: write the signing material from secrets before the board build keys/dev/ is gitignored, so the build job stopped in check_keys for want of dev-signing.key.pem. build.yml now writes the CA certificate and the signing pair from the OTA_KEYRING_PEM, OTA_SIGNING_CERT_PEM and OTA_SIGNING_KEY_PEM secrets and checks that the certificate chains to the CA and matches the key, so a wrong secret fails before the build starts. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/build.yml | 23 +++++++++++++++++++ README.md | 6 ++++- .../001-ci-cd-pipeline/contracts/workflows.md | 3 ++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6bff31..9655553 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,6 +78,29 @@ jobs: dl-${{ matrix.board }}- dl- + # keys/dev/ is gitignored, so a runner never has it. The same CA must sign every CI image, or + # a device flashed from one run could not install a bundle made from another. + - name: Install signing material + shell: bash + env: + OTA_KEYRING_PEM: ${{ secrets.OTA_KEYRING_PEM }} + OTA_SIGNING_CERT_PEM: ${{ secrets.OTA_SIGNING_CERT_PEM }} + OTA_SIGNING_KEY_PEM: ${{ secrets.OTA_SIGNING_KEY_PEM }} + run: | + if [ -z "$OTA_KEYRING_PEM" ] || [ -z "$OTA_SIGNING_CERT_PEM" ] || [ -z "$OTA_SIGNING_KEY_PEM" ]; then + echo "::error::Secrets OTA_KEYRING_PEM, OTA_SIGNING_CERT_PEM and OTA_SIGNING_KEY_PEM must all be set (contents of keys/dev/dev-ca.cert.pem, dev-signing.cert.pem, dev-signing.key.pem)." + exit 1 + fi + umask 077 + mkdir -p keys/dev + printf '%s\n' "$OTA_KEYRING_PEM" > keys/dev/dev-ca.cert.pem + printf '%s\n' "$OTA_SIGNING_CERT_PEM" > keys/dev/dev-signing.cert.pem + printf '%s\n' "$OTA_SIGNING_KEY_PEM" > keys/dev/dev-signing.key.pem + # Fails here, not an hour into the build, if a secret holds something other than the pair. + openssl verify -CAfile keys/dev/dev-ca.cert.pem -purpose codesign keys/dev/dev-signing.cert.pem + test "$(openssl x509 -in keys/dev/dev-signing.cert.pem -noout -pubkey)" \ + = "$(openssl pkey -in keys/dev/dev-signing.key.pem -pubout)" + - name: Build environment image run: make docker-build diff --git a/README.md b/README.md index f5f7045..7edf623 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,11 @@ GitHub Actions (GitHub-hosted `ubuntu-24.04` runners): (Actions → build → Run workflow) or when a `v*` tag is pushed, never on pull requests. The downloaded sources in `dl/` are cached between runs. Each board's `sdcard.img.xz` is kept as a workflow artifact for 14 days. On a tag, if every board built, a **draft** release is created - with the images and `SHA256SUMS`. + with the images and `SHA256SUMS`. `keys/dev/` is not in the repository, so `build.yml` writes it from + three repository secrets, `OTA_KEYRING_PEM`, `OTA_SIGNING_CERT_PEM` and `OTA_SIGNING_KEY_PEM` (the + contents of `dev-ca.cert.pem`, `dev-signing.cert.pem` and `dev-signing.key.pem`), and fails at once if + one is missing or the certificate does not match the key. Every CI image then shares the CA of your + local builds. A green build is **not** a boot test. Boot each image on hardware to a login prompt on the serial console before publishing a draft release. Images are xz-compressed: see Flashing below. Release diff --git a/specs/001-ci-cd-pipeline/contracts/workflows.md b/specs/001-ci-cd-pipeline/contracts/workflows.md index 4276a86..0bdec48 100644 --- a/specs/001-ci-cd-pipeline/contracts/workflows.md +++ b/specs/001-ci-cd-pipeline/contracts/workflows.md @@ -26,7 +26,8 @@ 1. **boards**: derive the board list from `configs/*_defconfig`; output JSON array; fail if empty. 2. **build** (`needs: boards`, matrix `board`, `fail-fast: false`, `timeout-minutes: 350`): checkout (submodules recursive, full history and tags so the image `VERSION` is meaningful) -> - free runner disk -> restore `dl/` cache -> `make docker-build` -> build board in container -> + free runner disk -> restore `dl/` cache -> write `keys/dev/` from the secrets + `OTA_KEYRING_PEM`, `OTA_SIGNING_CERT_PEM`, `OTA_SIGNING_KEY_PEM` and verify the pair -> `make docker-build` -> build board in container -> compress image, write `SHA256SUMS`, copy `build-info` -> upload artifact `-image` (retention 14 days) -> save `dl/` cache (`if: always()`) -> on failure, print disk usage and an error naming the exceeded limit. Writes a job summary with image size and elapsed time.