diff --git a/bin/omamobile b/bin/omamobile index f3e089b34..ef06f82d2 100755 --- a/bin/omamobile +++ b/bin/omamobile @@ -28,7 +28,9 @@ Usage: [DEVICE=] omamobile capture [name] Save what the connected phone exposes (Android over adb, or fastboot) into $REFERENCE_DIR/ - initramfs Build the M1 initramfs (Alpine + dropbear + our init) into $KERNEL_OUT + initramfs [--release] + Build the M1 initramfs into $KERNEL_OUT. --release omits + the builder's SSH keys from distributable boot images initramfs-config Write only the device's files for the shared init (storage-guard allowlist, trigger, ...) into , to check what initramfs packs @@ -385,6 +387,13 @@ cmd_initramfs_config() { cmd_initramfs() { local dl="$WORK/downloads/alpine" stage="$KERNEL_OUT/initramfs" ver=3.24.2 + local release=0 + case ${1:-} in + '') ;; + --release) release=1 ;; + *) die "initramfs: expected --release or no argument" ;; + esac + (($# <= 1)) || die "initramfs: expected --release or no argument" load_device # A leading slash is repo-root relative, so devices share initramfs/init. # Anything else is relative to device//. @@ -537,9 +546,15 @@ cmd_initramfs() { || die "reboot-to failed to link" say "No $DEV_PACKAGE bootctl; built freestanding devmem and musl reboot-to" fi - mkdir -p "$stage/root/.ssh" - cat "$HOME"/.ssh/*.pub > "$stage/root/.ssh/authorized_keys" - chmod 700 "$stage/root/.ssh" && chmod 600 "$stage/root/.ssh/authorized_keys" + rm -rf "$stage/root/.ssh" + if ((release)); then + rm -f "$stage/etc/dropbear"/dropbear_*_host_key + say "Release initramfs: no builder SSH keys" + else + mkdir -p "$stage/root/.ssh" + cat "$HOME"/.ssh/*.pub > "$stage/root/.ssh/authorized_keys" + chmod 700 "$stage/root/.ssh" && chmod 600 "$stage/root/.ssh/authorized_keys" + fi (cd "$stage" && find . | cpio -o -H newc --owner=0:0 --quiet) | lz4 -l -9 -q > "$KERNEL_OUT/initramfs.cpio.lz4" ls -lh "$KERNEL_OUT/initramfs.cpio.lz4" @@ -986,7 +1001,7 @@ cmd_kernel_shell() { case "${1:-}" in capture) shift; cmd_capture "$@" ;; - initramfs) cmd_initramfs ;; + initramfs) shift; cmd_initramfs "$@" ;; initramfs-config) shift; cmd_initramfs_config "$@" ;; kernel) cmd_kernel ;; modules) cmd_modules ;; diff --git a/docs/RELEASES.md b/docs/RELEASES.md index a8c0cfd1b..00c63cd51 100644 --- a/docs/RELEASES.md +++ b/docs/RELEASES.md @@ -34,7 +34,7 @@ The audit behind this design (2026-10-13). "Step" names the roadmap step that re | `bin/omamobile capture` | the default capture name `cheetah-` | 1 (done) | | `bin/omamobile push`, `flash` | the partition lookup assumes the main LUN is `sda` | 1 (allowlist check and `BOOT_IMAGES` layouts done; the Pixel 6 has no `init_boot` or `vendor_kernel_boot`, [oriole NOTES](../device/oriole/NOTES.md)), 3 | | `initramfs/init` | `probe()` when `BRINGUP_PROBE=1` and the board matches `COMPATIBLE` (watchdog and DPP reads); the main LUN `sda`. The TRIG_CON write is `SIMPLEFB_TRIG_CON`, the storage-guard allowlist `UFS_RW` and the USB product string `USB_PRODUCT`, all packed from the descriptor into that device's initramfs only | 2 (trigger, allowlist and USB name done; the rest still step 2) | -| `bin/omamobile initramfs` | the developer's `~/.ssh/*.pub` baked in as `authorized_keys` (fine for development, never for a release) | 2 | +| `bin/omamobile initramfs` | the developer's `~/.ssh/*.pub` baked in as `authorized_keys` (fine for development, never for a release); `--release` leaves them out, and `tools/make-bundle` refuses to sign an initramfs that has them | 2 (done) | | `tools/extract-vendor-firmware` | `BOARD="google,gs201-cheetah"`, `DEVICE="cheetah"`, the firmware `MAP` | 4 | | `tools/extract-vendor-chroot`, `extract-fingerprint-vendor` | `DEVICE="cheetah"`, cheetah's file lists | 4 | | `tools/aoc-stage` | the AoC firmware path under `vendor/google/cheetah` | bring-up tool, per plan | @@ -165,7 +165,7 @@ The device package, not the kernel package, turns the kernel into bootable slot- The same Alpine-based initramfs, with release differences: -- **No developer keys.** It ships without `authorized_keys`. The hook appends a second, tiny cpio to the ramdisk that holds the phone's own `/root/.ssh/authorized_keys` (the kernel unpacks concatenated cpio archives in order), so SSH into the initramfs keeps working for the phone's owner and nobody else. +- **No developer keys.** It ships without `authorized_keys`: `bin/omamobile initramfs --release` builds it that way, and `tools/make-bundle` refuses to sign a bundle whose initramfs still holds SSH keys. The hook appends a second, tiny cpio to the ramdisk that holds the phone's own `/root/.ssh/authorized_keys` (the kernel unpacks concatenated cpio archives in order), so SSH into the initramfs keeps working for the phone's owner and nobody else. - **No bring-up probes.** `probe()` and `omamobile.debug` stay in development builds only. - **Quirks from the descriptor.** The trigger write is already per device: `bin/omamobile initramfs` packs `SIMPLEFB_TRIG_CON` into `/etc/omamobile-simplefb-trig` and `COMPATIBLE` beside it. The init writes the pair only when the board's first compatible string matches. A device without the trigger key gets no register write. The storage guard's allowlist is packed the same way, from `UFS_RW` into `/etc/omamobile-ufs-rw`, and the init leaves every partition read-only without a valid one. So is the USB product string (`USB_PRODUCT`, else `NAME`). Step 2 still turns the remaining quirk (`MAIN_LUN`) into a generated `/etc/omamobile/device.conf` the shared init reads at boot. That remaining step changes what boots, so it gets its own runbook and a test boot from `bin/omamobile push`; it is not a refactor. - **Reproducible:** fixed mtimes (`SOURCE_DATE_EPOCH`), sorted file list, `cpio --reproducible`. @@ -341,7 +341,7 @@ Per release, in order. Stop at any failed step. 1. **Kernel:** every subsystem branch meant for the release merged into `omamobile-int`; it boots on each released device, with `uname -r` and the result in that device's NOTES. 2. **Curate:** move what has passed into `omamobile` (ยง8); publish `omamobile` and the `omamobile-int` snapshot; tag `omamobile-int-`. 3. **Build** the kernel from the tag in the pinned container, release `LOCALVERSION`; pack `linux-omamobile`. -4. **Images** for every device: `DEVICE= bin/omamobile images`, twice, checksums equal. +4. **Images** for every device: `DEVICE= bin/omamobile initramfs --release`, then `DEVICE= bin/omamobile images`, twice, checksums equal. 5. **Packages:** every changed package has a bumped `version`, its `test/all` passes, `tools/build-packages` builds and signs them and the database on the laptop (`tools/repo-build` on a phone only as an opt-in shortcut). 6. **Test install** on each released device, attended: the bundle's `install` on a phone whose stock slot A and backups are known good; first boot, device package installed, `omarchy update` clean, then a package-hook kernel update and a reboot into it. 7. **Identifiers:** grep the bundle, the root image's file list, `MANIFEST` and the release notes for MAC addresses (`[0-9a-f]{2}(:[0-9a-f]{2}){5}`), serial numbers, SSIDs and account names; confirm no file from a factory image is in any artifact. diff --git a/tests/all b/tests/all index abcf72172..4afae7bc4 100755 --- a/tests/all +++ b/tests/all @@ -24,7 +24,7 @@ sh -n device/flame/initramfs/init sh -n device/flame/initramfs/build bash -n tools/build-flame-probe echo "ok - scripts parse" -for t in tests/pr-check tests/kernel-pr-check tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/phone-provision tests/initramfs-grow tests/images-layout tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/boot-method tests/flame-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package; do +for t in tests/pr-check tests/kernel-pr-check tests/alarm-wake-test tests/install-phone tests/build-rootfs tests/phone-provision tests/initramfs-grow tests/images-layout tests/device-overlays tests/simplefb-trigger tests/initramfs-steps tests/storage-guard tests/usb-product tests/boot-method tests/make-bundle-keys tests/flame-probe packages/omamobile-firstboot/test/all packages/omamobile-device-felix/test/all packages/omamobile-device-lynx/test/all packages/omamobile-device-panther/test/all tests/local-builds tests/phone-install-package; do echo "# $t" "$t" done diff --git a/tests/make-bundle-keys b/tests/make-bundle-keys new file mode 100755 index 000000000..ec2cfe1cb --- /dev/null +++ b/tests/make-bundle-keys @@ -0,0 +1,55 @@ +#!/bin/bash +# SPDX-License-Identifier: MIT +# A signed bundle must refuse a development initramfs that grants its +# builder SSH access, while an unsigned development bundle may use it. +set -euo pipefail +cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." +for tool in cpio lz4 sha256sum; do + command -v "$tool" >/dev/null || { echo "ok - # skip: no $tool"; exit 0; } +done +t=$(mktemp -d) +trap 'rm -rf "$t"' EXIT +r=$t/repo +mkdir -p "$r/tools" "$r/device/testdev" "$r/packages/omamobile-keyring" \ + "$r/out" "$t/kernel/include/config" "$t/ramdisk/root/.ssh" +cp tools/make-bundle "$r/tools/" +: > "$r/tools/install-phone" +printf 'BOOT_IMAGES="boot"\nNAME="Test device"\n' > "$r/device/testdev/device.conf" +: > "$r/packages/omamobile-keyring/omamobile.gpg" +echo test-release > "$t/kernel/include/config/kernel.release" +printf x > "$r/out/omamobile-rootfs-test-aarch64.img.zst" +sha256sum "$r/out/omamobile-rootfs-test-aarch64.img.zst" > \ + "$r/out/omamobile-rootfs-test-aarch64.img.zst.sha256" +printf 'device: testdev\nkernel modules: test-release\n' > \ + "$r/out/omamobile-rootfs-test-aarch64.MANIFEST" +archive=$t/kernel/initramfs.cpio.lz4 +pack() { + (cd "$t/ramdisk" && find . | cpio -o -H newc --quiet) | lz4 -l -9 -q > "$archive" +} +run() { + DEVICE=testdev KERNEL_OUT="$t/kernel" "$r/tools/make-bundle" --version test \ + --rootfs "$r/out/omamobile-rootfs-test-aarch64.img.zst" "$@" 2>&1 +} +expect_refusal() { + local output + output=$(run "${@:2}") && { echo "not ok - accepted $1" >&2; exit 1; } + grep -cF "$1" <<<"$output" >/dev/null || { + echo "not ok - wrong refusal: $output" >&2; exit 1; + } +} + +printf 'developer key\n' > "$t/ramdisk/root/.ssh/authorized_keys" +pack +expect_refusal 'initramfs contains SSH credentials' +echo 'ok - signed bundle refuses the builder SSH key' +expect_refusal 'holds images for' --unsigned +echo 'ok - unsigned development bundle may pass the key guard' + +rm -rf "$t/ramdisk/root/.ssh" +pack +expect_refusal 'holds images for' +echo 'ok - release initramfs passes the key guard' + +printf corrupt > "$archive" +expect_refusal 'not a valid initramfs archive' +echo 'ok - signed bundle refuses a corrupt initramfs' diff --git a/tools/make-bundle b/tools/make-bundle index d5daf2e08..f2a484246 100755 --- a/tools/make-bundle +++ b/tools/make-bundle @@ -68,6 +68,14 @@ modules_release=$(sed -n 's/^kernel modules: \([^ ]*\).*/\1/p' "$manifest") die "the root image has modules for $modules_release, but the boot images are $release: rebuild one to match" root_digest=$(sha256sum < "$rootfs" | cut -d' ' -f1) [[ $(cut -d' ' -f1 "$rootfs.sha256") == "$root_digest" ]] || die "$rootfs doesn't match its .sha256" +if ((unsigned == 0)); then + initramfs=$KERNEL_OUT/initramfs.cpio.lz4 + [[ -f $initramfs ]] || die "no $initramfs: build it with bin/omamobile initramfs --release" + entries=$(lz4 -dc "$initramfs" | cpio -t --quiet 2>/dev/null) || die "$initramfs is not a valid initramfs archive" + if grep -cE '^(\./)?root/\.ssh(/|$)|^(\./)?etc/dropbear/dropbear_.*_host_key$' <<<"$entries" >/dev/null; then + die "initramfs contains SSH credentials: rebuild with bin/omamobile initramfs --release, then bin/omamobile images" + fi +fi name=omamobile-$DEVICE-$version out=out/bundle