diff --git a/probes/cli_contract_guest.py b/probes/cli_contract_guest.py new file mode 100644 index 0000000..57bf5ef --- /dev/null +++ b/probes/cli_contract_guest.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +"""Run inside normal acceptance VMs; stdout is a single acceptance record.""" +import json +from pathlib import Path +import subprocess +import sys + + +def call(*args, success=True): + p = subprocess.run(['archipelago', *args], text=True, capture_output=True, timeout=600) + assert (p.returncode == 0) == success, (args, p.returncode, p.stdout, p.stderr) + return p + + +def query(*args, success=True): + p = call(*args, '--json', success=success) + assert not p.stderr, ('JSON mode must not print progress', p.stderr) + result = json.loads(p.stdout) + assert isinstance(result, dict) + if not success: + assert isinstance(result.get('error'), dict), result + return result + + +phase = sys.argv[1] +marker = 'archipelago.acceptance=retained' +if phase == 'prepare': + status = query('status') + assert status['booted']['deployment_id'] + human = call('status') + assert not human.stdout.lstrip().startswith('{') + assert all(word not in human.stdout + human.stderr for word in ['retry token:', 'admission:', 'Checked plan ']) + debug = call('status', '--debug', '--json') + assert json.loads(debug.stdout)['booted'] == status['booted'] + assert any(json.loads(line)['event'] == 'result' for line in debug.stderr.splitlines()) + before = query('kargs') + rejected = query('kargs', '--append=ostree=/invalid', success=False) + assert rejected['error']['message'] + assert query('kargs') == before, 'Invalid edit changed deployment' + first = query('kargs', '--append-if-missing=archipelago.acceptance=initial') + assert first['outcome'] == 'staged' + second = query('kargs', '--replace=archipelago.acceptance=initial=retained', '--delete-if-present=quiet') + assert second['outcome'] == 'staged' + selected = query('kargs')['selected'] + assert marker in selected['arguments'] and 'quiet' not in selected['arguments'] + unchanged = query('kargs', '--append-if-missing=' + marker) + assert unchanged['outcome'] == 'no-change' + assert query('kargs')['selected']['deployment_id'] == selected['deployment_id'] + human = call('kargs', '--append-if-missing=' + marker) + assert all(word not in human.stdout + human.stderr for word in ['retry token:', 'admission:', 'Checked plan ', '{']) + Path('/var/tmp/archipelago-cli-contract.json').write_text(json.dumps({'marker':marker, 'original':before})) +elif phase == 'verify': + evidence = json.loads(Path('/var/tmp/archipelago-cli-contract.json').read_text()) + assert evidence['marker'] in Path('/proc/cmdline').read_text().split() + assert 'quiet' not in Path('/proc/cmdline').read_text().split(), 'Extension staging reset user kargs' + state = query('kargs') + booted = next(d for d in state['deployments'] if d['booted']) + assert marker in booted['arguments'] and 'quiet' not in booted['arguments'] + history = query('transaction', 'list') + assert not history['next_cursor'], 'Acceptance must read complete history' + assert any(r['Kind'] == 'kernel-arguments' and r['State'] == 'succeeded' for r in history['transactions']) +else: + raise ValueError('Unknown acceptance phase') +print(json.dumps({'passed':True,'phase':phase,'cli_formats':['human','json','debug-json'],'kernel_arguments':marker})) diff --git a/probes/core_iso_acceptance.py b/probes/core_iso_acceptance.py index a993341..b6e7472 100644 --- a/probes/core_iso_acceptance.py +++ b/probes/core_iso_acceptance.py @@ -95,9 +95,9 @@ def main(): # Use the authenticated CLI as root, just like the failed operation. child.expect(r"(?:root|coretest)@[^\r\n]*[#$] ") if privileged: - diagnostic = """archipelago transaction list; python3 - <<'PY' + diagnostic = """archipelago transaction list --json; python3 - <<'PY' import json, subprocess -p = subprocess.run(['archipelago', 'transaction', 'list'], capture_output=True, text=True) +p = subprocess.run(['archipelago', 'transaction', 'list', '--json'], capture_output=True, text=True) if p.returncode == 0: data = json.loads(p.stdout) for record in data['transactions']: @@ -274,6 +274,9 @@ journalctl -u archipelagod.service -n 80 --no-pager reboot() command(marker_check) command("archipelago self-check", True) + if args.production_cli: + cli_contract = Path(__file__).with_name('cli_contract_guest.py').read_text() + command("python3 -c " + shlex.quote(cli_contract) + " prepare", True) command("archipelago extension enable; archipelago extension add nano; ! command -v nano", True) if args.extensions_sequence: command("archipelago extension add mc htop; ! command -v mc; ! command -v htop", True) @@ -286,6 +289,8 @@ journalctl -u archipelagod.service -n 80 --no-pager "cmp /run/pending-before /run/pending-after; archipelago status", True) reboot() command("nano --version; " + marker_check) + if args.production_cli: + command("python3 -c " + shlex.quote(cli_contract) + " verify", True) command("archipelago self-check", True) command("archipelago status; pacman -Q nano; systemctl is-active systemd-networkd systemd-resolved sshd", True) if args.extensions_sequence: @@ -324,7 +329,7 @@ journalctl -u archipelagod.service -n 80 --no-pager "assert outcomes.count('staged')==3, outcomes; " "assert outcomes.count('no-change')==1, outcomes" ) - command("archipelago transaction list | python3 -c " + shlex.quote(history_check), True) + command("archipelago transaction list --json | python3 -c " + shlex.quote(history_check), True) else: command("test \"$(wc -l < /usr/lib/archipelago/host-extensions)\" = 4; " "test \"$(find /var/lib/archipelago/host-extensions/generations -name staged | wc -l)\" = 3; " diff --git a/probes/gnome_native_acceptance.py b/probes/gnome_native_acceptance.py index 6874175..4ca46ff 100644 --- a/probes/gnome_native_acceptance.py +++ b/probes/gnome_native_acceptance.py @@ -160,8 +160,10 @@ systemctl is-active archipelagod.service systemctl is-active display-manager NetworkManager ostree-finalize-staged.service runuser -u coretest -- sh -c 'echo "clean dropin candidate" > /var/home/coretest/.archipelago-clean-persistence' archipelago extension enable -archipelago extension add nano ''', timeout=provisioning_timeout + 1800) + cli_contract = Path(__file__).with_name('cli_contract_guest.py').read_text() + guest('python3 -c ' + shlex.quote(cli_contract) + ' prepare', timeout=1800) + guest('archipelago extension add nano', timeout=1800) wayland = '''until loginctl list-sessions --no-legend | awk '$3=="coretest" {print $1}' | xargs -r -n1 loginctl show-session -p Type --value | grep -qx wayland; do sleep 3; done''' guest('timeout 120 bash -c ' + shlex.quote(wayland), timeout=150) guest('''set -e @@ -200,6 +202,8 @@ runuser -u coretest -- env XDG_RUNTIME_DIR=/run/user/$uid toolbox run sh -ec 'te raise RuntimeError('Guest did not complete reboot within 360 seconds') check_zram() result['zram']['active_after_extension_reboot'] = True + guest('python3 -c ' + shlex.quote(cli_contract) + ' verify', timeout=180) + result['cli_contract'] = {'human': True, 'json': True, 'debug_json': True, 'kernel_arguments_activated': True} guest('''set -e uid=$(id -u coretest) runuser -u coretest -- env XDG_RUNTIME_DIR=/run/user/$uid toolbox run sh -ec 'grep -qx toolbox-persistence "$HOME/.archipelago-toolbox-persistence"; test "$(id -u)" != 0' diff --git a/probes/update_rollout_guest.py b/probes/update_rollout_guest.py index 5f4c846..c5bbc28 100644 --- a/probes/update_rollout_guest.py +++ b/probes/update_rollout_guest.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 -"""Validate a terra-signed candidate on the retained GNOME VM, then rollback. +"""Validate the configured, signed update target on a retained GNOME VM, then rollback. -Candidate checksum is an explicit validation input, not an advanced public channel. -The normal updater verifies the commit signature before staging. No /usr injection. +The candidate must already be the target of the VM's configured track. Private +pre-publication validation requires a private track; plans are never rewritten. +This optional rollout probe is not part of release-cycle installed-ISO acceptance. """ import argparse import json @@ -102,21 +103,19 @@ try: install -m644 /var/tmp/rollout-update.json /etc/archipelago/update.json ''') run('''set -e +systemctl is-active archipelagod.service archipelago self-check getent passwd coretest > /var/tmp/rollout-account test "$(cat /var/home/coretest/.archipelago-clean-persistence)" = "clean dropin candidate" -/var/tmp/archipelago-updater update plan > /var/tmp/rollout-channel-plan +/var/tmp/archipelago-updater update plan --json > /var/tmp/rollout-channel-plan ''') - # Explicit candidate plan for pre-publication validation. All other captured - # preconditions stay unchanged. The production updater still verifies GPG. - text = run('cat /var/lib/archipelago/updates/plan-$(sed -n "s/^Plan: //p" /var/tmp/rollout-channel-plan).json') + text = run('cat /var/tmp/rollout-channel-plan') plan = json.JSONDecoder().raw_decode(text[text.index('{'):])[0] - plan['target'] = args.candidate - run('printf %s ' + shlex.quote(json.dumps(plan, sort_keys=True)) + ' > /var/tmp/rollout-candidate-plan.json\n' - 'hash=$(sha256sum /var/tmp/rollout-candidate-plan.json | cut -d" " -f1)\n' - 'cp /var/tmp/rollout-candidate-plan.json /var/lib/archipelago/updates/plan-$hash.json\n' - 'printf %s "$hash" > /var/tmp/rollout-plan-id\n' - '/var/tmp/archipelago-updater update apply --plan "$hash"', timeout=3600) + assert plan['target'] == args.candidate, 'Candidate must match the configured verified track' + plan_id = plan['plan_id'] + assert len(plan_id) == 64 and all(c in '0123456789abcdef' for c in plan_id) + run('printf %s ' + shlex.quote(plan_id) + ' > /var/tmp/rollout-plan-id\n' + '/var/tmp/archipelago-updater update apply --json --plan ' + shlex.quote(plan_id), timeout=3600) pending = next(d['checksum'] for d in state() if d['staged']) result['updated'] = pending run('systemctl reboot', check=False) @@ -138,13 +137,14 @@ for ref in policy['applications']: subprocess.run(['flatpak', 'info', '--system', runtime], check=True) PY ostree admin status --json > /var/tmp/rollout-before-stale -if archipelago update apply --plan "$(cat /var/tmp/rollout-plan-id)"; then exit 1; fi +if archipelago update apply --json --plan "$(cat /var/tmp/rollout-plan-id)"; then exit 1; fi ostree admin status --json > /var/tmp/rollout-after-stale cmp /var/tmp/rollout-before-stale /var/tmp/rollout-after-stale ''') metadata = run('cat /usr/lib/archipelago/extensions.json') metadata = json.JSONDecoder().raw_decode(metadata[metadata.index('{'):])[0] - assert metadata['base'] == args.candidate and metadata['requested'] == ['nano'] + assert metadata['base'] == args.candidate + assert metadata['version'] == 3 and metadata['requested'] == ['nano'] # Authenticate through native GDM; do not inject autologin configuration. ui = ['python3', str(Path(__file__).resolve().parent / 'gnome_vm_input.py'), str(args.vm)] active = run('''loginctl list-sessions --no-legend | awk '$3=="coretest" {print $1}' | xargs -r -n1 loginctl show-session -p Type --value | grep -qx wayland && echo WAYLAND_ALREADY_ACTIVE || true''')