set -euo pipefail umask 077 test "$(hostname -s | tr A-Z a-z)" = absdev-ci stage=$(mktemp -d /var/tmp/absdev-rehearsal-revocation.XXXXXX) suffix=$(tr '[:upper:]' '[:lower:]' <<< "${stage##*.}") account="abrev$suffix" runner="abrnr$suffix" outsider="aboth$suffix" runner_created=0 outsider_created=0 created=0 cleanup() { rc=$? if ((outsider_created)); then userdel "$outsider" || rc=1; fi if ((created)); then userdel "$account" || rc=1; fi if ((runner_created)); then userdel "$runner" || rc=1; fi rm -rf -- "$stage" || rc=1 exit "$rc" } trap cleanup EXIT mkdir "$stage/source" "$stage/evidence" "$stage/tmp" tar -xm -f - -C "$stage/source" chmod 0711 "$stage" chmod -R a+rX "$stage/source" useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$account" created=1 install -d -m 0750 -o root -g "$account" "$stage/authority" install -d -m 0700 -o "$account" -g "$account" "$stage/operator-tmp" useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$runner" runner_created=1 useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$outsider" outsider_created=1 install -d -m 0750 -o root -g "$runner" "$stage/rehearsal" python3 -c 'import secrets,sys; sys.stdout.buffer.write(secrets.token_bytes(32))' > "$stage/rehearsal/key" chgrp "$runner" "$stage/rehearsal/key" chmod 0440 "$stage/rehearsal/key" install -m 0440 -o root -g "$account" "$stage/rehearsal/key" "$stage/authority/rehearsal-key" install -d -m 0700 -o "$runner" -g "$runner" "$stage/runner-tmp" runuser -u "$runner" -- test -r "$stage/rehearsal/key" runuser -u "$account" -- test -r "$stage/authority/rehearsal-key" deny() { if "$@"; then exit 1; fi; } deny runuser -u "$runner" -- test -x "$stage/authority" deny runuser -u "$outsider" -- test -r "$stage/rehearsal/key" deny runuser -u "$outsider" -- test -x "$stage/authority" deny runuser -u "$runner" -- test -w "$stage/rehearsal/key" deny runuser -u "$account" -- test -w "$stage/authority/rehearsal-key" export TMPDIR="$stage/tmp" out="$stage/evidence" cd "$stage/source" printf 'host=%s\nrevision=2a001b1269804f997c3d76bbe030b4126745e51e\noperator_uid=%s\n' "$(hostname -s)" "$(id -u "$account")" > "$out/scope.txt" python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json" runuser -u "$runner" -- env TMPDIR="$stage/runner-tmp" python3 -B worker.py "$stage/rehearsal/key" --attest > "$stage/authority/attestation.json" chgrp "$account" "$stage/authority/attestation.json" chmod 0440 "$stage/authority/attestation.json" python3 -B controller.py "$account" "$(id -u "$account")" "$(id -g "$account")" "$stage/authority" "$runner" "baseline" > "$out/checks.jsonl" printf '%s\n' '{"check":"separate rehearsal runner issued attestation accepted by approval runtime; outsider denied key access","result":"PASS"}' >> "$out/checks.jsonl" userdel "$outsider" outsider_created=0 userdel "$account" created=0 userdel "$runner" runner_created=0 rm -rf -- "$stage/authority" "$stage/operator-tmp" "$stage/rehearsal" if getent passwd "$account"; then exit 1; fi printf '%s\n' '{"check":"disposable operator and authority files removed","result":"PASS"}' >> "$out/checks.jsonl" if test "baseline" = fixed; then bash scripts/ci-check.sh > "$out/framework-ci.txt" 2>&1 || { tail -80 "$out/framework-ci.txt" >&2; exit 1; } fi python3 -B bin/absdev-deploy capabilities > "$out/capabilities-after.json" cmp "$out/capabilities-before.json" "$out/capabilities-after.json" (cd "$out" && sha256sum ./* > SHA256SUMS) tar -czf - -C "$out" .