| new file mode 100644 |
| index 00000000..0b8f2260 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-12-01-hosted-2-dev-live-plan.md |
| @@ -0,0 +1,1017 @@ |
| +# Hosted runners slice 2, Task 34: the dev drill in `kass` (for Paul's GO) |
| + |
| +**Revision:** 0 (2026-12-01), a draft for Fable to shape, then Astra (three rounds at most), then |
| +Paul's one GO. **No AWS command or SDK call of any kind was made while writing it, not even a |
| +read.** It is written in the shape of Task 17b (`2026-11-30-hosted-1a-task17b-live-plan.md`): |
| +hard stops only for safety, `FINDING:` lines for everything else, a ledger, systemd user units, |
| +teardown verified by direct reads. The run machinery is `equipo-hosted-ops` (slice 2 Task 33), so |
| +this drill is that tool's first real run, ahead of the production bring-up |
| +(`2026-11-30-hosted-prod-account-plan.md`, "the account plan" below). Section numbers below are |
| +this plan's own. |
| + |
| +## What Paul approves |
| + |
| +One drill in account `640012953448` (profile `kass`), region `eu-west-1`. Nothing touches |
| +`149757027610` in any form: `ops` refuses any other account (`-account` must be one of the two it |
| +knows, and every AWS call is verified through STS first), the OpenTofu providers carry |
| +`allowed_account_ids = ["640012953448"]`, and `ledger rec` refuses any other account's ARN. |
| +Every AWS call goes through `ops`, `img` (`equipo-hosted-image`) or `cert`'s controller calls, each |
| +behind the guard. `kass` names no `role_arn`, so every `ops` call passes `-role user/remote-agent`, |
| +the caller Task 17b recorded for `kass` (`HOSTED-SLICE1-PROGRESS.md`, 0.3 of attempts 4 and 5); the |
| +first guard binds it, and `img` must name the same caller (`-expect-role`). |
| + |
| +The drill, in order: builds and publishes a dev hosted release from the branch pin (a forge tag, no |
| +AWS); deploys the branch to the staging Equipo instance; applies `envs/dev/network`, `config` and |
| +`services`; creates the connector; builds and publishes the image (one Large version); runs one |
| +certification launch, which is the egress matrix and the containment suite inside a real MicroVM; |
| +**Paul signs the certificate offline**; wires the staging instance to the controller; runs three |
| +hosted checks end to end (pass, fail, new module) and two Task 30 drills on real VMs (the |
| +controller away mid-step, the certificate withdrawn mid-step); then tears everything down, fence and |
| +unfence included, deletes the connector (its first real interface cleanup) and verifies every |
| +resource gone by a direct read. |
| + |
| +**Hard stops** (exit 99, then section S): the guard fails; the run's estimate reaches **$35**; a |
| +MicroVM of the run's image is live more than 10 minutes after its step ended, or live and in neither |
| +the ledger nor the controller's table; anything outside the ledger or the checked plan (a name |
| +collision, a `plan-check.py` refusal, a foreign owner or account); the egress boundary differs (the |
| +network assert, a blocked probe that reached, the status assert); a teardown step that cannot |
| +complete. **Everything else** that differs is a `FINDING:` line. A failure that blocks the rest of |
| +the drill but is not a safety problem is a FINDING plus **skip to teardown** (section 8), which Paul |
| +pre-approves here: teardown is the safe direction, and waiting costs money. |
| + |
| +**Pre-approved fallbacks:** one base image version down, once (3.3); one `ops tf reconcile` and one |
| +re-apply after a failed apply, which is where OpenTofu import adoption runs if it is needed (2.3, |
| +2.4, 4.1); the connector delete's own retry with the managed-operator condition dropped (inside |
| +`ops connector delete`); skip to teardown as above. Guarded, read-only calls on this run's own |
| +resources are pre-approved. Any other change to a command, or any other AWS call, comes back to Paul. |
| + |
| +**Spend** (section 9): the bill is expected at about **$1.60**, at most about $5. The run's own |
| +estimate, which charges every admitted VM at four times the Large rate for 90 minutes, ends near |
| +$26.60 when everything goes to plan and has a proven worst case of $32.22. Self-stop at **$35**; |
| +approval ceiling **$45**. |
| + |
| +**Paul's own steps:** sign the certificate (5.4, bounded 12 hours); start five small tasks on |
| +staging (6.2 and 7, bounded 6 hours). Past a bound, the watchdog runs section S, which stops the |
| +controller host and leaves the rest at about $1.15 a day until Paul decides. |
| + |
| +## Decisions owed to Paul (with recommendations) |
| + |
| +1. **A dev hosted release on the forge.** Hosts download the controller and proxy by URL from the |
| + release (`release.url` in the services root), so the drill must publish one: |
| + `scripts/release-hosted.sh` pushes the tag `hosted-<DEV_VERSION>` for the unmerged pin and |
| + creates the release. A published release is never replaced. *Recommendation:* publish |
| + `hosted-0.0.1` as the dev drill's release; production takes its own release after the merge. |
| +2. **Staging runs the branch.** Hosted checks need this branch's instance (migrations 0125 onward, |
| + protocol 39) and the owner's staging runner at protocol 39. *Recommendation:* deploy the pin to |
| + staging with `scripts/staging-thin.py release` (0.3) and keep it there until the branch merges: |
| + main's instance would meet a database with migrations it does not know. |
| +3. **Who starts the checks.** The account plan has Paul start them. *Recommendation:* Paul, on a |
| + scratch Go project of his on staging (6.2, 7). The alternative is the headless suite's person, |
| + which has no hosted scenario today. |
| +4. **Drills the kit cannot run.** `ops` has no command to stop a proxy host, to stop one VM, or to |
| + plant a VM outside the controller, and a fenced controller is never restarted. So the proxy-kill, |
| + VM-stop and orphan drills, and "a launch refused while fenced" (`infra/hosted/README.md`, dev |
| + differences), are not run (7.3). *Recommendation:* accept that for this drill (the orphan path was |
| + proven live in Task 17b on the same reaper); if Paul wants them, a small task first adds two |
| + `ops` subcommands: stop and start one recorded host, and terminate one recorded VM. |
| +5. **Spend:** self-stop $35, ceiling $45 (section 9). **Human-wait bounds:** 12 hours for the |
| + signature, 6 hours for the tasks. |
| + |
| +## Inputs filled at GO |
| + |
| +| Input | What | Used in | |
| +| --- | --- | --- | |
| +| `<PIN>` | the full SHA of the branch commit at GO: the code tip, after Paul's three copy titles are accepted (the runner kit needs `copy-release-check` green); it must contain `d67ba3db` (ops), `ada99ffd` (pins), `3193a57f` (image fixes) and `8ed317b6` (copy) | 0.1 only | |
| +| `<DEV_VERSION>` | the dev release version, `0.0.1` recommended | 0.1 only | |
| +| `<CERT_PUB>` | the contents of Paul's `paul-cert-1.pub` (ed25519, standard base64); key ID `paul-cert-1` | 2.2 only | |
| +| `<ALERT_EMAIL>` | owed, but the dev stacks have no email subscription (`envs/dev/config` has a topic with no subscriber), so the drill does not use it; see section 11 | none | |
| +| Staging | app `equipo-staging`, account `bds`, console `https://console.carloku.com`, host `equipo-staging.bds.oncarlos.com`, as `scripts/staging-thin.py` names them; Paul confirms | 0.3, 2.2, 6.1, 8.1 | |
| +| Scratch project | a Go repository of Paul's on staging whose checks pass | 6.2, 7 | |
| + |
| +## Order of execution |
| + |
| +| Order | Section | Roughly | |
| +| --- | --- | --- | |
| +| 1 | 0. Pin, scratch, dev release, staging (no AWS) | 60 to 90 min | |
| +| 2 | 1. Guard, inventory, quota, recovery rehearsal | 15 min | |
| +| 3 | 2. State bucket, keys, network, config, connector | 40 min | |
| +| 4 | 3. Image | 20 to 50 min | |
| +| 5 | 4. Controller and proxies | 30 min | |
| +| 6 | 5. Certification, then Paul signs | 45 min, plus the signature | |
| +| 7 | 6. Staging wired, three hosted checks | 20 min, plus Paul's tasks | |
| +| 8 | 7. Two drills on real VMs | 60 min | |
| +| 9 | 8. Teardown and verification | 60 to 180 min | |
| + |
| +## Rules for every block |
| + |
| +- **Shape.** Every block is a script file, `$P/blocks/<id>.sh`, written exactly as printed (only |
| + `<P printed by 0.1>` filled in), and starts `set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env"`. |
| + Blocks that call AWS run with the agent sandbox **off** (Task 17 attempt 1: the sandbox proxy |
| + blocks AWS). One block at a time. |
| +- **Short blocks** run in the foreground as `ops block <id> --stop 35 -- bash "$P/blocks/<id>.sh"`: |
| + the guard and the estimate first, then the script; exit 99, or any non-zero exit, runs section S |
| + and exits 99. Teardown blocks (section 8) pass `--stop 45` instead, so spend never blocks a |
| + teardown short of the approval ceiling. |
| +- **Long blocks** (the bound column below) run as transient systemd user units (R44, R45 ported): |
| + `ops unit start <id> -- bash "$P/blocks/<id>.sh"`, then `ops unit wait <id> --max <bound>`. A long |
| + block's script makes its own admission check first (`ops estimate --stop 35`; teardown units skip |
| + it). `ops unit wait` blocks until the unit ends, so the agent runs it with the Bash tool's |
| + `run_in_background` and a timeout above the bound (the tool's maximum is 120 minutes; if the |
| + background call ends without an exit status, the agent runs the same wait again: it measures the |
| + bound from the unit's start). A failed unit or an expired bound runs section S and exits 99. |
| + Bounds: 2.3 20m, 2.4 15m, 2.5 25m, 3.3 105m, 4.1 30m, 4.2 25m, 5.1 15m, 5.2 40m, 7.1 15m, 8.2 50m, |
| + 8.3 20m, 8.4 45m, 8.5 130m, 8.6 40m. |
| +- **Section S** is always `ops safe-stop`, started with `run_in_background` and a 40-minute timeout |
| + (it can take up to 35 minutes: a fence, a settle with its 10-minute repeat). If the background |
| + call ends without an exit status, run `ops safe-stop` again: it joins the running recovery unit |
| + and waits for it. **A safe stop ends the drill:** it journals `FENCED`, after which |
| + `ops controller reboot` refuses for the rest of the run. Paul then decides on section 8. |
| +- **Fatal checks are `ops assert`, observations are `ops fact`** (a FINDING). An `ops` line in a |
| + script never carries a pipe, a redirection or `||`; a step whose failure is a FINDING is run |
| + between `set +e` and `set -e` and its exit status is recorded with `ops fact`. |
| +- **Skip to teardown.** `skip_to_teardown "<why>"` (from `run.env`) writes the reason and a FINDING; |
| + every block of sections 5 to 7 starts `if skipped; then exit 0; fi`. |
| +- **Ledger.** Every create has a durable intent before it (`ops tf` per planned address, `img publish` |
| + and `cert launch` through `-ledger "$P"`, every other `ops` create itself). Teardown acts only on |
| + confirmed records and OpenTofu state. Every VM ID seen is recorded and keeps its charge. |
| +- **Tags.** `purpose=equipo-hosted-dev` and `run=<RUN>` on every taggable resource (the dev roots' |
| + `default_tags`). MicroVMs carry no tags; `ops vms` finds them by the run's image ARN. |
| +- **docs-t1.** Scratch is `$P` (`mktemp -d` under `$TMPDIR`), removed in 8.8. Default Go caches, |
| + `CGO_ENABLED=0`, Go commands at `nice -n 19`. No sudo. Nothing listens on docs-t1. |
| +- **Records.** Results go to `docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md` under |
| + `## Task 34 live run (<RUN>)`, committed locally at the end (8.8). Never pushed by the run. |
| + Secrets never enter the journal, the record or a commit. |
| + |
| +--- |
| + |
| +## 0. Pin, scratch, dev release, staging (no AWS call) |
| + |
| +### 0.1 Pin, tools, scratch, worktree, binaries, run file |
| + |
| +Runs in the agent's shell, sandbox off (it starts a systemd probe unit). |
| + |
| +```sh |
| +set -euo pipefail |
| +PIN='<PIN>' |
| +REL='hosted-<DEV_VERSION>' |
| +W=/home/paulca/amadan.net/oficina/equipo-hosted-2 |
| +: "${TMPDIR:?TMPDIR is unset}" |
| +[[ "$PIN" =~ ^[0-9a-f]{40}$ ]] || { echo "ABORT: PIN is not a full commit SHA"; exit 1; } |
| +[[ "$REL" =~ ^hosted-[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "ABORT: REL is not hosted-MAJOR.MINOR.PATCH"; exit 1; } |
| +git -C "$W" rev-parse --verify "$PIN^{commit}" |
| +for c in d67ba3db ada99ffd 3193a57f 8ed317b6; do |
| + git -C "$W" merge-base --is-ancestor "$c" "$PIN" || { echo "ABORT: $PIN does not contain $c"; exit 1; } |
| +done |
| +git -C "$W" merge-base --is-ancestor "$PIN" HEAD || { echo "ABORT: HEAD does not contain $PIN"; exit 1; } |
| +[ -z "$(git -C "$W" diff "$PIN" HEAD -- . ':!docs')" ] || { echo "ABORT: code differs from $PIN outside docs/"; exit 1; } |
| +tofu version | head -1 | grep -q '^OpenTofu v1\.12\.' || { echo "ABORT: tofu 1.12 needed"; exit 1; } |
| +for t in aws jq podman curl systemd-run systemctl python3 carlos amadan sha256sum; do command -v "$t" >/dev/null || { echo "ABORT: missing $t"; exit 1; }; done |
| +aws --version; go version; podman --version |
| +P=$(mktemp -d "$TMPDIR/equipo-hosted-dev-XXXX") |
| +case "$P" in *[!A-Za-z0-9/._-]*) echo "ABORT: the scratch path has characters a systemd command line could misread"; exit 1;; esac |
| +RUN=$(date -u +%m%d)-$(head -c3 /dev/urandom | od -An -tx1 | tr -d ' \n') |
| +git -C "$W" worktree add --detach "$P/repo" "$PIN" |
| +mkdir -m 700 "$P/keys" "$P/bin" "$P/blocks" |
| +for c in equipo-hosted-ops equipo-hosted-controller equipo-hosted-image equipo-hosted-certify; do |
| + (cd "$P/repo" && CGO_ENABLED=0 nice -n 19 go build -o "$P/bin/$c" "./cmd/$c"); done |
| +(cd "$W" && CGO_ENABLED=0 nice -n 19 go test ./internal/hostedops/... ./cmd/equipo-hosted-ops ./cmd/equipo-hosted-image ./cmd/equipo-hosted-certify -count=1) |
| +(cd "$P/repo" && nice -n 19 make copy-release-check) |
| +cat > "$P/run.env" <<EOF |
| +P=$P |
| +RUN=$RUN |
| +PIN=$PIN |
| +REPO=$P/repo |
| +REL=$REL |
| +export TF_PLUGIN_CACHE_DIR=\$HOME/.cache/tofu-plugins CGO_ENABLED=0 AWS_PAGER= |
| +IMAGE_DIGEST=\$(jq -r '.IMAGE_DIGEST // empty' "$P/repo/release/$REL.json" 2>/dev/null || true) |
| +ops() { "$P/bin/equipo-hosted-ops" -dir "$P" -run "$RUN" -profile kass -account 640012953448 -region eu-west-1 -role user/remote-agent "\$@"; } |
| +img() ( r=\$(ops guard -print-role) || exit 99; eval "\$(aws configure export-credentials --profile kass --format env)"; unset AWS_PROFILE; exec "$P/bin/equipo-hosted-image" -account 640012953448 -region eu-west-1 -prefix "equipo-hosted-dev-$RUN" -expect-role "\$r" "\$@" ) |
| +cert() { "$P/bin/equipo-hosted-certify" "\$@"; } |
| +tfo() { jq -er ".\$2.value" "$P/tf/\$1.outputs.json"; } |
| +skipped() { [ -e "$P/skip-to-teardown" ] && echo "skipped: \$(cat "$P/skip-to-teardown")"; } |
| +skip_to_teardown() { printf '%s\n' "\$1" > "$P/skip-to-teardown"; ops fact "skip to teardown" "\$1"; } |
| +EOF |
| +"$P/bin/equipo-hosted-ops" -dir "$P" -run "$RUN" ledger init |
| +"$P/bin/equipo-hosted-ops" -dir "$P" -run "$RUN" unit probe |
| +echo "P=$P RUN=$RUN" |
| +``` |
| + |
| +- Expected: the tests `ok`; `copy-release-check` passes; the probe unit starts, shows only |
| + allowlisted names and stops (`ops unit probe`); `P=... RUN=...` printed. |
| +- Abort if: any check fails. Nothing exists yet; fix and start again. |
| + |
| +### 0.2 The dev release (no AWS call; publishes on the forge) |
| + |
| +Runs in the agent's shell, sandbox off, with `run_in_background` and a 90-minute timeout. Not a |
| +unit: it needs the forge's credentials (git push, `amadan`), which the unit allowlist leaves out. |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +cd "$REPO" |
| +[ "$(git rev-parse HEAD)" = "$PIN" ] && [ -z "$(git status --porcelain)" ] || { echo "ABORT: the worktree is not clean at $PIN"; exit 1; } |
| +mkdir -m 700 "$P/inputs" "$P/bwrap" "$P/codex" |
| +scripts/build-hosted-bwrap.sh "$P/bwrap" |
| +cp "$P/bwrap/bwrap" "$P/inputs/bwrap" |
| +curl --fail --silent --show-error --location --proto '=https' --max-time 900 -o "$P/codex/codex.tar.gz" \ |
| + https://github.com/openai/codex/releases/download/rust-v0.165.0/codex-x86_64-unknown-linux-musl.tar.gz |
| +[ "$(sha256sum < "$P/codex/codex.tar.gz" | cut -d' ' -f1)" = be635d3486a5bd060d0fff582ae6d30160280c31344dd85719707fa920e187f0 ] || { echo "ABORT: the codex archive is not the pinned one"; exit 1; } |
| +tar -xzf "$P/codex/codex.tar.gz" -C "$P/codex" codex-x86_64-unknown-linux-musl |
| +cp "$P/codex/codex-x86_64-unknown-linux-musl" "$P/inputs/codex" |
| +nice -n 19 make release-runner |
| +KIT="$REPO/releases/equipo-runner-linux-amd64-$(git rev-parse --short HEAD)" |
| +scripts/release-hosted.sh --out "$P/release" --runner-kit "$KIT" --image-inputs "$P/inputs" "${REL#hosted-}" |
| +jq -e --arg pin "$PIN" '.Commit == $pin and .DryRun == false and .Dirty == false and (.IMAGE_DIGEST | test("^sha256:[0-9a-f]{64}$")) and .BaseImageVersion == "4" and (.HostAMI["eu-west-1"] | test("^ami-"))' "$REPO/release/$REL.json" |
| +echo "release $REL: $(jq -r .IMAGE_DIGEST "$REPO/release/$REL.json")" |
| +``` |
| + |
| +- Expected: `build-hosted-bwrap.sh` checks its result against the hosted pin (`1ebd5a3d…`); |
| + `release-hosted.sh` assembles the image (codex is checked against its member pin `c06a67fd…`, |
| + every RPM and the Go tarball against `pins.json`), publishes `$REL` and re-downloads every asset |
| + byte for byte; the manifest names the pin, `IMAGE_DIGEST`, base version 4 and the host AMI. |
| +- Abort if: any step fails. Nothing exists in AWS. A failure after the tag is pushed leaves the tag; |
| + Paul decides on a new `<DEV_VERSION>`. |
| + |
| +### 0.3 Staging at the pin (no AWS call) |
| + |
| +Runs in the agent's shell with `run_in_background` and a 60-minute timeout, after decision 2. |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +cd "$REPO" |
| +python3 scripts/staging-thin.py build |
| +python3 scripts/staging-thin.py release |
| +curl --fail --silent --max-time 15 https://equipo-staging.bds.oncarlos.com/api/version |
| +``` |
| + |
| +- Expected: `release` passes its idle check, upgrades both staging runner units, then deploys the |
| + instance; `/api/version` prints the pin's short SHA. `EQUIPO_HOSTED_RUNNERS` stays unset, so |
| + nothing hosted runs yet. |
| +- If staging is busy (the idle check refuses), wait and ask Paul. A failure here is a FINDING and |
| + the drill stops before any AWS call. |
| + |
| +## 1. Guard, inventory, quota, recovery rehearsal |
| + |
| +### 1.1 First AWS calls (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops guard |
| +ops inventory |
| +ops quota |
| +ops estimate --stop 35 |
| +``` |
| + |
| +Run through `ops block`, the guard runs first and binds the run to |
| +`arn:aws:iam::640012953448:user/remote-agent`. |
| +`ops inventory` runs before the run's first intent, so it journals every VPC and internet gateway as |
| +`PRE-RUN` facts (the default VPC's gateway then never holds up a network reconcile). A name |
| +starting `equipo-hosted` (role, bucket, image) is a hard stop; any other count is a FINDING. |
| +`ops quota` is a fact. |
| + |
| +### 1.2 Recovery rehearsal at $0 (block) |
| + |
| +The systemd recovery unit (one unit, an exclusive lock, `INVOCATION_ID` membership) has only run |
| +against fakes. This rehearses `ops safe-stop` for real in a **separate** run directory, whose own |
| +`FENCED` cannot reach this run's ledger. Nothing exists in it, so it makes only reads. |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +R="$P/rehearsal"; mkdir -m 700 "$R" |
| +rops() { "$P/bin/equipo-hosted-ops" -dir "$R" -run "r$RUN" -profile kass -account 640012953448 -region eu-west-1 -role user/remote-agent "$@"; } |
| +rops ledger init |
| +rops guard |
| +rops safe-stop |
| +grep -q 'SAFE-STOP end; waiting for Paul' "$R/journal.tsv" |
| +grep -q 'UNIT hdev-r.*-recovery.service' "$R/journal.tsv" |
| +rops unit stop --all |
| +``` |
| + |
| +- Expected: the recovery unit `hdev-r<RUN>-recovery.service` starts, runs S.0 to S.5 with nothing |
| + to act on, and ends with status 0; the requester sees `recovery done`. |
| +- A failure is a hard stop: nothing has been created, and safe stop cannot be trusted later. |
| + |
| +## 2. State bucket, keys, network, config, connector |
| + |
| +### 2.1 The state bucket (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops bucket create --name equipo-hosted-tfstate-640012953448 --versioning --sse AES256 --block-public --expected-owner 640012953448 |
| +``` |
| + |
| +### 2.2 Keys, variables, instance notes (block; no AWS call but the guard) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +K="$P/keys"; c="$P/bin/equipo-hosted-controller" |
| +$c keygen -ed25519 -out "$K/controller"; $c keygen -ed25519 -out "$K/instance"; $c keygen -ed25519 -out "$K/operator" |
| +$c keygen -ed25519 -out "$K/proxy-a"; $c keygen -ed25519 -out "$K/proxy-b" |
| +$c keygen -ca -out "$K/client-ca"; $c keygen -ca -out "$K/intercept-ca" |
| +chmod -R go-rwx "$K" |
| +ops tfvars --out "$P/dev.tfvars" --instance-host equipo-staging.bds.oncarlos.com --release "$REL" --keys "$K" --cert-pub '<CERT_PUB>' |
| +ops ledger note controller-pub "$(cat "$K/controller.pub")" |
| +ops ledger note instance-app equipo-staging |
| +ops ledger note instance-account bds |
| +``` |
| + |
| +The instance notes are written before any controller exists, so section S can always turn the |
| +staging flag off (S.1); with a controller and no notes, S.1 would be unresolved. |
| + |
| +### 2.3 Network (unit, bound 20m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops estimate --stop 35 |
| +set +e |
| +ops tf network dev-network |
| +rc=$? |
| +set -e |
| +if [ "$rc" != 0 ]; then |
| + ops fact "network apply" "exit $rc" "exit 0" |
| + ops tf reconcile network |
| + ops tf network dev-network |
| +fi |
| +ops assert network |
| +``` |
| + |
| +The checked plan (`plan-check.py --phase dev-network`) creates the VM VPC with DNS off, the services |
| +VPC, the peering, the routes, the VM security group (egress only to the proxies on 8443 and 8444, no |
| +ingress), the NACLs and the connector's operator role. `ops assert network` is fatal: DNS off on the |
| +VM VPC, the VM routes exactly local plus the two proxy `/32`s over the one peering, the services |
| +return route, the security group exactly as pinned, the peering active. The one re-apply is where a |
| +resource created outside state is adopted (a run-local import block, a plan checked with |
| +`plan-check.py --adopt`); its exit 99, or `tf reconcile`'s, is final. |
| + |
| +### 2.4 Config (unit, bound 15m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops estimate --stop 35 |
| +set +e |
| +ops tf config dev-config |
| +rc=$? |
| +set -e |
| +if [ "$rc" != 0 ]; then |
| + ops fact "config apply" "exit $rc" "exit 0" |
| + ops tf reconcile config |
| + ops tf config dev-config |
| +fi |
| +``` |
| + |
| +Creates the config, Litestream and image-input buckets, the controller, proxy and image-build roles, |
| +the build policy and log group, and the dev alert topic and budget (`envs/dev/config`). |
| + |
| +### 2.5 The connector (unit, bound 25m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops estimate --stop 35 |
| +VM_SUBNET=$(tfo network vm_subnet_id); VM_SG=$(tfo network vm_security_group_id); CONN_ROLE=$(tfo network connector_operator_role_arn) |
| +ops connector create --subnet "$VM_SUBNET" --security-group "$VM_SG" --role "$CONN_ROLE" |
| +``` |
| + |
| +Records the intent, creates the `VPC_EGRESS` connector `equipo-hosted-dev-<RUN>-egress`, waits for |
| +`ACTIVE` and records the `:1` qualified ARN (Task 17 fact). A refusal or a timeout is a hard stop. |
| + |
| +### 2.6 Private keys into the config bucket (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +CONFIG_BUCKET=$(tfo config config_bucket) |
| +ops keys upload --bucket "$CONFIG_BUCKET" --expected-owner 640012953448 --keys "$P/keys" --cert-key-id paul-cert-1 |
| +``` |
| + |
| +## 3. Image |
| + |
| +### 3.1 Build and Litestream (block; no AWS call but the guard) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops assert release-file "$P/release/image-source.tar" |
| +ops assert release-file "$P/release/image-manifest.json" |
| +ops assert release-file "$P/release/litestream-0.5.18-linux-x86_64.tar.gz" |
| +img build -bundle "$P/release/image-source.tar" -gitleaks-config "$REPO/.gitleaks.toml" -out "$P/image.zip" > "$P/build.json" |
| +ops assert image-digest "$(jq -er .Digest "$P/build.json")" |
| +ops litestream-install --file "$P/release/litestream-0.5.18-linux-x86_64.tar.gz" |
| +``` |
| + |
| +The release's files are the ones 0.2 published and re-downloaded byte for byte; each is checked |
| +again against the release manifest. A different image digest is a hard stop. |
| + |
| +### 3.2 Upload (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +INPUTS_BUCKET=$(tfo config image_inputs_bucket) |
| +ops object put --bucket "$INPUTS_BUCKET" --key "images/$IMAGE_DIGEST.zip" --file "$P/image.zip" --expected-owner 640012953448 |
| +``` |
| + |
| +### 3.3 Create the image and its Large version (unit, bound 105m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops estimate --stop 35 |
| +BUILD_ROLE=$(tfo config image_build_role_arn); LOG_GROUP=$(tfo config image_build_log_group); INPUTS_BUCKET=$(tfo config image_inputs_bucket) |
| +BASE=$(jq -er .BaseImageVersion "$REPO/release/$REL.json") |
| +ops reserve build 1 |
| +set +e |
| +img publish -ledger "$P" -base-version "$BASE" -name "equipo-hosted-dev-$RUN" -bucket "$INPUTS_BUCKET" -key "images/$IMAGE_DIGEST.zip" -build-role-arn "$BUILD_ROLE" -log-group "$LOG_GROUP" -size large -capabilities ALL -timeout 45m -out "$P/image.json" |
| +rc=$? |
| +set -e |
| +if [ "$rc" = 6 ]; then |
| + ops fact "image build on base $BASE" "failed state" "built" |
| + ops reserve build 1 |
| + set +e |
| + img publish -ledger "$P" -base-version "$BASE" -allow-step-down -name "equipo-hosted-dev-$RUN-b" -bucket "$INPUTS_BUCKET" -key "images/$IMAGE_DIGEST.zip" -build-role-arn "$BUILD_ROLE" -log-group "$LOG_GROUP" -size large -capabilities ALL -timeout 45m -out "$P/image.json" |
| + rc=$? |
| + set -e |
| +fi |
| +if [ "$rc" != 0 ]; then skip_to_teardown "the image did not build (img exit $rc)"; exit 0; fi |
| +ops ledger rec microvm-image "$(jq -er .ImageArn "$P/image.json")" |
| +ops ledger rec microvm-image-version "$(jq -er .VersionArn "$P/image.json")" |
| +ops fact "image base version" "$(jq -r .BaseImageVersion "$P/image.json")" "$BASE" |
| +``` |
| + |
| +This is the first build of the hosted image on AWS's real base (version 4): the 23 pinned AL2023 |
| +packages plus python3 and its 4 dependencies installed from the bundle, and the hosted bubblewrap |
| +checked against its pin by the Dockerfile. `img publish` journals the image and version as soon as |
| +they exist, so a failed build is still torn down. Exit 6 (a failed build) takes the pre-approved |
| +step down, once, under a new name; any other failure, or a second one, skips to teardown. Exit 4 |
| +(the guard) is a guard refusal: Paul is told; the run skips to teardown. |
| + |
| +## 4. Controller and proxies (`envs/dev/services`) |
| + |
| +### 4.1 Plan and apply (unit, bound 30m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +ops estimate --stop 35 |
| +ops tfvars --add-image "$P/image.json" --add-connector |
| +set +e |
| +ops tf services dev-services |
| +rc=$? |
| +set -e |
| +if [ "$rc" != 0 ]; then |
| + ops fact "services apply" "exit $rc" "exit 0" |
| + ops tf reconcile services |
| + ops tf services dev-services |
| +fi |
| +``` |
| + |
| +Creates the controller (`t4g.small`), proxies A and B (`t4g.micro`) with their Elastic IPs, roles' |
| +policies, profiles and groups, the alarms, the deny-launches policy and the budget action. The |
| +hosts' AMI is the release's `HostAMI` (`ami-045c7b3c3ad6e4cc1`). |
| + |
| +### 4.2 Hosts up (unit, bound 25m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +ops estimate --stop 35 |
| +CONFIG_BUCKET=$(tfo config config_bucket) |
| +PIN_HEX=$(ops wait object --bucket "$CONFIG_BUCKET" --key pins/controller.spki --max 15m | tail -n 1) |
| +[[ "$PIN_HEX" =~ ^[0-9a-f]{64}$ ]] || { echo "ABORT: pins/controller.spki is not a pin"; exit 99; } |
| +printf '%s\n' "$PIN_HEX" > "$P/controller.pin" |
| +ops ledger rec controller-pin "$PIN_HEX" |
| +jq -n --arg url "https://$(tfo services controller_public_ip)" --arg pin "$PIN_HEX" --arg key "$(cat "$P/keys/controller.pub")" '{url: $url, pin: $pin, key: $key}' > "$P/proxy-controller.json" |
| +ops object put --bucket "$CONFIG_BUCKET" --key proxy/a/controller.json --file "$P/proxy-controller.json" |
| +ops object put --bucket "$CONFIG_BUCKET" --key proxy/b/controller.json --file "$P/proxy-controller.json" |
| +``` |
| + |
| +The wait is `ops wait object --bucket "$CONFIG_BUCKET" --key pins/controller.spki --max 15m`. Each |
| +proxy's boot waits up to 15 minutes for its `controller.json`, counted from its own boot, so a |
| +controller that takes most of that to write its pin leaves the proxies little time (section 10). |
| + |
| +### 4.3 Status through the pin, and the restore check (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +sleep 120 |
| +ops assert status |
| +LS_BUCKET=$(tfo config litestream_bucket) |
| +set +e |
| +ops litestream-check --bucket "$LS_BUCKET" |
| +rc=$? |
| +set -e |
| +[ "$rc" = 0 ] || ops fact "litestream restore check" "exit $rc" "exit 0" |
| +``` |
| + |
| +`ops assert status` is fatal: the network audit passing, exactly one `provider_bound` row for |
| +`aws:640012953448:eu-west-1`, both proxies fed in the last 90 seconds, a clean reaper pass in the |
| +last 2 minutes, and the pin unchanged on a second read 60 seconds later. The two minutes first give |
| +the proxies time to fetch their `controller.json`. `ops litestream-check` restores the latest |
| +generation with the pinned Litestream and opens it; in dev a failure is a FINDING (production keeps |
| +it fatal: dev's database is thrown away at teardown). |
| + |
| +## 5. Certification: the egress matrix inside a real VM |
| + |
| +### 5.1 The candidate image, and launches on (unit, bound 15m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +ops estimate --stop 35 |
| +CONFIG_BUCKET=$(tfo config config_bucket) |
| +jq -n --arg d "$IMAGE_DIGEST" --arg i "$(jq -er .ImageArn "$P/image.json")" --arg v "$(jq -er .VersionArn "$P/image.json")" '[{digest: $d, image_arn: $i, version_arn: $v}]' > "$P/certification-images.json" |
| +printf 'EQUIPO_HOSTED_ENABLED=1\n' > "$P/controller.env" |
| +ops object put --bucket "$CONFIG_BUCKET" --key controller/certification-images.json --file "$P/certification-images.json" |
| +ops object put --bucket "$CONFIG_BUCKET" --key controller/env --file "$P/controller.env" |
| +ops controller reboot --enabled 1 --max 10m |
| +ops assert enabled |
| +``` |
| + |
| +The first real `ops controller reboot`: the host reboots, `ExecStartPre` fetches every `controller/` |
| +object again (`env` included), and `GET /v1/status` through the unchanged pin must answer with |
| +launches on within 10 minutes; else exit 99. Nothing else can launch: staging holds no instance key |
| +yet, and a checks launch needs a certificate. |
| + |
| +### 5.2 Certification launch (unit, bound 40m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +ops estimate --stop 35 |
| +IMAGE_ARN=$(jq -er .ImageArn "$P/image.json"); CTL="https://$(tfo services controller_public_ip)"; PIN_HEX=$(cat "$P/controller.pin") |
| +ops reserve vm 2 |
| +set +e |
| +cert launch -ledger "$P" -controller "$CTL" -controller-tls-pin "$PIN_HEX" -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key" -image "$IMAGE_DIGEST" -size large -timeout 20m -out "$P/evidence.json" > "$P/cert-launch.json" |
| +rc=$? |
| +ops vms adopt |
| +set -e |
| +ops vms settle --image "$IMAGE_ARN" --max 10m |
| +if [ "$rc" != 0 ]; then skip_to_teardown "the certification launch failed (cert exit $rc)"; exit 0; fi |
| +ops ledger rec cert-launch "$(jq -er .launch_id "$P/cert-launch.json")" |
| +``` |
| + |
| +The VM's one egress service is the staging host (its positive control); it reports through a |
| +proxy's bootstrap listener, signed by its own key; the controller signs the evidence and stops the |
| +VM with proof. The settle (three clean provider scans 30 seconds apart) runs whatever the launch |
| +did; a live VM after 10 minutes is a hard stop. A launch refused for a missing permission (for |
| +example `lambda:PassNetworkConnector`, which Task 28 added untested) is a FINDING and skips to |
| +teardown. |
| + |
| +### 5.3 Judge, and the probe facts (block; no AWS call but the guard) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +jq -er .evidence "$P/evidence.json" | base64 -d > "$P/evidence.plain.json" |
| +leaks=$(jq -r '.report | (.root + .user + .sandbox)[] | select(.outcome == "reached" and .name != "user_instance_protocol" and .name != "sandbox_go_tree_read") | .name' "$P/evidence.plain.json" | tr '\n' ' ') |
| +ops assert egress-leaks "$leaks" "" |
| +while IFS=$'\t' read -r name outcome detail; do |
| + ops ledger note probe "$name $outcome $detail" |
| +done < <(jq -r '.report | (.root + .user + .sandbox)[] | [.name, .outcome, .detail] | @tsv' "$P/evidence.plain.json") |
| +set +e |
| +cert judge -evidence "$P/evidence.json" -release "$P/release/image-manifest.json" -controller-pub "$P/keys/controller.pub" -out "$P/snapshot.json" > "$P/judge.json" 2> "$P/judge.err" |
| +rc=$? |
| +set -e |
| +if [ "$rc" != 0 ]; then skip_to_teardown "the evidence does not certify: $(head -c 400 "$P/judge.err")"; exit 0; fi |
| +``` |
| + |
| +Every probe row goes into the ledger as a note, so the record shows exactly what the metadata and |
| +resolver probes saw (`root_vpc_dns_silent`, `root_metadata_no_credential`, |
| +`sandbox_managed_resolvers`, `sandbox_metadata`), and how the hosted bubblewrap and the containment |
| +suite did on the real MicroVM. A probe the matrix expects blocked that **reached** is a hard stop |
| +(the egress boundary differs). Any other judge failure (an inconclusive probe, a failed containment |
| +test, a measured digest that differs) is a FINDING and skips to teardown. |
| + |
| +### 5.4 Paul signs (HUMAN, bounded 12 hours) |
| + |
| +**5.4a, the hand-over (block).** |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +H="$P/handoff"; mkdir -m 700 "$H" |
| +cp "$P/evidence.json" "$P/release/image-manifest.json" "$P/keys/controller.pub" "$H/" |
| +(cd "$H" && sha256sum evidence.json image-manifest.json controller.pub > SHA256SUMS) |
| +want=$(jq -er '.Artifacts[] | select(.Name == "image-manifest.json") | .SHA256' "$REPO/release/$REL.json") |
| +ops assert handoff-manifest "$(sha256sum < "$H/image-manifest.json" | cut -d' ' -f1)" "$want" |
| +ops wait-human cert-signed --max 12h --background |
| +echo "for Paul: $H"; cat "$H/SHA256SUMS" |
| +``` |
| + |
| +The agent then tells Paul: the directory `$H` on docs-t1 (its absolute path), the three files and |
| +their SHA-256s, that `image-manifest.json`'s SHA-256 is the one the release `$REL` lists on the |
| +forge, and the controller public key itself. |
| + |
| +**What Paul does, on his own signing machine** (the certification key never touches docs-t1). |
| +`equipo-hosted-certify` is built from `<PIN>` on that machine (`go build ./cmd/equipo-hosted-certify`) |
| +or is the release's `equipo-hosted-certify-linux-amd64`: |
| + |
| +```sh |
| +cert() { equipo-hosted-certify "$@"; } |
| +scp 'docs-t1:<H>/evidence.json' 'docs-t1:<H>/image-manifest.json' 'docs-t1:<H>/controller.pub' 'docs-t1:<H>/SHA256SUMS' . |
| +sha256sum -c SHA256SUMS |
| +cert sign -evidence evidence.json -release image-manifest.json -controller-pub controller.pub -key ~/equipo-cert/paul-cert-1 -key-id paul-cert-1 -out certificate.json |
| +scp certificate.json 'docs-t1:<H>/certificate.json' |
| +``` |
| + |
| +`cert sign` judges the evidence again and signs only the snapshot it derives from it. What comes |
| +back is `certificate.json` in `$H`. **Meanwhile** the three hosts, their addresses and volumes, the |
| +image (storage), the connector and the buckets stay up: about $0.055 an hour by the estimate, about |
| +$0.66 for the full 12 hours. No VM runs (5.2 settled it), and nothing can launch checks: there is no |
| +certificate and staging holds no instance key. If the 12 hours pass, the watchdog unit runs |
| +section S itself; the drill ends there (Paul decides on section 8). |
| + |
| +**5.4b, the certificate in place (block), when Paul says it is signed.** |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +H="$P/handoff"; CONFIG_BUCKET=$(tfo config config_bucket); CTL="https://$(tfo services controller_public_ip)"; PIN_HEX=$(cat "$P/controller.pin") |
| +CERT_PUB=$(ops ledger show | jq -er '.notes["cert-pub"]') |
| +jq -n --arg pub "$CERT_PUB" '{keys: [{id: "paul-cert-1", public_key: $pub}]}' > "$P/cert-keys.json" |
| +set +e |
| +cert verify -cert "$H/certificate.json" -cert-keys "$P/cert-keys.json" > "$P/verify.json" |
| +rc=$? |
| +set -e |
| +if [ "$rc" != 0 ]; then echo "the certificate does not verify (exit $rc); ask Paul to sign again; the clock still runs"; exit 0; fi |
| +ops wait-human cert-signed --done |
| +jq '{certificates: [.]}' "$H/certificate.json" > "$P/certificates.json" |
| +ops object put --bucket "$CONFIG_BUCKET" --key controller/certificates.json --file "$P/certificates.json" |
| +set +e |
| +cert reload -controller "$CTL" -controller-tls-pin "$PIN_HEX" -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key" |
| +rc=$? |
| +set -e |
| +if [ "$rc" != 0 ]; then skip_to_teardown "the controller did not take the certificate (cert reload exit $rc)"; exit 0; fi |
| +ops assert cert-listed "$IMAGE_DIGEST" |
| +``` |
| + |
| +`cert sign` writes one certificate; the controller's `certificates.json` is a set, |
| +`{"certificates": [...]}` (`internal/hostedctl/ctlcert/certs.go`), so the block wraps it. |
| + |
| +## 6. Staging wired, and three hosted checks |
| + |
| +### 6.1 The staging instance's settings (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +CTL="https://$(tfo services controller_public_ip)"; PIN_HEX=$(cat "$P/controller.pin") |
| +S=(--app equipo-staging --account bds --console https://console.carloku.com) |
| +carlos env set "${S[@]}" --no-prompt EQUIPO_HOSTED_CONTROLLER="$CTL" EQUIPO_HOSTED_CONTROLLER_TLS_PIN="$PIN_HEX" \ |
| + EQUIPO_HOSTED_CONTROLLER_PUB="$(cat "$P/keys/controller.pub")" EQUIPO_HOSTED_KEY_ID=instance \ |
| + EQUIPO_HOSTED_IMAGE="$IMAGE_DIGEST" EQUIPO_HOSTED_ACCOUNT=equipo-staging |
| +carlos secrets set "${S[@]}" EQUIPO_HOSTED_KEY - < "$P/keys/instance.key" |
| +carlos env set "${S[@]}" --no-prompt EQUIPO_HOSTED_RUNNERS=1 |
| +sleep 120 |
| +carlos logs "${S[@]}" --grep hosted_controller --since 5m -n 20 > "$P/staging-hosted.log" |
| +if ! grep -q 'hosted_controller_reachable' "$P/staging-hosted.log"; then skip_to_teardown "staging does not reach the controller"; exit 0; fi |
| +``` |
| + |
| +The secret is read from standard input (`carlos secrets set ... KEY -`), so it never appears in an |
| +argument list. The last `env set` turns hosted work on and restarts staging. Section S and 8.1 turn |
| +it off with the notes from 2.2. |
| + |
| +### 6.2 Three hosted checks (HUMAN start, bounded 6 hours) |
| + |
| +**6.2a (block):** `ops reserve vm 6` (three steps, each with one retry), then |
| +`ops wait-human tasks-done --max 6h --background`. The same clock covers 7.1 and 7.2's tasks. |
| + |
| +**Paul:** on staging, in his scratch Go project, turns on "Run checks in a hosted VM" (owner only) |
| +and starts three small tasks: (a) a change whose checks pass; (b) a change with a failing test; |
| +(c) a change that adds a module the base's `go.sum` does not pin. He tells the agent each step's |
| +result as the task view shows it. |
| + |
| +**6.2b (block), every 5 minutes while the steps run, and once after Paul reports all three:** |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +IMAGE_ARN=$(jq -er .ImageArn "$P/image.json") |
| +set +e |
| +ops vms adopt |
| +set -e |
| +ops vms scan --image "$IMAGE_ARN" |
| +``` |
| + |
| +**6.2c (block), after Paul reports the three results;** the agent fills the three `<result ...>` |
| +values from Paul's words, the only text it fills in: |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +IMAGE_ARN=$(jq -er .ImageArn "$P/image.json") |
| +ops vms settle --image "$IMAGE_ARN" --max 10m |
| +ops fact "hosted check a" '<result a>' 'passed, sandboxed bubblewrap, certified' |
| +ops fact "hosted check b" '<result b>' 'failed, sandboxed bubblewrap, certified' |
| +ops fact "hosted check c" '<result c>' 'cannot_run needs_network deps_new_module' |
| +``` |
| + |
| +Expected (Task 30's `TestChainHostedCheckPasses`, `TestChainFailingCheck`, `TestChainNewModule`): |
| +`waiting_hosted` within seconds, enrolment within 2 minutes, the three results above, each VM stopped |
| +with proof, usage settled. A live VM 10 minutes after the last step ended is a hard stop. |
| + |
| +## 7. Drills on real VMs |
| + |
| +Each drill needs a step that is still running when the agent strikes: Paul starts a task whose |
| +candidate adds a test that sleeps 240 seconds (it runs in the base's gates, inside bubblewrap). |
| +Before each, `ops reserve vm 2`. The agent strikes once `ops vms scan --image "$IMAGE_ARN"` lists a |
| +live VM and 90 more seconds have passed (enrolment is within 2 minutes). |
| + |
| +### 7.1 The controller away mid-step (unit, bound 15m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +ops estimate --stop 35 |
| +ops controller reboot --enabled 1 --max 10m |
| +ops assert status |
| +``` |
| + |
| +A reboot keeps the controller away for a minute or two (5.1 measures it). Expected, as |
| +`TestChainKillControllerMidStep` allows: the step passes, certified, either on its first VM |
| +(admission refreshed within its 2-minute freshness) or, if the outage outlasted it, after the first |
| +job fails `hosted_unavailable` and one retry on a new VM. A reboot is shorter than the feed's |
| +5-minute life, so the proxies' close-at-expiry path is not exercised (section 11). After Paul |
| +reports: `ops vms settle --image "$IMAGE_ARN" --max 10m`, then |
| +`ops fact "drill controller away" '<result>' 'passed, certified, at most 2 jobs'`. |
| + |
| +### 7.2 The certificate withdrawn mid-step (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +CONFIG_BUCKET=$(tfo config config_bucket); CTL="https://$(tfo services controller_public_ip)"; PIN_HEX=$(cat "$P/controller.pin") |
| +printf '{"certificates":[]}\n' > "$P/no-certificates.json" |
| +ops object put --bucket "$CONFIG_BUCKET" --key controller/certificates.json --file "$P/no-certificates.json" |
| +set +e |
| +cert reload -controller "$CTL" -controller-tls-pin "$PIN_HEX" -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key" |
| +rc=$? |
| +set -e |
| +[ "$rc" = 0 ] || ops fact "withdrawing the certificate" "cert reload exit $rc" "exit 0" |
| +``` |
| + |
| +Expected (`TestChainCertWithdrawnMidStep`): the running job fails `uncertified`, its VM stopped with |
| +proof, and **its result is not kept**: the step does not pass, has no sandbox and no base checks. |
| +Placed again once, the controller launches nothing for it (no certificate), and after the launch |
| +window it ends `cannot_run` `hosted_unavailable`. When Paul reports the step ended, the agent |
| +restores the certificate and settles (block 7.2b): |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +CONFIG_BUCKET=$(tfo config config_bucket); CTL="https://$(tfo services controller_public_ip)"; PIN_HEX=$(cat "$P/controller.pin"); IMAGE_ARN=$(jq -er .ImageArn "$P/image.json") |
| +ops object put --bucket "$CONFIG_BUCKET" --key controller/certificates.json --file "$P/certificates.json" |
| +set +e |
| +cert reload -controller "$CTL" -controller-tls-pin "$PIN_HEX" -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key" |
| +rc=$? |
| +set -e |
| +[ "$rc" = 0 ] || ops fact "restoring the certificate" "cert reload exit $rc" "exit 0" |
| +ops vms settle --image "$IMAGE_ARN" --max 10m |
| +ops fact "drill certificate withdrawn" '<result>' 'not passed, no sandbox, cannot_run hosted_unavailable' |
| +ops wait-human tasks-done --done |
| +``` |
| + |
| +A withdrawn certificate whose VM's result was counted as passed or sandboxed is a safety failure: |
| +the record cannot carry `Task 34 PASSED`. |
| + |
| +### 7.3 Not run with this kit |
| + |
| +`TestChainKillProxyMidStep` (no `ops` command stops a proxy host), `TestChainStopVMMidStep` |
| +(`ops vms settle --terminate` stops every VM of the image, the retry's too), `TestChainOrphanVM` |
| +(planting a VM needs a launch outside the controller; Task 17b proved the reaper on the same code), |
| +and a launch refused while fenced (the fence stops the controller, and a fenced controller is never |
| +restarted). Each is noted with `ops ledger note drill-not-run "<name>: <why>"` and listed in the |
| +record. See decision 4. |
| + |
| +### 7.4 The alert path (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if skipped; then exit 0; fi |
| +CTL="https://$(tfo services controller_public_ip)"; PIN_HEX=$(cat "$P/controller.pin") |
| +set +e |
| +cert alert-test -controller "$CTL" -controller-tls-pin "$PIN_HEX" -controller-pub "$P/keys/controller.pub" -operator-id operator -operator-key "$P/keys/operator.key" |
| +rc=$? |
| +set -e |
| +ops fact "alert test" "exit $rc" "exit 0" |
| +``` |
| + |
| +The controller publishes to the dev topic, which has no subscriber, so no email is checked; the |
| +call's success is what the drill sees. |
| + |
| +## 8. Teardown and verification |
| + |
| +Section 8 runs after section 7, after a skip to teardown, or, with Paul's word, after section S. |
| +Every block passes `--stop 45`; the units make no spend check. |
| + |
| +### 8.1 Staging off (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops unit stop --all |
| +S=(--app equipo-staging --account bds --console https://console.carloku.com) |
| +set +e |
| +carlos env unset "${S[@]}" --no-prompt EQUIPO_HOSTED_RUNNERS |
| +rc=$? |
| +carlos env unset "${S[@]}" --no-prompt EQUIPO_HOSTED_CONTROLLER EQUIPO_HOSTED_CONTROLLER_TLS_PIN EQUIPO_HOSTED_CONTROLLER_PUB EQUIPO_HOSTED_KEY_ID EQUIPO_HOSTED_IMAGE EQUIPO_HOSTED_ACCOUNT |
| +carlos secrets unset "${S[@]}" EQUIPO_HOSTED_KEY |
| +set -e |
| +[ "$rc" = 0 ] || ops fact "staging hosted work off" "exit $rc" "exit 0" |
| +``` |
| + |
| +`ops unit stop --all` first stops any wait-human watchdog still running (after a skip to |
| +teardown). Unsetting a variable that was never set (an early skip) is a FINDING, not a stop. |
| +Staging stays on the branch build (decision 2). |
| + |
| +### 8.2 Fence and settle (unit, bound 50m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops fence |
| +ops vms reconcile |
| +for IMAGE_ARN in $(awk -F'\t' '{print $2}' "$P/journal.tsv" | awk '$1 == "REC" && $2 == "microvm-image" {print $3}' | sort -u); do |
| + ops vms settle --image "$IMAGE_ARN" --terminate --max 15m |
| +done |
| +ops ledger reconcile |
| +``` |
| + |
| +`ops fence` attaches `deny_launches` to the controller role and stops the controller host. Each |
| +settle terminates every known VM, proves the image clear by three scans, requires a direct read of |
| +every known ID, and repeats after 10 minutes. A live VM after the bound is a hard stop. |
| + |
| +### 8.3 The images (unit, bound 20m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +for IMAGE_ARN in $(awk -F'\t' '{print $2}' "$P/journal.tsv" | awk '$1 == "REC" && $2 == "microvm-image" {print $3}' | sort -u); do |
| + img delete -arn "$IMAGE_ARN" -timeout 15m |
| + ops ledger deleted microvm-image "$IMAGE_ARN" img-delete |
| +done |
| +``` |
| + |
| +### 8.4 Controller terminate, unfence, services destroy (unit, bound 45m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops controller terminate |
| +ops unfence |
| +if grep -q 'TF-APPLY services start' "$P/journal.tsv"; then |
| + ops tf services destroy-dev-services |
| +fi |
| +``` |
| + |
| +In this order and nothing between them: `ops controller terminate` reads every controller host back |
| +`terminated`; `ops unfence` detaches `deny_launches` only with that proof, every image settled with |
| +its repeat after the fence and no image creation unresolved, and reads the detach back; the services |
| +destroy refuses while the policy is attached. These are the first real runs of all three. A refusal |
| +is a hard stop with the policy left attached; Paul decides. |
| + |
| +### 8.5 The connector (unit, bound 130m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops connector delete |
| +``` |
| + |
| +The first real exercise of the connector's interface cleanup: this drill's VMs used the connector |
| +for egress, so Lambda-managed interfaces may exist in the VM subnet for the first time. On |
| +`DELETE_FAILED`, one retry with the managed-operator condition dropped (the subnet condition kept); |
| +interfaces left after the delete are waited for within the same 120-minute budget and verified gone, |
| +never deleted by hand. What it saw (interface count, time to gone, whether the retry ran) goes into |
| +the record. A second failure is a hard stop. |
| + |
| +### 8.6 Buckets, config, network (unit, bound 40m) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +if grep -q 'TF-APPLY config start' "$P/journal.tsv"; then |
| + ops bucket empty --name "$(tfo config config_bucket)" --expected-owner 640012953448 |
| + ops bucket empty --name "$(tfo config litestream_bucket)" --expected-owner 640012953448 |
| + ops bucket empty --name "$(tfo config image_inputs_bucket)" --expected-owner 640012953448 |
| + ops tf config destroy-dev-config |
| +fi |
| +if grep -q 'TF-APPLY network start' "$P/journal.tsv"; then |
| + ops tf network destroy-dev-network |
| +fi |
| +``` |
| + |
| +A root whose apply never started has nothing in state and is skipped. `ops tf` itself refuses a |
| +destroy while an intent that depends on the root is unresolved. If the config apply failed before |
| +its outputs were written, `tfo` fails here and the block stops: the buckets are then emptied by |
| +name with Paul's word. |
| + |
| +### 8.7 Verify, then the state bucket (block) |
| + |
| +```sh |
| +set -euo pipefail; P='<P printed by 0.1>'; . "$P/run.env" |
| +ops verify-gone |
| +ops bucket empty --name equipo-hosted-tfstate-640012953448 --expected-owner 640012953448 |
| +ops bucket delete --name equipo-hosted-tfstate-640012953448 --expected-owner 640012953448 |
| +ops verify-gone --all |
| +ops estimate |
| +``` |
| + |
| +`ops verify-gone` reads every recorded resource directly (the tag index is a cross-check whose lag is |
| +recorded, not chased). The state bucket goes last, after every other deletion is proven. |
| + |
| +### 8.8 Records and docs-t1 (agent's shell) |
| + |
| +1. `ops report --out "$P/report.md"` and `ops bundle --out "$P/bundle.json"`; copy the bundle to |
| + `docs/superpowers/plans/HOSTED-DEV-RUN-<RUN>.json`. |
| +2. Append `## Task 34 live run (<RUN>)` to `HOSTED-SLICE2-PROGRESS.md`: the pin, `$REL` and its |
| + `IMAGE_DIGEST`, every FINDING (`grep FINDING "$P/journal.tsv"`), the probe notes, the drill |
| + results, the first-real-run results of section 10, the connector's interface facts, the final |
| + estimate and the bill items, the rehearsal's result. |
| +3. Write the line `Task 34 PASSED (run <RUN>, <n> FINDINGs)` at the start of a line **only if every |
| + safety check passed**: no hard stop; every guard passed; `ops assert network`, `status`, `enabled`, |
| + `cert-listed`, `egress-leaks`, `release-file`, `image-digest` and `handoff-manifest` passed; the |
| + judge passed and Paul's certificate verified; every settle proved its image clear; hosted check |
| + (a) passed certified and (b) failed certified; drill 7.2's result was not kept; fence, terminate |
| + and unfence ran in order; `ops verify-gone --all` passed; the final estimate stayed under $35. |
| + Otherwise write `Task 34 NOT PASSED` with the failed check. The production plan's 0.1 looks for |
| + the PASSED line at its release. |
| +4. Commit both files locally (subject under 80 characters, the trailer); never push. |
| +5. On docs-t1: `ops unit stop --all`; `rm -rf "$P/keys"`; `git worktree remove --force "$P/repo"`; |
| + `rm -rf "$P"`; check that no `hdev-<RUN>-*` or `hdev-r<RUN>-*` unit is loaded. Podman's AL2023 |
| + image from 0.2 stays for the next build (`podman rmi` if Paul prefers). |
| + |
| +## S. Safe stop |
| + |
| +`ops safe-stop`, in the background (rules above). S.0 stops every journalled unit; S.1 unsets |
| +`EQUIPO_HOSTED_RUNNERS` on staging from 2.2's notes; S.2 fences (deny attach, controller host |
| +stopped); S.3 identifies every VM; S.4 settles each image with its repeat, then reconciles every |
| +other intent and any interrupted `tf` root; S.5 writes the bundle and `report.md --stopped`. It |
| +never checks spend, never unfences, never terminates the controller and deletes nothing but VMs. |
| +What is left costs about $1.15 a day on the bill (proxies running, the controller stopped, three |
| +addresses, three volumes, the image), and the estimate counts $1.31 a day, until Paul says to run |
| +section 8 (from 8.1; 8.2's fence runs again harmlessly). |
| + |
| +## 9. Spend |
| + |
| +All figures use `ops estimate`'s model (`internal/hostedops/estimate.go`), which is the account |
| +plan's section 11: hosts' hours since creation, rounded up per host, at on-demand rates with each |
| +host's public IPv4 address ($0.005/h) and 8 GB gp3 volume ($0.000964/h); every VM ever recorded at |
| +4x the Large rate for its full 90-minute life ($1.86); every reservation not yet used ($1.86 a VM, |
| +$1 a build); each image build $1; each image's storage at its one-week minimum ($8 × 7/30 = $1.87), |
| +then $8 a month pro rata; $1 for S3, SNS and alarms. |
| + |
| +Hosts, per hour: controller `t4g.small` $0.0184 + $0.005 + $0.000964 = $0.024364; each proxy |
| +`t4g.micro` $0.0092 + $0.005 + $0.000964 = $0.015164; the three together **$0.054692 an hour**, |
| +$1.31 a day. |
| + |
| +Reservations (each reservation is either used by a VM or stays counted, so the estimate always |
| +holds every one): 5.2 two, 6.2 six, 7.1 two, 7.2 two: **12 VMs, $22.32**. Builds: one, plus one |
| +for the step-down only if it runs. |
| + |
| +| | Expected (to plan) | Worst case | |
| +| --- | --- | --- | |
| +| Hosts | 7 h × $0.054692 = $0.38 | 24 h × $0.054692 = $1.31 | |
| +| VMs and VM reservations | 12 × $1.86 = $22.32 | 13 × $1.86 = $24.18 (a late VM found by a settle repeat) | |
| +| Image builds | 1 × $1 = $1.00 | 2 × $1 = $2.00 (the step-down) | |
| +| Image storage | 1 × $1.87 | 2 × $1.87 = $3.73 (the step-down image) | |
| +| S3, SNS, alarms | $1.00 | $1.00 | |
| +| **Estimate** | **$26.57** | **$32.22** | |
| + |
| +The worst case's 24 host hours: services up and status (0.75 h), certification (1 h), the signing |
| +wait at its 12-hour bound, wiring (0.25 h), the tasks at their 6-hour bound, the drills (1.5 h), |
| +teardown to the hosts' termination (1.5 h): 23 hours, rounded up per host. The self-stop at **$35** |
| +leaves $2.78, about two days of hosts after a safe stop. The approval ceiling is **$45**: the stop |
| +is checked only when a block or reservation starts, and the estimate leaves out the connector (no |
| +listed charge), the state bucket and data transfer. |
| + |
| +**The bill** is far below the estimate, which is a ceiling by design. Expected: hosts for 7 hours |
| +about $0.38; VMs at the Large baseline of about $0.32 an hour (the account plan's rates): |
| +certification 30 minutes $0.16, five checks VMs and two retries at about 15 minutes each $0.56; |
| +the image build about $0.20; image storage for a day about $0.27; S3, SNS and CloudWatch under $0.10: |
| +**about $1.60**. At most about $5, if every VM bursts at 4x and storage bills its full week. |
| + |
| +## 10. First real runs, and what happens if each one fails |
| + |
| +| Path | Where | If it fails | |
| +| --- | --- | --- | |
| +| systemd units and the env allowlist | 0.1 `ops unit probe` | abort before any AWS call | |
| +| the recovery unit (lock, membership, safe stop) | 1.2 rehearsal, separate run | hard stop; nothing exists | |
| +| OpenTofu import adoption | 2.3, 2.4, 4.1, only if an apply fails | one `tf reconcile` and one re-apply, pre-approved; then hard stop. If no apply fails, adoption stays unexercised (recorded) | |
| +| the default VPC's gateway as `PRE-RUN` | 1.1, used by any network reconcile | a gateway nobody accounts for leaves the intent unresolved: hard stop | |
| +| AWS's build of the image on base version 4, with the 23 + 5 RPMs | 3.3 | step down one base version once; then skip to teardown | |
| +| the hosted bubblewrap and the containment suite on a real MicroVM | 5.2, 5.3 | FINDING, skip to teardown | |
| +| the metadata and resolver probes (resolver `169.254.169.253` unconfirmed) | 5.3 | a reached probe: hard stop; inconclusive: FINDING, skip to teardown; the details are recorded either way | |
| +| `lambda:PassNetworkConnector` on the controller role | 5.2 | FINDING, skip to teardown | |
| +| proxies booting with `controller.json` written late | 4.2, 4.3 | `ops assert status` fails: hard stop | |
| +| Litestream install and restore check | 3.1, 4.3 | install: hard stop (digest); check: FINDING in dev | |
| +| `ops controller reboot` | 5.1, 7.1 | exit 99: hard stop | |
| +| `cert reload` with a wrapped certificate set | 5.4b, 7.2 | FINDING, skip to teardown | |
| +| `ops fence`, `ops controller terminate`, `ops unfence` | 8.2, 8.4 | hard stop; the policy stays attached; Paul decides | |
| +| the connector's interface cleanup | 8.5 | the built-in retry; then hard stop | |
| +| `ops verify-gone` with real direct reads | 8.7 | hard stop; the record lists what reads present | |
| + |
| +## 11. Unconfirmed, and open questions |
| + |
| +- The resolver address `169.254.169.253` (release pins): a probe passes on a timeout, so a wrong |
| + address passes too. With VPC DNS off, the drill cannot show the address is the resolver. The |
| + image probes only that address, not the VM VPC's `+2` address (`10.43.0.2`); VPC DNS being off is |
| + asserted separately (2.3). |
| +- The MicroVM metadata protocol: the probe assumes the EC2 credentials path and a VM with no role |
| + has no credentials to find, so "the probe detects credentials when present" cannot be shown here. |
| +- How long a controller reboot keeps the controller away, and whether 7.1's step needs its retry. |
| +- Whether `carlos env unset` of a variable that is not set fails (8.1, S.1). |
| +- Ireland rates for MicroVMs, `t4g` hosts and image storage; the bill confirms them. |
| +- Whether a failed image build leaves an image AWS charges storage for (the estimate assumes yes). |
| +- The release's tag for an unmerged commit, staging on the branch, and who starts the tasks: |
| + decisions 1 to 3. |
| +- `<ALERT_EMAIL>`: the dev topic has no subscription, so the drill cannot test the alert email; a dev |
| + subscription needs a `phases.json` and `envs/dev/config` change. |