Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Add experimental T2 installation with preserved firmware and platform recovery (#844)

Dee2b741f31c4f0
diff --git a/.github/workflows/os-t2.yml b/.github/workflows/os-t2.yml
new file mode 100644
index 000000000..00adbcbfc
--- /dev/null
+++ b/.github/workflows/os-t2.yml
@@ -0,0 +1,150 @@
+name: Harness OS T2 image
+
+on:
+ workflow_dispatch:
+ inputs:
+ image_run_id:
+ description: 'Reuse an exact T2 image built from this source for machine acceptance'
+ required: false
+ type: string
+ push:
+ branches: ['os-candidate/t2-*']
+ paths: ['os/**', '.github/workflows/os-t2.yml']
+
+permissions:
+ contents: read
+ actions: read
+
+concurrency:
+ group: harness-t2-image-${{ github.ref }}
+ cancel-in-progress: false
+
+jobs:
+ image:
+ if: ${{ !inputs.image_run_id }}
+ runs-on: ubuntu-24.04
+ timeout-minutes: 45
+ env:
+ CARGO_INCREMENTAL: '0'
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
+ - name: Require frozen public runtime inputs for the private T2 candidate
+ run: |
+ df -h .
+ python3 - <<'PY'
+ import subprocess
+ expected = {'tui': '1ec2af97a8695bdcc8429ddc498747bd86eada08',
+ 'cli': '27f50e77fa9bdc8de75a64c9e9166c932c559a8b',
+ 'store': 'ea5589e2d8db518a85453fa3c9efc60d29a16085'}
+ for path, tree in expected.items():
+ assert subprocess.check_output(['git', 'rev-parse', 'HEAD:' + path], text=True).strip() == tree, path
+ PY
+ make -C os check
+ go run github.com/rhysd/actionlint/cmd/[email protected] .github/workflows/os-t2.yml
+ - uses: actions/setup-node@v7
+ with:
+ node-version: '22.23.2'
+ cache: npm
+ cache-dependency-path: cli/package-lock.json
+ - uses: dtolnay/rust-toolchain@stable
+ with:
+ toolchain: '1.99.0'
+ targets: x86_64-unknown-linux-musl
+ - name: Build the frozen runtime and verify the pinned kernel archive
+ run: |
+ sudo apt-get update -qq
+ sudo apt-get install -y --no-install-recommends musl=1.2.4-2 musl-dev=1.2.4-2 musl-tools=1.2.4-2 zstd
+ make -C os runtime
+ python3 - <<'PY'
+ import hashlib, json, subprocess
+ from pathlib import Path
+ expected = {'harness-tui': 'bd221059a24d7f7ca8ce69bb3b6d69c2fb66cb655aae6658627c278a548a8fa8',
+ 'cli.js': '23b46a7c498fd1ef8ff5936aeb431f1de08b959b957141fa732d2cede870d147',
+ 'notify.mjs': '5690159e964f9ce022bdb2a5e4bc9d853e595e822f254478df241e1386dde68e'}
+ for name, digest in expected.items():
+ assert hashlib.sha256((Path('os/work/runtime') / name).read_bytes()).hexdigest() == digest, name
+ lock = json.loads(Path('os/platforms/apple-t2/kernel.json').read_text())
+ folder = Path('os/work/t2-inputs')
+ folder.mkdir(parents=True, exist_ok=False)
+ package = lock['package']
+ subprocess.run(['curl', '--fail', '--location', '--proto', '=https', '--proto-redir', '=https',
+ '--max-time', '180', package['url'], '-o', str(folder / package['filename'])], check=True)
+ PY
+ python3 os/tools/prepare-t2-kernel.py --package os/work/t2-inputs/*.pkg.tar.zst --output os/work/t2-kernel-bundle
+ - name: Build the isolated T2 live and installed image
+ run: |
+ docker run --rm --privileged \
+ -v "$PWD:/src" -w /src/os \
+ -e SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)" \
+ -e HARNESS_OS_SOURCE_SHA="$(git rev-parse HEAD)" \
+ -e HARNESS_OS_RUNTIME_DIR=/src/os/work/runtime \
+ -e HARNESS_OS_PLATFORM=apple-t2 \
+ -e HARNESS_OS_T2_BUNDLE=/src/os/work/t2-kernel-bundle \
+ archlinux:base-devel@sha256:51dd3d24f7fba779e7c471caeee7804c50e8c134ad948e19685a1c83a42facc3 \
+ bash -c 'set -euo pipefail; pacman -Syu --noconfirm archiso python git; bash build.sh'
+ - name: Retain private image and exact package inputs
+ uses: actions/upload-artifact@v6
+ with:
+ name: harness-os-t2-image
+ path: os/dist/
+ retention-days: 7
+ compression-level: 0
+ - name: Retain diagnostics
+ if: failure()
+ uses: actions/upload-artifact@v6
+ with:
+ name: harness-os-t2-build-diagnostics
+ path: |
+ os/work/profile/profiledef.sh
+ os/work/profile/pacman.conf
+ os/work/archiso/x86_64/airootfs/var/log/pacman.log
+ retention-days: 7
+
+ machine:
+ needs: image
+ if: ${{ always() && !cancelled() && (needs.image.result == 'success' || inputs.image_run_id != '') }}
+ runs-on: ubuntu-24.04
+ timeout-minutes: 25
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
+ - uses: actions/download-artifact@v6
+ with:
+ name: harness-os-t2-image
+ path: os/dist
+ run-id: ${{ inputs.image_run_id || github.run_id }}
+ github-token: ${{ github.token }}
+ - name: Install native VM tools
+ run: |
+ python3 -m unittest discover -s os/tests -p test_t2_observer.py -v
+ sudo apt-get update -qq
+ sudo apt-get install -y --no-install-recommends qemu-system-x86 qemu-utils ovmf python3-pil tesseract-ocr
+ sudo chmod a+rw /dev/kvm
+ - name: Install offline, preserve firmware, cold boot, update and recover
+ run: python3 os/tests/t2_install_vm.py --iso os/dist/*.iso --output os/test-results/t2-install
+ - name: Show bounded failure diagnostics
+ if: failure()
+ run: |
+ python3 - <<'PY'
+ from pathlib import Path
+ for name in ['receipt.json', 'qemu.log', 'serial.log']:
+ path = Path('os/test-results/t2-install') / name
+ if path.exists():
+ print(name, path.read_text(errors='replace')[-16000:])
+ PY
+ - name: Retain source, boot, preservation and recovery evidence
+ if: always()
+ uses: actions/upload-artifact@v6
+ with:
+ name: harness-os-t2-install
+ path: |
+ os/test-results/t2-install/
+ !os/test-results/t2-install/*.qcow2
+ !os/test-results/t2-install/OVMF_VARS.fd
+ !os/test-results/t2-install/synthetic-firmware/
+ !os/test-results/t2-install/*.tar
+ retention-days: 14
+ compression-level: 0
diff --git a/os/boot_profile.py b/os/boot_profile.py
new file mode 100644
index 000000000..f93f814c1
--- /dev/null
+++ b/os/boot_profile.py
@@ -0,0 +1,76 @@
+"""The boot files and early input stack belonging to an installed platform."""
+import importlib.util
+import json
+from pathlib import Path
+import tarfile
+
+
+PROFILES = {
+ 'pc': {'kernel': 'linux-lts', 'modules': [], 'parameters': []},
+ 'apple-t2': {'kernel': 'linux-t2', 'modules': ['t2bce_dma', 't2bce_core', 't2bce_vhci'],
+ 'parameters': ['intel_iommu=on', 'iommu=pt', 'pm_async=off']},
+}
+
+
+def profile(identity):
+ if not isinstance(identity, str) or identity not in PROFILES:
+ raise ValueError('Unknown Harness boot platform.')
+ return dict(PROFILES[identity], id=identity)
+
+
+def selected(root=Path('/')):
+ path = root / 'etc/harness-platform.json'
+ if path.is_symlink():
+ raise ValueError('The boot platform record must be a regular file.')
+ if not path.exists():
+ return profile('pc') # Published PC images predate explicit profiles.
+ if not path.is_file():
+ raise ValueError('The boot platform record must be a regular file.')
+ value = json.loads(path.read_text())
+ if not isinstance(value, dict) or set(value) != {'schema', 'id'} or type(value['schema']) is not int or value['schema'] != 1:
+ raise ValueError('Invalid Harness boot platform record.')
+ return profile(value['id'])
+
+
+def boot_files(identity):
+ kernel = profile(identity)['kernel']
+ return {'vmlinuz-' + kernel, 'initramfs-' + kernel + '.img', 'grub/grub.cfg'}
+
+
+def validate_update(package, root=Path('/')):
+ if selected(root)['id'] != 'apple-t2':
+ return
+ # The initial T2 image has one verified kernel. A general PC package must
+ # not remove its helpers or silently advance the required T2 kernel. A
+ # future kernel change needs its own staged, verified package transaction.
+ pin = 'usr/share/harness-os/apple-t2/kernel.json'
+ required = {'usr/lib/harness-os/' + name + '.py' for name in
+ ['boot_profile', 't2_install', 't2_firmware', 'firmware_names']}
+ with tarfile.open(package, 'r:gz') as archive:
+ files = {entry.name: entry for entry in archive}
+ if any(name not in files or not files[name].isfile() for name in required | {pin}):
+ raise ValueError('This update does not include the T2 platform. Nothing updated.')
+ if files[pin].size > 65536:
+ raise ValueError('Invalid T2 kernel requirements in the update.')
+ requested = json.loads(archive.extractfile(files[pin]).read())
+ if requested != json.loads((root / pin).read_text()):
+ raise ValueError('This update needs a different T2 kernel; a verified T2 kernel update is required. Nothing updated.')
+
+
+def restore_firmware(root=Path('/')):
+ if selected(root)['id'] == 'apple-t2':
+ helper = module('t2_install')
+ helper.restore(root, helper.retained(root))
+
+
+def module(name):
+ paths = {'t2_install': 't2_install.py', 't2_firmware': 'tools/prepare-t2-firmware.py'}
+ if name not in paths:
+ raise ValueError('Unknown platform helper.')
+ path = Path(__file__).with_name(name + '.py')
+ if not path.is_file():
+ path = Path(__file__).parent / paths[name]
+ spec = importlib.util.spec_from_file_location('harness_' + name, path)
+ value = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(value)
+ return value
diff --git a/os/build.sh b/os/build.sh
index 323078ac1..133143e3c 100644
--- a/os/build.sh
+++ b/os/build.sh
@@ -14,6 +14,8 @@ VERSION=$(python3 -c 'import json; print(json.load(open("lock.json"))["version"]
SNAPSHOT=$(python3 -c 'import json; print(json.load(open("lock.json"))["arch_snapshot"])')
BUILD_DIR=${HARNESS_OS_BUILD_DIR:-$OS_DIR/work}
RUNTIME_DIR=${HARNESS_OS_RUNTIME_DIR:-$OS_DIR/work/runtime}
+PLATFORM=${HARNESS_OS_PLATFORM:-pc}
+[[ $PLATFORM == pc || $PLATFORM == apple-t2 ]] || { echo 'Unknown OS boot platform.' >&2; exit 1; }
[[ -s "$RUNTIME_DIR/source.json" && -x "$RUNTIME_DIR/harness-tui" ]] || {
echo 'Build the OS runtimes first with make -C os runtime on x86_64 Linux.' >&2
exit 1
@@ -45,13 +47,25 @@ EOF
# Use the same source-versioned identity as its update-channel package. An ISO
# installation should not immediately be offered this identical build again.
python3 tools/build-package.py --runtime "$RUNTIME_DIR" --output "$BUILD_DIR/repo" --development
-repo-add "$BUILD_DIR/repo/harness-build.db.tar.gz" "$BUILD_DIR/repo/"*.pkg.tar.gz
-python3 tools/build-hardware.py --config "$PROFILE/pacman.conf" \
+PROFILE_ARGS=(--profile "$PROFILE" --platform "$PLATFORM")
+if [[ $PLATFORM == apple-t2 ]]; then
+ [[ -n ${HARNESS_OS_T2_BUNDLE:-} ]] || { echo 'Prepare the pinned T2 kernel bundle first.' >&2; exit 1; }
+ PROFILE_ARGS+=(--t2-bundle "$HARNESS_OS_T2_BUNDLE")
+fi
+python3 tools/configure-boot-profile.py "${PROFILE_ARGS[@]}"
+REPO_PACKAGES=("$BUILD_DIR/repo/"*.pkg.tar.gz)
+if [[ $PLATFORM == apple-t2 ]]; then
+ REPO_PACKAGES+=("$BUILD_DIR/repo/"*.pkg.tar.zst)
+fi
+repo-add "$BUILD_DIR/repo/harness-build.db.tar.gz" "${REPO_PACKAGES[@]}"
+if [[ $PLATFORM == pc ]]; then
+ python3 tools/build-hardware.py --config "$PROFILE/pacman.conf" \
--work "$BUILD_DIR/hardware-build" \
--output "$PROFILE/airootfs/usr/share/harness-os/hardware/broadcom"
-python3 tools/build-nvidia.py --config "$PROFILE/pacman.conf" \
+ python3 tools/build-nvidia.py --config "$PROFILE/pacman.conf" \
--work "$BUILD_DIR/nvidia-build" \
--output "$PROFILE/airootfs/usr/share/harness-os/hardware/nvidia"
+fi
cp -a live/. "$PROFILE/airootfs/"
mkdir -p "$PROFILE/airootfs/root" "$PROFILE/airootfs/etc/pacman.d/hooks"
cp tools/customize-live.sh "$PROFILE/airootfs/root/setup-live.sh"
@@ -67,7 +81,7 @@ Exec = /bin/bash /root/setup-live.sh
EOF
cat >> "$PROFILE/profiledef.sh" <<EOF
-iso_name="harness"
+iso_name="$([[ $PLATFORM == apple-t2 ]] && echo harness-t2 || echo harness)"
iso_label="HN_OS"
iso_publisher="OpenHarness"
iso_application="Harness: boot into hn"
@@ -79,30 +93,6 @@ file_permissions=(
["/root"]="0:0:750"
)
EOF
-# Use the same LTS kernel in the live USB and on disk.
-python3 - "$PROFILE" <<'PY'
-from pathlib import Path
-import re, sys
-p = Path(sys.argv[1])
-for d in ['syslinux', 'efiboot', 'grub']:
- for f in (p / d).rglob('*'):
- if f.is_file():
- try: s = f.read_text()
- except UnicodeDecodeError: continue
- s = s.replace('vmlinuz-linux', 'vmlinuz-linux-lts').replace('initramfs-linux.img', 'initramfs-linux-lts.img')
- s = s.replace('Arch Linux install medium', 'Install Harness')
- # The 256 MiB Archiso default cannot install even one current agent.
- # tmpfs grows on demand; this is a ceiling, not reserved memory.
- s = s.replace('archisobasedir=%INSTALL_DIR%', 'archisobasedir=%INSTALL_DIR% cow_spacesize=50%')
- # Keep a short opportunity to choose recovery media or firmware tools.
- s = re.sub(r'(?m)^timeout(?:=|\s+)\d+', lambda m: 'timeout=1' if '=' in m[0] else 'timeout 1', s)
- s = re.sub(r'(?m)^TIMEOUT\s+\d+', 'TIMEOUT 10', s) # Syslinux uses tenths of a second.
- s = re.sub(r'(?m)^beep on$', 'beep off', s)
- s = re.sub(r'(?m)^play .*$', '', s)
- s = s.replace('MENU TITLE Arch Linux', 'MENU TITLE Harness')
- s = re.sub(r'(?m)^MENU BACKGROUND .*\n', '', s)
- f.write_text(s)
-PY
chown -R 0:0 "$PROFILE/airootfs"
mkarchiso -v -w "$BUILD_DIR/archiso" -o "$OS_DIR/dist" "$PROFILE"
python3 tools/manifest.py "$OS_DIR/dist" "$BUILD_DIR/archiso/x86_64/airootfs"
diff --git a/os/hardware.py b/os/hardware.py
index d97e3ae50..18284ee8f 100644
--- a/os/hardware.py
+++ b/os/hardware.py
@@ -67,6 +67,16 @@ def installation_blocker(sysfs=Path('/sys')):
# and the currently bound driver. The stock image does not ship its stack.
# https://github.com/t2linux/linux-t2-patches/blob/main/1001-Add-t2bce-driver-stack.patch
if any(device['id'] == '106b:1801' for device in pci_devices(sysfs)):
+ path = Path(__file__).with_name('boot_profile.py')
+ if path.is_file():
+ spec = importlib.util.spec_from_file_location('harness_boot_profile', path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ if module.selected()['id'] == 'apple-t2':
+ pkgbase = Path('/usr/lib/modules') / os.uname().release / 'pkgbase'
+ if read(pkgbase) == 'linux-t2':
+ return None
+ return 'Boot this Mac using the Harness T2 image before installing.'
return 'This Harness image does not support Apple T2 Macs yet.'
return None
diff --git a/os/installer.py b/os/installer.py
index 5e6cd8d1d..3f52f773f 100644
--- a/os/installer.py
+++ b/os/installer.py
@@ -2,7 +2,7 @@
"""Offline full-disk installer. Nothing is erased until the exact disk is confirmed."""
from __future__ import annotations
import argparse
-from contextlib import contextmanager
+from contextlib import contextmanager, ExitStack
import curses
from datetime import datetime, timezone
import hashlib
@@ -38,6 +38,13 @@ def hardware_module():
return hardware
+def boot_module():
+ spec = importlib.util.spec_from_file_location('harness_boot_profile', Path(__file__).with_name('boot_profile.py'))
+ value = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(value)
+ return value
+
+
def require_install_platform(sysfs=Path('/sys')):
blocker = hardware_module().installation_blocker(sysfs)
if blocker:
@@ -247,6 +254,12 @@ def preflight(config, source):
payload = subprocess.check_output(['unsquashfs', '-cat', str(source), kernel['path']], stderr=COMMAND_LOG)
if hashlib.sha256(payload).hexdigest() != kernel['sha256']:
raise ValueError('The installation kernel failed verification. No disk has been erased.')
+ profile = boot_module().selected()
+ if kernel.get('platform', 'pc') != profile['id']:
+ raise ValueError('The installation image uses a different boot platform.')
+ pkgbase = run('unsquashfs', '-cat', source, str(Path(kernel['path']).with_name('pkgbase')), capture=True)
+ if pkgbase.strip() != profile['kernel']:
+ raise ValueError('The installation image has the wrong platform kernel.')
return kernel
@@ -337,6 +350,14 @@ def copy_image(source, target, broadcom=Path('/usr/share/harness-os/hardware/bro
def install(config, source, target, progress=None):
+ # All preserved platform data must outlive disk erasure and be released only
+ # after installation/cleanup completes. There is no user-supplied platform
+ # override: the selected image determines its kernel and preservation needs.
+ with ExitStack() as resources:
+ return install_image(config, source, target, progress, resources)
+
+
+def install_image(config, source, target, progress, resources):
report = progress or (lambda message: print(message, flush=True))
validate_config(config)
require_install_platform()
@@ -350,6 +371,11 @@ def install(config, source, target, progress=None):
raise ValueError('Explicit confirmation of the exact disk is required.')
report('Checking installation files…')
kernel = preflight(config, source)
+ platform = boot_module().selected()
+ preserved = None
+ if platform['id'] == 'apple-t2':
+ report('Preserving this Mac’s wireless firmware…')
+ preserved = resources.enter_context(boot_module().module('t2_install').preserve(config['disk']))
trial = trial_source(config)
selected_disk(config)
pbkdf_memory = encryption_memory() if config['encrypt'] else None
@@ -368,6 +394,10 @@ def install(config, source, target, progress=None):
'-n', '3:0:0', '-t', '3:8309' if config['encrypt'] else '3:8300', '-c', '3:HN ROOT', disk)
run('udevadm', 'settle')
run('mkfs.fat', '-F', '32', '-n', 'HNBOOT', boot)
+ if preserved:
+ # Make the validated firmware discoverable on a retry/reinstall,
+ # before encryption or the larger root copy can fail.
+ boot_module().module('t2_install').persist_boot(boot, preserved)
root_device = root_partition
luks_uuid = None
if config['encrypt']:
@@ -411,7 +441,8 @@ def install(config, source, target, progress=None):
shutil.rmtree(boot_staging)
# mkarchiso moves the live /boot files out of SquashFS. Regenerate the
# disk initramfs around this verified, package-owned kernel instead.
- shutil.copyfile(target / kernel['path'], target / 'boot/vmlinuz-linux-lts')
+ shutil.copyfile(target / kernel['path'], target / ('boot/vmlinuz-' + platform['kernel']))
+ apple_firmware = boot_module().module('t2_install').restore(target, preserved) if preserved else None
report('Setting up your account…')
# The live image is immutable. Only projects is transferred explicitly;
# live account passwords, agent credentials, SSH keys and sessions stay out.
@@ -442,6 +473,9 @@ def install(config, source, target, progress=None):
'HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole '
+ ('plymouth ' if config['encrypt'] else '')
+ 'block sd-encrypt filesystems fsck)\nCOMPRESSION="zstd"\n')
+ if platform['modules']:
+ write(target, '/etc/mkinitcpio.conf.d/20-harness-platform.conf',
+ 'MODULES+=(' + ' '.join(platform['modules']) + ')\n')
write(target, '/etc/vconsole.conf', 'KEYMAP=us\n')
if config['encrypt']:
write(target, '/etc/plymouth/plymouthd.conf',
@@ -462,6 +496,8 @@ def install(config, source, target, progress=None):
# Do not send a person who paused at the prompt into emergency mode.
root_flags = 'subvol=@' + (',x-systemd.device-timeout=0' if config['encrypt'] else '')
kernel_args = f'quiet loglevel=3 rootflags={root_flags}'
+ if platform['parameters']:
+ kernel_args += ' ' + ' '.join(platform['parameters'])
if config.get('serial_console'):
# Keep the screen as /dev/console, as on an ordinary installation.
# Making the diagnostic serial port primary can introduce serial-TTY
@@ -487,7 +523,8 @@ def install(config, source, target, progress=None):
chroot(target, '/usr/lib/harness-os/init-keyring')
# Keep the live marker through this initial optional package transaction,
# so recovery hooks do not checkpoint an unfinished installation.
- run('/usr/bin/python3', '/usr/lib/harness-os/hardware.py', 'configure-install', target)
+ if platform['id'] == 'pc':
+ run('/usr/bin/python3', '/usr/lib/harness-os/hardware.py', 'configure-install', target)
(target / 'etc/harness-live').unlink()
chroot(target, 'mkinitcpio', '-P')
chroot(target, 'grub-install', '--target=i386-pc', '--recheck', disk)
@@ -495,7 +532,10 @@ def install(config, source, target, progress=None):
chroot(target, 'grub-mkconfig', '-o', '/boot/grub/grub.cfg')
receipt = {'version': lock['version'], 'installed_at': datetime.now(timezone.utc).isoformat(),
'duration_seconds': round(time.monotonic() - started, 3), 'encrypted': config['encrypt'],
- 'disk_bytes': selected_size(config), 'root_uuid': root_uuid, 'boot_uuid': boot_uuid}
+ 'disk_bytes': selected_size(config), 'root_uuid': root_uuid, 'boot_uuid': boot_uuid,
+ 'platform': platform['id']}
+ if apple_firmware:
+ receipt['apple_firmware'] = apple_firmware
if pbkdf_memory is not None:
receipt['pbkdf_memory_limit_kib'] = pbkdf_memory
if trial_receipt is not None:
diff --git a/os/platforms/apple-t2/README.md b/os/platforms/apple-t2/README.md
index e560486cd..3d1c7e276 100644
--- a/os/platforms/apple-t2/README.md
+++ b/os/platforms/apple-t2/README.md
@@ -1,8 +1,9 @@
-# Apple T2 platform preparation
+# Apple T2 experimental image
-This directory pins the maintained T2 kernel and its required modules. It is
-preparation for a separate Intel Mac boot profile, not a supported T2 installer.
-The ordinary image still refuses T2 installation before any disk write.
+This directory pins the maintained T2 kernel and its required modules. A separate
+`apple-t2` build profile uses that kernel for both USB and installed boot. It is
+not yet a physically validated Mac release. The ordinary PC image still refuses
+T2 installation before any disk write.
`kernel.json` records the upstream recipe, patch commit and exact release archive.
`prepare-t2-kernel.py` verifies its checksum, package identity, kernel release and
@@ -17,10 +18,12 @@ kernel compatibility, then cold boots and types through the graphical unlock and
Harness. Source, package hashes, boot output and screenshots are retained. A VM
cannot establish that physical T2 devices work.
-Before enabling T2 installation, integrate the same kernel into both USB and
-installed boot, preserve model-specific Apple wireless firmware before erasing
-macOS, and make updates/recovery preserve the selected platform. Then validate
-built-in input, Wi-Fi, audio, graphics and suspend on real Macs. In particular,
+The experimental installer preserves model-specific Apple wireless firmware in
+RAM before erasing macOS, restores it with the installed image, and retains it
+in root checkpoints. A pacman hook restores this board data after firmware
+package updates. Kernel files, early input modules and GRUB parameters follow
+the platform through offline recovery. Physical built-in input, Wi-Fi, audio,
+graphics and suspend still require validation on real Macs. In particular,
iMac Pro firmware needs the macOS export route. Never add a moving unsigned
repository or copy Apple firmware into the public ISO as a shortcut.
@@ -29,7 +32,8 @@ repository or copy Apple firmware into the public ISO as a shortcut.
`os/tools/prepare-t2-firmware.py` is a separate preparation tool. It reads the
Intel Mac's own `/usr/share/firmware` while macOS is running and creates a local
archive. It does not install Harness, mount or change a disk, or enable the T2
-installer. It is not added to the generic PC image.
+installer. The small validation helpers are also packaged for OS updates; no
+Apple firmware or T2 kernel is added to the generic PC image.
From a checkout on the Intel Mac, with Python 3.10 or later already available:
@@ -44,15 +48,21 @@ collected. An iMac Pro export also reads its calibration filenames from IORegist
it stops if those files cannot be identified. Three BCM4377 models additionally
require the Bluetooth firmware available in macOS Monterey or later.
-The future T2 installer can validate the archive against the detected model and
-stage it in a fresh RAM-backed directory before erasing the source disk. The
+The experimental T2 installer validates the archive against the detected model
+and stages it in a fresh RAM-backed directory before erasing the source disk. The
tool's `verify` and `stage` commands implement that data boundary; `--model` is
explicit for development, not an installer override. Archive checks reject links,
special files, unexpected paths, duplicate entries, excessive sizes and altered
inventories. Every staged file has a size and SHA-256 in the retained manifest.
These checks establish local copy integrity, not a signature from Apple or proof
-that a physical radio works. Restoring into the installed system and preserving
-the firmware through updates/recovery remain part of the T2 installer integration.
+that a physical radio works. The archive is retained privately under
+`/var/lib/harness-os/apple-firmware.tar`, and the installation receipt records its
+model and checksum. A second verified copy is written to the newly formatted
+boot partition before encryption or root extraction, so a reinstall can recover
+it after macOS is gone. A failed installation also retains its verified RAM copy
+for the rest of the live session. Checkpoint creation and recovery recheck the
+retained identity. The firmware itself is board data, not user credentials; the
+boot partition copy is unencrypted, like the kernel and initramfs.
The naming rules derive from the MIT-licensed upstream conversion script at
`t2linux/wiki@11fc0a8d8cfb61affd0cb9d1ac245c1b6c16d3cd`; its full SHA-256 is
@@ -60,8 +70,36 @@ The naming rules derive from the MIT-licensed upstream conversion script at
The **Harness OS Apple firmware preservation** workflow checks local CLI round
trips and malformed-input refusal on Linux and macOS, then compares filenames and
bytes with that pinned converter. Fixtures contain invented bytes only. No
-physical Mac's firmware is stored in CI. The existing T2 installation refusal
-remains in place until the USB kernel, installer and recovery path are complete.
+physical Mac's firmware is stored in CI. The ordinary PC image keeps its T2
+installation refusal; only the separate profile running its T2 kernel can proceed.
+
+## Private image acceptance
+
+The **Harness OS T2 image** workflow builds only private artifacts. Its initial
+candidate requires the exact public preview 14 `tui/`, `cli/` and `store/` source
+trees while shared products are being refactored. The image checksum and full
+payload are inspected before a native KVM journey. Synthetic Mac DMI and invented
+firmware exercise refusal before erasure, an encrypted offline install, the real
+firmware package hook, graphical unlock, keyboard input and offline checkpoint
+recovery. These fixtures do not emulate T2 hardware or establish Mac support.
+
+On the target Mac, an export named `harness-apple-firmware.tar` can be placed at
+the root of its EFI partition before booting the experimental image. The installer
+only mounts that partition read-only. Alternatively, it searches read-only APFS
+volumes for the Mac's own `/usr/share/firmware`; FileVault or an inaccessible
+volume may prevent this route. An iMac Pro requires the explicit macOS export.
+Missing or invalid firmware stops installation before partitioning.
+
+Build with `HARNESS_OS_PLATFORM=apple-t2` and `HARNESS_OS_T2_BUNDLE` pointing to a
+fresh verified bundle from `prepare-t2-kernel.py`. The output is named
+`harness-t2-<version>-x86_64.iso`. The default PC build and its NVIDIA/Broadcom
+bundle selection are unchanged.
+
+The initial image retains its pinned T2 kernel during ordinary Arch updates.
+An OS update must retain the T2 helpers and the identical kernel pin; older PC
+packages and a changed pin are refused before mutation. Automatic T2 kernel
+upgrades need a separately validated download/transaction path before this image
+can become a supported release. Do not add a moving unsigned repository.
Upstream references: [maintained kernel](https://github.com/NoaHimesaka1873/linux-t2-arch),
[early input and kernel parameters](https://wiki.t2linux.org/guides/postinstall/),
diff --git a/os/runtime_update.py b/os/runtime_update.py
index 280f35389..dac3a374a 100644
--- a/os/runtime_update.py
+++ b/os/runtime_update.py
@@ -23,6 +23,8 @@ RUNTIME = Path('/usr/share/harness-os/runtime.json')
LOCK = Path('/usr/share/harness-os/lock.json')
PACKAGE_DB = Path('/var/lib/pacman/local')
RESTART_REQUIRED = Path('/run/harness-os-restart-required')
+BOOTSTRAP_FILES = ('apply-update.py', 'boot_profile.py', 't2_install.py',
+ 't2_firmware.py', 'firmware_names.py')
def digest(path):
@@ -47,6 +49,13 @@ def system_module():
return module
+def boot_module():
+ spec = importlib.util.spec_from_file_location('harness_boot_profile', Path(__file__).with_name('boot_profile.py'))
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
def relative_path(value):
path = PurePosixPath(value)
if path.is_absolute() or '..' in path.parts or not path.parts or str(path) != value.rstrip('/'):
@@ -139,6 +148,7 @@ def validate_bundle(folder, base):
if path.is_symlink() or not path.is_file() or package.get('bytes') != path.stat().st_size or digest(path) != package.get('sha256'):
raise ValueError('Package checksum or size mismatch; download the complete bundle again.')
inspect_package(path, version, runtime)
+ boot_module().validate_update(path)
return manifest, path
@@ -221,6 +231,7 @@ def apply(folder, system, base, installation):
if previous and previous['status'] not in ('applied', 'rolled-back'):
raise ValueError('The previous Harness update did not finish. Run rollback first; its checkpoint is retained.')
manifest, source_package = validate_bundle(folder, base)
+ boot = boot_module()
target_date = system.snapshot_date(manifest['arch_snapshot'])
if target_date > base['arch_snapshot']:
dates = set(re.findall(r'https://archive\.archlinux\.org/repos/(\d{4}/\d{2}/\d{2})/', system.PACMAN_CONFIG.read_text()))
@@ -256,6 +267,7 @@ def apply(folder, system, base, installation):
# installed OS integration. /run clears this only on a real reboot.
system.write_json(RESTART_REQUIRED, {'status': 'applying', 'package': manifest['package']['version']})
install_package(incoming / source_package.name, manifest['package']['version'], manifest['runtime'])
+ boot.restore_firmware()
# Plymouth and other initramfs assets may change without a kernel
# package transaction, so rebuild them on this path as well.
system.run('mkinitcpio', '-P')
@@ -285,10 +297,15 @@ def rollback(system, installation):
if digest(backup) != receipt['backup_sha256']:
raise ValueError('Rollback package checksum mismatch. Recover the recorded checkpoint from the live USB.')
inspect_package(backup, receipt['previous_version'], receipt['previous_runtime'])
+ # A legacy PC rollback removes the new platform helpers from disk. Retain
+ # the loaded helper until this transaction finishes using it.
+ boot = boot_module()
+ boot.validate_update(backup)
receipt.update(status='rolling-back', rollback_started_at=now())
system.write_json(folder / 'receipt.json', receipt)
system.write_json(RESTART_REQUIRED, {'status': 'failed'})
install_package(backup, receipt['previous_version'], receipt['previous_runtime'])
+ boot.restore_firmware()
system.run('mkinitcpio', '-P')
receipt.update(status='rolled-back', rollback_finished_at=now())
system.write_json(folder / 'receipt.json', receipt)
diff --git a/os/system.py b/os/system.py
index 359be0e6f..097ce3c9f 100644
--- a/os/system.py
+++ b/os/system.py
@@ -6,6 +6,7 @@ from contextlib import contextmanager
from datetime import datetime, timedelta, timezone
import fcntl
import hashlib
+import importlib.util
import json
import os
from pathlib import Path
@@ -21,6 +22,13 @@ UPDATE_RECEIPT = Path('/var/lib/harness-os/update.json')
CHECKPOINTS = Path('/.snapshots')
+def boot_module():
+ spec = importlib.util.spec_from_file_location('harness_boot_profile', Path(__file__).with_name('boot_profile.py'))
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
def run(*args, capture=False):
return subprocess.run([str(a) for a in args], check=True, text=True,
stdout=subprocess.PIPE if capture else None).stdout
@@ -79,7 +87,7 @@ def validate_checkpoint(meta, root_uuid):
raise ValueError('Checkpoint belongs to a different root filesystem.')
if not re.fullmatch(r'[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}', meta.get('boot_uuid', '')):
raise ValueError('Checkpoint has an invalid boot partition identifier.')
- required = {'vmlinuz-linux-lts', 'initramfs-linux-lts.img', 'grub/grub.cfg'}
+ required = boot_module().boot_files(meta.get('platform', 'pc'))
if not required.issubset(meta.get('boot_sha256', {})):
raise ValueError('Checkpoint is missing the kernel, initramfs or boot configuration.')
@@ -134,6 +142,11 @@ def checkpoint(reason='manual', pacman_hook=False):
if pacman_hook and pending_update():
raise ValueError('A full system update did not finish. Run sudo hn-os update to complete it before changing packages, or recover its checkpoint from the live USB.')
info = installed()
+ platform = boot_module().selected()
+ if info.get('platform', 'pc') != platform['id']:
+ raise ValueError('The installed system and its boot platform differ.')
+ if platform['id'] == 'apple-t2':
+ boot_module().module('t2_install').retained()
if Path('/var/lib/pacman/db.lck').exists() and not pacman_hook:
raise ValueError('Wait for the active package transaction before making a checkpoint.')
name = datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ-') + uuid.uuid4().hex[:8]
@@ -146,7 +159,7 @@ def checkpoint(reason='manual', pacman_hook=False):
shutil.copytree('/boot', pending / 'boot')
metadata = {'name': name, 'created_at': datetime.now(timezone.utc).isoformat(),
'reason': reason, 'root_uuid': info['root_uuid'], 'boot_uuid': info['boot_uuid'],
- 'boot_sha256': boot_hashes(pending / 'boot')}
+ 'boot_sha256': boot_hashes(pending / 'boot'), 'platform': platform['id']}
validate_checkpoint(metadata, info['root_uuid'])
write_json(pending / 'checkpoint.json', metadata)
run('sync')
@@ -203,6 +216,12 @@ def update(date, *, noninteractive=False):
command.append('--noconfirm')
result = subprocess.run(command, stdin=subprocess.DEVNULL if noninteractive else None,
env=dict(os.environ, HN_OS_UPDATE_CHECKPOINT='1'))
+ if result.returncode == 0 and boot_module().selected()['id'] == 'apple-t2':
+ # Package updates must not replace Apple board data with generic radio
+ # fallbacks. Keep the saved private bundle in the root snapshot too.
+ boot_module().restore_firmware()
+ run('mkinitcpio', '-P')
+ run('grub-mkconfig', '-o', '/boot/grub/grub.cfg')
receipt.update(finished_at=datetime.now(timezone.utc).isoformat(), exit_status=result.returncode)
write_json(UPDATE_RECEIPT, receipt)
if result.returncode:
@@ -255,6 +274,10 @@ def recover(device, name=None):
meta = read_json(chosen / 'checkpoint.json')
actual_uuid = run('blkid', '-s', 'UUID', '-o', 'value', device, capture=True).strip()
validate_checkpoint(meta, actual_uuid)
+ if boot_module().selected(chosen / 'root')['id'] != meta.get('platform', 'pc'):
+ raise ValueError('Checkpoint root has a different boot platform.')
+ if meta.get('platform', 'pc') == 'apple-t2':
+ boot_module().module('t2_install').retained(chosen / 'root')
if boot_hashes(chosen / 'boot') != meta['boot_sha256']:
raise ValueError('Checkpoint boot-file checksums do not match. Nothing restored.')
boot_device = Path('/dev/disk/by-uuid') / meta['boot_uuid']
diff --git a/os/t2_install.py b/os/t2_install.py
new file mode 100644
index 000000000..9a4d247d4
--- /dev/null
+++ b/os/t2_install.py
@@ -0,0 +1,230 @@
+"""Preserve a T2 Mac's wireless firmware before a whole-disk installation."""
+from contextlib import contextmanager
+import hashlib
+import importlib.util
+import json
+import os
+from pathlib import Path
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+
+def helper():
+ path = Path(__file__).with_name('t2_firmware.py')
+ if not path.is_file():
+ path = Path(__file__).parent / 'tools/prepare-t2-firmware.py'
+ spec = importlib.util.spec_from_file_location('harness_t2_firmware', path)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ return module
+
+
+def model(sysfs=Path('/sys')):
+ value = (sysfs / 'class/dmi/id/product_name').read_text().strip()
+ helper().check_model(value)
+ return value
+
+
+def run(*args, **kwargs):
+ return subprocess.run([str(arg) for arg in args], check=True, timeout=20, **kwargs)
+
+
+def partitions(disk):
+ data = json.loads(run('lsblk', '--json', '--paths', '--output', 'NAME,TYPE,FSTYPE', disk,
+ stdout=subprocess.PIPE, text=True).stdout)
+ devices = data.get('blockdevices', [])
+ if len(devices) != 1 or devices[0].get('name') != disk or devices[0].get('type') != 'disk':
+ raise ValueError('Cannot identify the Mac disk before firmware preservation.')
+ result = []
+ for child in devices[0].get('children', []):
+ name = child.get('name', '')
+ if child.get('type') != 'part' or not re.fullmatch(r'/dev/[a-zA-Z0-9_-]+', name):
+ raise ValueError('Unexpected Mac disk partition.')
+ if child.get('fstype') in {'vfat', 'apfs'}:
+ result.append((name, child['fstype']))
+ return result
+
+
+@contextmanager
+def mounted(device, kind, folder, volume=None):
+ options = 'ro,nosuid,nodev,noexec'
+ if volume is not None:
+ options += ',vol=' + str(volume)
+ run('mount', '-t', kind, '-o', options, device, folder, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ try:
+ yield folder
+ finally:
+ # Never erase or clean a still-mounted macOS filesystem. A failure here
+ # propagates out of preparation, before the installer can partition.
+ run('umount', folder)
+
+
+def find_bundle(disk, work, expected_model, exports=None):
+ firmware = helper()
+ # A preserved export on the live medium is read as data, never as a script.
+ # An already installed system can supply its own private preserved bundle.
+ if exports is None:
+ exports = [Path('/run/archiso/bootmnt/harness-apple-firmware.tar'),
+ Path('/var/lib/harness-os/apple-firmware.tar')]
+ for path in exports:
+ if path.exists():
+ firmware.verify(path, expected_model)
+ return path
+ failures = []
+ mountpoint = work / 'source'
+ mountpoint.mkdir()
+ for device, kind in partitions(disk):
+ for volume in (range(6) if kind == 'apfs' else (None,)):
+ # Failed mounts are expected when probing APFS volume slots. A
+ # failed unmount is never swallowed; the caller must not erase.
+ try:
+ context = mounted(device, kind, mountpoint, volume)
+ context.__enter__()
+ except subprocess.SubprocessError:
+ if mountpoint.is_mount():
+ raise ValueError('A macOS volume is still mounted. No disk has been erased.')
+ continue
+ try:
+ bundle = mountpoint / 'harness-apple-firmware.tar'
+ if kind == 'vfat' and bundle.is_file():
+ firmware.verify(bundle, expected_model)
+ destination = work / 'preserved.tar'
+ shutil.copyfile(bundle, destination)
+ firmware.verify(destination, expected_model)
+ return destination
+ source = mountpoint / 'usr/share/firmware'
+ if kind == 'apfs' and source.is_dir() and expected_model != 'iMacPro1,1':
+ destination = work / 'preserved.tar'
+ firmware.prepare(source, destination, expected_model)
+ return destination
+ except (OSError, ValueError) as error:
+ failures.append(str(error))
+ (work / 'preserved.tar').unlink(missing_ok=True)
+ finally:
+ context.__exit__(None, None, None)
+ message = 'Preserve this Mac’s Wi-Fi firmware from macOS before installing Harness. No disk has been erased.'
+ if failures:
+ message += ' ' + failures[-1]
+ raise ValueError(message)
+
+
+@contextmanager
+def preserve(disk, expected_model=None, *, runtime=Path('/run')):
+ expected_model = expected_model or model()
+ helper().check_model(expected_model)
+ # /run is RAM-backed on the live system. Nothing here depends on a disk
+ # that is about to be erased, or on the user's projects/home directory.
+ work = Path(tempfile.mkdtemp(prefix='harness-apple-', dir=runtime))
+ prepared = succeeded = False
+ try:
+ bundle = find_bundle(disk, work, expected_model)
+ private = work / 'verified.tar'
+ shutil.copyfile(bundle, private)
+ manifest, _ = helper().verify(private, expected_model)
+ helper().stage(private, work / 'verified', expected_model)
+ prepared = True
+ yield {'bundle': private, 'manifest': manifest}
+ succeeded = True
+ except BaseException as error:
+ if prepared:
+ error.add_note('The verified Mac firmware remains in ' + str(work / 'verified.tar'))
+ raise
+ finally:
+ if (work / 'source').is_mount():
+ raise ValueError('A macOS volume could not be unmounted. Preserved files remain in ' + str(work))
+ if not prepared or succeeded:
+ shutil.rmtree(work)
+
+
+def persist_boot(device, preserved):
+ """Retain a verified reinstall copy on the freshly formatted boot partition."""
+ firmware = helper()
+ firmware.verify(preserved['bundle'], preserved['manifest']['model'])
+ folder = Path(tempfile.mkdtemp(prefix='harness-apple-boot-', dir='/run'))
+ mounted = False
+ try:
+ run('mount', '-t', 'vfat', '-o', 'rw,nosuid,nodev,noexec', device, folder)
+ mounted = True
+ target = folder / 'harness-apple-firmware.tar'
+ with target.open('xb') as output, preserved['bundle'].open('rb') as source:
+ shutil.copyfileobj(source, output)
+ output.flush()
+ os.fsync(output.fileno())
+ manifest, _ = firmware.verify(target, preserved['manifest']['model'])
+ if manifest != preserved['manifest']:
+ raise ValueError('The boot partition firmware copy failed verification.')
+ finally:
+ if mounted:
+ run('umount', folder)
+ # Never recurse into a still-mounted boot volume after an error.
+ if not folder.is_mount():
+ folder.rmdir()
+
+
+def restore(target, preserved):
+ """Copy only validated wireless data into a new image or managed root."""
+ firmware = helper()
+ manifest, files = firmware.verify(preserved['bundle'], preserved['manifest']['model'])
+ if manifest != preserved['manifest']:
+ raise ValueError('Preserved Apple firmware changed before restoration.')
+ folder = target / 'usr/lib/firmware/brcm'
+ for path in [target / 'usr', target / 'usr/lib', target / 'usr/lib/firmware', folder]:
+ if path.is_symlink():
+ raise ValueError('Firmware restoration requires real system directories.')
+ path.mkdir(exist_ok=True)
+ for name, data in files.items():
+ path = folder / name
+ # These exact files are model data selected before erasure. Replace a
+ # package's fallback link/file without ever following its destination.
+ temporary = folder / ('.harness-' + name)
+ fd = os.open(temporary, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, 0o644)
+ try:
+ with os.fdopen(fd, 'wb') as handle:
+ handle.write(data)
+ handle.flush()
+ os.fsync(handle.fileno())
+ temporary.replace(path)
+ finally:
+ temporary.unlink(missing_ok=True)
+ if firmware.identity(firmware.regular_bytes(path, firmware.MAX_FILE)) != manifest['files'][name]:
+ raise ValueError('Installed Apple firmware failed its readback check.')
+ state = target / 'var/lib/harness-os'
+ for path in [target / 'var', target / 'var/lib', state]:
+ if path.is_symlink():
+ raise ValueError('Firmware state requires real system directories.')
+ path.mkdir(exist_ok=True)
+ saved = state / 'apple-firmware.tar'
+ if saved != preserved['bundle']:
+ if saved.is_symlink():
+ raise ValueError('Preserved firmware state must not be a symbolic link.')
+ shutil.copyfile(preserved['bundle'], saved)
+ saved.chmod(0o600)
+ firmware.verify(saved, manifest['model'])
+ return {'model': manifest['model'], 'files': len(files),
+ 'sha256': hashlib.sha256(saved.read_bytes()).hexdigest()}
+
+
+def retained(root=Path('/')):
+ bundle = root / 'var/lib/harness-os/apple-firmware.tar'
+ # The model is recorded when installation succeeds. Do not guess from the
+ # recovery computer's hardware, which may be a different machine.
+ info = json.loads((root / 'var/lib/harness-os/install.json').read_text())
+ expected = info['apple_firmware']
+ manifest, _ = helper().verify(bundle, expected['model'])
+ if hashlib.sha256(bundle.read_bytes()).hexdigest() != expected['sha256']:
+ raise ValueError('The saved Mac firmware failed verification.')
+ return {'bundle': bundle, 'manifest': manifest}
+
+
+if __name__ == '__main__':
+ if sys.argv[1:] != ['restore'] or os.geteuid() != 0:
+ raise SystemExit('Use the installed system’s firmware update hook.')
+ # Initial image assembly has no machine-specific export or installation.
+ if Path('/var/lib/harness-os/install.json').is_file():
+ try:
+ restore(Path('/'), retained())
+ except (OSError, ValueError, KeyError, TypeError) as error:
+ raise SystemExit('Mac firmware restoration failed: ' + str(error))
diff --git a/os/tests/hardware_install_vm.py b/os/tests/hardware_install_vm.py
index 7896b4f5d..5cc0140b8 100644
--- a/os/tests/hardware_install_vm.py
+++ b/os/tests/hardware_install_vm.py
@@ -80,6 +80,10 @@ def main():
'--candidate-sha256', candidate['sha256']]
if args.candidate_installer:
candidate = receipt['candidate_installer']
+ helper = args.candidate_installer.with_name('boot_profile.py')
+ receipt['candidate_boot_profile'] = candidate_record(helper)
+ copy_file(vm, helper.read_bytes(), '/usr/lib/harness-os/boot_profile.py')
+ assert hashlib.sha256(vm.read_file('/usr/lib/harness-os/boot_profile.py')).hexdigest() == receipt['candidate_boot_profile']['sha256']
copy_file(vm, args.candidate_installer.read_bytes(), '/run/installer-candidate.py')
command += ['--candidate-installer', '/run/installer-candidate.py',
'--installer-sha256', candidate['sha256']]
diff --git a/os/tests/hardware_update_guest.py b/os/tests/hardware_update_guest.py
index a716f1252..c3dadeaba 100644
--- a/os/tests/hardware_update_guest.py
+++ b/os/tests/hardware_update_guest.py
@@ -307,6 +307,7 @@ def install(lock, candidate_path):
installed_system = target / SYSTEM.relative_to('/')
assert digest(installed_system) == result['image_system_sha256']
installed_system.write_bytes(candidate_path.read_bytes())
+ installed_system.with_name('boot_profile.py').write_bytes(candidate_path.with_name('boot_profile.py').read_bytes())
# Apply before the first installed boot; no public feed may replace the
# frozen runtime. These are private fixture settings in the root snapshot.
for name in MASKS:
diff --git a/os/tests/hardware_update_vm.py b/os/tests/hardware_update_vm.py
index 13b76dd5d..936530d5d 100644
--- a/os/tests/hardware_update_vm.py
+++ b/os/tests/hardware_update_vm.py
@@ -146,6 +146,10 @@ def main():
manifest = verify_image(args.iso.resolve(), lock)
candidate = candidate_record(args.candidate_system)
assert candidate['path'] == 'os/system.py', 'Only the OS update/recovery helper may be overlaid'
+ boot_helper = args.candidate_system.with_name('boot_profile.py')
+ boot_candidate = candidate_record(boot_helper)
+ assert boot_candidate['path'] == 'os/boot_profile.py'
+ assert boot_candidate['source_commit'] == candidate['source_commit']
sources = {name: candidate_record(Path(__file__).with_name(name)) for name in
('hardware_update_vm.py', 'hardware_update_guest.py',
'vm.py', 'footprint_vm.py', 'hardware_install_vm.py')}
@@ -160,7 +164,8 @@ def main():
config = dict(username='me', password='test-password-123', encrypt=True)
receipt = {'status': 'running', 'started_at': time.time(), 'image_source_commit': manifest['source_commit'],
'image_run_id': lock['baseline']['image_run_id'], 'iso': lock['baseline']['iso'],
- 'candidate_system': candidate, 'test_sources': sources, 'memory_mib': 2048, 'firmware': 'uefi',
+ 'candidate_system': candidate, 'candidate_boot_profile': boot_candidate,
+ 'test_sources': sources, 'memory_mib': 2048, 'firmware': 'uefi',
'limits': ['Full-upgrade API, not public Update UI activation.',
'Synthetic PCI selection and real software hooks, no physical radio or GPU.',
'Combined driver row does not prove NVIDIA-only dependency footprint.',
@@ -225,12 +230,14 @@ def main():
vm.command('stty -echo; nmcli networking off')
transfer(True)
copy_file(vm, args.candidate_system.read_bytes(), '/run/system-candidate.py')
+ copy_file(vm, boot_helper.read_bytes(), '/run/boot_profile.py')
receipt['installation'] = guest('install', live=True, extra=('--candidate-system', '/run/system-candidate.py'), seconds=360)
assert receipt['installation']['candidate_system_sha256'] == candidate['sha256']
vm.screenshot('01-installed-offline')
graceful_stop(vm, False)
installed_boot('baseline')
+ assert hashlib.sha256(vm.read_file('/usr/lib/harness-os/boot_profile.py')).hexdigest() == boot_candidate['sha256']
baseline = guest('baseline')
assert baseline['system_sha256'] == candidate['sha256']
live = guest('live-start')
@@ -273,6 +280,8 @@ def main():
original = hashlib.sha256(vm.read_file(str(Path('/usr/lib/harness-os/system.py')))).hexdigest()
assert original == receipt['installation']['image_system_sha256']
copy_file(vm, args.candidate_system.read_bytes(), '/usr/lib/harness-os/system.py')
+ copy_file(vm, boot_helper.read_bytes(), '/usr/lib/harness-os/boot_profile.py')
+ assert hashlib.sha256(vm.read_file('/usr/lib/harness-os/boot_profile.py')).hexdigest() == boot_candidate['sha256']
receipt['recovery_system_sha256'] = hashlib.sha256(vm.read_file('/usr/lib/harness-os/system.py')).hexdigest()
assert receipt['recovery_system_sha256'] == candidate['sha256']
vm.command('printf %s ' + shlex.quote(config['password']) + ' | cryptsetup open --key-file=- /dev/vda3 hn-recovery')
diff --git a/os/tests/nvidia_install_vm.py b/os/tests/nvidia_install_vm.py
index 5099a6451..4450b4fda 100644
--- a/os/tests/nvidia_install_vm.py
+++ b/os/tests/nvidia_install_vm.py
@@ -58,7 +58,7 @@ def main():
if args.candidate_bundle:
source = Path(__file__).resolve().parents[1]
receipt['candidate_sha256'] = {}
- for local, guest in [('hardware.py', 'hardware.py'), ('installer.py', 'install.py')]:
+ for local, guest in [('hardware.py', 'hardware.py'), ('installer.py', 'install.py'), ('boot_profile.py', 'boot_profile.py')]:
copy_file(vm, (source / local).read_bytes(), '/usr/lib/harness-os/' + guest)
receipt['candidate_sha256'][local] = digest(source / local)
# Stream once into the writable overlay; never store a second 325 MiB copy.
diff --git a/os/tests/platform_preflight_guest.py b/os/tests/platform_preflight_guest.py
index 0370f4a68..9dfd2003b 100644
--- a/os/tests/platform_preflight_guest.py
+++ b/os/tests/platform_preflight_guest.py
@@ -67,6 +67,7 @@ def main():
'real_dmi': report['computer'], 'fixture_pci_ids': [device['id'] for device in report['pci']],
'hardware_sha256': hashlib.sha256(hardware_path.read_bytes()).hexdigest(),
'installer_sha256': hashlib.sha256(installer_path.read_bytes()).hexdigest(),
+ 'boot_profile_sha256': hashlib.sha256(installer_path.with_name('boot_profile.py').read_bytes()).hexdigest(),
'elapsed_seconds': round(time.monotonic() - started, 3),
}), flush=True)
diff --git a/os/tests/platform_preflight_vm.py b/os/tests/platform_preflight_vm.py
index 4d746ba97..e58931521 100644
--- a/os/tests/platform_preflight_vm.py
+++ b/os/tests/platform_preflight_vm.py
@@ -51,7 +51,8 @@ def main():
folder.mkdir(parents=True, exist_ok=False)
(folder / 'image-manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
root = Path(__file__).resolve().parents[1]
- candidates = {'hardware': root / 'hardware.py', 'installer': root / 'installer.py'}
+ candidates = {'hardware': root / 'hardware.py', 'installer': root / 'installer.py',
+ 'boot_profile': root / 'boot_profile.py'}
scripts = ['platform_preflight_vm.py', 'platform_preflight_guest.py', 'vm.py',
'footprint_vm.py', 'hardware_install_vm.py', 'session_vm.py']
receipt = dict(status='running', started_at=time.time(), image_source_commit=manifest['source_commit'],
@@ -82,8 +83,13 @@ def main():
vm.command('test ! -e /mnt/harness-os && test "$(id -u me)" = 1000')
receipt['original_image_files'] = {}
for name, source in candidates.items():
- destination = '/usr/lib/harness-os/' + ('install.py' if name == 'installer' else 'hardware.py')
- receipt['original_image_files'][name] = hashlib.sha256(vm.read_file(destination)).hexdigest()
+ destination = '/usr/lib/harness-os/' + ('install.py' if name == 'installer' else name + '.py')
+ _, exists = vm.command('test -f ' + shlex.quote(destination), check=False)
+ if exists:
+ assert exists == 1 and name == 'boot_profile', 'Unexpected missing baseline file: ' + name
+ receipt['original_image_files'][name] = None # Published PC image predates this helper.
+ else:
+ receipt['original_image_files'][name] = hashlib.sha256(vm.read_file(destination)).hexdigest()
copy_file(vm, source.read_bytes(), destination)
actual = hashlib.sha256(vm.read_file(destination)).hexdigest()
assert actual == receipt['candidates'][name]['sha256']
diff --git a/os/tests/release_update_vm.py b/os/tests/release_update_vm.py
index b9f309790..5f37f803c 100644
--- a/os/tests/release_update_vm.py
+++ b/os/tests/release_update_vm.py
@@ -9,17 +9,34 @@ import time
from session_vm import put, PROBE
+def relocate_boot_loader(source, directory):
+ """Keep candidate-only dependencies outside the legacy package's file set."""
+ directory = Path(directory)
+ if not directory.is_absolute():
+ raise ValueError('The private bootstrap directory must be absolute')
+ original = "Path(__file__).with_name('boot_profile.py')"
+ if source.count(original) != 1:
+ raise ValueError('The candidate boot loader changed; review its fixture relocation')
+ return source.replace(original, 'Path(' + repr(str(directory / 'boot_profile.py')) + ')')
+
+
def exercise(vm, manifest, config):
# Retain the new bootstrap outside pacman-owned paths before restoring the
# public preview. It has no updater; this is its one-time migration path.
vm.command('mkdir -p /tmp/system-channel; cp /usr/lib/harness-os/release_update.py '
'/usr/lib/harness-os/runtime_update.py /usr/lib/harness-os/system.py /usr/lib/harness-os/live_update.py '
+ '/usr/lib/harness-os/boot_profile.py /usr/lib/harness-os/t2_install.py '
+ '/usr/lib/harness-os/t2_firmware.py /usr/lib/harness-os/firmware_names.py '
'/usr/lib/harness-os/open-updates /tmp/system-channel/; '
'sudo cat /etc/sudoers.d/30-harness-updates > /tmp/system-channel/30-harness-updates')
source = Path(__file__).resolve().parents[1]
helper_hashes = {}
- for name in ['system.py', 'release_update.py', 'runtime_update.py', 'live_update.py']:
- expected = hashlib.sha256((source / name).read_bytes()).hexdigest()
+ helpers = {name: name for name in ['system.py', 'release_update.py', 'runtime_update.py',
+ 'live_update.py', 'boot_profile.py', 't2_install.py']}
+ helpers.update({'t2_firmware.py': 'tools/prepare-t2-firmware.py',
+ 'firmware_names.py': 'platforms/apple-t2/firmware_names.py'})
+ for name, relative in helpers.items():
+ expected = hashlib.sha256((source / relative).read_bytes()).hexdigest()
assert hashlib.sha256(vm.read_file('/tmp/system-channel/' + name)).hexdigest() == expected, \
'The candidate package contains a different updater: ' + name
helper_hashes[name] = expected
@@ -82,8 +99,22 @@ metadata = dict(schema=1, channel='preview', architecture='x86_64',
# Restore the candidate UI on the old package solely to exercise its new
# combined action. Only the root helper's parser default uses the private
# loopback feed; the shipped helper never accepts a user-owned feed cache.
+ # This case tests the candidate's combined action on the old package, after
+ # the independent real bootstrap/rollback checks. Its system updater must
+ # match the new caller (the old update() has no noninteractive argument).
+ # Keep new dependencies in a root-owned private directory so pacman can
+ # install its actual files without an "exists in filesystem" collision.
+ baseline_system_sha256 = hashlib.sha256(vm.read_file('/usr/lib/harness-os/system.py')).hexdigest()
+ output, _ = vm.command('printf "HN_UPDATE_BOOTSTRAP=%s\\n" "$(sudo mktemp -d /tmp/harness-update-bootstrap.XXXXXXXX)"')
+ match = re.search(r'HN_UPDATE_BOOTSTRAP=(/tmp/harness-update-bootstrap\.[A-Za-z0-9]+)', output)
+ assert match, 'The private root bootstrap directory was not created'
+ bootstrap = match[1]
+ for name in ['boot_profile.py', 't2_install.py', 't2_firmware.py', 'firmware_names.py']:
+ vm.command('sudo install -m 644 ' + shlex.quote('/tmp/system-channel/' + name) + ' ' + shlex.quote(bootstrap + '/' + name))
+ system_helper = relocate_boot_loader(vm.read_file('/tmp/system-channel/system.py').decode(), bootstrap)
+ put(vm, '/tmp/system-channel/test-system-helper.py', system_helper)
vm.command('sudo install -m 644 /tmp/system-channel/live_update.py /usr/lib/harness-os/live_update.py; '
- 'sudo install -m 644 /tmp/system-channel/system.py /usr/lib/harness-os/system.py; '
+ 'sudo install -m 644 /tmp/system-channel/test-system-helper.py /usr/lib/harness-os/system.py; '
'sudo install -m 755 /tmp/system-channel/open-updates /usr/lib/harness-os/open-updates; '
# The old package does not own the new policy path. Use a
# fixture-only name so pacman can install its actual owned file
@@ -96,7 +127,7 @@ metadata = dict(schema=1, channel='preview', architecture='x86_64',
put(vm, '/tmp/system-channel/test-release-helper.py', helper)
vm.command('sudo install -m 644 /tmp/system-channel/test-release-helper.py /usr/lib/harness-os/release_update.py; '
'sudo visudo -c -f /etc/sudoers')
- for name, expected in [('system.py', helper_hashes['system.py']),
+ for name, expected in [('system.py', hashlib.sha256(system_helper.encode()).hexdigest()),
('release_update.py', hashlib.sha256(helper.encode()).hexdigest())]:
assert hashlib.sha256(vm.read_file('/usr/lib/harness-os/' + name)).hexdigest() == expected, \
'The test helper was not activated: ' + name
@@ -140,6 +171,11 @@ metadata = dict(schema=1, channel='preview', architecture='x86_64',
public_retry = json.loads(vm.read_file('/tmp/system-channel/public-retry.json'))
assert public_retry['status'] == 'passed' and public_retry['runtime_update']['candidate'] == manifest
public_retry['candidate_helpers_sha256'] = helper_hashes
+ public_retry['baseline_system_sha256'] = baseline_system_sha256
+ public_retry['private_system_helper'] = {'path': '/usr/lib/harness-os/system.py',
+ 'sha256': hashlib.sha256(system_helper.encode()).hexdigest(),
+ 'boot_loader_directory': bootstrap,
+ 'scope': 'Candidate system helper with only its boot dependency path relocated; real legacy upgrade and rollback are separate checks'}
public_retry['private_feed_helper'] = {'path': '/usr/lib/harness-os/release_update.py',
'sha256': hashlib.sha256(helper.encode()).hexdigest()}
public_retry['fixture_sha256'] = fixture_hashes
diff --git a/os/tests/t2_install_guest.py b/os/tests/t2_install_guest.py
new file mode 100644
index 000000000..79714e2de
--- /dev/null
+++ b/os/tests/t2_install_guest.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python3
+"""Guest-side T2 preservation evidence using invented firmware bytes only."""
+import hashlib
+import importlib.util
+import io
+import json
+import os
+from pathlib import Path
+import subprocess
+import sys
+import tarfile
+import tempfile
+
+
+def module(name):
+ spec = importlib.util.spec_from_file_location(name, '/usr/lib/harness-os/' + name + '.py')
+ value = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(value)
+ return value
+
+
+def verify():
+ t2, system, boot = module('t2_install'), module('system'), module('boot_profile')
+ assert boot.selected()['id'] == 'apple-t2'
+ saved = t2.retained()
+ manifest, files = t2.helper().verify(saved['bundle'], saved['manifest']['model'])
+ boot_bundle = Path('/boot/harness-apple-firmware.tar')
+ assert boot_bundle.read_bytes() == saved['bundle'].read_bytes()
+ for name, expected in files.items():
+ path = Path('/usr/lib/firmware/brcm') / name
+ assert not path.is_symlink() and path.read_bytes() == expected, name
+ record = {'model': manifest['model'], 'files': len(files),
+ 'firmware_sha256': hashlib.sha256(saved['bundle'].read_bytes()).hexdigest(),
+ 'boot_sha256': system.boot_hashes(Path('/boot'))}
+ system.validate_checkpoint({'platform': 'apple-t2', **system.installed(), 'boot_sha256': record['boot_sha256']},
+ system.installed()['root_uuid'])
+ return record
+
+
+def package():
+ verify()
+ t2 = module('t2_install')
+ saved = t2.retained()
+ _, files = t2.helper().verify(saved['bundle'], saved['manifest']['model'])
+ # The deliberate overwrite is restricted to one synthetic fixture file in
+ # this VM. No live Apple firmware or user data participates in CI.
+ name = next(iter(sorted(files)))
+ path = 'usr/lib/firmware/brcm/' + name
+ process = subprocess.check_output(['pgrep', '-xo', 'hn|harness-tui'], text=True).strip()
+ with tempfile.TemporaryDirectory(prefix='t2-update-fixture-') as temp:
+ archive = Path(temp) / 'linux-firmware-harness-fixture-1-1-any.pkg.tar.gz'
+ with tarfile.open(archive, 'w:gz') as output:
+ entries = {'.PKGINFO': b'pkgname = linux-firmware-harness-fixture\npkgver = 1-1\narch = any\n',
+ path: b'package fallback fixture'}
+ for name, data in entries.items():
+ entry = tarfile.TarInfo(name)
+ entry.size, entry.mode = len(data), 0o644
+ output.addfile(entry, io.BytesIO(data))
+ # Pacman splits --overwrite on commas, including the comma in Apple's
+ # board filenames. This archive contains exactly one firmware member;
+ # match that separator with one glob character rather than two patterns.
+ overwrite = path.replace(',', '?')
+ subprocess.run(['pacman', '--noconfirm', '--overwrite', overwrite, '-U', str(archive)], check=True, timeout=150)
+ assert subprocess.check_output(['pgrep', '-xo', 'hn|harness-tui'], text=True).strip() == process
+ return verify()
+
+
+def fingerprint():
+ assert subprocess.check_output(['lsblk', '-dn', '-o', 'SERIAL', '/dev/vda'], text=True).strip() == 'HN_OS_TEST'
+ digest = hashlib.sha256()
+ with Path('/dev/vda').open('rb', buffering=0) as handle:
+ digest.update(handle.read(1048576))
+ handle.seek(-1048576, os.SEEK_END)
+ digest.update(handle.read(1048576))
+ with Path('/dev/vda1').open('rb', buffering=0) as handle:
+ for data in iter(lambda: handle.read(1048576), b''):
+ digest.update(data)
+ return {'sha256': digest.hexdigest()}
+
+
+if __name__ == '__main__':
+ result = {'verify': verify, 'package': package, 'fingerprint': fingerprint}[sys.argv[1]]()
+ print('T2_RESULT=' + json.dumps(result))
diff --git a/os/tests/t2_install_vm.py b/os/tests/t2_install_vm.py
new file mode 100644
index 000000000..c1ab56220
--- /dev/null
+++ b/os/tests/t2_install_vm.py
@@ -0,0 +1,219 @@
+#!/usr/bin/env python3
+"""Install and recover the actual T2 image; synthetic firmware, no physical Mac claim."""
+import argparse
+import hashlib
+import json
+import os
+from pathlib import Path
+import re
+import shlex
+import subprocess
+import time
+
+from footprint_vm import copy_file
+from hardware_update_vm import graceful_stop
+from session_vm import screen_text
+from test_t2_firmware import firmware, source_fixture
+from vm import VM, check_graphical_keyboard
+
+
+def guest_result(output):
+ # Shell integration may put OSC metadata before the first output line.
+ # Compare the structured evidence, never the changing shell transcript.
+ matches = re.findall(r'T2_RESULT=(\{[^\r\n]+\})', output)
+ if len(matches) != 1:
+ raise ValueError('Expected exactly one T2 guest result.')
+ return json.loads(matches[0])
+
+
+def image_source_binding(root, image_source, observer_source):
+ def git(*args):
+ return subprocess.check_output(['git', '-C', str(root), *args], text=True).strip()
+ if not re.fullmatch(r'[a-f0-9]{40}', image_source):
+ raise ValueError('Invalid image source identity.')
+ changed = git('diff', '--no-renames', '--name-only', image_source, observer_source).splitlines()
+ workflow = '.github/workflows/os-t2.yml'
+ if any(not name.startswith('os/tests/') and name != workflow for name in changed):
+ raise ValueError('Image build or runtime inputs changed; build a new T2 image.')
+ if workflow in changed:
+ old = git('show', image_source + ':' + workflow)
+ new = git('show', observer_source + ':' + workflow)
+ if '\n machine:' not in old or '\n machine:' not in new or old.split('\n machine:', 1)[0] != new.split('\n machine:', 1)[0]:
+ raise ValueError('Image workflow inputs changed; build a new T2 image.')
+ return {'image_source': image_source, 'observer_source': observer_source,
+ 'changed_paths': changed, 'build_inputs_identical': True,
+ 'scope': 'Complete repository except OS test observers and the machine-only workflow job; image job is byte-identical.'}
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--iso', type=Path, required=True)
+ parser.add_argument('--output', type=Path, required=True)
+ args = parser.parse_args()
+ if not os.access('/dev/kvm', os.R_OK | os.W_OK):
+ parser.error('Native x86 KVM is required.')
+ iso, folder = args.iso.resolve(), args.output.absolute()
+ image = json.loads(iso.with_name('manifest.json').read_text())
+ source = subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip()
+ if subprocess.check_output(['git', 'status', '--porcelain'], text=True).strip():
+ parser.error('Commit the observer before native acceptance.')
+ assert image['platform'] == 'apple-t2'
+ binding = image_source_binding(Path(__file__).resolve().parents[2], image['source_commit'], source)
+ assert iso.name == image['iso']['name'] and iso.stat().st_size == image['iso']['bytes']
+ with iso.open('rb') as handle:
+ assert hashlib.file_digest(handle, 'sha256').hexdigest() == image['iso']['sha256']
+ folder.mkdir(parents=True, exist_ok=False)
+ model = 'MacBookAir9,1'
+ source_fixture(folder / 'synthetic-firmware')
+ bundle = folder / 'harness-apple-firmware.tar'
+ firmware.prepare(folder / 'synthetic-firmware', bundle, model)
+ lock = json.loads((Path(__file__).parents[1] / 'platforms/apple-t2/kernel.json').read_text())
+ record = {'status': 'running', 'started_at': time.time(), 'source_commit': source,
+ 'image_source_commit': image['source_commit'], 'source_binding': binding,
+ 'image': image['iso'], 'kernel': lock, 'synthetic_model': model, 'checks': [],
+ 'limits': ['QEMU does not emulate the T2 bridge, built-in input, radios, audio, graphics or suspend.',
+ 'Firmware contains invented sentinel bytes. This tests preservation, not radio functionality.',
+ 'Kernel is unchanged across this package transaction; a future T2 kernel upgrade remains a separate gate.']}
+ vm = VM(folder, iso, 'uefi', 2048, cpu='Haswell-noTSX', apple_model=model)
+ config = dict(disk='/dev/vda', expected_serial='HN_OS_TEST', confirm_erase='/dev/vda',
+ username='me', hostname='harness', password='test-password-123', encrypt=True, serial_console=True)
+
+ def live():
+ vm.start(live=True)
+ vm.monitor('set_link', name='hnnet', up=False)
+ vm.wait(r'root@[^\r\n]*[#] ')
+ vm.shell_ready = True
+ vm.command('stty -echo; nmcli networking off')
+ vm.command('test "$(uname -r)" = ' + shlex.quote(lock['kernel_release']))
+ vm.command('test "$(cat /sys/class/dmi/id/product_name)" = ' + shlex.quote(model))
+
+ def installed(label):
+ vm.start(live=False)
+ vm.monitor('set_link', name='hnnet', up=False)
+ vm.login_installed(config)
+ vm.command('printf %s ' + shlex.quote(config['password'] + '\n') + ' | sudo -S -v')
+ vm.command('systemctl --user stop harness-update.timer harness-update.service')
+ vm.command('test "$(uname -r)" = ' + shlex.quote(lock['kernel_release']))
+ vm.command('test "$(cat /usr/lib/modules/$(uname -r)/pkgbase)" = linux-t2')
+ vm.command('! pacman -Q linux-lts')
+ command_line = vm.read_file('/proc/cmdline').decode()
+ assert set(lock['kernel_parameters']) <= set(command_line.split())
+ record[label + '_boot_id'] = vm.read_file('/proc/sys/kernel/random/boot_id').decode().strip()
+ # This machine stays offline: first use legitimately presents Wi-Fi.
+ # Exercise the owner's normal terminal escape, without fabricating an
+ # onboarded marker or treating a running process as a visible workspace.
+ deadline = time.monotonic() + 30
+ while time.monotonic() < deadline:
+ text = screen_text(vm, label + '-offline-first-use')
+ if 'me@harness' in re.sub(r'\s+', '', text):
+ break
+ if 'connect to wi-fi' in text:
+ vm.keys('meta_l', 't')
+ break
+ time.sleep(.5)
+ else:
+ raise TimeoutError('The installed offline workspace did not render.')
+ record[label + '_keyboard'] = check_graphical_keyboard(vm, label)
+ output, _ = vm.command('sudo -n lsinitcpio --list /boot/initramfs-linux-t2.img')
+ (folder / (label + '-initramfs.txt')).write_text(output)
+ for module in lock['early_modules']:
+ assert '/' + module + '.ko' in output, module
+ output, _ = vm.command('sudo -n lsinitcpio --config /boot/initramfs-linux-t2.img')
+ for module in lock['early_modules']:
+ assert module in output, module
+ for module in lock['required_modules']:
+ output, _ = vm.command('modinfo -F vermagic ' + module)
+ assert lock['kernel_release'] in output, module
+ copy_file(vm, Path(__file__).with_name('t2_install_guest.py').read_bytes(), '/tmp/t2-guest.py')
+ output, _ = vm.command('sudo -n python3 /tmp/t2-guest.py verify')
+ (folder / (label + '-verification.log')).write_text(output)
+ return guest_result(output)
+
+ try:
+ live()
+ record['checks'].append('The live ISO actually boots its pinned T2 kernel and observes the synthetic Mac model.')
+ vm.command('test "$(lsblk -dn -o SERIAL /dev/vda)" = HN_OS_TEST && '
+ 'sgdisk --zap-all --new=1:2048:+256M --typecode=1:ef00 --new=2:0:0 --typecode=2:8300 /dev/vda && '
+ 'udevadm settle && mkfs.fat -F32 /dev/vda1')
+ copy_file(vm, json.dumps(config).encode(), '/tmp/install.json')
+ copy_file(vm, Path(__file__).with_name('t2_install_guest.py').read_bytes(), '/tmp/t2-guest.py')
+ install = 'harness install --config /tmp/install.json --yes-erase-disk'
+ # Hash both GPT copies and the full export partition around refusals.
+ fingerprint = 'python3 /tmp/t2-guest.py fingerprint'
+ before, _ = vm.command(fingerprint)
+ before = guest_result(before)
+ output, status = vm.command(install, timeout=90, check=False)
+ (folder / 'missing-firmware.log').write_text(output)
+ assert status != 0 and 'No disk has been erased' in output
+ after, _ = vm.command(fingerprint)
+ after = guest_result(after)
+ record['missing_firmware_disk'] = {'before': before, 'after': after}
+ assert before == after, 'Missing firmware changed the disk'
+ vm.command('mkdir /tmp/mac-efi && mount /dev/vda1 /tmp/mac-efi && '
+ 'printf corrupt > /tmp/mac-efi/harness-apple-firmware.tar && umount /tmp/mac-efi')
+ before, _ = vm.command(fingerprint)
+ before = guest_result(before)
+ output, status = vm.command(install, timeout=90, check=False)
+ (folder / 'corrupt-firmware.log').write_text(output)
+ assert status != 0 and 'No disk has been erased' in output
+ after, _ = vm.command(fingerprint)
+ after = guest_result(after)
+ record['invalid_firmware_disk'] = {'before': before, 'after': after}
+ assert before == after, 'Invalid firmware changed the disk'
+ record['checks'].append('Missing and corrupt firmware both refuse installation; both GPT copies and the export partition remain byte-identical.')
+ vm.command('mount /dev/vda1 /tmp/mac-efi')
+ copy_file(vm, bundle.read_bytes(), '/tmp/mac-efi/harness-apple-firmware.tar')
+ vm.command('sync && umount /tmp/mac-efi')
+ output, _ = vm.command(install, timeout=420)
+ (folder / 'install.log').write_text(output)
+ record['checks'].append('The real installer preserves verified firmware from EFI before erasure and completes an encrypted offline installation.')
+ graceful_stop(vm, False)
+ baseline = installed('installed')
+ record['installed'] = baseline
+ vm.command('mkdir -p ~/projects/t2-survivor && printf before > ~/projects/t2-survivor/work.txt')
+ output, _ = vm.command('sudo -n hn-os checkpoint')
+ name = re.search(r'Checkpoint ([A-Za-z0-9_-]+)', output)[1]
+ record['checkpoint'] = name
+ # A real package transaction replaces a firmware file, runs the shipped
+ # pacman hook and preserves the running terminal. The package is a fixture.
+ output, _ = vm.command('sudo -n python3 /tmp/t2-guest.py package', timeout=180)
+ (folder / 'firmware-package.log').write_text(output)
+ output, _ = vm.command('sudo -n python3 /tmp/t2-guest.py verify')
+ (folder / 'after-package.log').write_text(output)
+ record['checks'].append('An actual pacman firmware transaction runs the automatic restoration hook and keeps the same Harness process alive.')
+ vm.command('printf after-checkpoint >> ~/projects/t2-survivor/work.txt && '
+ 'printf changed | sudo -n tee /etc/harness-t2-recovery-fixture >/dev/null && '
+ 'printf changed | sudo -n tee /boot/grub/grub.cfg >/dev/null')
+ graceful_stop(vm, True)
+ live()
+ vm.command('printf %s ' + shlex.quote(config['password']) + ' | cryptsetup open --key-file=- /dev/vda3 hn-recovery')
+ output, _ = vm.command('hn-os recover /dev/mapper/hn-recovery ' + shlex.quote(name), timeout=180)
+ (folder / 'recovery.log').write_text(output)
+ vm.command('cryptsetup close hn-recovery')
+ graceful_stop(vm, False)
+ restored = installed('recovered')
+ assert record['installed_boot_id'] != record['recovered_boot_id']
+ assert baseline['boot_sha256'] == restored['boot_sha256']
+ assert baseline['firmware_sha256'] == restored['firmware_sha256']
+ vm.command('test ! -e /etc/harness-t2-recovery-fixture && ! pacman -Q linux-firmware-harness-fixture && '
+ 'test "$(cat ~/projects/t2-survivor/work.txt)" = beforeafter-checkpoint')
+ record['restored'] = restored
+ record['checks'].append('Offline recovery restores the matching T2 root, boot files and firmware, preserves newer project work, and cold boots through graphical disk unlock into Harness.')
+ graceful_stop(vm, True)
+ record['status'] = 'passed'
+ except Exception as error:
+ record.update(status='failed', error=repr(error))
+ if vm.process and vm.process.poll() is None:
+ vm.screenshot('failure')
+ raise
+ finally:
+ vm.stop()
+ vm.log.close()
+ vm.stderr.close()
+ vm.control.cleanup()
+ record['duration_seconds'] = round(time.time() - record['started_at'], 3)
+ (folder / 'receipt.json').write_text(json.dumps(record, indent=2) + '\n')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/os/tests/test_boot_profile.py b/os/tests/test_boot_profile.py
new file mode 100644
index 000000000..1fb841b0e
--- /dev/null
+++ b/os/tests/test_boot_profile.py
@@ -0,0 +1,65 @@
+import importlib.util
+import io
+import json
+from pathlib import Path
+import tarfile
+import tempfile
+import unittest
+
+
+spec = importlib.util.spec_from_file_location('boot_profile', Path(__file__).parents[1] / 'boot_profile.py')
+boot = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(boot)
+
+
+class BootProfiles(unittest.TestCase):
+ def test_t2_update_requires_platform_helpers_and_identical_kernel_pin(self):
+ with tempfile.TemporaryDirectory() as temp:
+ root = Path(temp)
+ marker = root / 'etc/harness-platform.json'
+ marker.parent.mkdir()
+ marker.write_text(json.dumps({'schema': 1, 'id': 'apple-t2'}))
+ pin = root / 'usr/share/harness-os/apple-t2/kernel.json'
+ pin.parent.mkdir(parents=True)
+ pin.write_text('{"kernel_release":"tested"}')
+ package = root / 'package.tar.gz'
+ def archive(version, helpers=True):
+ with tarfile.open(package, 'w:gz') as output:
+ entries = {'usr/share/harness-os/apple-t2/kernel.json': json.dumps({'kernel_release': version}).encode()}
+ if helpers:
+ entries.update({'usr/lib/harness-os/' + name + '.py': b'fixture' for name in
+ ['boot_profile', 't2_install', 't2_firmware', 'firmware_names']})
+ for name, data in entries.items():
+ info = tarfile.TarInfo(name)
+ info.size = len(data)
+ output.addfile(info, io.BytesIO(data))
+ archive('tested')
+ boot.validate_update(package, root)
+ archive('untested')
+ with self.assertRaisesRegex(ValueError, 'different T2 kernel'):
+ boot.validate_update(package, root)
+ archive('tested', False)
+ with self.assertRaisesRegex(ValueError, 'does not include the T2 platform'):
+ boot.validate_update(package, root)
+
+ def test_legacy_pc_and_t2_require_their_own_boot_files(self):
+ with tempfile.TemporaryDirectory() as temp:
+ root = Path(temp)
+ self.assertEqual(boot.selected(root)['kernel'], 'linux-lts')
+ marker = root / 'etc/harness-platform.json'
+ marker.parent.mkdir()
+ marker.write_text(json.dumps({'schema': 1, 'id': 'apple-t2'}))
+ self.assertEqual(boot.selected(root)['kernel'], 'linux-t2')
+ self.assertEqual(boot.boot_files('apple-t2'), {'vmlinuz-linux-t2', 'initramfs-linux-t2.img', 'grub/grub.cfg'})
+ for value in [{'schema': True, 'id': 'pc'}, {'schema': 1, 'id': 'unknown'}, {}, []]:
+ marker.write_text(json.dumps(value))
+ with self.assertRaises(ValueError):
+ boot.selected(root)
+ marker.unlink()
+ marker.symlink_to(root / 'missing')
+ with self.assertRaises(ValueError):
+ boot.selected(root)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/os/tests/test_publish_update.py b/os/tests/test_publish_update.py
index 052999f42..a0f871120 100644
--- a/os/tests/test_publish_update.py
+++ b/os/tests/test_publish_update.py
@@ -18,9 +18,10 @@ class PublicationGuards(unittest.TestCase):
self.fixture.runtime['versions'] = {'hn': '0.1.12', 'cli': '0.3.57'}
self.fixture.make_package()
self.bundle = self.fixture.root
- (self.bundle / 'apply-update.py').write_text('# fixture bootstrap\n')
+ for name in publish.bootstrap_files():
+ (self.bundle / name).write_text('# fixture bootstrap\n')
(self.bundle / 'SHA256SUMS').write_text(''.join(publish.digest(path) + ' ' + path.name + '\n' for path in
- [self.fixture.package, self.bundle / 'package-manifest.json', self.bundle / 'apply-update.py']))
+ [self.fixture.package, self.bundle / 'package-manifest.json', *[self.bundle / name for name in publish.bootstrap_files()]]))
self.run = dict(status='completed', conclusion='success', path='.github/workflows/os.yml', head_sha='a' * 40)
self.receipt = dict(status='passed', update=dict(status='passed', source_commit='a' * 40, candidate=self.fixture.manifest['package']),
fast_updates=dict(status='passed'), system_channel=dict(status='passed', package=self.fixture.manifest['package'],
@@ -29,12 +30,19 @@ class PublicationGuards(unittest.TestCase):
def test_exact_package_and_complete_receipt_can_be_prepared(self):
self.assertEqual(publish.validate(self.bundle, self.receipt, self.run)['source_commit'], 'a' * 40)
+ def test_bootstrap_cannot_omit_a_platform_helper(self):
+ path = self.bundle / 'SHA256SUMS'
+ path.write_text(''.join(line for line in path.read_text().splitlines(keepends=True)
+ if not line.endswith(' boot_profile.py\n')))
+ with self.assertRaisesRegex(ValueError, 'complete bootstrap bundle'):
+ publish.validate(self.bundle, self.receipt, self.run)
+
def test_official_bundle_can_migrate_a_preview_through_its_existing_feed(self):
self.fixture.manifest['requires_os_version'] = '0.1.0'
self.fixture.manifest['upgrades_from'] = [self.fixture.base]
self.fixture.make_package()
(self.bundle / 'SHA256SUMS').write_text(''.join(publish.digest(path) + ' ' + path.name + '\n' for path in
- [self.fixture.package, self.bundle / 'package-manifest.json', self.bundle / 'apply-update.py']))
+ [self.fixture.package, self.bundle / 'package-manifest.json', *[self.bundle / name for name in publish.bootstrap_files()]]))
self.assertEqual(publish.validate(self.bundle, self.receipt, self.run)['requires_os_version'], '0.1.0')
# The original installed updater must accept the explicit migration too.
test_runtime_update.update.validate_bundle(self.bundle, self.fixture.base)
diff --git a/os/tests/test_release_update_fixture.py b/os/tests/test_release_update_fixture.py
new file mode 100644
index 000000000..4c94e1f7a
--- /dev/null
+++ b/os/tests/test_release_update_fixture.py
@@ -0,0 +1,38 @@
+"""The combined-update fixture must use a complete, compatible helper set."""
+import importlib.util
+import inspect
+from pathlib import Path
+import shutil
+import tempfile
+import unittest
+
+from release_update_vm import relocate_boot_loader
+
+
+class ReleaseUpdateFixture(unittest.TestCase):
+ def test_relocation_loads_the_real_new_api_and_only_changes_its_dependency_path(self):
+ source = Path(__file__).resolve().parents[1]
+ original = (source / 'system.py').read_text()
+ with tempfile.TemporaryDirectory() as temporary:
+ root = Path(temporary)
+ shutil.copyfile(source / 'boot_profile.py', root / 'boot_profile.py')
+ relocated = relocate_boot_loader(original, root)
+ self.assertEqual(relocated.replace('Path(' + repr(str(root / 'boot_profile.py')) + ')',
+ "Path(__file__).with_name('boot_profile.py')"), original)
+ target = root / 'candidate-system.py'
+ target.write_text(relocated)
+ spec = importlib.util.spec_from_file_location('candidate_system_fixture', target)
+ module = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(module)
+ self.assertIn('noninteractive', inspect.signature(module.update).parameters)
+ self.assertEqual(module.boot_module().selected(root)['id'], 'pc')
+ self.assertEqual(Path(module.boot_module().__file__), root / 'boot_profile.py')
+ with self.assertRaises(ValueError):
+ relocate_boot_loader(original, 'relative')
+ for changed in [original + original, original.replace("with_name('boot_profile.py')", "with_name('other.py')")]:
+ with self.assertRaises(ValueError):
+ relocate_boot_loader(changed, '/tmp/unused')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/os/tests/test_runtime_update.py b/os/tests/test_runtime_update.py
index 220460212..22cdd74e4 100644
--- a/os/tests/test_runtime_update.py
+++ b/os/tests/test_runtime_update.py
@@ -6,6 +6,7 @@ import json
from pathlib import Path
import tarfile
import tempfile
+from types import SimpleNamespace
import unittest
from unittest.mock import patch
@@ -55,6 +56,50 @@ class BundleGuards(unittest.TestCase):
self.assertEqual(manifest, self.manifest)
self.assertEqual(package, self.package)
+ def test_standalone_bootstrap_includes_and_loads_its_transitive_helpers(self):
+ source = Path(__file__).resolve().parents[2]
+ spec = importlib.util.spec_from_file_location('build_package', source / 'os/tools/build-package.py')
+ builder = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(builder)
+ folder = self.root / 'standalone'
+ folder.mkdir()
+ paths = builder.bootstrap(source, folder)
+ self.assertEqual({p.name for p in paths}, set(update.BOOTSTRAP_FILES))
+ spec = importlib.util.spec_from_file_location('isolated_bootstrap', folder / 'apply-update.py')
+ standalone = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(standalone)
+ self.assertEqual(standalone.validate_bundle(self.root, self.base)[1], self.package)
+ # Resolve imports from this standalone folder, without installed files.
+ helper = standalone.boot_module().module('t2_install').helper()
+ helper.check_model('MacBookAir9,1')
+ self.assertEqual(Path(helper.__file__).parent, folder)
+
+ def test_legacy_rollback_completes_after_package_removes_platform_helper(self):
+ folder = self.root / 'installed'
+ folder.mkdir()
+ for name in ('runtime_update.py', 'boot_profile.py'):
+ (folder / name).write_bytes((Path(__file__).parents[1] / name).read_bytes())
+ spec = importlib.util.spec_from_file_location('installed_updater', folder / 'runtime_update.py')
+ installed = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(installed)
+ receipt = {'id': '20261003T120000Z-12345678', 'status': 'applied', 'root_uuid': 'test-root',
+ 'previous_version': self.version, 'previous_runtime': self.runtime,
+ 'backup_sha256': update.digest(self.package)}
+ backup = self.root / receipt['id']
+ backup.mkdir()
+ (backup / 'previous.pkg.tar.gz').write_bytes(self.package.read_bytes())
+ calls = []
+ system = SimpleNamespace(write_json=lambda path, value: path.write_text(json.dumps(value)),
+ run=lambda *args: calls.append(args))
+ with patch.object(installed, 'STATE', self.root), patch.object(installed, 'latest', return_value=receipt), \
+ patch.object(installed, 'RESTART_REQUIRED', self.root / 'restart.json'), \
+ patch.object(installed, 'install_package', side_effect=lambda *args: (folder / 'boot_profile.py').unlink()):
+ installed.rollback(system, {'root_uuid': 'test-root'})
+ self.assertFalse((folder / 'boot_profile.py').exists())
+ self.assertEqual(receipt['status'], 'rolled-back')
+ self.assertEqual(calls, [('mkinitcpio', '-P')])
+ self.assertEqual(json.loads((self.root / 'restart.json').read_text())['status'], 'ready')
+
def test_incomplete_download_is_rejected_before_a_checkpoint_or_transaction(self):
self.package.write_bytes(self.package.read_bytes()[:-10])
with self.assertRaisesRegex(ValueError, 'checksum or size'):
diff --git a/os/tests/test_system.py b/os/tests/test_system.py
index 5c5b9ec3b..2f86f4f54 100644
--- a/os/tests/test_system.py
+++ b/os/tests/test_system.py
@@ -24,6 +24,15 @@ class RecoveryGuards(unittest.TestCase):
with self.assertRaises(ValueError):
system.validate_checkpoint(bad, 'root-identity')
+ def test_t2_checkpoint_requires_its_matching_boot_files(self):
+ good = {'platform': 'apple-t2', 'root_uuid': 'root-identity', 'boot_uuid': 'ABCD-1234',
+ 'boot_sha256': {name: 'digest' for name in ['vmlinuz-linux-t2', 'initramfs-linux-t2.img', 'grub/grub.cfg']}}
+ system.validate_checkpoint(good, 'root-identity')
+ with self.assertRaises(ValueError):
+ system.validate_checkpoint(dict(good, platform='pc'), 'root-identity')
+ with self.assertRaises(ValueError):
+ system.validate_checkpoint(dict(good, platform='unknown'), 'root-identity')
+
def test_snapshot_is_a_complete_real_date(self):
self.assertEqual(system.snapshot_date('2026/10/01'), '2026/10/01')
for date in ['2026/2/1', '2026/02/30', '2099/01/01', '../2026/01/01']:
diff --git a/os/tests/test_t2_install.py b/os/tests/test_t2_install.py
new file mode 100644
index 000000000..d908fd68f
--- /dev/null
+++ b/os/tests/test_t2_install.py
@@ -0,0 +1,132 @@
+from contextlib import contextmanager
+import importlib.util
+import json
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+import unittest
+from unittest.mock import patch
+
+from test_t2_firmware import firmware, source_fixture
+
+
+spec = importlib.util.spec_from_file_location('t2_install', Path(__file__).parents[1] / 't2_install.py')
+t2 = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(t2)
+
+
+class FirmwarePreservation(unittest.TestCase):
+ def setUp(self):
+ self.temp = tempfile.TemporaryDirectory()
+ self.addCleanup(self.temp.cleanup)
+ self.root = Path(self.temp.name)
+ self.model = 'MacBookAir9,1'
+ self.source = self.root / 'firmware'
+ source_fixture(self.source)
+ self.bundle = self.root / 'harness-apple-firmware.tar'
+ self.manifest = firmware.prepare(self.source, self.bundle, self.model)
+ self.work = self.root / 'work'
+ self.work.mkdir()
+
+ def test_export_is_copied_to_ram_verified_restored_and_recoverable(self):
+ with patch.object(t2, 'find_bundle', return_value=self.bundle):
+ with t2.preserve('/dev/vda', self.model, runtime=self.work) as preserved:
+ self.assertTrue(preserved['bundle'].is_relative_to(self.work))
+ target = self.root / 'installed'
+ target.mkdir()
+ receipt = t2.restore(target, preserved)
+ (target / 'var/lib/harness-os/install.json').write_text(json.dumps({'apple_firmware': receipt}))
+ retained = t2.retained(target)
+ self.assertEqual(retained['manifest'], self.manifest)
+ _, files = firmware.verify(self.bundle, self.model)
+ self.assertEqual({p.name: p.read_bytes() for p in (target / 'usr/lib/firmware/brcm').iterdir()}, files)
+ # Simulate a package replacing board data with a fallback link.
+ sentinel = self.root / 'outside'
+ sentinel.write_bytes(b'untouched')
+ name = next(iter(files))
+ changed = target / 'usr/lib/firmware/brcm' / name
+ changed.unlink()
+ changed.symlink_to(sentinel)
+ t2.restore(target, retained)
+ self.assertEqual(changed.read_bytes(), files[name])
+ self.assertFalse(changed.is_symlink())
+ self.assertEqual(sentinel.read_bytes(), b'untouched')
+ self.assertEqual(receipt, t2.restore(target, retained))
+ retained['bundle'].write_bytes(b'changed')
+ with self.assertRaises(ValueError):
+ t2.retained(target)
+ self.assertEqual(list(self.work.iterdir()), [])
+
+ def test_missing_and_wrong_machine_exports_do_not_yield_installation_input(self):
+ with patch.object(t2, 'partitions', return_value=[]), self.assertRaisesRegex(ValueError, 'No disk has been erased'):
+ t2.find_bundle('/dev/vda', self.work, self.model, exports=[])
+ with self.assertRaises(ValueError):
+ t2.find_bundle('/dev/vda', self.work, 'MacBookPro16,1', exports=[self.bundle])
+
+ def test_failed_install_retains_verified_ram_export_for_recovery(self):
+ with patch.object(t2, 'find_bundle', return_value=self.bundle), self.assertRaisesRegex(ValueError, 'failed installation'):
+ with t2.preserve('/dev/vda', self.model, runtime=self.work) as preserved:
+ saved = preserved['bundle']
+ raise ValueError('failed installation')
+ self.assertEqual(firmware.verify(saved, self.model)[0], self.manifest)
+
+ def test_efi_export_is_preserved_before_unmount_and_source_disappearance(self):
+ calls = []
+ @contextmanager
+ def mount(device, kind, folder, volume):
+ calls.append(('mount', device, kind, volume))
+ shutil.copyfile(self.bundle, folder / self.bundle.name)
+ try:
+ yield folder
+ finally:
+ (folder / self.bundle.name).unlink()
+ calls.append(('unmount',))
+ with patch.object(t2, 'partitions', return_value=[('/dev/vda1', 'vfat')]), patch.object(t2, 'mounted', mount):
+ saved = t2.find_bundle('/dev/vda', self.work, self.model, exports=[])
+ self.assertEqual(calls, [('mount', '/dev/vda1', 'vfat', None), ('unmount',)])
+ self.assertEqual(firmware.verify(saved, self.model)[0], self.manifest)
+
+ def test_apfs_mounts_are_read_only_and_unmount_failure_stops_preservation(self):
+ with patch.object(t2, 'run') as run:
+ with t2.mounted('/dev/vda2', 'apfs', self.work, 2):
+ pass
+ self.assertEqual(run.call_args_list[0].args[:6], ('mount', '-t', 'apfs', '-o', 'ro,nosuid,nodev,noexec,vol=2', '/dev/vda2'))
+ self.assertEqual(run.call_args_list[1].args, ('umount', self.work))
+ @contextmanager
+ def stuck(device, kind, folder, volume):
+ shutil.copyfile(self.bundle, folder / self.bundle.name)
+ yield folder
+ raise subprocess.CalledProcessError(1, ['umount'])
+ with patch.object(t2, 'partitions', return_value=[('/dev/vda1', 'vfat')]), patch.object(t2, 'mounted', stuck):
+ with self.assertRaises(subprocess.CalledProcessError):
+ t2.find_bundle('/dev/vda', self.work, self.model, exports=[])
+
+ def test_apfs_volume_probe_converts_only_found_system_firmware(self):
+ seen = []
+ @contextmanager
+ def mounted(device, kind, folder, volume):
+ seen.append(volume)
+ if volume != 2:
+ raise subprocess.CalledProcessError(1, ['mount'])
+ shutil.copytree(self.source, folder / 'usr/share/firmware')
+ yield folder
+ with patch.object(t2, 'partitions', return_value=[('/dev/vda2', 'apfs')]), patch.object(t2, 'mounted', mounted):
+ saved = t2.find_bundle('/dev/vda', self.work, self.model, exports=[])
+ self.assertEqual(seen, [0, 1, 2])
+ self.assertEqual(firmware.verify(saved, self.model)[0], self.manifest)
+
+ def test_wrong_disk_identity_and_partition_paths_are_refused(self):
+ def output(devices):
+ return subprocess.CompletedProcess([], 0, json.dumps({'blockdevices': devices}))
+ for device in [
+ {'name': '/dev/vdb', 'type': 'disk'},
+ {'name': '/dev/vda', 'type': 'part'},
+ {'name': '/dev/vda', 'type': 'disk', 'children': [{'name': '/dev/../etc', 'type': 'part', 'fstype': 'vfat'}]},
+ ]:
+ with patch.object(t2, 'run', return_value=output([device])), self.assertRaises(ValueError):
+ t2.partitions('/dev/vda')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/os/tests/test_t2_kernel.py b/os/tests/test_t2_kernel.py
index 79b2edce1..34a6b2c08 100644
--- a/os/tests/test_t2_kernel.py
+++ b/os/tests/test_t2_kernel.py
@@ -8,6 +8,7 @@ import subprocess
import tarfile
import tempfile
import unittest
+from unittest.mock import patch
spec = importlib.util.spec_from_file_location('t2_kernel', Path(__file__).parents[1] / 'tools/prepare-t2-kernel.py')
t2 = importlib.util.module_from_spec(spec)
@@ -53,6 +54,45 @@ class T2KernelBundleTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, 'fresh'):
t2.prepare(self.package, output, lock)
+ def test_live_profile_and_runtime_package_have_no_file_conflicts(self):
+ source = Path(__file__).resolve().parents[2]
+ def load(name, path):
+ spec = importlib.util.spec_from_file_location(name, path)
+ value = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(value)
+ return value
+ profile = load('image_profile', source / 'os/tools/configure-boot-profile.py')
+ package = load('image_package', source / 'os/tools/build-package.py')
+ selected = profile.boot.profile('apple-t2')
+ self.lock.update(early_modules=selected['modules'], required_modules=selected['modules'],
+ kernel_parameters=selected['parameters'])
+ for name in selected['modules']:
+ self.files['usr/lib/modules/7.2.8-test-t2/kernel/' + name + '.ko.zst'] = b'module fixture'
+ self.write_package()
+ lock = self.root / 'lock.json'
+ lock.write_text(json.dumps(self.lock))
+ runtime = self.root / 'runtime'
+ runtime.mkdir()
+ # Assembly checks do not execute this format-only ELF fixture.
+ (runtime / 'harness-tui').write_bytes(b'\x7fELF\x02\x01' + bytes(12) + b'\x3e\x00')
+ (runtime / 'cli.js').write_text('// fixture\n')
+ (runtime / 'notify.mjs').write_text('// fixture\n')
+ (runtime / 'source.json').write_text(json.dumps({
+ 'dirty': False, 'source_commit': 'a' * 40, 'target': 'x86_64-unknown-linux-musl'}))
+ staged = self.root / 'package'
+ package.stage(source, runtime, staged, 'a' * 40)
+ owned = {p.relative_to(staged) for p in staged.rglob('*') if not p.is_dir()}
+ self.assertIn(Path('usr/share/harness-os/apple-t2/kernel.json'), owned)
+ for identity in ('pc', 'apple-t2'):
+ with self.subTest(identity=identity):
+ folder = self.root / identity / 'profile'
+ (folder / 'airootfs').mkdir(parents=True)
+ (folder / 'packages.x86_64').write_text('linux-lts\nharness-os\n')
+ with patch.object(profile, 'module', return_value=t2), patch.object(t2, 'LOCK', lock):
+ profile.configure(folder, identity, self.root)
+ overlay = {p.relative_to(folder / 'airootfs') for p in (folder / 'airootfs').rglob('*') if not p.is_dir()}
+ self.assertEqual(owned & overlay, set(), 'Live files must not preempt package-owned files')
+
def test_corruption_fails_before_archive_tool_runs(self):
self.package.write_bytes(b'truncated')
with self.assertRaisesRegex(ValueError, 'pinned artifact'):
diff --git a/os/tests/test_t2_observer.py b/os/tests/test_t2_observer.py
new file mode 100644
index 000000000..8cc97d6b8
--- /dev/null
+++ b/os/tests/test_t2_observer.py
@@ -0,0 +1,59 @@
+"""Keep serial metadata and observer-only changes out of T2 image identity."""
+import json
+from pathlib import Path
+import subprocess
+import tempfile
+import unittest
+
+from t2_install_vm import guest_result, image_source_binding
+
+
+class T2Observer(unittest.TestCase):
+ def test_result_ignores_shell_metadata_but_not_changed_data(self):
+ value = {'sha256': 'a' * 64}
+ output = '\x1b]3008;start=first\x1b\\T2_RESULT=' + json.dumps(value) + '\r\n'
+ self.assertEqual(guest_result(output), guest_result(output.replace('start=first', 'start=second')))
+ self.assertNotEqual(guest_result(output), guest_result(output.replace('a' * 64, 'b' * 64)))
+ for invalid in ['', output + output, 'T2_RESULT={bad json}\n']:
+ with self.subTest(output=invalid), self.assertRaises(ValueError):
+ guest_result(invalid)
+
+ def test_reuse_requires_identical_build_inputs_and_image_workflow(self):
+ with tempfile.TemporaryDirectory() as temporary:
+ root = Path(temporary)
+ def git(*args):
+ return subprocess.check_output(['git', '-C', str(root), *args], text=True, stderr=subprocess.PIPE).strip()
+ git('init', '-b', 'main')
+ git('config', 'user.name', 'Harness Test')
+ git('config', 'user.email', 'test@localhost')
+ files = {'os/installer.py': 'original', 'tui/source': 'original',
+ 'os/tests/observer.py': 'original',
+ '.github/workflows/os-t2.yml': 'jobs:\n image: original\n machine: original\n'}
+ for name, content in files.items():
+ path = root / name
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(content)
+ git('add', '.')
+ git('commit', '-m', 'Original image')
+ baseline = git('rev-parse', 'HEAD')
+ (root / 'os/tests/observer.py').write_text('corrected observer')
+ (root / '.github/workflows/os-t2.yml').write_text('jobs:\n image: original\n machine: corrected\n')
+ git('commit', '-am', 'Observer only')
+ observer = git('rev-parse', 'HEAD')
+ self.assertTrue(image_source_binding(root, baseline, observer)['build_inputs_identical'])
+ for name in ['os/installer.py', 'tui/source', '.github/workflows/os-t2.yml']:
+ with self.subTest(path=name):
+ git('reset', '--hard', observer)
+ (root / name).write_text('different build input')
+ git('commit', '-am', 'Changed input')
+ with self.assertRaisesRegex(ValueError, 'build a new T2 image'):
+ image_source_binding(root, baseline, git('rev-parse', 'HEAD'))
+ git('reset', '--hard', observer)
+ git('mv', 'os/installer.py', 'os/tests/moved-installer.py')
+ git('commit', '-m', 'Move production input into test directory')
+ with self.assertRaisesRegex(ValueError, 'build a new T2 image'):
+ image_source_binding(root, baseline, git('rev-parse', 'HEAD'))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/os/tests/vm.py b/os/tests/vm.py
index a80138840..a81e53e11 100644
--- a/os/tests/vm.py
+++ b/os/tests/vm.py
@@ -85,7 +85,7 @@ print('HN_LIVE_MEDIA=' + json.dumps(dict(mode=mode, payload=str(payload), payloa
class VM:
- def __init__(self, folder, iso, firmware, memory, live_transport='cdrom', cpu=None, video='virtio-vga', audio=False):
+ def __init__(self, folder, iso, firmware, memory, live_transport='cdrom', cpu=None, video='virtio-vga', audio=False, apple_model=None):
self.folder, self.iso, self.firmware, self.memory = folder, iso, firmware, memory
self.live_transport = live_transport
self.cpu = cpu
@@ -93,6 +93,9 @@ class VM:
raise ValueError('Unsupported test display: ' + video)
self.video = video
self.audio = audio
+ if apple_model is not None and not re.fullmatch(r'(?:MacBook(?:Air|Pro)|Macmini|MacPro|iMac|iMacPro)[0-9]+,[0-9]+', apple_model):
+ raise ValueError('Invalid synthetic Apple DMI model.')
+ self.apple_model = apple_model
self.unlock_count = 0
self.boot_count = 0
self.process = None
@@ -134,6 +137,10 @@ class VM:
'-device', 'virtio-net-pci,netdev=net,id=hnnet', '-netdev', 'user,id=net',
'-serial', f'unix:{self.control_path / "serial.sock"},server=on,wait=off',
'-qmp', f'unix:{self.control_path / "qmp.sock"},server=on,wait=off']
+ if self.apple_model:
+ # Explicit synthetic DMI for firmware selection tests. This does
+ # not emulate the T2 bridge, physical input, radios or audio.
+ args += ['-smbios', 'type=1,manufacturer=Apple Inc.,product=' + self.apple_model.replace(',', ',,')]
if self.audio:
args += ['-audiodev', f'wav,id=sound,path={self.folder / ("audio-" + str(self.boot_count) + ".wav")}',
'-device', 'intel-hda', '-device', 'hda-duplex,audiodev=sound']
diff --git a/os/tools/build-package.py b/os/tools/build-package.py
index 7dcb6d8d7..4054beb8f 100644
--- a/os/tools/build-package.py
+++ b/os/tools/build-package.py
@@ -3,6 +3,7 @@
import argparse
import gzip
import hashlib
+import importlib.util
import json
from pathlib import Path
import re
@@ -47,6 +48,11 @@ def stage(source, runtime, destination, commit):
'os/projects.py': 'usr/lib/harness-os/projects.py',
'os/trial_projects.py': 'usr/lib/harness-os/trial_projects.py',
'os/system.py': 'usr/lib/harness-os/system.py',
+ 'os/boot_profile.py': 'usr/lib/harness-os/boot_profile.py',
+ 'os/t2_install.py': 'usr/lib/harness-os/t2_install.py',
+ 'os/tools/prepare-t2-firmware.py': 'usr/lib/harness-os/t2_firmware.py',
+ 'os/platforms/apple-t2/firmware_names.py': 'usr/lib/harness-os/firmware_names.py',
+ 'os/platforms/apple-t2/kernel.json': 'usr/share/harness-os/apple-t2/kernel.json',
'os/runtime_update.py': 'usr/lib/harness-os/runtime_update.py',
'os/live_update.py': 'usr/lib/harness-os/live_update.py',
'os/release_update.py': 'usr/lib/harness-os/release_update.py',
@@ -114,6 +120,21 @@ def archive_package(root, output, pkginfo, timestamp):
partial.unlink(missing_ok=True)
+def bootstrap(source, folder):
+ """Ship every helper needed before the first platform-aware OS package."""
+ files = {'apply-update.py': 'runtime_update.py', 'boot_profile.py': 'boot_profile.py',
+ 't2_install.py': 't2_install.py', 't2_firmware.py': 'tools/prepare-t2-firmware.py',
+ 'firmware_names.py': 'platforms/apple-t2/firmware_names.py'}
+ spec = importlib.util.spec_from_file_location('bootstrap_runtime', source / 'os/runtime_update.py')
+ updater = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(updater)
+ if set(files) != set(updater.BOOTSTRAP_FILES):
+ raise ValueError('Incomplete standalone updater helpers.')
+ for name, relative in files.items():
+ shutil.copyfile(source / 'os' / relative, folder / name)
+ return [folder / name for name in files]
+
+
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--runtime', type=Path, required=True)
@@ -160,10 +181,9 @@ def main():
(folder / 'package-manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
(folder / (package.name + '.sha256')).write_text(f'{manifest["package"]["sha256"]} {package.name}\n')
# A preview 4 installation can bootstrap the updater from this same bundle.
- bootstrap = folder / 'apply-update.py'
- shutil.copyfile(source / 'os/runtime_update.py', bootstrap)
+ standalone = bootstrap(source, folder)
(folder / 'SHA256SUMS').write_text(''.join(f'{digest(path)} {path.name}\n' for path in
- [package, folder / 'package-manifest.json', bootstrap]))
+ [package, folder / 'package-manifest.json', *standalone]))
print(json.dumps(manifest, indent=2))
diff --git a/os/tools/configure-boot-profile.py b/os/tools/configure-boot-profile.py
new file mode 100644
index 000000000..3dae4c010
--- /dev/null
+++ b/os/tools/configure-boot-profile.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python3
+"""Select the same kernel/input stack for USB and installed boot."""
+import argparse
+import importlib.util
+import json
+from pathlib import Path
+import re
+import shutil
+
+
+def module(name, path):
+ spec = importlib.util.spec_from_file_location(name, path)
+ value = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(value)
+ return value
+
+
+SOURCE = Path(__file__).parents[1]
+boot = module('harness_boot_profile', SOURCE / 'boot_profile.py')
+
+
+def configure(folder, identity, bundle=None):
+ selected = boot.profile(identity)
+ root = folder / 'airootfs'
+ if not root.is_dir():
+ raise ValueError('Configure a fresh Archiso profile.')
+ if identity == 'apple-t2':
+ kernel = module('harness_t2_kernel', SOURCE / 'tools/prepare-t2-kernel.py')
+ lock = json.loads(kernel.LOCK.read_text())
+ if not bundle:
+ raise ValueError('The T2 image requires its verified kernel bundle.')
+ package = bundle / lock['package']['filename']
+ verified = kernel.inspect(package, lock)
+ if selected['modules'] != lock['early_modules'] or selected['parameters'] != lock['kernel_parameters']:
+ raise ValueError('T2 boot profile and verified kernel requirements differ.')
+ repository = folder.parent / 'repo'
+ repository.mkdir(exist_ok=True)
+ destination = repository / package.name
+ if destination.exists():
+ raise ValueError('Use a fresh kernel package repository.')
+ shutil.copyfile(package, destination)
+ kernel.inspect(destination, lock)
+ packages = folder / 'packages.x86_64'
+ lines = packages.read_text().splitlines()
+ if lines.count('linux-lts') != 1:
+ raise ValueError('Expected exactly one base kernel selection.')
+ packages.write_text('\n'.join('linux-t2' if line == 'linux-lts' else line for line in lines) + '\n')
+ config = root / 'etc/mkinitcpio.conf.d/20-harness-platform.conf'
+ config.parent.mkdir(parents=True, exist_ok=True)
+ config.write_text('MODULES+=(' + ' '.join(selected['modules']) + ')\n')
+ load = root / 'etc/modules-load.d/harness-t2.conf'
+ load.parent.mkdir(parents=True, exist_ok=True)
+ load.write_text('t2bce_vhci\n')
+ hook = root / 'etc/pacman.d/hooks/80-harness-t2-firmware.hook'
+ hook.parent.mkdir(parents=True, exist_ok=True)
+ hook.write_text('[Trigger]\nOperation = Install\nOperation = Upgrade\nType = Package\n'
+ 'Target = linux-firmware*\nTarget = linux-t2\n\n[Action]\n'
+ 'Description = Preserving this Mac’s wireless firmware\nWhen = PostTransaction\n'
+ 'Exec = /usr/bin/python3 /usr/lib/harness-os/t2_install.py restore\n')
+ # kernel.json belongs to the harness-os package. Precreating it in the
+ # live overlay makes pacman refuse the image with a file conflict.
+ manifest = root / 'usr/share/harness-os/apple-t2/manifest.json'
+ manifest.parent.mkdir(parents=True, exist_ok=True)
+ manifest.write_text(json.dumps({'kernel': lock, 'verified_files': verified}, indent=2) + '\n')
+ marker = root / 'etc/harness-platform.json'
+ marker.parent.mkdir(parents=True, exist_ok=True)
+ marker.write_text(json.dumps({'schema': 1, 'id': identity}) + '\n')
+ for directory in ['syslinux', 'efiboot', 'grub']:
+ for path in (folder / directory).rglob('*'):
+ if not path.is_file():
+ continue
+ try:
+ text = path.read_text()
+ except UnicodeDecodeError:
+ continue
+ text = text.replace('vmlinuz-linux', 'vmlinuz-' + selected['kernel'])
+ text = text.replace('initramfs-linux.img', 'initramfs-' + selected['kernel'] + '.img')
+ text = text.replace('Arch Linux install medium', 'Install Harness')
+ args = 'archisobasedir=%INSTALL_DIR% cow_spacesize=50%'
+ if selected['parameters']:
+ args += ' ' + ' '.join(selected['parameters'])
+ text = text.replace('archisobasedir=%INSTALL_DIR%', args)
+ text = re.sub(r'(?m)^timeout(?:=|\s+)\d+', lambda match: 'timeout=1' if '=' in match[0] else 'timeout 1', text)
+ text = re.sub(r'(?m)^TIMEOUT\s+\d+', 'TIMEOUT 10', text)
+ text = re.sub(r'(?m)^beep on$', 'beep off', text)
+ text = re.sub(r'(?m)^play .*$', '', text)
+ text = text.replace('MENU TITLE Arch Linux', 'MENU TITLE Harness')
+ text = re.sub(r'(?m)^MENU BACKGROUND .*\n', '', text)
+ path.write_text(text)
+ return selected
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('--profile', type=Path, required=True)
+ parser.add_argument('--platform', choices=boot.PROFILES, default='pc')
+ parser.add_argument('--t2-bundle', type=Path)
+ args = parser.parse_args()
+ print(json.dumps(configure(args.profile, args.platform, args.t2_bundle)))
diff --git a/os/tools/customize-live.sh b/os/tools/customize-live.sh
index 7a5e7cfd4..3cf50bfdf 100644
--- a/os/tools/customize-live.sh
+++ b/os/tools/customize-live.sh
@@ -34,8 +34,12 @@ mkdir -p /etc/systemd/system/[email protected]
printf '[Service]\nExecStart=\nExecStart=-/usr/bin/agetty --autologin root --noclear %%I 115200\n' > /etc/systemd/system/[email protected]/live.conf
systemctl enable [email protected]
python3 - <<'PY'
-import hashlib, json
+import hashlib, json, importlib.util
from pathlib import Path
+spec = importlib.util.spec_from_file_location('harness_boot_profile', '/usr/lib/harness-os/boot_profile.py')
+boot = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(boot)
+profile = boot.selected()
lock = json.loads(Path('/usr/share/harness-os/lock.json').read_text())
snapshot = lock['arch_snapshot']
Path('/etc/pacman.conf').write_text(
@@ -43,13 +47,13 @@ Path('/etc/pacman.conf').write_text(
''.join(f'[{repo}]\nServer = https://archive.archlinux.org/repos/{snapshot}/$repo/os/$arch\n' for repo in ['core', 'extra']))
# archiso removes /boot from SquashFS after placing boot files on the ISO.
# Keep the exact package-owned kernel location for an offline disk install.
-kernels = [p.parent / 'vmlinuz' for p in Path('/usr/lib/modules').glob('*/pkgbase') if p.read_text().strip() == 'linux-lts']
+kernels = [p.parent / 'vmlinuz' for p in Path('/usr/lib/modules').glob('*/pkgbase') if p.read_text().strip() == profile['kernel']]
if len(kernels) != 1 or not kernels[0].is_file():
- raise SystemExit('Expected one package-owned LTS kernel for the installer.')
+ raise SystemExit('Expected one package-owned platform kernel for the installer.')
kernel = kernels[0]
with kernel.open('rb') as handle:
digest = hashlib.file_digest(handle, 'sha256').hexdigest()
-Path('/usr/share/harness-os/kernel.json').write_text(json.dumps({'path': str(kernel.relative_to('/')), 'sha256': digest}) + '\n')
+Path('/usr/share/harness-os/kernel.json').write_text(json.dumps({'path': str(kernel.relative_to('/')), 'sha256': digest, 'platform': profile['id']}) + '\n')
PY
pacman -Q > /usr/share/harness-os/packages.txt
# Archiso removes pacman's sync databases during cleanup. Preserve the two
diff --git a/os/tools/inspect_image.py b/os/tools/inspect_image.py
index e48142891..3039e2f6c 100644
--- a/os/tools/inspect_image.py
+++ b/os/tools/inspect_image.py
@@ -36,6 +36,11 @@ def inspect(iso):
'usr/lib/harness-os/projects.py': source / 'projects.py',
'usr/lib/harness-os/trial_projects.py': source / 'trial_projects.py',
'usr/lib/harness-os/system.py': source / 'system.py',
+ 'usr/lib/harness-os/boot_profile.py': source / 'boot_profile.py',
+ 'usr/lib/harness-os/t2_install.py': source / 't2_install.py',
+ 'usr/lib/harness-os/t2_firmware.py': source / 'tools/prepare-t2-firmware.py',
+ 'usr/lib/harness-os/firmware_names.py': source / 'platforms/apple-t2/firmware_names.py',
+ 'usr/share/harness-os/apple-t2/kernel.json': source / 'platforms/apple-t2/kernel.json',
'usr/lib/harness-os/runtime_update.py': source / 'runtime_update.py',
'usr/lib/harness-os/live_update.py': source / 'live_update.py',
'usr/lib/harness-os/release_update.py': source / 'release_update.py',
@@ -71,7 +76,12 @@ def inspect(iso):
kernel = json.loads(read('usr/share/harness-os/kernel.json'))
assert re.fullmatch(r'usr/lib/modules/[a-zA-Z0-9._+-]+/vmlinuz', kernel['path'])
assert hashlib.sha256(read(kernel['path'])).hexdigest() == kernel['sha256'], 'Offline install kernel mismatch'
- assert read(str(Path(kernel['path']).with_name('pkgbase'))).strip() == b'linux-lts'
+ platform = manifest['platform']
+ assert platform in {'pc', 'apple-t2'}
+ assert json.loads(read('etc/harness-platform.json')) == {'schema': 1, 'id': platform}
+ assert kernel['platform'] == platform
+ pkgbase = 'linux-lts' if platform == 'pc' else 'linux-t2'
+ assert read(str(Path(kernel['path']).with_name('pkgbase'))).decode().strip() == pkgbase
packages = read('usr/share/harness-os/packages.txt').decode()
assert packages == (iso.parent / 'packages.txt').read_text(), 'Package inventory mismatch'
inventory = dict(row.split(maxsplit=1) for row in packages.splitlines())
@@ -82,34 +92,47 @@ def inspect(iso):
expected_version = re.escape(version.replace('-preview.', 'pre')) + r'\.r\d+\.g' + manifest['source_commit'][:10] + '-1'
assert re.fullmatch(expected_version, package_version), 'OS package version differs from the image source'
assert package_version == manifest['package_version'], 'OS package version differs from the manifest'
- assert set(manifest['capabilities']) == {'runtime-updates', 'system-updates', 'single-action-updates', 'broadcom-offline', 'nvidia-offline', 'install-first'}, 'Image capabilities differ from the manifest'
- hardware_root = 'usr/share/harness-os/hardware/broadcom/'
- hardware = json.loads(read(hardware_root + 'manifest.json'))
- assert hardware == manifest['hardware']['broadcom'], 'Hardware manifest differs from the payload'
- assert hardware['kernel'] == Path(kernel['path']).parent.name, 'Wi-Fi module targets a different kernel'
- assert hardware['arch_snapshot'] == manifest['arch_snapshot']
- assert all(inventory.get(name) == version for name, version in hardware['base_packages'].items())
- assert not names & {'gcc', 'make', 'dkms', 'broadcom-wl-dkms', 'linux-lts-headers'}, 'Optional Wi-Fi build tools entered the default image'
- for name, expected in hardware['files'].items():
- assert not Path(name).is_absolute() and '..' not in Path(name).parts
- path = hardware_root + name
- data = read(path)
- assert len(data) == expected['bytes'] and hashlib.sha256(data).hexdigest() == expected['sha256'], f'Hardware bundle mismatch: {name}'
- assert owners.get(path) == '0/0', f'Hardware file is not root-owned: {name}'
- nvidia_root = 'usr/share/harness-os/hardware/nvidia/'
- nvidia = json.loads(read(nvidia_root + 'manifest.json'))
- assert nvidia == manifest['hardware']['nvidia']
- assert nvidia['kernel'] == Path(kernel['path']).parent.name
- assert nvidia['arch_snapshot'] == manifest['arch_snapshot']
- assert all(inventory.get(name) == version for name, version in nvidia['base_packages'].items())
+ capabilities = {'runtime-updates', 'system-updates', 'single-action-updates', 'install-first'}
+ capabilities |= {'broadcom-offline', 'nvidia-offline'} if platform == 'pc' else {'t2-kernel', 'apple-firmware-preservation'}
+ assert set(manifest['capabilities']) == capabilities, 'Image capabilities differ from the manifest'
+ assert not names & {'gcc', 'make', 'dkms', 'broadcom-wl-dkms', 'linux-lts-headers', 'linux-t2-headers'}, 'Hardware build tools entered the default image'
assert not names & {'nvidia-utils', 'nvidia-open-lts'}, 'Optional GPU packages entered the generic image'
- for name, expected in nvidia['files'].items():
- assert not Path(name).is_absolute() and '..' not in Path(name).parts
- path = nvidia_root + name
- data = read(path)
- assert len(data) == expected['bytes'] and hashlib.sha256(data).hexdigest() == expected['sha256'], f'NVIDIA bundle mismatch: {name}'
- assert owners.get(path) == '0/0', f'NVIDIA file is not root-owned: {name}'
+ if platform == 'pc':
+ assert set(manifest['hardware']) == {'broadcom', 'nvidia'}
+ for driver in ['broadcom', 'nvidia']:
+ prefix = 'usr/share/harness-os/hardware/' + driver + '/'
+ hardware = json.loads(read(prefix + 'manifest.json'))
+ assert hardware == manifest['hardware'][driver], 'Hardware manifest differs from the payload'
+ assert hardware['kernel'] == Path(kernel['path']).parent.name, 'Driver targets another kernel'
+ assert hardware['arch_snapshot'] == manifest['arch_snapshot']
+ assert all(inventory.get(name) == version for name, version in hardware['base_packages'].items())
+ for name, expected in hardware['files'].items():
+ assert not Path(name).is_absolute() and '..' not in Path(name).parts
+ path = prefix + name
+ data = read(path)
+ assert len(data) == expected['bytes'] and hashlib.sha256(data).hexdigest() == expected['sha256'], f'Hardware bundle mismatch: {name}'
+ assert owners.get(path) == '0/0', f'Hardware file is not root-owned: {name}'
+ else:
+ assert set(manifest['hardware']) == {'apple-t2'}
+ hardware = json.loads(read('usr/share/harness-os/apple-t2/manifest.json'))
+ pin = json.loads((source / 'platforms/apple-t2/kernel.json').read_text())
+ assert hardware == manifest['hardware']['apple-t2'] and hardware['kernel'] == pin
+ assert inventory['linux-t2'] == pin['package']['version'] and 'linux-lts' not in names
+ assert Path(kernel['path']).parent.name == pin['kernel_release']
+ assert read('etc/mkinitcpio.conf.d/20-harness-platform.conf').decode() == 'MODULES+=(' + ' '.join(pin['early_modules']) + ')\n'
+ assert read('etc/modules-load.d/harness-t2.conf') == b't2bce_vhci\n'
+ assert b'Exec = /usr/bin/python3 /usr/lib/harness-os/t2_install.py restore' in read('etc/pacman.d/hooks/80-harness-t2-firmware.hook')
+ assert set(hardware['verified_files']) == {'.PKGINFO', 'pkgbase', 'vmlinuz', *pin['required_modules']}
+ for name, expected in hardware['verified_files'].items():
+ if name == '.PKGINFO':
+ continue # This is package metadata, not an installed file.
+ assert expected['path'].startswith('usr/lib/modules/' + pin['kernel_release'] + '/')
+ data = read(expected['path'])
+ assert len(data) == expected['bytes'] and hashlib.sha256(data).hexdigest() == expected['sha256']
+ assert not any(path.endswith('harness-apple-firmware.tar') or path.endswith('apple-firmware.tar') for path in owners), 'A private Apple firmware export entered the ISO'
wanted = {row.strip() for row in (source / 'packages.x86_64').read_text().splitlines() if row.strip() and not row.startswith('#')}
+ if platform == 'apple-t2':
+ wanted = (wanted - {'linux-lts'}) | {'linux-t2'}
assert wanted.issubset(names), f'Missing packages: {wanted - names}'
config = read('etc/pacman.conf').decode()
assert config.count('/' + manifest['arch_snapshot'] + '/') == 2 and '[harness-build]' not in config
diff --git a/os/tools/manifest.py b/os/tools/manifest.py
index a56ff5be1..e2925c3a4 100644
--- a/os/tools/manifest.py
+++ b/os/tools/manifest.py
@@ -30,6 +30,10 @@ if (root / 'usr/lib/harness-os/release_update.py').is_file():
if (root / 'etc/sudoers.d/30-harness-updates').is_file():
capabilities.append('single-action-updates')
hardware = {}
+platform = json.loads((root / 'etc/harness-platform.json').read_text())['id']
+if platform == 'apple-t2':
+ capabilities.extend(['t2-kernel', 'apple-firmware-preservation'])
+ hardware['apple-t2'] = json.loads((root / 'usr/share/harness-os/apple-t2/manifest.json').read_text())
for driver in ['broadcom', 'nvidia']:
path = root / f'usr/share/harness-os/hardware/{driver}/manifest.json'
if path.is_file():
@@ -37,6 +41,7 @@ for driver in ['broadcom', 'nvidia']:
hardware[driver] = json.loads(path.read_text())
manifest = {
'version': lock['version'], 'architecture': 'x86_64',
+ 'platform': platform,
'source_commit': os.environ.get('HARNESS_OS_SOURCE_SHA') or subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip(),
'built_at_unix': int(time.time()), 'arch_snapshot': lock['arch_snapshot'],
'iso': {'name': iso.name, 'bytes': iso.stat().st_size, 'sha256': digest},
diff --git a/os/tools/prepare-t2-firmware.py b/os/tools/prepare-t2-firmware.py
index a2765c520..75e343bb5 100644
--- a/os/tools/prepare-t2-firmware.py
+++ b/os/tools/prepare-t2-firmware.py
@@ -17,7 +17,9 @@ import tarfile
import tempfile
-CONVERTER = Path(__file__).parents[1] / 'platforms/apple-t2/firmware_names.py'
+CONVERTER = Path(__file__).with_name('firmware_names.py')
+if not CONVERTER.is_file():
+ CONVERTER = Path(__file__).parents[1] / 'platforms/apple-t2/firmware_names.py'
spec = importlib.util.spec_from_file_location('harness_apple_firmware_names', CONVERTER)
names = importlib.util.module_from_spec(spec)
spec.loader.exec_module(names)
@@ -202,6 +204,13 @@ def unique_object(pairs):
def verify(bundle, model):
+ try:
+ return verify_archive(bundle, model)
+ except (tarfile.TarError, UnicodeError, KeyError, TypeError) as error:
+ raise ValueError('Invalid preserved firmware archive.') from error
+
+
+def verify_archive(bundle, model):
check_model(model)
data = regular_bytes(bundle, MAX_ARCHIVE)
files, manifest = {}, None
diff --git a/os/tools/publish-update.py b/os/tools/publish-update.py
index 1326498ea..ae01898e5 100644
--- a/os/tools/publish-update.py
+++ b/os/tools/publish-update.py
@@ -17,6 +17,13 @@ REPO = 'autonomous-ai/openharness'
CHANNEL = 'os-preview-updates'
+def bootstrap_files():
+ spec = importlib.util.spec_from_file_location('harness_runtime_update', Path(__file__).parents[1] / 'runtime_update.py')
+ updater = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(updater)
+ return updater.BOOTSTRAP_FILES
+
+
def digest(path):
with path.open('rb') as handle:
return hashlib.file_digest(handle, 'sha256').hexdigest()
@@ -47,7 +54,7 @@ def validate(bundle, receipt, run):
raise ValueError('Package, fast runtime and system-channel checks must all pass.')
if not receipt['system_channel'].get('reboot_keyboard'):
raise ValueError('The channel update has not passed its actual encrypted reboot and keyboard check.')
- expected = {manifest['package']['name'], 'package-manifest.json', 'apply-update.py'}
+ expected = {manifest['package']['name'], 'package-manifest.json', *updater.BOOTSTRAP_FILES}
checksums = {}
for line in (bundle / 'SHA256SUMS').read_text().splitlines():
checksum, name = line.split(' ', 1)
@@ -93,7 +100,7 @@ def main():
bundle_name = 'harness-update-' + manifest['requires_os_version'] + '-' + manifest['source_commit'][:9] + '-x86_64.zip'
archive = output / bundle_name
with zipfile.ZipFile(archive, 'w', compression=zipfile.ZIP_DEFLATED) as zipped:
- for name in [manifest['package']['name'], 'package-manifest.json', 'apply-update.py', 'SHA256SUMS']:
+ for name in [manifest['package']['name'], 'package-manifest.json', *bootstrap_files(), 'SHA256SUMS']:
entry = zipfile.ZipInfo(name, date_time=(1980, 1, 1, 0, 0, 0))
entry.external_attr = 0o100644 << 16
zipped.writestr(entry, (args.bundle / name).read_bytes(), compress_type=zipfile.ZIP_DEFLATED)