plans: Task 17 live plan, review round 1
Astra round 1 (2 Critical, 11 Important) and rulings R32-R35: strict bash helpers, journalled ledger with intents, phase-aware safe stop, image-scoped VM settling, scoped IAM, all taggable defaults tagged, code pinned to 3103334e, SDK audit before any launch, no billing call, recalculated worst-case spend.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+1,274
−926
docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md+1,274 −926
diff --git a/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md b/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md| index 88a1e7ba..6f08b95c 100644 |
| --- a/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md |
| +++ b/docs/superpowers/plans/2026-11-23-hosted-1a-task17-live-plan.md |
| @@ -1,431 +1,689 @@ |
| -# Hosted runners 1a, Task 17: live check plan (for Paul's approval, 2026-11-23) |
| - |
| -**Status:** draft for approval. Nothing in this file has been run. No AWS command or SDK call of any |
| -kind was made while writing it. |
| - |
| -**What Paul approves:** every command below, run once, in the order in "Order of execution", by one |
| -agent, in AWS account `640012953448` (profile `kass`), region `eu-west-1`, with every resource tagged |
| -`purpose=equipo-hosted-dev`. Nothing touches account `149757027610` (`equipo-hosted`). Any change to a |
| -command, any extra AWS call, and any result that differs from a step's "Expected" comes back to Paul |
| -before the next command runs. |
| - |
| -**Sources:** plan `2026-11-19-hosted-runners-slice-1a.md` (Task 17, Global constraints); spec |
| -`2026-11-18-hosted-runners-microvms.md` §3, §10, §15; `internal/isolatedjob/awsjob/doc.go`, |
| -`runner.go`, `network.go`, `live_test.go`; `cmd/equipo-hosted-controller/config.go`, `main.go`, |
| -`crashpoint.go`, `keygen_live_test.go`; `internal/hostedclient/live_test.go`; rulings R7, R17, R21, |
| -R22, R28 to R30 in the SDD progress file; the pre-flight report |
| -`.superpowers/sdd/2026-11-19-hosted-runners-slice-1a/task-17-preflight-report.md` (commits |
| -`d94d7454`, `1ebf6e61`, `60a06822`). CLI command and flag names were checked against the AWS CLI |
| -2.36.10 service models installed in `~/.local/aws-cli/v2/2.36.10` and against the AWS SDK for Go v2 |
| -sources (`lambdamicrovms@v1.13.0`, `lambdacore@v1.14.0`). AWS documentation pages used: |
| -`microvms-images`, `microvms-getting-started`, `microvms-networking`, `microvms-launching`, |
| -`microvms-security` (all under `docs.aws.amazon.com/lambda/latest/dg/`), the managed policy page for |
| -`AWSLambdaNetworkConnectorOperatorPolicy`, and the Lambda pricing page. |
| - |
| -## What the run proves |
| - |
| -1. The adapter's contract passes against real MicroVMs (`TestLiveContract`). |
| -2. The controller on docs-t1, bound to `127.0.0.1`, drives one Small VM through launch, drain, |
| - quiescent, suspend, resume (epoch and timings recorded) and stop with proof. |
| -3. A controller killed between the provider call and transaction 2 leaves exactly one VM, which |
| - Replay claims after a restart. |
| -4. A VM planted outside the controller is stopped by the reaper after the 10-minute grace. |
| -5. The R7 facts AWS does not document are measured and recorded (section 9). |
| -6. Everything is torn down and confirmed gone by type and by tag. |
| +# Hosted runners 1a, Task 17: live check plan (for Paul's approval) |
| + |
| +**Revision:** 2 (2026-11-23), after Astra's plan review round 1 (2 Critical, 11 Important) and |
| +rulings R32 to R35. **Status:** draft for approval. Nothing in this file has been run; no AWS |
| +command or SDK call of any kind was made while writing it. |
| + |
| +## What Paul approves with one GO |
| + |
| +- **Where.** Account `640012953448` (profile `kass`), region `eu-west-1`. Every AWS call runs |
| + through one guard that clears ambient credentials and endpoint overrides, pins the profile and |
| + region, and checks the STS account before the block does anything else. Nothing touches |
| + `149757027610`; any ARN naming it aborts. |
| +- **Global endpoint, one exception.** No Cost Explorer or other billing call (R33): spend is |
| + estimated from rates and the recorded lifetimes of what the run created, and Paul reads the bill |
| + himself. IAM is a global service with no regional endpoint; the plan needs two roles (the image |
| + build role and the connector's network-interface role), so it makes 6 IAM create calls and 5 IAM |
| + delete calls, all under the same account guard. Approving the plan approves those IAM calls. |
| +- **Tags (R34).** Every taggable resource gets `purpose=equipo-hosted-dev` and `run=<RUN>` (a |
| + random run ID chosen in 0.2): the VPC, its default security group (and that group's two default |
| + rules), its main route table and its default network ACL, the subnet, the route table, the |
| + security group, both IAM roles, the connector, the S3 bucket and the S3 object, the log group, |
| + the SNS topic and the MicroVM image. Two kinds of resource cannot carry our tags: |
| + - **MicroVMs** have no tag field. Each is recorded by ID in the run's VM ledger (from the launch |
| + reply, from test and controller logs, and from every image-scoped List of this run's image, |
| + R32), and teardown proves each one ended. |
| + - **The connector's network interfaces** are created and deleted by Lambda. They are recorded by |
| + ID when the connector is ACTIVE and verified gone after the connector is deleted. |
| +- **Code.** The exact revision `PIN_SHA` (the pre-flight's final commit, R35). Before anything is |
| + built, 0.1 checks that HEAD contains it, that it contains R32 (`f95575c6`), and that nothing |
| + outside `docs/` differs from it, committed or not. |
| +- **The reaper is scoped to this run's image (R32).** The controller's List, and so its orphan |
| + scan, reads only VMs of the configured image ARN, which is this run's image, named with the run |
| + ID. It cannot see or stop other people's MicroVMs in `kass`. Account-wide VM counts in 0.4 are |
| + observations only. |
| +- **Spend.** Expected about $0.55. Worst case across every approved branch, failed cleanup |
| + included, about $7.70 (section 11). **$10 is the approval ceiling**, not a guaranteed maximum. The |
| + operational stop rule: the run's own estimate (section 11.2) is computed at the end of every |
| + section; at $5, or when any VM is live outside its step, the agent runs the safe stop. |
| +- **Deviations.** Any changed command, any extra AWS call, any result outside a step's expected |
| + branches: safe stop, then ask. |
| ## Order of execution |
| -Sections are numbered as Paul asked, but they run in this order, because the client-token facts |
| -decide how to read the contract results, and the facts VMs must be gone before the controller's |
| -reaper starts listing: |
| - |
| | Run order | Section | Roughly | |
| | --- | --- | --- | |
| -| 1 | 0. Guard rails | 10 min | |
| +| 1 | 0. Guard rails, code pin, collision checks | 10 min | |
| | 2 | 1. Network | 10 min | |
| | 3 | 2. Connector | 10 to 15 min | |
| -| 4 | 3. Image | 30 to 40 min | |
| +| 4 | 3. Image | 30 to 45 min | |
| | 5 | 4. SNS topic | 2 min | |
| -| 6 | 5. Controller config, keys and TLS | 10 min | |
| -| 7 | 9.A to 9.F (facts, by CLI, no controller running) | 35 min | |
| +| 6 | 5. Keys, config, builds, and the audit-only controller run | 15 min | |
| +| 7 | 9.A to 9.F, facts by CLI (no controller running) | 40 min | |
| | 8 | 6. Live contract | 30 min | |
| -| 9 | 7. Controller sequence and crash check | 40 min | |
| -| 10 | 8. Orphan | 20 min | |
| -| 11 | 9.G (final facts) | 5 min | |
| -| 12 | 10. Teardown and verification | 40 to 70 min | |
| -| 13 | 10.8 Spend record, at least 24 h later | 5 min | |
| - |
| -## Rules that hold for every step |
| - |
| -- **Stop and ask.** Any non-zero exit that a step does not list as expected, any output that differs |
| - from "Expected", any error text not named in the step, and any prompt for credentials: stop. Run |
| - only the safe stop below, then report to Paul with the exact command and output. Do not retry with |
| - changed flags, do not try alternatives, do not "fix" a resource. |
| -- **Safe stop** (pre-approved, the only thing that runs after an abort): stop the controller if it |
| - runs (section 7.7 command), terminate every live VM from this run's image (section 10.1 commands), |
| - and leave every other resource in place for Paul to decide. |
| -- **Ledger first.** Every ID is written to the ledger by `rec` in the same command that creates it, |
| - before anything else runs. The ledger is the only list teardown works from. Never delete anything |
| - that is not in the ledger. |
| -- **Shell state does not persist** between agent tool calls. Every block below starts with |
| - `. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1`, which reloads the profile, the helpers and the |
| - ledger and checks the account. If `$TMPDIR` is different from the path printed in step 0.2, stop |
| - and ask. |
| -- **Sandbox network.** AWS calls need the agent sandbox to allow `*.amazonaws.com` (STS, EC2, IAM, |
| - Lambda, S3, SNS, CloudWatch Logs, Resource Groups Tagging, and in 10.8 Cost Explorer) and whatever |
| - host the `kass` credential process contacts. Declare these in `allowed_domains`; nothing else. |
| -- **docs-t1 rules.** The controller listens on `127.0.0.1` only (API and metrics). The hook server in |
| - section 3 listens on `:9000` inside the MicroVM, not on docs-t1. Scratch is under |
| - `$TMPDIR/equipo-t17` and is deleted in 10.7. Go caches stay at their defaults; no `GOCACHE`, |
| - `GOMODCACHE` or `GOTMPDIR`. No sudo. |
| -- **Polling loops** use `sleep` inside a loop. Blocks that can run longer than the tool's 10-minute |
| - foreground limit (2.3, 3.8, 6.1, 7.2, 7.5, 8.2, 10.2, 10.3) run with the Bash tool's |
| - `run_in_background`; wait for the exit notification, then read the output. Do the same for any |
| - other block if the harness refuses a foreground command that sleeps. |
| -- **Records.** After each section, append its results (IDs, outputs named in "Record", timings) to |
| - `docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md` under a new heading `## Task 17 live run |
| - (2026-11-2x)`. Commit that file locally at the end (subject under 80 characters); do not push. |
| +| 9 | 7. Controller sequence and crash check | 45 min | |
| +| 10 | 8. Orphan | 25 min | |
| +| 11 | 9.G, final facts | 10 min | |
| +| 12 | 10. Teardown and verification | 45 to 75 min | |
| + |
| +The SDK-side network audit (5.6) runs before any VM is launched, so the connector's `VersionArn` |
| +and Elastic IP setting, which the installed CLI cannot show, are checked before the first launch. |
| + |
| +## Rules for every block |
| + |
| +- **One block, one Bash tool call, run by bash.** Every block begins with |
| + `set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"` and, if it calls AWS, `guard`. The |
| + environment file (0.2) defines every helper the blocks use; nothing is pasted by hand. |
| +- **Failure is loud.** A failed command ends the block. Calls that are expected to fail run under |
| + `try` and pass only through an explicit branch (`expect_err`, `code_in`) that names the accepted |
| + error codes; anything else aborts. Every poll fails when its bound runs out. |
| +- **Abort means the safe stop (section S), then ask Paul.** Nothing else runs after an abort. |
| +- **Ledger.** Before each create call the block writes an `INTENT` line (kind, run-specific name or |
| + token); after the call it records the confirmed ID with `rec` (checked writes, ARN checks). Every |
| + MicroVM ID that appears anywhere is added to the VM ledger with `vmrec`. A deletion is recorded |
| + with `deleted` only after a direct read shows it gone. Teardown and the safe stop work only from |
| + these records; nothing is ever adopted or deleted because its name looks right. |
| +- **Long blocks.** Blocks that can run past the Bash tool's 10-minute foreground limit (2.3, 3.8, |
| + 3.9, 6.1, 7.2, 7.4, 7.5, 8.2, 9.A, 9.C, 10.1, 10.2) are started with the tool's background |
| + option and read when they exit. The block itself does not depend on that option. |
| +- **The controller** is started with `setsid nohup` by `start_ctl`, which writes its PID and, when |
| + it ends, its exit status to files. `stop_ctl` checks the PID still belongs to this run's binary |
| + (via `/proc/<pid>/cmdline`) before signalling it. If the process does not survive between tool |
| + calls, or `/proc` hides it while its ports are open, that is an abort. |
| +- **docs-t1.** The controller listens on `127.0.0.1:18443` (API) and `127.0.0.1:18444` (metrics) |
| + only, checked after every start. The hook server in the image listens on port 9000 inside the |
| + MicroVM, not on docs-t1. Scratch is `$TMPDIR/equipo-t17`, removed in 10.9. Go caches stay at |
| + their defaults; every Go command runs with `CGO_ENABLED=0`. No sudo. |
| +- **Sandbox network.** AWS blocks need `*.amazonaws.com` in the Bash tool's `allowed_domains` |
| + (STS, EC2, IAM, Lambda, S3, SNS, CloudWatch Logs and Resource Groups Tagging, all in |
| + `eu-west-1` except IAM), plus any host the `kass` credential process contacts. |
| +- **Records.** After each section, append its results to |
| + `docs/superpowers/plans/HOSTED-SLICE1-PROGRESS.md` under `## Task 17 live run`, and commit that |
| + file locally at the end (subject under 80 characters). Never push. |
| --- |
| ## 0. Guard rails |
| -### 0.1 Check the local tools (no AWS call) |
| +### 0.1 Code pin and local tools (no AWS call) |
| + |
| +`PIN_SHA` is `3103334e` (`3103334e2a3c8d4b20fc113c0310569f17087674`), the pre-flight's final commit |
| +(cleanup fixes and evidence logging, after `41178b00`), relayed by the coordinator. |
| ```sh |
| -cd /home/paulca/amadan.net/oficina/equipo-hosted-1a && git log --oneline -1 && git status --short |
| +set -euo pipefail |
| +PIN_SHA='3103334e2a3c8d4b20fc113c0310569f17087674' |
| +case "$PIN_SHA" in *'<'*|'') echo "ABORT: PIN_SHA is not filled in"; exit 1;; esac |
| +cd /home/paulca/amadan.net/oficina/equipo-hosted-1a |
| +git rev-parse --verify "$PIN_SHA^{commit}" |
| +git merge-base --is-ancestor f95575c6 "$PIN_SHA" || { echo "ABORT: $PIN_SHA does not contain R32 (f95575c6)"; exit 1; } |
| +git merge-base --is-ancestor "$PIN_SHA" HEAD || { echo "ABORT: HEAD does not contain $PIN_SHA"; exit 1; } |
| +d=$(git diff "$PIN_SHA" HEAD -- . ':!docs'); [ -z "$d" ] || { echo "ABORT: code differs from $PIN_SHA outside docs/"; exit 1; } |
| +s=$(git status --porcelain --untracked-files=all -- . ':!docs'); [ -z "$s" ] || { echo "ABORT: uncommitted changes outside docs/:"; echo "$s"; exit 1; } |
| +git log --oneline -1 |
| aws --version |
| go version |
| -for t in jq openssl sha256sum curl ss python3; do command -v "$t" >/dev/null || echo "MISSING $t"; done |
| +for t in jq openssl sha256sum curl ss python3 setsid nohup; do command -v "$t" >/dev/null || { echo "ABORT: missing $t"; exit 1; }; done |
| +echo "code pin ok: $PIN_SHA" |
| ``` |
| -- Expected: HEAD is `60a06822` or a later commit on `hosted-runners-1a` that Paul has named; `git |
| - status` empty or only untracked scratch; `aws-cli/2.36.x`; `go1.26.x`; no `MISSING` line. |
| -- Abort if: HEAD is not the approved commit, or a tool is missing. |
| +- Expected: `code pin ok`; `aws-cli/2.36.x`; `go1.26.x`. |
| +- Abort if: any check fails. |
| -### 0.2 Write the environment file and the ledger (no AWS call) |
| +### 0.2 Scratch, the environment file and the run names (no AWS call) |
| ```sh |
| -mkdir -p "$TMPDIR/equipo-t17"/{out,image,iam,keys,bin} && chmod 700 "$TMPDIR/equipo-t17" && echo "T17=$TMPDIR/equipo-t17" |
| -cat > "$TMPDIR/equipo-t17/env.sh" <<'EOF' |
| -unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_DEFAULT_PROFILE |
| -export AWS_PROFILE=kass AWS_REGION=eu-west-1 AWS_DEFAULT_REGION=eu-west-1 AWS_PAGER="" |
| -export T17="$TMPDIR/equipo-t17" |
| -export LEDGER="$T17/ledger.env" |
| -export REPO=/home/paulca/amadan.net/oficina/equipo-hosted-1a |
| -export ACCOUNT=640012953448 |
| -export NAME=equipo-hosted-dev-t17 |
| -export TAGV=equipo-hosted-dev |
| +set -euo pipefail |
| +: "${TMPDIR:?TMPDIR is unset}" |
| +[ ! -e "$TMPDIR/equipo-t17" ] || { echo "ABORT: $TMPDIR/equipo-t17 already exists"; exit 1; } |
| +mkdir -m 700 "$TMPDIR/equipo-t17" |
| +mkdir -m 700 "$TMPDIR/equipo-t17"/{out,image,iam,keys,bin} |
| +cat > "$TMPDIR/equipo-t17/env.sh" <<'ENVEOF' |
| +# env.sh: sourced by every block, after `set -euo pipefail`. Task 17 only. |
| +: "${TMPDIR:?TMPDIR is unset}" |
| +unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SECURITY_TOKEN AWS_DEFAULT_PROFILE \ |
| + AWS_CONFIG_FILE AWS_SHARED_CREDENTIALS_FILE AWS_ROLE_ARN AWS_ROLE_SESSION_NAME AWS_WEB_IDENTITY_TOKEN_FILE \ |
| + AWS_CA_BUNDLE AWS_ENDPOINT_URL AWS_USE_FIPS_ENDPOINT AWS_USE_DUALSTACK_ENDPOINT |
| +for _v in $(env | sed -n 's/^\(AWS_ENDPOINT_URL_[A-Z0-9_]*\)=.*/\1/p'); do unset "$_v"; done |
| +export AWS_PROFILE=kass AWS_REGION=eu-west-1 AWS_DEFAULT_REGION=eu-west-1 AWS_PAGER="" \ |
| + AWS_STS_REGIONAL_ENDPOINTS=regional AWS_RETRY_MODE=standard AWS_MAX_ATTEMPTS=3 |
| +export CGO_ENABLED=0 |
| +export T17="$TMPDIR/equipo-t17" REPO=/home/paulca/amadan.net/oficina/equipo-hosted-1a |
| +export ACCOUNT=640012953448 TAGV=equipo-hosted-dev |
| +export LEDGER="$T17/ledger.env" JOURNAL="$T17/journal.tsv" VMS="$T17/vms.tsv" |
| export NO_INGRESS=arn:aws:lambda:eu-west-1:aws:network-connector:aws-network-connector:NO_INGRESS |
| -export LOG_GROUP=/aws/lambda-microvms/equipo-hosted-dev-t17 |
| export API=127.0.0.1:18443 METRICS=127.0.0.1:18444 |
| -# rec NAME VALUE: append to the ledger at once; refuse anything that names the hosted account. |
| +[ -d "$T17" ] || { echo "ABORT: $T17 does not exist; was TMPDIR changed?" >&2; exit 1; } |
| +[ -f "$T17/run.env" ] && . "$T17/run.env" |
| +[ -f "$LEDGER" ] && . "$LEDGER" |
| + |
| +die() { echo "ABORT: $*" >&2; jw "ABORT $*" 2>/dev/null || true; exit 1; } |
| +# need VAR...: each must be set, non-empty, and not None or null. |
| +need() { local v; for v; do [ -n "${!v:-}" ] && [ "${!v}" != None ] && [ "${!v}" != null ] || die "$v is unset"; done; } |
| +# arn_ok ARN: in this account and eu-west-1 (IAM and S3 ARNs have no region). |
| +arn_ok() { |
| + case "$1" in |
| + *149757027610*) die "ARN $1 names account 149757027610";; |
| + arn:aws:*:eu-west-1:640012953448:*|arn:aws:iam::640012953448:role/*|arn:aws:s3:::*) ;; |
| + *) die "ARN $1 is not in 640012953448 and eu-west-1";; |
| + esac |
| +} |
| +# jw TEXT: one journal line; a failed write is an abort. |
| +jw() { printf '%s\t%s\n' "$(date -u +%FT%T.%3NZ)" "$*" >> "$JOURNAL" || { echo "ABORT: journal write failed" >&2; exit 1; }; } |
| +# intent KIND KEY DETAIL...: written BEFORE a create call. |
| +intent() { jw "INTENT $*"; } |
| +# rec VAR VALUE: written AFTER a create call returned the ID; checked; exported. |
| rec() { |
| - case "$2" in *149757027610*) echo "ABORT: $1=$2 names account 149757027610"; return 1;; esac |
| - [ -n "$2" ] && [ "$2" != None ] && [ "$2" != null ] || { echo "ABORT: $1 is empty ($2)"; return 1; } |
| - printf 'export %s=%q\n' "$1" "$2" >> "$LEDGER" |
| - printf '%s %s=%s\n' "$(date -u +%FT%TZ)" "$1" "$2" >> "$T17/ledger.log" |
| + [ $# = 2 ] || die "rec needs a name and a value" |
| + case "$2" in ""|None|null) die "rec $1: empty value";; *149757027610*) die "rec $1=$2 names account 149757027610";; esac |
| + printf 'export %s=%q\n' "$1" "$2" >> "$LEDGER" || die "ledger write failed" |
| + jw "CONFIRMED $1 $2" |
| export "$1=$2" |
| } |
| +# deleted KIND ID HOW: written after a deletion is confirmed by a direct read. |
| +deleted() { jw "DELETED $*"; } |
| +# try CMD...: run CMD; never exits; sets OUT, ERR, RC and ECODE (the AWS error code, if any). |
| +try() { |
| + local had=0 e; case $- in *e*) had=1;; esac |
| + e=$(mktemp "$T17/err.XXXXXX") || { echo "ABORT: mktemp" >&2; exit 1; } |
| + set +e; OUT=$("$@" 2>"$e"); RC=$?; [ "$had" = 1 ] && set -e |
| + ERR=$(cat "$e"); rm -f "$e" |
| + ECODE=$(printf '%s' "$ERR" | sed -n 's/.*An error occurred (\([A-Za-z0-9.]*\)).*/\1/p' | head -n 1) |
| + return 0 |
| +} |
| +# must: after try, the call must have succeeded. |
| +must() { [ "$RC" = 0 ] || die "call failed (rc $RC, ${ECODE:-no code}): $ERR"; } |
| +# code_in CODE...: after try, 0 if the call failed with one of CODE. |
| +code_in() { local c; [ "$RC" != 0 ] || return 1; for c; do [ "$ECODE" = "$c" ] && return 0; done; return 1; } |
| +# expect_err CODE...: after try, the call must have failed with one of CODE (an expected-failure branch). |
| +expect_err() { code_in "$@" || die "expected one of [$*], got rc $RC ${ECODE:-no code}: ${ERR:-$OUT}"; } |
| guard() { |
| - local a; a=$(aws sts get-caller-identity --query Account --output text) || { echo "ABORT: STS failed"; return 1; } |
| - [ "$a" = "$ACCOUNT" ] || { echo "ABORT: account is $a, not $ACCOUNT"; return 1; } |
| + [ "$AWS_PROFILE" = kass ] && [ "$AWS_REGION" = eu-west-1 ] && [ "$AWS_DEFAULT_REGION" = eu-west-1 ] || die "profile or region changed" |
| + [ -z "${AWS_ACCESS_KEY_ID:-}" ] || die "AWS_ACCESS_KEY_ID is set" |
| + try aws sts get-caller-identity --query Account --output text; must |
| + [ "$OUT" = "$ACCOUNT" ] || die "account is $OUT, not $ACCOUNT" |
| } |
| -vm_state() { aws lambda-microvms get-microvm --microvm-identifier "$1" --query state --output text 2>&1; } |
| -# wait_vm ID STATE SECONDS: poll every 5 s; GONE accepts TERMINATED or not found. |
| -wait_vm() { |
| - local end=$(( $(date +%s) + $3 )) s |
| +# poll SECONDS INTERVAL WHAT FN ARGS...: FN returns 0 done, 1 not yet, anything else fatal. |
| +poll() { |
| + local secs=$1 iv=$2 what=$3 rc had=0 end; end=$(( $(date +%s) + secs )); shift 3 |
| + case $- in *e*) had=1;; esac |
| while :; do |
| - s=$(vm_state "$1"); echo "$(date -u +%T) $1 $s" |
| - [ "$s" = "$2" ] && return 0 |
| - [ "$2" = GONE ] && { [ "$s" = TERMINATED ] || case "$s" in *ResourceNotFound*) true;; *) false;; esac; } && return 0 |
| - [ "$(date +%s)" -ge "$end" ] && return 1 |
| - sleep 5 |
| + set +e; "$@"; rc=$?; [ "$had" = 1 ] && set -e |
| + [ "$rc" = 0 ] && return 0 |
| + [ "$rc" = 1 ] || die "$what: fatal (rc $rc)" |
| + [ "$(date +%s)" -lt "$end" ] || die "$what: not done within $secs s" |
| + sleep "$iv" |
| done |
| } |
| -# live_vms: every MicroVM in the account and region that is not TERMINATED, any image. |
| -live_vms() { aws lambda-microvms list-microvms --query "items[?state!='TERMINATED'].[microvmId,state,imageArn,startedAt]" --output text; } |
| -# our_live: live VMs from this run's image only. |
| -our_live() { aws lambda-microvms list-microvms --query "items[?state!='TERMINATED' && imageArn=='$IMAGE_ARN'].[microvmId,state,startedAt]" --output text; } |
| -metrics() { curl -fsS "http://$METRICS/metrics" | grep -E '^equipo_hosted_'; } |
| -[ -f "$LEDGER" ] && . "$LEDGER" |
| + |
| +# --- MicroVMs: recorded by ID (they have no tags), found by the image-scoped List --- |
| +vmrec() { grep -q "^$1 " "$VMS" 2>/dev/null || { printf '%s\t%s\t%s\n' "$1" "$2" "$(date -u +%FT%TZ)" >> "$VMS" || die "VM ledger write failed"; jw "VM $1 $2"; }; } |
| +vm_ids() { [ -f "$VMS" ] && cut -f1 "$VMS" | sort -u || true; } |
| +# scan: one image-scoped List, every page, every state; records every ID; writes last_scan.tsv. |
| +scan() { |
| + need IMAGE_ARN |
| + try aws lambda-microvms list-microvms --image-identifier "$IMAGE_ARN" --output json; must |
| + printf '%s' "$OUT" | jq -e '.items | type == "array"' >/dev/null || die "list reply has no items array" |
| + printf '%s' "$OUT" | jq -e --arg a "$IMAGE_ARN" 'all(.items[]; .imageArn == $a)' >/dev/null || die "list returned a VM of another image" |
| + printf '%s' "$OUT" | jq -r '.items[] | [.microvmId, .state, .startedAt] | @tsv' > "$T17/last_scan.tsv" |
| + local id; for id in $(cut -f1 "$T17/last_scan.tsv"); do vmrec "$id" scan; done |
| + cat "$T17/last_scan.tsv" |
| +} |
| +live_ids() { awk -F'\t' '$2 != "TERMINATED" {print $1}' "$T17/last_scan.tsv"; } |
| +# vm_get ID: sets VST to the state, NOTFOUND, or ERROR:<code>. |
| +vm_get() { |
| + try aws lambda-microvms get-microvm --microvm-identifier "$1" --query state --output text |
| + if [ "$RC" = 0 ]; then VST=$OUT; elif [ "$ECODE" = ResourceNotFoundException ]; then VST=NOTFOUND; else VST="ERROR:${ECODE:-rc$RC}"; fi |
| +} |
| +_vm_check() { vm_get "$1"; echo "$(date -u +%T) $1 $VST"; [ "$VST" = "$2" ] && return 0; case " $3 ThrottlingException " in *" ${VST#ERROR:} "*) return 1;; esac; return 2; } |
| +# vm_wait ID TARGET SECONDS ALLOWED...: wait for TARGET; a state outside ALLOWED is fatal. |
| +vm_wait() { local id=$1 t=$2 s=$3; shift 3; poll "$s" 5 "VM $id to $t" _vm_check "$id" "$t" "$*"; } |
| +# vm_end ID: terminate and confirm: TERMINATED, or not found twice at least 60 s apart. |
| +vm_end() { |
| + try aws lambda-microvms terminate-microvm --microvm-identifier "$1" |
| + [ "$RC" = 0 ] || [ "$ECODE" = ResourceNotFoundException ] || die "terminate $1: ${ECODE:-rc$RC} $ERR" |
| + local nf=0 end=$(( $(date +%s) + 600 )) |
| + while :; do |
| + vm_get "$1"; echo "$(date -u +%T) $1 $VST" |
| + case "$VST" in |
| + TERMINATED) jw "VMGONE $1 TERMINATED"; return 0;; |
| + NOTFOUND) [ "$nf" = 0 ] && nf=$(date +%s); [ $(( $(date +%s) - nf )) -ge 60 ] && { jw "VMGONE $1 NOTFOUND-TWICE"; return 0; };; |
| + PENDING|RUNNING|SUSPENDING|SUSPENDED|TERMINATING|ERROR:ThrottlingException) nf=0;; |
| + *) die "VM $1: $VST";; |
| + esac |
| + [ "$(date +%s)" -lt "$end" ] || die "VM $1 has not ended after 10 min" |
| + sleep 10 |
| + done |
| +} |
| +# settle_all: end every recorded and every listed live VM; done only after three scans 30 s apart show none live. |
| +settle_all() { |
| + need IMAGE_ARN; local round i clean id |
| + for round in 1 2 3; do |
| + scan >/dev/null |
| + for id in $(live_ids); do vm_end "$id"; done |
| + for id in $(vm_ids); do grep -q "VMGONE $id " "$JOURNAL" || vm_end "$id"; done |
| + clean=0 |
| + for i in 1 2 3; do |
| + scan >/dev/null |
| + [ -n "$(live_ids)" ] && break |
| + clean=$((clean + 1)); [ "$i" -lt 3 ] && sleep 30 |
| + done |
| + [ "$clean" = 3 ] && { jw "SETTLED $(vm_ids | wc -l) recorded"; echo "settled: $(vm_ids | wc -l) VMs recorded, none live in three scans"; return 0; } |
| + done |
| + die "VMs still live after three settle rounds" |
| +} |
| +# launch LABEL TOKEN MAXSECONDS PAYLOADFILE: one run-microvm (Small, NO_INGRESS, the connector); records any VM it returns. |
| +launch() { |
| + need IMAGE_ARN VER_SMALL CONN_QARN; [ -f "$4" ] || die "no payload file $4" |
| + intent vm "$1" "token=$2" "max=$3" |
| + try aws lambda-microvms run-microvm --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --client-token "$2" \ |
| + --ingress-network-connectors "$NO_INGRESS" --egress-network-connectors "$CONN_QARN" \ |
| + --maximum-duration-in-seconds "$3" --run-hook-payload "file://$4" --output json |
| + printf '%s\n' "$OUT" > "$T17/out/launch-$1.json"; printf '%s\n' "$ERR" > "$T17/out/launch-$1.err" |
| + L_RC=$RC; L_CODE=$ECODE; L_ID="" |
| + if [ "$RC" = 0 ]; then |
| + L_ID=$(printf '%s' "$OUT" | jq -r '.microvmId // empty') |
| + [ -n "$L_ID" ] || die "launch $1 succeeded with no microvmId" |
| + vmrec "$L_ID" "$1" |
| + fi |
| + echo "launch $1: rc=$L_RC code=${L_CODE:-none} id=${L_ID:-none}" |
| +} |
| +# harvest LOG SOURCE: record every MicroVM ID a test or controller log names. |
| +harvest() { local id; for id in $(grep -oE 'mvm-[0-9A-Za-z-]+' "$1" | sort -u); do vmrec "$id" "$2"; done; } |
| + |
| +# --- the controller process --- |
| +ctl_pid() { [ -s "$T17/controller.pid" ] && cat "$T17/controller.pid"; } |
| +# ctl_alive: 0 if this run's controller process is alive; dies if the PID is alive but is something else. |
| +ctl_alive() { |
| + local p; p=$(ctl_pid) || return 1 |
| + [ -d "/proc/$p" ] || return 1 |
| + tr '\0' ' ' < "/proc/$p/cmdline" | grep -qF "$T17/bin/controller" || die "PID $p is alive but is not this run's controller" |
| +} |
| +listeners() { ss -ltnH '( sport = :18443 or sport = :18444 )' | awk '{print $4}' | sort -u | tr '\n' ' '; } |
| +# start_ctl BINARY LABEL [VAR=VALUE...]: start in its own session; PID and exit status go to files. |
| +start_ctl() { |
| + local bin=$1 label=$2; shift 2 |
| + [ -x "$bin" ] || die "no binary $bin" |
| + ! ctl_alive || die "a controller is already running" |
| + [ -z "$(listeners)" ] || die "ports 18443 or 18444 are in use: $(listeners)" |
| + rm -f "$T17/controller.pid" "$T17/controller.exit" |
| + jw "CONTROLLER start $label $bin $*" |
| + setsid nohup env -u EQUIPO_HOSTED_CRASH_AFTER_LAUNCH -u EQUIPO_HOSTED_ENABLED "$@" bash -c \ |
| + '"$0" -config "$1" >>"$2" 2>&1 & echo $! >"$3"; wait $!; echo $? >"$4"' \ |
| + "$bin" "$T17/controller.json" "$T17/controller.log" "$T17/controller.pid" "$T17/controller.exit" \ |
| + </dev/null >/dev/null 2>&1 & |
| + local i; for i in $(seq 1 50); do [ -s "$T17/controller.pid" ] && break; sleep 0.1; done |
| + ctl_alive || die "the controller did not start (see controller.log)" |
| + echo "controller $label started, PID $(ctl_pid)" |
| +} |
| +_ctl_ready() { |
| + [ -s "$T17/controller.exit" ] && return 2 |
| + local m; m=$(curl -fsS "http://$METRICS/metrics" 2>/dev/null) || return 1 |
| + printf '%s\n' "$m" | grep -q '^equipo_hosted_network_audit_passing 0$' && return 3 |
| + printf '%s\n' "$m" | grep -q '^equipo_hosted_network_audit_passing 1$' || return 1 |
| + printf '%s\n' "$m" | grep -q '^equipo_hosted_reap_last_age_seconds ' || return 1 |
| + printf '%s\n' "$m" | grep -q '^equipo_hosted_reap_last_error 0$' || return 4 |
| + return 0 |
| +} |
| +# ctl_ready: within 240 s the audit has passed and a reaper pass has finished cleanly; listeners are 127.0.0.1 only. |
| +ctl_ready() { |
| + poll 240 5 "controller ready" _ctl_ready |
| + [ "$(listeners)" = "127.0.0.1:18443 127.0.0.1:18444 " ] || die "listeners are [$(listeners)], want 127.0.0.1:18443 and :18444 only" |
| + echo "controller ready: $(curl -fsS "http://$METRICS/metrics" | grep -E '^equipo_hosted_(network_audit_passing|reap_last_error|reap_last_age_seconds|store_readable) ' | tr '\n' ' ')" |
| +} |
| +# stop_ctl: SIGTERM, then SIGKILL after 45 s if still alive; ports must close. |
| +stop_ctl() { |
| + local i |
| + if ctl_alive; then |
| + jw "CONTROLLER stop $(ctl_pid)"; kill -TERM "$(ctl_pid)" |
| + for i in $(seq 1 45); do ctl_alive || break; sleep 1; done |
| + if ctl_alive; then jw "CONTROLLER kill $(ctl_pid)"; kill -KILL "$(ctl_pid)"; sleep 2; fi |
| + ! ctl_alive || die "the controller is still alive" |
| + fi |
| + for i in $(seq 1 10); do [ -s "$T17/controller.exit" ] && break; sleep 1; done |
| + [ -z "$(listeners)" ] || die "a listener is still open: $(listeners)" |
| + jw "CONTROLLER exited $(cat "$T17/controller.exit" 2>/dev/null || echo unknown)" |
| + echo "controller stopped; exit status $(cat "$T17/controller.exit" 2>/dev/null || echo unknown)" |
| +} |
| +metrics() { curl -fsS "http://$METRICS/metrics" | grep -E '^equipo_hosted_' || die "metrics unreadable"; } |
| +# dbread SQL: read a copy of the stopped controller's database. |
| +dbread() { |
| + ! ctl_alive || die "stop the controller before reading its database" |
| + rm -rf "$T17/dbcopy"; mkdir "$T17/dbcopy"; cp "$T17"/controller.db* "$T17/dbcopy/" |
| + python3 -I -c 'import sqlite3,sys |
| +con = sqlite3.connect(sys.argv[1]) |
| +for r in con.execute(sys.argv[2]): print("\t".join("" if c is None else str(c) for c in r))' "$T17/dbcopy/controller.db" "$1" |
| +} |
| +# gotest LOG ARGS...: run go test with output to LOG; record VM IDs it names; return its status. |
| +gotest() { |
| + local log=$1 rc had=0; shift; case $- in *e*) had=1;; esac |
| + set +e; (cd "$REPO" && CGO_ENABLED=0 go test "$@") > "$log" 2>&1; rc=$?; [ "$had" = 1 ] && set -e |
| + harvest "$log" "$(basename "$log")" |
| + grep -E '^(=== RUN|--- (PASS|FAIL|SKIP)|PASS|FAIL|ok|panic)' "$log" | tail -n 40 |
| + return "$rc" |
| +} |
| true |
| -EOF |
| -touch "$TMPDIR/equipo-t17/ledger.env" "$TMPDIR/equipo-t17/ledger.log" |
| +ENVEOF |
| +RUN=$(date -u +%m%d)-$(openssl rand -hex 3) |
| +NAME=equipo-hosted-dev-t17-$RUN |
| +cat > "$TMPDIR/equipo-t17/run.env" <<RUNEOF |
| +export PIN_SHA='3103334e2a3c8d4b20fc113c0310569f17087674' |
| +export RUN=$RUN NAME=$NAME |
| +export OPERATOR_ROLE=$NAME-conn-op BUILD_ROLE=$NAME-build CONN_NAME=$NAME-egress IMAGE_NAME=$NAME |
| +export BUCKET=$NAME-640012953448 LOG_GROUP=/aws/lambda-microvms/$NAME TOPIC_NAME=$NAME-alerts SG_NAME=$NAME-vm |
| +export TAGS_EC2="Key=purpose,Value=equipo-hosted-dev Key=run,Value=$RUN" |
| +RUNEOF |
| +touch "$TMPDIR/equipo-t17/ledger.env" "$TMPDIR/equipo-t17/journal.tsv" "$TMPDIR/equipo-t17/vms.tsv" |
| +. "$TMPDIR/equipo-t17/env.sh" |
| +case "$PIN_SHA" in *'<'*) die "PIN_SHA in run.env is not filled in";; esac |
| +jw "RUN $RUN start pin=$PIN_SHA" |
| +echo "T17=$T17 RUN=$RUN NAME=$NAME" |
| ``` |
| -- Expected: one line `T17=<path>`. Record that path; every later block must see the same `$TMPDIR`. |
| -- Abort if: the directory cannot be created. |
| +- The `PIN_SHA` line in `run.env` carries the same value as 0.1. |
| +- Expected: one line with the scratch path, the run ID and the base name. Every later block must see |
| + the same `$TMPDIR` (the environment file refuses to load otherwise). |
| +- Abort if: the scratch directory already exists. |
| -### 0.3 First AWS command: who am I |
| +### 0.3 First AWS call: who am I |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && aws sts get-caller-identity --query '[Account,Arn]' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +aws sts get-caller-identity --query '[Account,Arn]' --output text |
| ``` |
| - Expected: `640012953448` and an ARN in that account. |
| -- Abort if: the account is anything else, or the call fails. Nothing else runs. |
| +- Abort if: anything else. Nothing else runs. |
| -### 0.4 Nothing else is running MicroVMs here, and nothing from an earlier run is left |
| +### 0.4 Observations and collision checks |
| -The controller's reaper stops every live VM in the account and region that its job table does not |
| -know, after 10 minutes. It must never meet a VM that is not ours. |
| +Every name below contains the random run ID, so a collision is not expected; each check still reads |
| +the exact name and must get the "does not exist" answer. |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -echo "live VMs:"; live_vms |
| -echo "images:"; aws lambda-microvms list-microvm-images --query 'items[].[name,imageArn,state]' --output text |
| -echo "connectors:"; aws lambda-core list-network-connectors --query 'NetworkConnectors[].[Name,Arn,State]' --output text |
| -echo "tagged:"; aws resourcegroupstaggingapi get-resources --tag-filters Key=purpose,Values=$TAGV --query 'ResourceTagMappingList[].ResourceARN' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need RUN NAME OPERATOR_ROLE BUILD_ROLE CONN_NAME IMAGE_NAME BUCKET LOG_GROUP TOPIC_NAME |
| +try aws lambda-microvms list-microvms --query "length(items[?state!='TERMINATED'])" --output text; must |
| +echo "observation: live MicroVMs in the account and region (any image, not ours to touch): $OUT" |
| +try aws resourcegroupstaggingapi get-resources --tag-filters Key=purpose,Values=$TAGV --query 'ResourceTagMappingList[].ResourceARN' --output text; must |
| +echo "observation: resources already tagged purpose=$TAGV (not ours, never touched): [$OUT]" |
| +try aws ec2 describe-vpcs --filters Name=tag:run,Values=$RUN --query 'Vpcs[].VpcId' --output text; must; [ -z "$OUT" ] || die "a VPC already has run=$RUN" |
| +for r in "$OPERATOR_ROLE" "$BUILD_ROLE"; do try aws iam get-role --role-name "$r"; expect_err NoSuchEntity; done |
| +try aws lambda-core get-network-connector --identifier "$CONN_NAME"; expect_err ResourceNotFoundException |
| +try aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_NAME"; expect_err ResourceNotFoundException |
| +try aws s3api head-bucket --bucket "$BUCKET"; expect_err 404 |
| +try aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].logGroupName' --output text; must; [ -z "$OUT" ] || die "log group exists: $OUT" |
| +try aws sns get-topic-attributes --topic-arn "arn:aws:sns:eu-west-1:$ACCOUNT:$TOPIC_NAME"; expect_err NotFound NotFoundException |
| +jw "COLLISION-CHECKS clean"; echo "collision checks clean" |
| ``` |
| -- Expected: no live VMs; no image or connector whose name starts with `equipo-hosted-dev-t17`; no |
| - resource tagged `purpose=equipo-hosted-dev`. |
| -- Abort if: any live VM exists (whoever owns it), or any name or tag above is already taken. Paul |
| - decides; the run does not touch them. |
| -- Note: the `list-network-connectors` output key is read from the CLI model |
| - (`NetworkConnectors`); see UNCONFIRMED U3. |
| +- Expected: two observation lines; `collision checks clean`. |
| +- Abort if: any name exists, or a lookup fails in any other way (for the bucket, `403` means another |
| + account owns the name). |
| --- |
| ## 1. Network |
| -### 1.1 VPC with DNS support and DNS hostnames off |
| +### 1.1 VPC, DNS off, and its default resources tagged |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -VPC=$(aws ec2 create-vpc --cidr-block 10.177.0.0/16 \ |
| - --tag-specifications "ResourceType=vpc,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME}]" \ |
| - --query Vpc.VpcId --output text) && rec VPC "$VPC" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need RUN NAME TAGS_EC2 |
| +intent vpc "tag:run=$RUN" |
| +try aws ec2 create-vpc --cidr-block 10.177.0.0/16 \ |
| + --tag-specifications "ResourceType=vpc,Tags=[{Key=purpose,Value=$TAGV},{Key=run,Value=$RUN},{Key=Name,Value=$NAME}]" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/1.1-vpc.json" |
| +rec VPC "$(jq -r .Vpc.VpcId "$T17/out/1.1-vpc.json")" |
| aws ec2 wait vpc-available --vpc-ids "$VPC" |
| aws ec2 modify-vpc-attribute --vpc-id "$VPC" --enable-dns-hostnames '{"Value":false}' |
| aws ec2 modify-vpc-attribute --vpc-id "$VPC" --enable-dns-support '{"Value":false}' |
| -aws ec2 describe-vpc-attribute --vpc-id "$VPC" --attribute enableDnsSupport --query EnableDnsSupport.Value --output text |
| -aws ec2 describe-vpc-attribute --vpc-id "$VPC" --attribute enableDnsHostnames --query EnableDnsHostnames.Value --output text |
| -aws ec2 describe-vpcs --vpc-ids "$VPC" --query 'Vpcs[0].Tags' --output text |
| +v=$(aws ec2 describe-vpc-attribute --vpc-id "$VPC" --attribute enableDnsSupport --query EnableDnsSupport.Value --output text); [ "$v" = False ] || die "enableDnsSupport is $v" |
| +v=$(aws ec2 describe-vpc-attribute --vpc-id "$VPC" --attribute enableDnsHostnames --query EnableDnsHostnames.Value --output text); [ "$v" = False ] || die "enableDnsHostnames is $v" |
| +DEF=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values="$VPC" Name=group-name,Values=default --query 'SecurityGroups[].GroupId' --output text) |
| +[ "$(wc -w <<<"$DEF")" = 1 ] || die "default groups: [$DEF]"; rec DEF_SG "$DEF" |
| +DEF=$(aws ec2 describe-route-tables --filters Name=vpc-id,Values="$VPC" Name=association.main,Values=true --query 'RouteTables[].RouteTableId' --output text) |
| +[ "$(wc -w <<<"$DEF")" = 1 ] || die "main route tables: [$DEF]"; rec MAIN_RTB "$DEF" |
| +DEF=$(aws ec2 describe-network-acls --filters Name=vpc-id,Values="$VPC" Name=default,Values=true --query 'NetworkAcls[].NetworkAclId' --output text) |
| +[ "$(wc -w <<<"$DEF")" = 1 ] || die "default network ACLs: [$DEF]"; rec DEF_ACL "$DEF" |
| +DEF=$(aws ec2 describe-security-group-rules --filters Name=group-id,Values="$DEF_SG" --query 'SecurityGroupRules[].SecurityGroupRuleId' --output text) |
| +[ -n "$DEF" ] || die "the default group has no rules to tag"; rec DEF_SG_RULES "$DEF" |
| +aws ec2 create-tags --resources "$DEF_SG" "$MAIN_RTB" "$DEF_ACL" $DEF_SG_RULES --tags $TAGS_EC2 |
| +n=$(aws ec2 describe-tags --filters Name=resource-id,Values="$VPC,$DEF_SG,$MAIN_RTB,$DEF_ACL,$(tr '\t ' ',,' <<<"$DEF_SG_RULES")" Name=key,Values=purpose --query 'length(Tags)' --output text) |
| +[ "$n" = $(( 4 + $(wc -w <<<"$DEF_SG_RULES") )) ] || die "purpose tag on $n resources" |
| +echo "VPC $VPC: DNS support and hostnames off; defaults tagged: $DEF_SG $MAIN_RTB $DEF_ACL $DEF_SG_RULES" |
| ``` |
| -- Expected: a `vpc-` ID in the ledger; both attribute reads print `False`; tags show |
| - `purpose equipo-hosted-dev` and `Name equipo-hosted-dev-t17`. |
| -- Abort if: either attribute reads `True`, or the tags are missing. |
| +- Expected: the last line. The defaults go with the VPC in 10.3 and are verified gone in 10.8. |
| +- Abort if: any check fails. |
| ### 1.2 One VM subnet |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -SUBNET=$(aws ec2 create-subnet --vpc-id "$VPC" --cidr-block 10.177.1.0/24 --availability-zone eu-west-1a \ |
| - --tag-specifications "ResourceType=subnet,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME-vm}]" \ |
| - --query Subnet.SubnetId --output text) && rec SUBNET "$SUBNET" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VPC RUN NAME |
| +intent subnet "tag:run=$RUN" |
| +try aws ec2 create-subnet --vpc-id "$VPC" --cidr-block 10.177.1.0/24 --availability-zone eu-west-1a \ |
| + --tag-specifications "ResourceType=subnet,Tags=[{Key=purpose,Value=$TAGV},{Key=run,Value=$RUN},{Key=Name,Value=$NAME-vm}]" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/1.2-subnet.json" |
| +rec SUBNET "$(jq -r .Subnet.SubnetId "$T17/out/1.2-subnet.json")" |
| aws ec2 wait subnet-available --subnet-ids "$SUBNET" |
| -aws ec2 describe-subnets --subnet-ids "$SUBNET" --query 'Subnets[0].[VpcId,CidrBlock,AvailabilityZone,MapPublicIpOnLaunch]' --output text |
| +got=$(aws ec2 describe-subnets --subnet-ids "$SUBNET" --query 'Subnets[0].[VpcId,CidrBlock,AvailabilityZone,MapPublicIpOnLaunch]' --output text) |
| +[ "$got" = "$VPC 10.177.1.0/24 eu-west-1a False" ] || die "subnet is [$got]" |
| +echo "subnet $SUBNET ok" |
| ``` |
| -- Expected: `<VPC> 10.177.1.0/24 eu-west-1a False`. |
| -- Abort if: any field differs. |
| +- Abort if: creation fails (an unsupported zone is a stop: U10) or the readback differs. |
| -### 1.3 Its own route table, local route only |
| +### 1.3 The subnet's own route table, local route only |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -RTB=$(aws ec2 create-route-table --vpc-id "$VPC" \ |
| - --tag-specifications "ResourceType=route-table,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME-vm}]" \ |
| - --query RouteTable.RouteTableId --output text) && rec RTB "$RTB" || exit 1 |
| -RTB_ASSOC=$(aws ec2 associate-route-table --route-table-id "$RTB" --subnet-id "$SUBNET" \ |
| - --query AssociationId --output text) && rec RTB_ASSOC "$RTB_ASSOC" || exit 1 |
| -aws ec2 describe-route-tables --route-table-ids "$RTB" --query 'RouteTables[0].Routes[].[DestinationCidrBlock,DestinationIpv6CidrBlock,GatewayId,State]' --output text |
| -aws ec2 describe-route-tables --filters Name=association.subnet-id,Values="$SUBNET" --query 'RouteTables[].RouteTableId' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VPC SUBNET RUN NAME |
| +intent route-table "tag:run=$RUN" |
| +try aws ec2 create-route-table --vpc-id "$VPC" \ |
| + --tag-specifications "ResourceType=route-table,Tags=[{Key=purpose,Value=$TAGV},{Key=run,Value=$RUN},{Key=Name,Value=$NAME-vm}]" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/1.3-rtb.json" |
| +rec RTB "$(jq -r .RouteTable.RouteTableId "$T17/out/1.3-rtb.json")" |
| +intent route-table-association "$RTB/$SUBNET" |
| +rec RTB_ASSOC "$(aws ec2 associate-route-table --route-table-id "$RTB" --subnet-id "$SUBNET" --query AssociationId --output text)" |
| +got=$(aws ec2 describe-route-tables --route-table-ids "$RTB" --query 'RouteTables[0].Routes[].[DestinationCidrBlock,GatewayId,State]' --output text) |
| +[ "$got" = "10.177.0.0/16 local active" ] || die "routes are [$got]" |
| +got=$(aws ec2 describe-route-tables --filters Name=association.subnet-id,Values="$SUBNET" --query 'RouteTables[].RouteTableId' --output text) |
| +[ "$got" = "$RTB" ] || die "the subnet uses [$got]" |
| +echo "route table $RTB: local route only, associated" |
| ``` |
| -- Expected: exactly one route line, `10.177.0.0/16 None local active`; the subnet's table is `$RTB`. |
| -- Abort if: any other route, or the subnet maps to another table. |
| - |
| ### 1.4 Security group with no rules |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -SG=$(aws ec2 create-security-group --group-name "$NAME-vm" --description "Task 17 VM group, no rules" --vpc-id "$VPC" \ |
| - --tag-specifications "ResourceType=security-group,Tags=[{Key=purpose,Value=$TAGV},{Key=Name,Value=$NAME-vm}]" \ |
| - --query GroupId --output text) && rec SG "$SG" || exit 1 |
| -EGRESS_RULES=$(aws ec2 describe-security-group-rules --filters Name=group-id,Values="$SG" \ |
| - --query 'SecurityGroupRules[?IsEgress].SecurityGroupRuleId' --output text) |
| -echo "default egress rules: $EGRESS_RULES" |
| -aws ec2 revoke-security-group-egress --group-id "$SG" --security-group-rule-ids $EGRESS_RULES --query Return --output text |
| -aws ec2 describe-security-groups --group-ids "$SG" --query 'SecurityGroups[0].[length(IpPermissions),length(IpPermissionsEgress)]' --output text |
| -aws ec2 describe-security-group-rules --filters Name=group-id,Values="$SG" --query 'length(SecurityGroupRules)' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VPC RUN SG_NAME |
| +intent security-group "$SG_NAME" |
| +try aws ec2 create-security-group --group-name "$SG_NAME" --description "Task 17 VM group, no rules" --vpc-id "$VPC" \ |
| + --tag-specifications "ResourceType=security-group,Tags=[{Key=purpose,Value=$TAGV},{Key=run,Value=$RUN},{Key=Name,Value=$SG_NAME}]" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/1.4-sg.json" |
| +rec SG "$(jq -r .GroupId "$T17/out/1.4-sg.json")" |
| +aws ec2 describe-security-group-rules --filters Name=group-id,Values="$SG" --output json > "$T17/out/1.4-rules.json" |
| +jq -e '[.SecurityGroupRules[] | select(.IsEgress)] | length == 1' "$T17/out/1.4-rules.json" >/dev/null || die "not exactly one default egress rule" |
| +jq -e '.SecurityGroupRules[] | select(.IsEgress) | .IpProtocol == "-1" and .CidrIpv4 == "0.0.0.0/0"' "$T17/out/1.4-rules.json" >/dev/null || die "the default egress rule is not all traffic to 0.0.0.0/0" |
| +jq -e '[.SecurityGroupRules[] | select(.IsEgress | not)] | length == 0' "$T17/out/1.4-rules.json" >/dev/null || die "the new group has inbound rules" |
| +rule=$(jq -r '.SecurityGroupRules[] | select(.IsEgress) | .SecurityGroupRuleId' "$T17/out/1.4-rules.json") |
| +[ "$(aws ec2 revoke-security-group-egress --group-id "$SG" --security-group-rule-ids "$rule" --query Return --output text)" = True ] || die "revoke failed" |
| +got=$(aws ec2 describe-security-groups --group-ids "$SG" --query 'SecurityGroups[0].[length(IpPermissions),length(IpPermissionsEgress)]' --output text) |
| +[ "$got" = "0 0" ] || die "rules left: [$got]" |
| +[ "$(aws ec2 describe-security-group-rules --filters Name=group-id,Values="$SG" --query 'length(SecurityGroupRules)' --output text)" = 0 ] || die "rule list not empty" |
| +echo "security group $SG: no rules" |
| ``` |
| -- Expected: one default egress rule ID (`sgr-...`, the IPv4 all-traffic rule); revoke prints `True`; |
| - then `0 0` and `0`. |
| -- Abort if: more than one default egress rule, revoke fails, or any rule remains. |
| -- Record: VPC, subnet, route table, group IDs, and the three verification outputs. |
| - |
| --- |
| ## 2. Connector |
| -### 2.1 Operator role for the connector's network interfaces |
| +### 2.1 The connector's network-interface role (least privilege) |
| -The connector needs an IAM role Lambda assumes to create its network interfaces in the subnet. AWS |
| -publishes a managed policy for it; the SDK says the role also needs delete and describe permissions, |
| -which the managed policy does not hold, so a small inline policy adds them. |
| +The trust policy is the one AWS documents for the connector operator role (Lambda Web Functions |
| +networking guide: `lambda.amazonaws.com`, `sts:AssumeRole`), plus `sts:TagSession`, which only lets |
| +Lambda tag the session it assumes; it does not widen who can assume the role. The permissions |
| +replace the broad managed policy `AWSLambdaNetworkConnectorOperatorPolicy` (which allows creating |
| +interfaces in any subnet with any group) with statements scoped to this subnet and this group. The |
| +pinned SDK says the role also needs `ec2:DeleteNetworkInterface` and describe calls; delete is |
| +limited to interfaces in this subnet. EC2 `Describe*` calls have no resource-level scoping, so they |
| +are a separate statement on `*`, read-only. |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -cat > "$T17/iam/operator-trust.json" <<'EOF' |
| -{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole","Condition":{"StringEquals":{"aws:SourceAccount":"640012953448"}}}]} |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need SUBNET SG OPERATOR_ROLE RUN |
| +cat > "$T17/iam/lambda-trust.json" <<'EOF' |
| +{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":["sts:AssumeRole","sts:TagSession"]}]} |
| EOF |
| -cat > "$T17/iam/operator-extra.json" <<'EOF' |
| +A=arn:aws:ec2:eu-west-1:640012953448 |
| +cat > "$T17/iam/operator.json" <<EOF |
| {"Version":"2012-10-17","Statement":[ |
| - {"Effect":"Allow","Action":"ec2:DeleteNetworkInterface","Resource":"arn:aws:ec2:eu-west-1:640012953448:network-interface/*"}, |
| - {"Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeSubnets","ec2:DescribeSecurityGroups","ec2:DescribeVpcs"],"Resource":"*"}]} |
| + {"Sid":"CreateEniInThisSubnetWithThisGroup","Effect":"Allow","Action":"ec2:CreateNetworkInterface", |
| + "Resource":["$A:subnet/$SUBNET","$A:security-group/$SG"]}, |
| + {"Sid":"CreateConnectorEniInThisSubnet","Effect":"Allow","Action":"ec2:CreateNetworkInterface", |
| + "Resource":"$A:network-interface/*", |
| + "Condition":{"ArnEquals":{"ec2:Subnet":"$A:subnet/$SUBNET"}, |
| + "ForAllValues:StringEquals":{"aws:TagKeys":["aws:lambda:networkConnectorName","aws:lambda:networkConnectorId"]}}}, |
| + {"Sid":"TagConnectorEniOnCreate","Effect":"Allow","Action":"ec2:CreateTags","Resource":"$A:network-interface/*", |
| + "Condition":{"StringEquals":{"ec2:CreateAction":"CreateNetworkInterface","ec2:ManagedResourceOperator":"network-connectors.lambda.amazonaws.com"}}}, |
| + {"Sid":"DeleteEniInThisSubnet","Effect":"Allow","Action":"ec2:DeleteNetworkInterface","Resource":"$A:network-interface/*", |
| + "Condition":{"ArnEquals":{"ec2:Subnet":"$A:subnet/$SUBNET"}}}, |
| + {"Sid":"DescribeHasNoResourceScope","Effect":"Allow","Action":["ec2:DescribeNetworkInterfaces","ec2:DescribeSubnets","ec2:DescribeSecurityGroups","ec2:DescribeVpcs"],"Resource":"*"}]} |
| EOF |
| -OPERATOR_ROLE=$NAME-connector-operator |
| -OPERATOR_ROLE_ARN=$(aws iam create-role --role-name "$OPERATOR_ROLE" --description "Task 17 connector ENI operator" \ |
| - --assume-role-policy-document "file://$T17/iam/operator-trust.json" --tags Key=purpose,Value=$TAGV \ |
| - --query Role.Arn --output text) && rec OPERATOR_ROLE "$OPERATOR_ROLE" && rec OPERATOR_ROLE_ARN "$OPERATOR_ROLE_ARN" || exit 1 |
| -aws iam attach-role-policy --role-name "$OPERATOR_ROLE" --policy-arn arn:aws:iam::aws:policy/AWSLambdaNetworkConnectorOperatorPolicy |
| -aws iam put-role-policy --role-name "$OPERATOR_ROLE" --policy-name t17-eni-extra --policy-document "file://$T17/iam/operator-extra.json" |
| +jq -e . "$T17/iam/operator.json" >/dev/null |
| +intent iam-role "$OPERATOR_ROLE" |
| +try aws iam create-role --role-name "$OPERATOR_ROLE" --description "Task 17 connector network interfaces, run $RUN" \ |
| + --assume-role-policy-document "file://$T17/iam/lambda-trust.json" \ |
| + --tags Key=purpose,Value=$TAGV Key=run,Value=$RUN --query Role.Arn --output text; must |
| +arn_ok "$OUT"; rec OPERATOR_ROLE_ARN "$OUT" |
| +aws iam put-role-policy --role-name "$OPERATOR_ROLE" --policy-name t17-connector-eni --policy-document "file://$T17/iam/operator.json" |
| aws iam wait role-exists --role-name "$OPERATOR_ROLE" |
| -aws iam list-attached-role-policies --role-name "$OPERATOR_ROLE" --query 'AttachedPolicies[].PolicyName' --output text |
| -aws iam list-role-policies --role-name "$OPERATOR_ROLE" --query PolicyNames --output text |
| +[ "$(aws iam list-role-policies --role-name "$OPERATOR_ROLE" --query 'PolicyNames' --output text)" = t17-connector-eni ] || die "inline policy missing" |
| +[ "$(aws iam list-attached-role-policies --role-name "$OPERATOR_ROLE" --query 'length(AttachedPolicies)' --output text)" = 0 ] || die "managed policy attached" |
| sleep 15 |
| +echo "operator role $OPERATOR_ROLE_ARN ready" |
| ``` |
| -- Expected: role ARN `arn:aws:iam::640012953448:role/equipo-hosted-dev-t17-connector-operator`; |
| - attached `AWSLambdaNetworkConnectorOperatorPolicy`; inline `t17-eni-extra`. The 15 s wait lets IAM |
| - propagate. |
| -- Abort if: any call fails. |
| +- Abort if: any call fails. A connector that later fails with `InsufficientRolePermissions` is a stop |
| + (U2); the policy is not widened without approval. |
| ### 2.2 Create the VPC_EGRESS connector for MicroVMs |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-core create-network-connector --name "$NAME-egress" \ |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need SUBNET SG OPERATOR_ROLE_ARN CONN_NAME RUN |
| +intent connector "$CONN_NAME" "token=$CONN_NAME-1" |
| +try aws lambda-core create-network-connector --name "$CONN_NAME" \ |
| --configuration "{\"VpcEgressConfiguration\":{\"SubnetIds\":[\"$SUBNET\"],\"SecurityGroupIds\":[\"$SG\"],\"NetworkProtocol\":\"IPv4\",\"AssociatedComputeResourceTypes\":[\"MicroVm\"]}}" \ |
| - --operator-role "$OPERATOR_ROLE_ARN" --tags purpose=$TAGV --client-token "$NAME-egress-1" \ |
| - --output json > "$T17/out/2.2-connector.json" || exit 1 |
| -rec CONN_ARN "$(jq -r .Arn "$T17/out/2.2-connector.json")" && rec CONN_ID "$(jq -r .Id "$T17/out/2.2-connector.json")" || exit 1 |
| + --operator-role "$OPERATOR_ROLE_ARN" --tags purpose=$TAGV,run=$RUN --client-token "$CONN_NAME-1" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/2.2-connector.json" |
| +arn_ok "$(jq -r .Arn "$T17/out/2.2-connector.json")" |
| +rec CONN_ARN "$(jq -r .Arn "$T17/out/2.2-connector.json")"; rec CONN_ID "$(jq -r .Id "$T17/out/2.2-connector.json")" |
| +[ "$CONN_ARN" = "arn:aws:lambda:eu-west-1:$ACCOUNT:network-connector:$CONN_ID" ] || die "connector ARN has an unexpected form: $CONN_ARN" |
| jq '{Arn,Id,State}' "$T17/out/2.2-connector.json" |
| ``` |
| -- Expected: `Arn` of the form `arn:aws:lambda:eu-west-1:640012953448:network-connector:<Id>`, |
| - `State` `PENDING`. No `ElasticIpConfiguration` is set, so the connector gets no Elastic IPs. |
| -- Abort if: an error, or the ARN does not have that form. |
| +- Expected: state `PENDING`. No `ElasticIpConfiguration` is sent, so the connector gets none; 5.6 |
| + confirms that through the SDK. |
| ### 2.3 Wait for ACTIVE (spike: about 4.5 min; bound 15 min) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -for i in $(seq 1 60); do |
| - s=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text) |
| - echo "$(date -u +%T) $s"; [ "$s" = ACTIVE ] && break |
| - [ "$s" = FAILED ] && { aws lambda-core get-network-connector --identifier "$CONN_ARN" --query '[StateReason,StateReasonCode]' --output text; exit 1; } |
| - sleep 15 |
| -done |
| -[ "$s" = ACTIVE ] || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need CONN_ARN |
| +_conn() { try aws lambda-core get-network-connector --identifier "$CONN_ARN" --query '[State,StateReasonCode,StateReason]' --output text |
| + [ "$RC" = 0 ] || return 3; echo "$(date -u +%T) $OUT"; case "$OUT" in ACTIVE*) return 0;; PENDING*) return 1;; esac; return 2; } |
| +poll 900 15 "connector ACTIVE" _conn |
| +jw "TIMING connector-active" |
| ``` |
| -- Expected: `ACTIVE` within 15 min. Record the time it took. |
| -- Abort if: `FAILED` (record `StateReason` and `StateReasonCode`), or not ACTIVE after 15 min. |
| +- Abort if: `FAILED` (the line shows its reason code) or the bound runs out. |
| -### 2.4 Read the version and build the version-qualified ARN |
| - |
| -There is no publish call: each update creates a new version, and `Version` on the unqualified read |
| -is the current one. The installed CLI's model has no `LatestVersionArn` field (the Go SDK has it), so |
| -the plan builds the qualified ARN as `<Arn>:<Version>`, the form the networking guide prints. The |
| -controller's network audit later confirms it: it reads the connector by this ARN and requires |
| -`VersionArn` to equal it (`network.go`, `checkConnector`). |
| +### 2.4 Version, qualified ARN, and the connector's network interfaces |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -CONN_VERSION=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query Version --output text) && rec CONN_VERSION "$CONN_VERSION" || exit 1 |
| -rec CONN_QARN "$CONN_ARN:$CONN_VERSION" || exit 1 |
| -[ "$(echo "$CONN_QARN" | awk -F: '{print NF, $7}')" = "8 $CONN_ID" ] && echo "qualified ARN shape ok: $CONN_QARN" |
| -aws lambda-core get-network-connector --identifier "$CONN_QARN" \ |
| - --query '[State,Version,Configuration.VpcEgressConfiguration.SubnetIds,Configuration.VpcEgressConfiguration.SecurityGroupIds,Configuration.VpcEgressConfiguration.AssociatedComputeResourceTypes]' --output json |
| -aws ec2 describe-network-interfaces --filters Name=subnet-id,Values="$SUBNET" --query 'NetworkInterfaces[].[NetworkInterfaceId,Status,InterfaceType,Description]' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need CONN_ARN CONN_ID SUBNET SG VPC |
| +v=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query Version --output text) |
| +case "$v" in ''|*[!0-9]*) die "connector version is [$v]";; esac |
| +rec CONN_VERSION "$v"; rec CONN_QARN "$CONN_ARN:$CONN_VERSION" |
| +aws lambda-core get-network-connector --identifier "$CONN_QARN" --output json > "$T17/out/2.4-qualified.json" |
| +jq -e --arg s "$SUBNET" --arg g "$SG" '.State == "ACTIVE" and (.Configuration.VpcEgressConfiguration.SubnetIds == [$s]) and (.Configuration.VpcEgressConfiguration.SecurityGroupIds == [$g]) and (.Configuration.VpcEgressConfiguration.AssociatedComputeResourceTypes == ["MicroVm"])' "$T17/out/2.4-qualified.json" >/dev/null || die "qualified read differs: $(cat "$T17/out/2.4-qualified.json")" |
| +aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC" --output json > "$T17/out/2.4-enis.json" |
| +jq -e --arg s "$SUBNET" 'all(.NetworkInterfaces[]; .SubnetId == $s)' "$T17/out/2.4-enis.json" >/dev/null || die "an interface outside the subnet" |
| +for e in $(jq -r '.NetworkInterfaces[].NetworkInterfaceId' "$T17/out/2.4-enis.json"); do jw "SERVICE-ENI $e"; done |
| +jq -r '.NetworkInterfaces[] | [.NetworkInterfaceId, .Status, .InterfaceType, (.TagSet // [] | map(.Key) | join(","))] | @tsv' "$T17/out/2.4-enis.json" |
| +echo "qualified connector ARN: $CONN_QARN" |
| ``` |
| -- Expected: `CONN_VERSION` is a whole number (likely `1`); "qualified ARN shape ok"; the qualified |
| - read shows `ACTIVE`, the version, `[SUBNET]`, `[SG]`, `["MicroVm"]`. The connector's network |
| - interfaces are listed (Lambda owns them; they are not ours to delete and are not put in the ledger |
| - as deletable). |
| -- Abort if: the version is not numeric, the qualified read fails, or the subnet or group lists hold |
| - anything else. |
| -- Record: connector ARN, ID, version, qualified ARN, time to ACTIVE, the interface IDs. |
| +- Expected: a whole-number version; the qualified read is `ACTIVE` with only this subnet, this group |
| + and `MicroVm`. The installed CLI cannot show `VersionArn`, so the qualified ARN is built as |
| + `<Arn>:<Version>` (the form the networking guide prints) and proven by the SDK audit in 5.6. |
| + The interfaces are Lambda's: recorded as `SERVICE-ENI`, never deleted by the run, verified gone |
| + in 10.2. |
| --- |
| ## 3. Image |
| -The API builds an image from a zip in S3 that holds a `Dockerfile` and its files, on a |
| -Lambda-managed base image, using a build role that can read the zip and write build logs |
| -(`microvms-images`, `microvms-getting-started`). It needs no ECR repository. Memory, x86_64 and the |
| -`ALL` OS capability are set per image version, so the Small (2048 MiB) and Large (4096 MiB) sizes are |
| -two versions of one image: create, then one update. |
| - |
| -The image is the smallest thing that answers the lifecycle hooks: a static Go binary that returns 200 |
| -to every hook path on port 9000 inside the VM. The run hook must answer, because the adapter always |
| -sends a run hook payload and the VM takes traffic only after `/run` returns 200. |
| +The API builds an image from a zip in S3 holding a `Dockerfile` and its files, on a Lambda-managed |
| +base image, with a build role that can read the zip and write build logs. Memory, x86_64 and the |
| +`ALL` capability are set per image version, so Small (2048 MiB) and Large (4096 MiB) are two |
| +versions: create, then one update. The image is a static Go binary that answers 200 on every hook |
| +path on port 9000 inside the VM; the run hook must answer, because the adapter always sends a run |
| +hook payload. |
| -### 3.1 S3 bucket for the code artifact |
| +### 3.1 S3 bucket |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -BUCKET=$NAME-$ACCOUNT-$(openssl rand -hex 3) |
| -aws s3api create-bucket --bucket "$BUCKET" --create-bucket-configuration LocationConstraint=eu-west-1 --query Location --output text && rec BUCKET "$BUCKET" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need BUCKET RUN |
| +intent s3-bucket "$BUCKET" |
| +try aws s3api create-bucket --bucket "$BUCKET" --create-bucket-configuration LocationConstraint=eu-west-1 --output json; must |
| +rec BUCKET_CREATED "$BUCKET" |
| aws s3api put-public-access-block --bucket "$BUCKET" --public-access-block-configuration BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true |
| -aws s3api put-bucket-tagging --bucket "$BUCKET" --tagging "TagSet=[{Key=purpose,Value=$TAGV}]" |
| -aws s3api get-bucket-tagging --bucket "$BUCKET" --query 'TagSet[].[Key,Value]' --output text |
| +aws s3api put-bucket-tagging --bucket "$BUCKET" --tagging "TagSet=[{Key=purpose,Value=$TAGV},{Key=run,Value=$RUN}]" |
| +[ "$(aws s3api get-bucket-tagging --bucket "$BUCKET" --query "TagSet[?Key=='run'].Value" --output text)" = "$RUN" ] || die "bucket tags missing" |
| +echo "bucket $BUCKET ok" |
| ``` |
| -- Expected: the bucket's location, then `purpose equipo-hosted-dev`. |
| -- Abort if: any call fails. |
| - |
| -### 3.2 Build log group (created by us so it carries the tag) |
| +### 3.2 Log group for the build |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws logs create-log-group --log-group-name "$LOG_GROUP" --tags purpose=$TAGV && rec LOG_GROUP_CREATED "$LOG_GROUP" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need LOG_GROUP RUN |
| +intent log-group "$LOG_GROUP" |
| +try aws logs create-log-group --log-group-name "$LOG_GROUP" --tags purpose=$TAGV,run=$RUN; must |
| +rec LOG_GROUP_CREATED "$LOG_GROUP" |
| aws logs put-retention-policy --log-group-name "$LOG_GROUP" --retention-in-days 1 |
| -aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].[logGroupName,retentionInDays]' --output text |
| +[ "$(aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].[logGroupName,retentionInDays]' --output text)" = "$LOG_GROUP 1" ] || die "log group readback differs" |
| ``` |
| -- Expected: `/aws/lambda-microvms/equipo-hosted-dev-t17 1`. |
| -- Abort if: the group already exists or a call fails. |
| +### 3.3 Build role (least privilege) |
| -### 3.3 Build role |
| +Same trust policy as 2.1. The current getting-started page prints `sts:AssumeRole` only; Astra's |
| +review cites a version with `sts:TagSession`. Granting both satisfies either. Permissions are the |
| +guide's, narrowed to the one S3 key and the one log group. It is a build role only: no VM ever gets |
| +an execution role (spec §3, §15). |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -cat > "$T17/iam/build-trust.json" <<'EOF' |
| -{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":"lambda.amazonaws.com"},"Action":"sts:AssumeRole"}]} |
| -EOF |
| -cat > "$T17/iam/build-policy.json" <<EOF |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need BUILD_ROLE BUCKET LOG_GROUP RUN |
| +L="arn:aws:logs:eu-west-1:640012953448:log-group:$LOG_GROUP" |
| +cat > "$T17/iam/build.json" <<EOF |
| {"Version":"2012-10-17","Statement":[ |
| - {"Effect":"Allow","Action":["s3:GetObject"],"Resource":"arn:aws:s3:::$BUCKET/*"}, |
| - {"Effect":"Allow","Action":["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],"Resource":"arn:aws:logs:eu-west-1:$ACCOUNT:*"}]} |
| + {"Sid":"ReadTheCodeArtifact","Effect":"Allow","Action":"s3:GetObject","Resource":"arn:aws:s3:::$BUCKET/t17/app.zip"}, |
| + {"Sid":"WriteBuildLogsToThisGroup","Effect":"Allow","Action":["logs:CreateLogGroup","logs:CreateLogStream","logs:PutLogEvents"],"Resource":["$L","$L:*"]}]} |
| EOF |
| -BUILD_ROLE=$NAME-image-build |
| -BUILD_ROLE_ARN=$(aws iam create-role --role-name "$BUILD_ROLE" --description "Task 17 MicroVM image build" \ |
| - --assume-role-policy-document "file://$T17/iam/build-trust.json" --tags Key=purpose,Value=$TAGV \ |
| - --query Role.Arn --output text) && rec BUILD_ROLE "$BUILD_ROLE" && rec BUILD_ROLE_ARN "$BUILD_ROLE_ARN" || exit 1 |
| -aws iam put-role-policy --role-name "$BUILD_ROLE" --policy-name t17-build --policy-document "file://$T17/iam/build-policy.json" |
| +jq -e . "$T17/iam/build.json" >/dev/null |
| +intent iam-role "$BUILD_ROLE" |
| +try aws iam create-role --role-name "$BUILD_ROLE" --description "Task 17 MicroVM image build, run $RUN" \ |
| + --assume-role-policy-document "file://$T17/iam/lambda-trust.json" \ |
| + --tags Key=purpose,Value=$TAGV Key=run,Value=$RUN --query Role.Arn --output text; must |
| +arn_ok "$OUT"; rec BUILD_ROLE_ARN "$OUT" |
| +aws iam put-role-policy --role-name "$BUILD_ROLE" --policy-name t17-build --policy-document "file://$T17/iam/build.json" |
| aws iam wait role-exists --role-name "$BUILD_ROLE" |
| -aws iam list-role-policies --role-name "$BUILD_ROLE" --query PolicyNames --output text |
| +[ "$(aws iam list-role-policies --role-name "$BUILD_ROLE" --query 'PolicyNames' --output text)" = t17-build ] || die "inline policy missing" |
| sleep 15 |
| ``` |
| -- Expected: role ARN in `640012953448`; inline policy `t17-build`. This is the trust policy and |
| - permission set the getting-started guide prints, narrowed to this bucket and this account's logs. |
| - It is a build role only: no VM ever gets an execution role (spec §3, §15). |
| -- Abort if: any call fails. |
| - |
| -### 3.4 The hook binary, the Dockerfile and the zip (local only) |
| +### 3.4 Hook binary, Dockerfile, hooks and zip (no AWS call) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -cd "$T17/image" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +cd "$T17/image" |
| cat > hookd.go <<'EOF' |
| // hookd answers every Lambda MicroVM lifecycle hook with 200. Task 17 only. |
| package main |
| @@ -456,196 +714,198 @@ cat > hooks.json <<'EOF' |
| "suspend":"ENABLED","suspendTimeoutInSeconds":10,"terminate":"ENABLED","terminateTimeoutInSeconds":10}, |
| "microvmImageHooks":{"ready":"ENABLED","readyTimeoutInSeconds":120,"validate":"DISABLED"}} |
| EOF |
| -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags=-s -o hookd hookd.go || exit 1 |
| +jq -e . hooks.json >/dev/null |
| +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags=-s -o hookd hookd.go |
| chmod 0755 hookd |
| -python3 -I -m zipfile -c app.zip Dockerfile hookd || exit 1 |
| -python3 -I -m zipfile -l app.zip |
| -file hookd 2>/dev/null || head -c 4 hookd | od -c | head -1 |
| +[ "$(head -c 4 hookd | od -An -c | tr -d ' ')" = '177ELF' ] || die "hookd is not an ELF binary" |
| +python3 -I -m zipfile -c app.zip Dockerfile hookd |
| +[ "$(python3 -I -c 'import zipfile;print(" ".join(sorted(zipfile.ZipFile("app.zip").namelist())))')" = "Dockerfile hookd" ] || die "zip contents differ" |
| sha256sum app.zip |
| ``` |
| -- Expected: the zip lists `Dockerfile` and `hookd`; `hookd` is an x86-64 ELF; one sha256 line. |
| -- Abort if: the build fails. |
| +### 3.5 Digest, and the upload that proves it (object tagged) |
| -### 3.5 The image digest, and the upload that proves it |
| - |
| -AWS has no content digest for a MicroVM image. The controller's allowlist key |
| -(`sha256:` and 64 lower-case hex digits, `config.go`) is therefore the SHA-256 of the exact code |
| -artifact zip the image is built from. The upload sends that checksum and S3 refuses the object if the |
| -bytes differ; the read-back shows S3 holds the same checksum. `get-microvm-image-version` later shows |
| -which S3 object each version was built from (`codeArtifact.uri`). Slice 1b replaces this with |
| -certificates. |
| +AWS has no content digest for a MicroVM image, so the controller's allowlist key (`sha256:` and 64 |
| +lower-case hex digits) is the SHA-256 of the exact zip the image is built from. S3 rejects the |
| +upload if the bytes do not match the checksum sent; the read-back shows S3 holds that checksum; |
| +3.8 shows each version names this object. |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -cd "$T17/image" || exit 1 |
| -rec DIGEST "sha256:$(sha256sum app.zip | cut -d' ' -f1)" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need BUCKET RUN |
| +cd "$T17/image" |
| +rec DIGEST "sha256:$(sha256sum app.zip | cut -d' ' -f1)" |
| B64=$(openssl dgst -sha256 -binary app.zip | base64) |
| -aws s3api put-object --bucket "$BUCKET" --key t17/app.zip --body app.zip --checksum-algorithm SHA256 --checksum-sha256 "$B64" \ |
| - --query ChecksumSHA256 --output text && rec ARTIFACT "s3://$BUCKET/t17/app.zip" || exit 1 |
| -GOT=$(aws s3api head-object --bucket "$BUCKET" --key t17/app.zip --checksum-mode ENABLED --query ChecksumSHA256 --output text) |
| -[ "$GOT" = "$B64" ] && echo "S3 checksum matches $DIGEST" |
| +intent s3-object "s3://$BUCKET/t17/app.zip" |
| +try aws s3api put-object --bucket "$BUCKET" --key t17/app.zip --body app.zip --checksum-algorithm SHA256 \ |
| + --checksum-sha256 "$B64" --tagging "purpose=$TAGV&run=$RUN" --query ChecksumSHA256 --output text; must |
| +[ "$OUT" = "$B64" ] || die "put-object checksum [$OUT]" |
| +rec ARTIFACT "s3://$BUCKET/t17/app.zip" |
| +[ "$(aws s3api head-object --bucket "$BUCKET" --key t17/app.zip --checksum-mode ENABLED --query ChecksumSHA256 --output text)" = "$B64" ] || die "S3 checksum differs" |
| +[ "$(aws s3api get-object-tagging --bucket "$BUCKET" --key t17/app.zip --query "TagSet[?Key=='run'].Value" --output text)" = "$RUN" ] || die "object tags missing" |
| +echo "artifact $ARTIFACT digest $DIGEST" |
| ``` |
| -- Expected: `DIGEST` like `sha256:<64 hex>`; put-object prints `$B64`; "S3 checksum matches". |
| -- Abort if: the checksums differ. |
| - |
| -### 3.6 Pick the managed base image and a version that supports x86_64 |
| +### 3.6 Managed base image and version |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-microvms list-managed-microvm-images --query 'items[].imageArn' --output text |
| -BASE_ARN=$(aws lambda-microvms list-managed-microvm-images --query "items[?ends_with(imageArn, ':microvm-image:al2023-1')].imageArn | [0]" --output text) && rec BASE_ARN "$BASE_ARN" || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +base=$(aws lambda-microvms list-managed-microvm-images --query "items[?imageArn=='arn:aws:lambda:eu-west-1:aws:microvm-image:al2023-1'].imageArn | [0]" --output text) |
| +[ "$base" = arn:aws:lambda:eu-west-1:aws:microvm-image:al2023-1 ] || die "no al2023-1 base image: [$base]" |
| +rec BASE_ARN "$base" |
| aws lambda-microvms list-managed-microvm-image-versions --image-identifier "$BASE_ARN" --query 'items[].[imageVersion,createdAt]' --output text |
| -BASE_VER=$(aws lambda-microvms list-managed-microvm-image-versions --image-identifier "$BASE_ARN" --query 'items[].imageVersion' --output text | tr '\t' '\n' | sort -V | tail -1) |
| -[ "${BASE_VER%%.*}" -ge 3 ] 2>/dev/null && rec BASE_VER "$BASE_VER" || { echo "ABORT: newest base version $BASE_VER is below 3"; exit 1; } |
| +v=$(aws lambda-microvms list-managed-microvm-image-versions --image-identifier "$BASE_ARN" --query 'items[].imageVersion' --output text | tr '\t' '\n' | sort -V | tail -n 1) |
| +case "${v%%.*}" in ''|*[!0-9]*) die "base version [$v]";; esac |
| +[ "${v%%.*}" -ge 3 ] || die "newest base version $v is below 3 (x86_64 needs 3 or later)" |
| +rec BASE_VER "$v" |
| ``` |
| -- Expected: `arn:aws:lambda:eu-west-1:aws:microvm-image:al2023-1`; the newest version is 3 or later |
| - (x86_64 needs version 3 or later). The installed CLI drops the `status` and |
| - `supportedCpuConfigurations` fields of this list; if the version cannot build x86_64, 3.7 fails |
| - with a `ValidationException`, which is a stop. |
| -- Abort if: no `al2023-1` image, or the newest version is below 3. |
| +- The installed CLI drops each version's `status` and `supportedCpuConfigurations` (U3), so this |
| + picks the newest listed version. If that version cannot build x86_64 or is not available, 3.7 |
| + fails with a `ValidationException`: a stop (U4), with no other version tried. |
| -### 3.7 Create the image: Small version (2048 MiB, X86_64, ALL) |
| +### 3.7 Create the image: Small version |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-microvms create-microvm-image --name "$NAME" --description "Task 17 minimal hook image, small" \ |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need IMAGE_NAME ARTIFACT BASE_ARN BASE_VER BUILD_ROLE_ARN LOG_GROUP RUN |
| +intent microvm-image "$IMAGE_NAME" "token=$IMAGE_NAME-create-1" |
| +try aws lambda-microvms create-microvm-image --name "$IMAGE_NAME" --description "Task 17 minimal hook image, small, run $RUN" \ |
| --code-artifact "uri=$ARTIFACT" --base-image-arn "$BASE_ARN" --base-image-version "$BASE_VER" \ |
| --build-role-arn "$BUILD_ROLE_ARN" --cpu-configurations '[{"architecture":"X86_64"}]' \ |
| --resources '[{"minimumMemoryInMiB":2048}]' --additional-os-capabilities '["ALL"]' \ |
| --hooks "file://$T17/image/hooks.json" --logging "{\"cloudWatch\":{\"logGroup\":\"$LOG_GROUP\"}}" \ |
| - --tags purpose=$TAGV --client-token "$NAME-create-1" --output json > "$T17/out/3.7-image.json" || exit 1 |
| -rec IMAGE_ARN "$(jq -r .imageArn "$T17/out/3.7-image.json")" && rec VER_SMALL "$(jq -r .imageVersion "$T17/out/3.7-image.json")" || exit 1 |
| -jq '{imageArn,imageVersion,state}' "$T17/out/3.7-image.json" |
| + --tags purpose=$TAGV,run=$RUN --client-token "$IMAGE_NAME-create-1" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/3.7-image.json" |
| +arn_ok "$(jq -r .imageArn "$T17/out/3.7-image.json")" |
| +rec IMAGE_ARN "$(jq -r .imageArn "$T17/out/3.7-image.json")"; rec VER_SMALL "$(jq -r .imageVersion "$T17/out/3.7-image.json")" |
| +[ "$IMAGE_ARN" = "arn:aws:lambda:eu-west-1:$ACCOUNT:microvm-image:$IMAGE_NAME" ] || die "image ARN [$IMAGE_ARN]" |
| ``` |
| -- Expected: `imageArn` `arn:aws:lambda:eu-west-1:640012953448:microvm-image:equipo-hosted-dev-t17`, |
| - an `imageVersion`, state `CREATING`. No `egressNetworkConnectors` is passed, so the build uses the |
| - default internet egress to pull the container base image; running VMs get only the connector. |
| -- Abort if: an error (a `ValidationException` about the architecture or base version included). |
| +- No `egressNetworkConnectors` is passed, so the build pulls its container base image over the |
| + default build path; running VMs get only the connector. |
| +- Abort if: an error; `X86_64` refused by the CLI or API (U3, U4, U5). |
| -### 3.8 Wait for the Small version (spike: about 2 min; bound 20 min) |
| +### 3.8 Wait for the Small version and check it (bound 20 min) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -for i in $(seq 1 80); do |
| - r=$(aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --query '[state,status]' --output text) |
| - echo "$(date -u +%T) $r"; case "$r" in SUCCESSFUL*ACTIVE) break;; FAILED*) break;; esac; sleep 15 |
| -done |
| -aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" \ |
| - --query '{state:state,status:status,reason:stateReason,arch:cpuConfigurations[].architecture,mem:resources[].minimumMemoryInMiB,caps:additionalOsCapabilities,artifact:codeArtifact.uri,hooks:hooks}' --output json |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need IMAGE_ARN VER_SMALL ARTIFACT LOG_GROUP |
| +_ver() { try aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$1" --query '[state,status]' --output text |
| + [ "$RC" = 0 ] || return 3; echo "$(date -u +%T) $1 $OUT"; case "$OUT" in "SUCCESSFUL ACTIVE") return 0;; PENDING*|IN_PROGRESS*) return 1;; esac; return 2; } |
| +if ! (poll 1200 15 "image version $VER_SMALL" _ver "$VER_SMALL"); then |
| + aws logs filter-log-events --log-group-name "$LOG_GROUP" --limit 50 --query 'events[].message' --output text || true |
| + die "the Small version did not build" |
| +fi |
| +aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --output json > "$T17/out/3.8-small.json" |
| +jq -e --arg a "$ARTIFACT" '[.cpuConfigurations[].architecture] == ["X86_64"] and [.resources[].minimumMemoryInMiB] == [2048] and .additionalOsCapabilities == ["ALL"] and .codeArtifact.uri == $a and .hooks.port == 9000' "$T17/out/3.8-small.json" >/dev/null || die "the Small version differs: $(jq -c '{cpuConfigurations,resources,additionalOsCapabilities,codeArtifact,hooks}' "$T17/out/3.8-small.json")" |
| +jq -c '{imageVersion,state,status,tags}' "$T17/out/3.8-small.json" |
| +jw "TIMING image-small-built" |
| ``` |
| -- Expected: `SUCCESSFUL ACTIVE`; `arch` `["X86_64"]`, `mem` `[2048]`, `caps` `["ALL"]`, `artifact` |
| - `$ARTIFACT`, the hooks as sent. These are exactly the fields the adapter's image check reads |
| - (`runner.go`, `checkImageVersion`). |
| -- Abort if: `FAILED` (then print the build log tail with |
| - `aws logs filter-log-events --log-group-name "$LOG_GROUP" --limit 50 --query 'events[].message' --output text` |
| - and stop), not done in 20 min, or any field differs. |
| +- Expected: `SUCCESSFUL ACTIVE`, then the exact fields the adapter's image check reads |
| + (`checkImageVersion`). The version's `tags` are recorded as read (U19). |
| -### 3.9 Large version (4096 MiB) by one update |
| +### 3.9 Large version by one update, then both versions checked |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-microvms update-microvm-image --image-identifier "$IMAGE_ARN" --description "Task 17 minimal hook image, large" \ |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need IMAGE_ARN IMAGE_NAME ARTIFACT BASE_ARN BASE_VER BUILD_ROLE_ARN LOG_GROUP VER_SMALL RUN |
| +intent microvm-image-version "$IMAGE_NAME" "token=$IMAGE_NAME-update-1" |
| +try aws lambda-microvms update-microvm-image --image-identifier "$IMAGE_ARN" --description "Task 17 minimal hook image, large, run $RUN" \ |
| --code-artifact "uri=$ARTIFACT" --base-image-arn "$BASE_ARN" --base-image-version "$BASE_VER" \ |
| --build-role-arn "$BUILD_ROLE_ARN" --cpu-configurations '[{"architecture":"X86_64"}]' \ |
| --resources '[{"minimumMemoryInMiB":4096}]' --additional-os-capabilities '["ALL"]' \ |
| --hooks "file://$T17/image/hooks.json" --logging "{\"cloudWatch\":{\"logGroup\":\"$LOG_GROUP\"}}" \ |
| - --client-token "$NAME-update-1" --output json > "$T17/out/3.9-image.json" || exit 1 |
| -rec VER_LARGE "$(jq -r .imageVersion "$T17/out/3.9-image.json")" || exit 1 |
| -[ "$VER_LARGE" != "$VER_SMALL" ] && echo "large version $VER_LARGE" |
| -``` |
| - |
| -Then run the 3.8 wait block again with `VER_SMALL` replaced by `VER_LARGE` (expected `mem` `[4096]`), |
| -and confirm both versions are usable: |
| - |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| + --client-token "$IMAGE_NAME-update-1" --output json; must |
| +printf '%s\n' "$OUT" > "$T17/out/3.9-image.json" |
| +rec VER_LARGE "$(jq -r .imageVersion "$T17/out/3.9-image.json")" |
| +[ "$VER_LARGE" != "$VER_SMALL" ] || die "the update returned the Small version" |
| +_ver() { try aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$1" --query '[state,status]' --output text |
| + [ "$RC" = 0 ] || return 3; echo "$(date -u +%T) $1 $OUT"; case "$OUT" in "SUCCESSFUL ACTIVE") return 0;; PENDING*|IN_PROGRESS*) return 1;; esac; return 2; } |
| +poll 1200 15 "image version $VER_LARGE" _ver "$VER_LARGE" |
| +aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_LARGE" --output json > "$T17/out/3.9-large.json" |
| +jq -e '[.cpuConfigurations[].architecture] == ["X86_64"] and [.resources[].minimumMemoryInMiB] == [4096] and .additionalOsCapabilities == ["ALL"]' "$T17/out/3.9-large.json" >/dev/null || die "the Large version differs" |
| +[ "$(aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --query '[state,status]' --output text)" = "SUCCESSFUL ACTIVE" ] || die "the Small version is no longer SUCCESSFUL ACTIVE (U14)" |
| +st=$(aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query state --output text); case "$st" in CREATED|UPDATED) ;; *) die "image state $st";; esac |
| +[ "$(aws lambda-microvms list-tags --resource "$IMAGE_ARN" --query 'Tags.run' --output text)" = "$RUN" ] || die "image tags missing" |
| aws lambda-microvms list-microvm-image-versions --image-identifier "$IMAGE_ARN" --query 'items[].[imageVersion,state,status,resources[0].minimumMemoryInMiB]' --output text |
| -aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query '[state,latestActiveImageVersion]' --output text |
| -aws lambda-microvms list-tags --resource "$IMAGE_ARN" --output json |
| ``` |
| -- Expected: two versions, both `SUCCESSFUL ACTIVE`, 2048 and 4096; image state `CREATED` or |
| - `UPDATED`; tag `purpose=equipo-hosted-dev`. No Large VM is launched in this run; the Large version |
| - exists so the config maps both sizes and the adapter's image check can read it. |
| -- Abort if: the Small version became `INACTIVE` after the update, or any build failed. |
| -- Record: image ARN, both versions, base image ARN and version, digest, build times. |
| +- Expected: two versions, both `SUCCESSFUL ACTIVE`, 2048 and 4096. No Large VM is launched; the |
| + Large version exists so the config maps both sizes and the image check reads it. |
| +- Abort if: any check fails. |
| --- |
| -## 4. SNS topic for alerts |
| +## 4. SNS topic |
| -The controller requires `sns_topic_arn` and refuses to start if a startup alert cannot be delivered |
| -(pre-flight concern 1). |
| +The controller requires `sns_topic_arn` and stops at the first startup alert it cannot deliver, |
| +including on the crash restart (pre-flight concern 1); the topic exists from here to 10.7. |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -TOPIC_ARN=$(aws sns create-topic --name "$NAME-alerts" --tags Key=purpose,Value=$TAGV --query TopicArn --output text) && rec TOPIC_ARN "$TOPIC_ARN" || exit 1 |
| -aws sns list-tags-for-resource --resource-arn "$TOPIC_ARN" --query 'Tags[].[Key,Value]' --output text |
| -aws sns list-subscriptions-by-topic --topic-arn "$TOPIC_ARN" --query 'length(Subscriptions)' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need TOPIC_NAME RUN |
| +intent sns-topic "$TOPIC_NAME" |
| +try aws sns create-topic --name "$TOPIC_NAME" --tags Key=purpose,Value=$TAGV Key=run,Value=$RUN --query TopicArn --output text; must |
| +[ "$OUT" = "arn:aws:sns:eu-west-1:$ACCOUNT:$TOPIC_NAME" ] || die "topic ARN [$OUT]" |
| +rec TOPIC_ARN "$OUT" |
| +[ "$(aws sns list-tags-for-resource --resource-arn "$TOPIC_ARN" --query "Tags[?Key=='run'].Value" --output text)" = "$RUN" ] || die "topic tags missing" |
| +[ "$(aws sns list-subscriptions-by-topic --topic-arn "$TOPIC_ARN" --query 'length(Subscriptions)' --output text)" = 0 ] || die "the new topic has subscriptions" |
| ``` |
| -- Expected: `arn:aws:sns:eu-west-1:640012953448:equipo-hosted-dev-t17-alerts`; the tag; `0` |
| - subscriptions. Alerts are counted in the controller's metrics |
| - (`equipo_hosted_alerts_total{kind,result}`) and that is how the run reads them. |
| -- No subscription is made. If Paul wants email, he writes the address here before approving: |
| - `EMAIL=________`; the agent then runs |
| - `aws sns subscribe --topic-arn "$TOPIC_ARN" --protocol email --notification-endpoint "$EMAIL" --query SubscriptionArn --output text` |
| - and Paul confirms the subscription from his inbox. Blank means skip. |
| +- 0.4 proved the name did not exist, so `create-topic`'s idempotent return cannot be someone else's |
| + topic. No subscription is made: alerts are read from the controller's metrics and database. |
| --- |
| -## 5. Controller config, keys and TLS |
| +## 5. Keys, config, builds, and the audit before any launch |
| -### 5.1 Keys and the self-signed certificate (pre-flight helper, offline) |
| +### 5.1 Keys and the self-signed certificate (pre-flight helper, no AWS call) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -cd "$REPO" && EQUIPO_HOSTED_KEYGEN_DIR="$T17/keys" go test -tags hostedlive ./cmd/equipo-hosted-controller -run 'TestLiveKeygen$' -count=1 -v || exit 1 |
| -ls -l "$T17/keys" |
| -openssl x509 -in "$T17/keys/tls.crt" -noout -subject -ext subjectAltName -enddate |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +cd "$REPO" && EQUIPO_HOSTED_KEYGEN_DIR="$T17/keys" CGO_ENABLED=0 go test -tags hostedlive ./cmd/equipo-hosted-controller -run 'TestLiveKeygen$' -count=1 -v |
| +for f in controller.key instance.key operator.key tls.key; do [ "$(stat -c %a "$T17/keys/$f")" = 600 ] || die "$f is not mode 600"; done |
| +for f in controller.pub verify_keys.json tls.crt; do [ -s "$T17/keys/$f" ] || die "$f missing"; done |
| +openssl x509 -in "$T17/keys/tls.crt" -noout -ext subjectAltName | grep -q 'IP Address:127.0.0.1' || die "certificate SAN is not 127.0.0.1" |
| +jq -r '.[] | [.id, .role] | @tsv' "$T17/keys/verify_keys.json" |
| ``` |
| -- Expected: `controller.key`, `instance.key`, `operator.key`, `tls.key` with mode `-rw-------`; |
| - `controller.pub`, `verify_keys.json`, `tls.crt`; SAN `IP Address:127.0.0.1`; valid 7 days. |
| -- Abort if: the test fails or a key file is readable by group or others. |
| +- Expected: `task17-instance instance` and `task17-operator operator`. |
| -### 5.2 Ports are free on 127.0.0.1 |
| +### 5.2 Ports free |
| ```sh |
| -ss -ltn '( sport = :18443 or sport = :18444 )' |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +[ -z "$(listeners)" ] || die "in use: $(listeners)"; echo "ports 18443 and 18444 free" |
| ``` |
| -- Expected: only the header line. |
| -- Abort if: either port is in use. (Picking other ports is a change; ask.) |
| - |
| -### 5.3 Controller config and live contract config (filled from the ledger) |
| +### 5.3 Controller config and live contract config |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -jq -n --slurpfile vk "$T17/keys/verify_keys.json" \ |
| - --arg api "$API" --arg met "$METRICS" --arg d "$T17" --arg digest "$DIGEST" --arg arn "$IMAGE_ARN" \ |
| - --arg small "$VER_SMALL" --arg large "$VER_LARGE" --arg vpc "$VPC" --arg subnet "$SUBNET" --arg sg "$SG" \ |
| - --arg conn "$CONN_QARN" --arg topic "$TOPIC_ARN" '{ |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +need DIGEST IMAGE_ARN VER_SMALL VER_LARGE VPC SUBNET SG CONN_QARN TOPIC_ARN |
| +jq -n --slurpfile vk "$T17/keys/verify_keys.json" --arg api "$API" --arg met "$METRICS" --arg d "$T17" \ |
| + --arg digest "$DIGEST" --arg arn "$IMAGE_ARN" --arg small "$VER_SMALL" --arg large "$VER_LARGE" \ |
| + --arg vpc "$VPC" --arg subnet "$SUBNET" --arg sg "$SG" --arg conn "$CONN_QARN" --arg topic "$TOPIC_ARN" '{ |
| listen: $api, metrics_listen: $met, |
| tls_cert_file: ($d + "/keys/tls.crt"), tls_key_file: ($d + "/keys/tls.key"), |
| database: ($d + "/controller.db"), signing_key_file: ($d + "/keys/controller.key"), |
| verify_keys: $vk[0], |
| images: [{digest: $digest, arn: $arn, versions: {small: $small, large: $large}}], |
| region: "eu-west-1", vpc_id: $vpc, vm_subnet_id: $subnet, vm_security_group_id: $sg, |
| - connector_arn: $conn, egress: [], sns_topic_arn: $topic}' > "$T17/controller.json" || exit 1 |
| + connector_arn: $conn, egress: [], sns_topic_arn: $topic}' > "$T17/controller.json" |
| jq -n --arg digest "$DIGEST" --arg arn "$IMAGE_ARN" --arg small "$VER_SMALL" --arg large "$VER_LARGE" \ |
| --arg vpc "$VPC" --arg subnet "$SUBNET" --arg sg "$SG" --arg conn "$CONN_QARN" '{ |
| region: "eu-west-1", connector_id: $conn, vpc_id: $vpc, vm_subnet_id: $subnet, vm_security_group_id: $sg, |
| - image: $digest, image_arn: $arn, versions: {small: $small, large: $large}, egress: []}' > "$T17/live.json" || exit 1 |
| + image: $digest, image_arn: $arn, versions: {small: $small, large: $large}, egress: []}' > "$T17/live.json" |
| +jq -e '[.. | strings] | all(. != "" and . != "null")' "$T17/controller.json" "$T17/live.json" >/dev/null || die "an empty value in a config" |
| +jq -e '.egress == []' "$T17/controller.json" "$T17/live.json" >/dev/null || die "egress is not empty (R30)" |
| cat "$T17/controller.json" "$T17/live.json" |
| ``` |
| -With the ledger filled in, `controller.json` reads like this (angle brackets are ledger values): |
| +Filled in, `controller.json` reads (angle brackets are ledger values): |
| ```json |
| { |
| @@ -670,700 +930,788 @@ With the ledger filled in, `controller.json` reads like this (angle brackets are |
| } |
| ``` |
| -- Expected: both files print with no empty value; `egress` is `[]` in both (ruling R30). |
| -- Abort if: any value is empty or `null`. |
| - |
| -### 5.4 Build the two controller binaries (offline) |
| +### 5.4 Build the two controller binaries (no AWS call) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -cd "$REPO" && go build -o "$T17/bin/controller" ./cmd/equipo-hosted-controller && \ |
| - go build -tags hostedlive -o "$T17/bin/controller-crash" ./cmd/equipo-hosted-controller && ls -l "$T17/bin" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +cd "$REPO" |
| +[ -z "$(git diff "$PIN_SHA" HEAD -- . ':!docs')" ] && [ -z "$(git status --porcelain --untracked-files=all -- . ':!docs')" ] || die "code changed since 0.1" |
| +CGO_ENABLED=0 go build -o "$T17/bin/controller" ./cmd/equipo-hosted-controller |
| +CGO_ENABLED=0 go build -tags hostedlive -o "$T17/bin/controller-crash" ./cmd/equipo-hosted-controller |
| +ls -l "$T17/bin" |
| ``` |
| -- Expected: two binaries. `controller` is the normal build (no crash point); `controller-crash` is |
| - only for 7.4. |
| -- Abort if: a build fails. |
| - |
| ---- |
| - |
| -## 6. Live contract |
| +- `controller` is the normal build (no crash point); `controller-crash` is used only in 7.4. |
| -Runs after 9.A to 9.F, so the client-token behaviour is already known. |
| - |
| -### 6.1 Run it |
| +### 5.5 Driver environment file (no AWS call) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -[ -z "$(live_vms)" ] || { echo "ABORT: live VMs before the contract"; live_vms; exit 1; } |
| -date -u +%FT%TZ > "$T17/out/6-start" |
| -cd "$REPO" && EQUIPO_HOSTED_LIVE_CONFIG="$T17/live.json" \ |
| - go test -tags hostedlive ./internal/isolatedjob/awsjob -run TestLiveContract -count=1 -v -timeout 60m 2>&1 | tee "$T17/out/6-contract.log" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +need DIGEST |
| +cat > "$T17/driver.env" <<EOF |
| +export EQUIPO_HOSTED_LIVE_URL=https://$API |
| +export EQUIPO_HOSTED_LIVE_CA_FILE=$T17/keys/tls.crt |
| +export EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance |
| +export EQUIPO_HOSTED_LIVE_KEY_FILE=$T17/keys/instance.key |
| +export EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE=$T17/keys/controller.pub |
| +export EQUIPO_HOSTED_LIVE_IMAGE=$DIGEST |
| +EOF |
| +cat "$T17/driver.env" |
| ``` |
| -- Expected: `--- PASS: TestLiveContract` with every subtest passing. The contract launches about 7 |
| - Small VMs, each with a 15-minute maximum duration and stopped by its own cleanup. |
| -- Pre-approved exceptions (record and continue to 6.2): `StopUnknownRef` fails because AWS answers a |
| - malformed ID with a `ValidationException` rather than not found; or `ChangedSpecConflicts` fails |
| - only because the error is not mapped to `ErrConflict`, and 9.A showed that a changed request with a |
| - used token creates no second VM. Either is a finding for an adapter fix after the run. |
| -- Abort if: any other subtest fails, or `ChangedSpecConflicts` shows a second VM. |
| +### 5.6 Audit-only controller run: the SDK checks the network before any VM exists |
| -### 6.2 Nothing left running |
| +Launches stay off (no `EQUIPO_HOSTED_ENABLED`). The reaper's first passes run the network audit |
| +through the SDK: VPC DNS both off, the subnet's table local-only, the group with no rules, and the |
| +connector read by its qualified ARN with `VersionArn` equal to it, `ACTIVE`, `MicroVm` only, this |
| +subnet and group only, and no service-managed Elastic IPs (`network.go`). This also binds the |
| +database to `aws:640012953448:eu-west-1` (R28) and proves the SNS topic takes startup alerts. |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -for i in $(seq 1 30); do l=$(our_live); [ -z "$l" ] && break; echo "$(date -u +%T) still live:"; echo "$l"; sleep 10; done |
| -echo "ours live: [$(our_live)]"; echo "any live: [$(live_vms)]" |
| -aws lambda-microvms list-microvms --query "items[?imageArn=='$IMAGE_ARN'].[microvmId,state,startedAt]" --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +start_ctl "$T17/bin/controller" audit-only |
| +ctl_ready |
| +grep -F 'launches enabled: false' "$T17/controller.log" || die "the controller did not report launches off" |
| +! grep -F 'hosted controller: network audit failed' "$T17/controller.log" || die "the log shows a failed network audit" |
| +stop_ctl |
| +dbread "select action, reason from audit where action in ('provider_bound','network_audit_passed','network_audit_failed') order by id" |
| +n=$(dbread "select count(*) from audit where action='network_audit_failed'"); [ "$n" = 0 ] || die "$n network audit failures" |
| +n=$(dbread "select count(*) from audit where action='network_audit_passed'"); [ "$n" -ge 1 ] || die "no network audit passed" |
| +dbread "select namespace from provider_binding" | grep -qx "aws:$ACCOUNT:eu-west-1" || die "database not bound to aws:$ACCOUNT:eu-west-1" |
| +jw "AUDIT passed before any launch" |
| ``` |
| -- Expected: both live lists empty within 5 minutes (TERMINATING may linger briefly); the full list |
| - shows this run's VMs as `TERMINATED` (record how many and when, for 9.F). |
| -- Abort if: a VM is still live after 5 minutes. Terminate it with |
| - `aws lambda-microvms terminate-microvm --microvm-identifier <id>`, record it as a leak, then stop. |
| -- Record: the PASS/FAIL lines, the visibility and List lag the log shows, VM count. |
| +- Expected: ready within 4 minutes with `network_audit_passing 1`, and no |
| + `hosted controller: network audit failed; launches refused` line in the log; `provider_bound` and at least one |
| + `network_audit_passed` row, no failure rows; clean stop, exit status 0. |
| +- Abort if: any check fails; the audit's failure row names the property (and the qualified ARN, if |
| + `VersionArn` differs: U3). |
| --- |
| -## 7. Controller on docs-t1 |
| +## 6. Live contract |
| -### 7.1 Start the controller (normal build), launches on |
| +Runs after 9.A to 9.F (client-token behaviour known, facts VMs settled). |
| -Start it with the Bash tool's `run_in_background`, so it outlives the call: |
| +### 6.1 Run it, then settle every VM it made |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -[ -z "$(live_vms)" ] || { echo "ABORT: live VMs before the controller starts"; exit 1; } |
| -cd "$REPO" && echo $$ > "$T17/controller.pid" && \ |
| - exec env EQUIPO_HOSTED_ENABLED=1 "$T17/bin/controller" -config "$T17/controller.json" >> "$T17/controller.log" 2>&1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need A3_RESULT IMAGE_ARN |
| +! ctl_alive || die "the controller is running" |
| +scan >/dev/null; [ -z "$(live_ids)" ] || die "live VMs of this image before the contract: $(live_ids)" |
| +jw "PHASE contract start" |
| +export EQUIPO_HOSTED_LIVE_CONFIG="$T17/live.json" |
| +if gotest "$T17/out/6-contract.log" -tags hostedlive ./internal/isolatedjob/awsjob -run TestLiveContract -count=1 -v -timeout 60m; then rc=0; else rc=$?; fi |
| +jw "PHASE contract end rc=$rc" |
| +settle_all |
| +grep -E 'visibility: Get showed new VM |list lag: List showed running VM ' "$T17/out/6-contract.log" || die "the contract logged no visibility or list-lag lines" |
| +fails=$(grep -oE -- '--- FAIL: TestLiveContract/[A-Za-z]+' "$T17/out/6-contract.log" | sed 's|.*/||' | sort -u | tr '\n' ' ') |
| +echo "rc=$rc failed subtests: [$fails]" |
| +if [ "$rc" = 0 ]; then echo "contract PASS"; exit 0; fi |
| +for f in $fails; do |
| + case "$f" in |
| + StopUnknownRef) grep -A8 -- "--- FAIL: TestLiveContract/StopUnknownRef" "$T17/out/6-contract.log" | grep -q ValidationException || die "StopUnknownRef failed without a ValidationException";; |
| + ChangedSpecConflicts) case "$A3_RESULT" in refused:*|same-vm) ;; *) die "ChangedSpecConflicts failed and 9.A found $A3_RESULT";; esac;; |
| + *) die "contract subtest $f failed";; |
| + esac |
| +done |
| +jw "FINDING contract failures within the approved exceptions: $fails" |
| +echo "contract: approved exceptions only: $fails" |
| ``` |
| -Then, in a new call: |
| +- Expected: `contract PASS`, and `settled: N VMs recorded` (about 7 contract VMs, each with a |
| + 15-minute maximum duration). The `visibility: Get showed new VM ...` and `list lag: List showed |
| + running VM ...` lines are the measured delays (the pre-flight's 60 s and 30 s are guesses). |
| +- Approved exceptions, recorded as findings for an adapter fix after the run (not a pass): |
| + `StopUnknownRef` failing with a `ValidationException` (U11); `ChangedSpecConflicts` failing only |
| + on error mapping when 9.A showed a changed request was refused or answered with the same VM. |
| +- Abort if: any other failure, or `settle_all` cannot settle. |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -ss -ltn '( sport = :18443 or sport = :18444 )' |
| -for i in $(seq 1 24); do metrics | grep -E 'network_audit_passing|store_readable|reap_last_error' && metrics | grep -q '^equipo_hosted_network_audit_passing 1' && break; sleep 10; done |
| -grep -E 'API on|launches enabled' "$T17/controller.log" |
| -``` |
| +--- |
| -- Expected: both listeners on `127.0.0.1` only; log line `API on 127.0.0.1:18443, metrics on |
| - 127.0.0.1:18444, launches enabled: true`; within 4 minutes |
| - `equipo_hosted_network_audit_passing 1`, `equipo_hosted_store_readable 1`, |
| - `equipo_hosted_reap_last_error 0`. The audit passing is the live proof that VPC DNS is off, the |
| - route table has only the local route, the group has no rules, and the qualified connector ARN |
| - matches `VersionArn` (U3). |
| -- Abort if: the controller exits (read the log), a listener is on another address, or the audit is |
| - not passing after 4 minutes (the log names the failed property). |
| +## 7. Controller on docs-t1 |
| -### 7.2 Driver sequence: launch Small, drain, quiescent, suspend, resume, stop with proof |
| +### 7.1 Start with launches on, check readiness |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -export EQUIPO_HOSTED_LIVE_URL=https://$API EQUIPO_HOSTED_LIVE_CA_FILE="$T17/keys/tls.crt" \ |
| - EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance EQUIPO_HOSTED_LIVE_KEY_FILE="$T17/keys/instance.key" \ |
| - EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE="$T17/keys/controller.pub" EQUIPO_HOSTED_LIVE_IMAGE="$DIGEST" |
| -cd "$REPO" && go test -tags hostedlive ./internal/hostedclient -run 'TestLiveControllerSequence$' -count=1 -v -timeout 30m 2>&1 | tee "$T17/out/7.2-sequence.log" |
| -grep -E 'attempt |timings:' "$T17/out/7.2-sequence.log" |
| -. "$TMPDIR/equipo-t17/env.sh" && echo "ours live: [$(our_live)]" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +scan >/dev/null; [ -z "$(live_ids)" ] || die "live VMs of this image: $(live_ids)" |
| +start_ctl "$T17/bin/controller" sequence EQUIPO_HOSTED_ENABLED=1 |
| +ctl_ready |
| +grep -F 'launches enabled: true' "$T17/controller.log" || die "launches are not enabled" |
| ``` |
| -- Expected: `--- PASS`; the `timings:` line (launch call a few seconds; `to_running` up to about a |
| - minute, because the controller reads states once per 60 s pass; the resume epoch one above the |
| - launch epoch; `stop_to_proof` within about 2 to 3 minutes, since R17 wants two not-found reads 60 s |
| - apart or a terminal state). `our_live` empty. |
| -- Abort if: FAIL. The test's cleanup stops its VM; confirm with `our_live`, then stop. |
| -- Record: attempt ID, VM ref, the whole `timings:` line, the epoch. |
| - |
| -### 7.3 Stop the controller |
| +### 7.2 Driver sequence: launch Small, drain, quiescent, suspend, resume, stop with proof |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -kill -TERM "$(cat "$T17/controller.pid")" |
| -for i in $(seq 1 40); do ss -ltn '( sport = :18443 )' | grep -q 18443 || break; sleep 1; done |
| -tail -3 "$T17/controller.log"; ss -ltn '( sport = :18443 or sport = :18444 )' |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +. "$T17/driver.env" |
| +ctl_alive || die "the controller is not running" |
| +jw "PHASE sequence start" |
| +if gotest "$T17/out/7.2-sequence.log" -tags hostedlive ./internal/hostedclient -run 'TestLiveControllerSequence$' -count=1 -v -timeout 30m; then rc=0; else rc=$?; fi |
| +jw "PHASE sequence end rc=$rc" |
| +grep -E 'attempt |launch:|running:|pause:|suspended:|resume:|stop:|timings:' "$T17/out/7.2-sequence.log" || true |
| +harvest "$T17/controller.log" controller |
| +stop_ctl |
| +settle_all |
| +[ "$rc" = 0 ] || die "TestLiveControllerSequence failed" |
| +att=$(grep -oE 'attempt task17-[0-9a-f]+' "$T17/out/7.2-sequence.log" | head -n 1 | cut -d' ' -f2); rec SEQ_ATTEMPT "$att" |
| +dbread "select attempt_id, state, vm_ref, epoch, pause_generation, stop_proof_json from jobs where attempt_id='$SEQ_ATTEMPT'" |
| +dbread "select action, reason from audit where attempt_id='$SEQ_ATTEMPT' order by id" |
| ``` |
| -- Expected: the listeners close within 40 s (30 s drain). If `kill` cannot see the process (the |
| - sandbox can hide processes from later calls), stop the background task with the agent's task-stop |
| - tool instead and check the ports the same way. |
| -- Abort if: the ports stay open. |
| +- Expected: PASS and the `timings:` line (launch call a few seconds; `to_running` up to about a |
| + minute, since states are read once per 60 s pass; resume epoch one above the launch epoch; |
| + `stop_to_proof` about 2 to 3 minutes, R17). The job row is `stopped` with stop proof; its audit |
| + rows show launch, drain, quiescent, suspend, resume and stop in order. |
| +- Abort if: FAIL (the controller is already stopped and VMs settled by this block). |
| -### 7.4 Crash between the provider call and transaction 2 |
| - |
| -Start the crash build in the background (`run_in_background`), same database: |
| +### 7.3 Crash between the provider call and transaction 2: the launch step |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -rec CRASH_ATTEMPT "task17-crash-$(openssl rand -hex 4)" || exit 1 |
| -date -u +%FT%T > "$T17/out/7.4-start" |
| -cd "$REPO" && echo $$ > "$T17/controller.pid" && \ |
| - exec env EQUIPO_HOSTED_ENABLED=1 EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1 "$T17/bin/controller-crash" -config "$T17/controller.json" >> "$T17/controller.log" 2>&1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +. "$T17/driver.env" |
| +rec CRASH_ATTEMPT "task17-crash-$(openssl rand -hex 4)" |
| +rec CRASH_START "$(date -u +%FT%T)" |
| +start_ctl "$T17/bin/controller-crash" crash EQUIPO_HOSTED_ENABLED=1 EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1 |
| +ctl_ready |
| +grep -F 'EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1' "$T17/controller.log" || die "the crash switch is not on" |
| +export EQUIPO_HOSTED_LIVE_ATTEMPT="$CRASH_ATTEMPT" EQUIPO_HOSTED_LIVE_CRASH_STEP=launch |
| +if gotest "$T17/out/7.3-launch.log" -tags hostedlive ./internal/hostedclient -run 'TestLiveCrashRecovery$' -count=1 -v -timeout 10m; then rc=0; else rc=$?; fi |
| +_exited() { [ -s "$T17/controller.exit" ] && return 0; return 1; } |
| +poll 60 2 "crash-build controller exit" _exited |
| +[ "$(cat "$T17/controller.exit")" = 137 ] || die "exit status $(cat "$T17/controller.exit"), want 137" |
| +[ -z "$(listeners)" ] || die "listeners still open" |
| +harvest "$T17/controller.log" controller |
| +vm=$(grep -oE "provider launched mvm-[0-9A-Za-z-]+ for $CRASH_ATTEMPT" "$T17/controller.log" | tail -n 1 | cut -d' ' -f3) |
| +rec CRASH_VM "$vm" |
| +vm_get "$CRASH_VM"; echo "crash VM $CRASH_VM: $VST" |
| +case "$VST" in PENDING|RUNNING) ;; *) die "crash VM state $VST";; esac |
| +[ "$rc" = 0 ] || die "the launch step failed (see 7.3-launch.log)" |
| +jw "CRASH controller exited 137 after launching $CRASH_VM" |
| ``` |
| -Wait for the audit as in 7.1 (`equipo_hosted_network_audit_passing 1`), then: |
| +- Expected: the launch fails in transport (the test passes); exit status 137; the log line |
| + `crash point: the provider launched <vm> for <attempt>; exiting before the Ref is saved`; the VM |
| + `PENDING` or `RUNNING`. If the launch is refused because no audit has passed recently, `ctl_ready` |
| + was not satisfied; that cannot happen after it returned, so it is an abort. |
| +- Abort if: the controller answered the launch, exit status is not 137, or no VM was launched. |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -grep -c 'CRASH_AFTER_LAUNCH=1' "$T17/controller.log" |
| -export EQUIPO_HOSTED_LIVE_URL=https://$API EQUIPO_HOSTED_LIVE_CA_FILE="$T17/keys/tls.crt" \ |
| - EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance EQUIPO_HOSTED_LIVE_KEY_FILE="$T17/keys/instance.key" \ |
| - EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE="$T17/keys/controller.pub" EQUIPO_HOSTED_LIVE_IMAGE="$DIGEST" \ |
| - EQUIPO_HOSTED_LIVE_ATTEMPT="$CRASH_ATTEMPT" EQUIPO_HOSTED_LIVE_CRASH_STEP=launch |
| -cd "$REPO" && go test -tags hostedlive ./internal/hostedclient -run 'TestLiveCrashRecovery$' -count=1 -v -timeout 10m 2>&1 | tee "$T17/out/7.4-launch.log" |
| -grep 'crash point' "$T17/controller.log" | tail -1 |
| -. "$TMPDIR/equipo-t17/env.sh" && rec CRASH_VM "$(grep -o 'provider launched [^ ]*' "$T17/controller.log" | tail -1 | cut -d' ' -f3)" |
| -ss -ltn '( sport = :18443 )'; vm_state "$CRASH_VM" |
| -``` |
| +### 7.4 Restart without the crash switch; Replay claims the one VM |
| -- Expected: the log shows the crash switch is on; the test PASSes (the launch fails in transport); |
| - the controller log ends with `crash point: the provider launched <vm> for <attempt>; exiting |
| - before the Ref is saved`; port 18443 is closed; the VM is `PENDING` or `RUNNING`. If the launch is |
| - refused with "no network audit has passed recently", run the test again after 10 s (pre-flight |
| - concern 2); a refused launch creates nothing. |
| -- Abort if: the controller answered the launch (the test says so), or no VM was launched. |
| - |
| -### 7.5 Restart without the crash switch; Replay claims the one VM |
| - |
| -Start the normal build in the background (`run_in_background`). The crash variable must not be set |
| -(pre-flight concern 3): |
| - |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -cd "$REPO" && echo $$ > "$T17/controller.pid" && \ |
| - exec env -u EQUIPO_HOSTED_CRASH_AFTER_LAUNCH EQUIPO_HOSTED_ENABLED=1 "$T17/bin/controller" -config "$T17/controller.json" >> "$T17/controller.log" 2>&1 |
| -``` |
| - |
| -Then: |
| +`start_ctl` always clears `EQUIPO_HOSTED_CRASH_AFTER_LAUNCH` and sets only what it is given |
| +(pre-flight concern 3). The readiness check comes before the recovery driver; Replay runs on the |
| +second reaper pass, about 60 s after start (pre-flight concern 2). |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -export EQUIPO_HOSTED_LIVE_URL=https://$API EQUIPO_HOSTED_LIVE_CA_FILE="$T17/keys/tls.crt" \ |
| - EQUIPO_HOSTED_LIVE_KEY_ID=task17-instance EQUIPO_HOSTED_LIVE_KEY_FILE="$T17/keys/instance.key" \ |
| - EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE="$T17/keys/controller.pub" EQUIPO_HOSTED_LIVE_IMAGE="$DIGEST" \ |
| - EQUIPO_HOSTED_LIVE_ATTEMPT="$CRASH_ATTEMPT" EQUIPO_HOSTED_LIVE_CRASH_STEP=recover \ |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +. "$T17/driver.env" |
| +need CRASH_ATTEMPT CRASH_VM CRASH_START |
| +start_ctl "$T17/bin/controller" recover EQUIPO_HOSTED_ENABLED=1 |
| +ctl_ready |
| +tr '\0' '\n' < "/proc/$(ctl_pid)/environ" | grep -q '^EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=' && die "the crash switch is set" |
| +export EQUIPO_HOSTED_LIVE_ATTEMPT="$CRASH_ATTEMPT" EQUIPO_HOSTED_LIVE_CRASH_STEP=recover \ |
| EQUIPO_HOSTED_LIVE_OPERATOR_KEY_ID=task17-operator EQUIPO_HOSTED_LIVE_OPERATOR_KEY_FILE="$T17/keys/operator.key" |
| -cd "$REPO" && go test -tags hostedlive ./internal/hostedclient -run 'TestLiveCrashRecovery$' -count=1 -v -timeout 15m 2>&1 | tee "$T17/out/7.5-recover.log" |
| -grep -E 'recover:|listed vm|stop:' "$T17/out/7.5-recover.log" |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-microvms list-microvms --query "items[?imageArn=='$IMAGE_ARN']" --output json \ |
| - | jq --arg t "$(cat "$T17/out/7.4-start")" '[.[] | select(.startedAt >= $t)] | map({microvmId,state,startedAt})' |
| -echo "ours live: [$(our_live)]" |
| +if gotest "$T17/out/7.4-recover.log" -tags hostedlive ./internal/hostedclient -run 'TestLiveCrashRecovery$' -count=1 -v -timeout 15m; then rc=0; else rc=$?; fi |
| +grep -E 'recover:|listed vm|stop:' "$T17/out/7.4-recover.log" || true |
| +harvest "$T17/controller.log" controller |
| +stop_ctl |
| +settle_all |
| +[ "$rc" = 0 ] || die "the recover step failed" |
| +grep -q "recover: job $CRASH_ATTEMPT holds vm $CRASH_VM" "$T17/out/7.4-recover.log" || die "the job does not hold $CRASH_VM" |
| +scan >/dev/null |
| +n=$(awk -F'\t' -v t="$CRASH_START" '$3 >= t' "$T17/last_scan.tsv" | wc -l) |
| +awk -F'\t' -v t="$CRASH_START" '$3 >= t' "$T17/last_scan.tsv" |
| +[ "$n" = 1 ] || die "$n VMs of this image started since the crash launch, want 1" |
| +dbread "select attempt_id, state, vm_ref, stop_proof_json from jobs where attempt_id='$CRASH_ATTEMPT'" |
| +dbread "select action, reason from audit where attempt_id='$CRASH_ATTEMPT' order by id" |
| ``` |
| -- Expected: `--- PASS`; `recover:` shows the job holding `$CRASH_VM` (the same ID as in 7.4); |
| - exactly one listed VM for the attempt and no unowned live VM; stop with proof. The CLI list of VMs |
| - started since 7.4 began holds exactly one entry, `$CRASH_VM`, now `TERMINATING` or `TERMINATED`. |
| - `our_live` empty. |
| -- Abort if: FAIL, a second VM for the attempt, or a VM ID other than `$CRASH_VM`. |
| -- Record: the attempt, the VM, the `recover:` and `stop:` lines, how long Replay took after restart. |
| - |
| -Leave this controller running for section 8. |
| +- Expected: PASS; no `restart stop requested, elapsed time unknown` line in the log; the job holds `$CRASH_VM`, the same ID the crashed controller launched; one VM |
| + for the attempt and no unowned live VM; stop with proof; exactly one VM of this image started |
| + since 7.3 began; audit rows show the intent, the replay, the saved Ref and the stop. |
| +- Abort if: any check fails. |
| --- |
| ## 8. Orphan |
| -### 8.1 Plant a VM the controller does not know |
| - |
| -The controller is running (from 7.5) with no waiting intent, so R22 deferral does not apply. |
| +### 8.1 Start the controller (launches off: reaping works regardless) and plant a VM |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -metrics | grep -E 'jobs\{|orphans|alerts_total' |
| -rec ORPHAN_TOKEN "t17-orphan-$(date +%s)" || exit 1 |
| -date -u +%FT%TZ > "$T17/out/8-planted" |
| -aws lambda-microvms run-microvm --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --client-token "$ORPHAN_TOKEN" \ |
| - --ingress-network-connectors "$NO_INGRESS" --egress-network-connectors "$CONN_QARN" \ |
| - --maximum-duration-in-seconds 1800 --run-hook-payload orphan \ |
| - --query '[microvmId,state,startedAt]' --output text > "$T17/out/8-orphan.txt" || exit 1 |
| -rec ORPHAN_VM "$(cut -f1 "$T17/out/8-orphan.txt")" && cat "$T17/out/8-orphan.txt" "$T17/out/8-planted" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +scan >/dev/null; [ -z "$(live_ids)" ] || die "live VMs of this image: $(live_ids)" |
| +start_ctl "$T17/bin/controller" orphan |
| +ctl_ready |
| +metrics | grep -E '^equipo_hosted_jobs\{state="waiting"\} 0$' || die "a waiting intent exists, so R22 would defer the orphan" |
| +printf 'orphan' > "$T17/out/payload-orphan" |
| +rec ORPHAN_TOKEN "t17-orphan-$RUN" |
| +rec ORPHAN_PLANTED "$(date -u +%FT%TZ)" |
| +launch orphan "$ORPHAN_TOKEN" 1800 "$T17/out/payload-orphan" |
| +[ "$L_RC" = 0 ] || die "the orphan launch failed: $L_CODE" |
| +rec ORPHAN_VM "$L_ID" |
| ``` |
| -- Expected: a VM ID, `PENDING`, and its start time. No job row or intent names this token. Its |
| - 1800 s maximum duration is the AWS backstop. |
| -- Abort if: the run fails; or `jobs{state="waiting"}` was above 0 before planting. |
| +- Expected: a VM ID; no job or intent names its token; its 1800 s maximum duration is the backstop. |
| ### 8.2 Watch the reaper stop it |
| Expected timeline from the plant time P: the reaper lists every 60 s, so it first sees the VM by |
| -about P+1:30 (including List lag); it stops an orphan on the first pass at least 10 minutes after |
| -that first sighting, after rechecking ownership; so the stop comes between about P+11:00 and |
| -P+12:30, and the VM is `TERMINATED` (or not found) within about a minute after that. |
| +about P+1:30; it stops an orphan on the first pass at least 10 minutes after the first sighting, |
| +after rechecking ownership; so the stop lands between about P+11:00 and P+12:30, and the VM ends |
| +within a minute or two after that. |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -P=$(date -d "$(cat "$T17/out/8-planted")" +%s) |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need ORPHAN_VM ORPHAN_PLANTED |
| +P=$(date -d "$ORPHAN_PLANTED" +%s) |
| while :; do |
| - now=$(date +%s); s=$(vm_state "$ORPHAN_VM") |
| - echo "P+$(( (now-P)/60 )):$(printf %02d $(( (now-P)%60 ))) $s $(metrics | grep -E 'orphans_stopped|orphan_stopped' | tr '\n' ' ')" |
| - case "$s" in TERMINATED|*ResourceNotFound*) break;; esac |
| - [ $(( now - P )) -ge 900 ] && { echo "ABORT: not stopped by P+15:00"; break; } |
| - sleep 30 |
| + ctl_alive || die "the controller stopped" |
| + now=$(date +%s); vm_get "$ORPHAN_VM" |
| + echo "P+$(( (now - P) / 60 )):$(printf %02d $(( (now - P) % 60 ))) $VST" |
| + case "$VST" in |
| + PENDING|RUNNING) [ $(( now - P )) -lt 900 ] || die "the orphan is still live at P+15:00";; |
| + TERMINATING|TERMINATED|NOTFOUND) break;; |
| + ERROR:ThrottlingException) ;; |
| + *) die "orphan state $VST";; |
| + esac |
| + sleep 20 |
| done |
| -grep -i orphan "$T17/controller.log" | tail -5 |
| +[ $(( now - P )) -ge 600 ] || die "the orphan was stopped before the 10-minute grace" |
| +jw "ORPHAN stopped by the reaper at P+$(( now - P ))s" |
| +metrics | grep -E 'orphan' |
| +metrics | grep -qE '^equipo_hosted_alerts_total\{kind="orphan_stopped",result="sent"\} 1$' || die "no orphan_stopped alert sent" |
| +grep -F 'hosted controller: orphan VM stopped' "$T17/controller.log" | grep -F "$ORPHAN_VM" || die "no orphan-stopped log line for $ORPHAN_VM" |
| +! grep -F 'hosted controller: orphan VM left running for a dispatched launch intent' "$T17/controller.log" | grep -qF "$ORPHAN_VM" || die "the orphan was deferred (R22)" |
| +stop_ctl |
| +vm_end "$ORPHAN_VM" |
| +settle_all |
| +dbread "select action, reason from audit where action like 'orphan%' order by id" |
| +n=$(dbread "select count(*) from audit where action='orphan_stopped' and reason like '%$ORPHAN_VM%'"); [ "$n" = 1 ] || die "$n orphan_stopped rows for $ORPHAN_VM" |
| ``` |
| -- Expected: the state stays `RUNNING` until about P+11:00 to P+12:30, then `TERMINATING` and |
| - `TERMINATED`; metrics show `equipo_hosted_alerts_total{kind="orphan_stopped",result="sent"} 1` |
| - (and `reap_last_orphans_stopped 1` on that pass); the controller log names the VM. |
| -- Abort if: the VM is stopped before P+10:00 (the grace is not being honoured), or it is still live |
| - at P+15:00. In the second case, terminate it: |
| - `aws lambda-microvms terminate-microvm --microvm-identifier "$ORPHAN_VM"`, record, stop. |
| - |
| -### 8.3 Confirm by Get and List, then stop the controller |
| - |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-microvms get-microvm --microvm-identifier "$ORPHAN_VM" --query '[state,stateReason,terminatedAt]' --output text 2>&1 |
| -echo "ours live: [$(our_live)]"; echo "any live: [$(live_vms)]" |
| -``` |
| - |
| -Then stop the controller with the 7.3 block. |
| - |
| -- Expected: `TERMINATED` (or not found); both live lists empty; controller stopped, ports closed. |
| -- Record: P, first sighting time if logged, stop time, terminated time, the alert and metric lines. |
| +- Expected: `RUNNING` until about P+11:00 to P+12:30; then the alert metric, the controller's log |
| + line `hosted controller: orphan VM stopped` naming the VM (no deferral line), one `orphan_seen` and one `orphan_stopped` audit row for it; the VM ends. |
| +- Abort if: stopped before P+10:00, still live at P+15:00, or any evidence check fails. |
| --- |
| ## 9. Facts to record (R7) |
| -9.A to 9.F run before section 6 with no controller running, so the reaper never sees these VMs. |
| -Every VM here uses this run's image, the Small version, `NO_INGRESS`, the qualified connector, and a |
| -short maximum duration as the AWS backstop; each is terminated as soon as its fact is read. |
| +9.A to 9.F run before section 6, with no controller running. Every VM here comes from the `launch` |
| +helper (Small, `NO_INGRESS`, the qualified connector, a short maximum duration as AWS's backstop), |
| +which journals the intent first and records any VM ID returned. Each experiment either ends every |
| +VM it made, confirmed, or aborts before the next experiment starts. Only the listed error codes |
| +count as results; any other error aborts. |
| -Helper for this section (paste at the top of each 9 block, after the env line): |
| +### 9.A Client token: same request, then changed request |
| ```sh |
| -runvm() { # runvm LABEL TOKEN MAXSECONDS PAYLOADFILE: write the reply to out/9-LABEL.json, the error to .err |
| - aws lambda-microvms run-microvm --image-identifier "$IMAGE_ARN" --image-version "$VER_SMALL" --client-token "$2" \ |
| - --ingress-network-connectors "$NO_INGRESS" --egress-network-connectors "$CONN_QARN" \ |
| - --maximum-duration-in-seconds "$3" --run-hook-payload "file://$4" --output json > "$T17/out/9-$1.json" 2> "$T17/out/9-$1.err" |
| - echo "exit $? $(jq -c '{microvmId,state,startedAt,ingressNetworkConnectors}' "$T17/out/9-$1.json" 2>/dev/null) $(cat "$T17/out/9-$1.err")" |
| -} |
| -``` |
| - |
| -### 9.A Client token: same request, changed request, replay after the end |
| - |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -# (paste runvm here) |
| -[ -z "$(live_vms)" ] || { echo "ABORT: live VMs"; exit 1; } |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +! ctl_alive || die "the controller is running" |
| +scan >/dev/null; [ -z "$(live_ids)" ] || die "live VMs of this image: $(live_ids)" |
| printf 'task17-a' > "$T17/out/payload-a"; printf 'task17-b' > "$T17/out/payload-b" |
| -rec TOKEN_A "t17-token-$(openssl rand -hex 4)" || exit 1 |
| -date -u +%FT%T.%3NZ > "$T17/out/9-A1.before" |
| -runvm A1 "$TOKEN_A" 1200 "$T17/out/payload-a" |
| -date -u +%FT%T.%3NZ > "$T17/out/9-A1.after" |
| -rec VM_A "$(jq -r .microvmId "$T17/out/9-A1.json")" || exit 1 |
| -runvm A2 "$TOKEN_A" 1200 "$T17/out/payload-a" |
| -runvm A3 "$TOKEN_A" 1200 "$T17/out/payload-b" |
| -A3=$(jq -r '.microvmId // empty' "$T17/out/9-A3.json" 2>/dev/null) |
| -[ -n "$A3" ] && [ "$A3" != "$VM_A" ] && { rec VM_A3 "$A3"; aws lambda-microvms terminate-microvm --microvm-identifier "$A3"; echo "FINDING: a changed request with a used token made a second VM"; } |
| +rec TOKEN_A "t17-token-$RUN" |
| +rec A1_BEFORE "$(date -u +%FT%T.%3NZ)" |
| +launch A1 "$TOKEN_A" 900 "$T17/out/payload-a" |
| +rec A1_AFTER "$(date -u +%FT%T.%3NZ)" |
| +[ "$L_RC" = 0 ] || die "A1 failed: $L_CODE" |
| +rec VM_A "$L_ID" |
| +launch A2 "$TOKEN_A" 900 "$T17/out/payload-a" |
| +if [ "$L_RC" = 0 ] && [ "$L_ID" = "$VM_A" ]; then rec A2_RESULT same-vm |
| +elif [ "$L_RC" = 0 ]; then vm_end "$L_ID"; vm_end "$VM_A"; rec A2_RESULT "new-vm:$L_ID"; die "a replay of the same request made a second VM" |
| +else vm_end "$VM_A"; die "A2 failed: $L_CODE"; fi |
| +launch A3 "$TOKEN_A" 900 "$T17/out/payload-b" |
| +if [ "$L_RC" != 0 ]; then |
| + case "$L_CODE" in ConflictException|ValidationException) rec A3_RESULT "refused:$L_CODE";; *) vm_end "$VM_A"; die "A3 failed with $L_CODE";; esac |
| +elif [ "$L_ID" = "$VM_A" ]; then rec A3_RESULT same-vm |
| +else vm_end "$L_ID"; rec A3_RESULT "new-vm:$L_ID"; jw "FINDING a changed request with a used token made a second VM"; fi |
| +cat "$T17/out/launch-A3.err" |
| +echo "A2=$A2_RESULT A3=$A3_RESULT" |
| ``` |
| -- Expected: A1 returns a new VM (`PENDING`). A2 (same token, same request) returns the same |
| - `microvmId`. A3 (same token, changed payload) is refused; record the exact error code and message |
| - (candidates: `ConflictException` or `ValidationException`). |
| -- If A3 returns `VM_A` itself: AWS ignores the body on replay; record it. |
| -- If A3 returns another VM: it is terminated at once; record it; 6.1's `ChangedSpecConflicts` |
| - exception no longer applies, so a contract failure there becomes a stop. |
| +- Expected: A2 returns `VM_A` (one attempt, one VM). A3 is refused with `ConflictException` or |
| + `ValidationException`; the exact message is recorded. |
| +- A3 answered with `VM_A` (AWS ignores the body on replay) or with a new VM (ended at once) are |
| + results, recorded; with a new VM, 6.1's `ChangedSpecConflicts` exception no longer applies. |
| +- `VM_A` stays up for 9.B to 9.D. |
| -Keep `VM_A` for 9.B to 9.D; 9.E terminates it and replays the token. |
| - |
| -### 9.B startedAt timing, NO_INGRESS literal and the Date header |
| +### 9.B startedAt, the NO_INGRESS literal, the Date header |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -cat "$T17/out/9-A1.before" "$T17/out/9-A1.after"; jq '{state,startedAt}' "$T17/out/9-A1.json" |
| -for i in $(seq 1 120); do |
| - r=$(aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '[state,startedAt]' --output text) |
| - echo "$(date -u +%T.%3N) $r"; case "$r" in RUNNING*|TERMINAT*) break;; esac; sleep 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VM_A A1_BEFORE A1_AFTER CONN_QARN |
| +echo "run call: $A1_BEFORE to $A1_AFTER; reply: $(jq -c '{state,startedAt}' "$T17/out/launch-A1.json")" |
| +_running() { try aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '[state,startedAt]' --output text |
| + [ "$RC" = 0 ] || return 3; echo "$(date -u +%T.%3N) $OUT"; case "$OUT" in RUNNING*) return 0;; PENDING*) return 1;; esac; return 2; } |
| +poll 120 1 "VM_A to RUNNING" _running |
| +aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --output json > "$T17/out/9.B-get.json" |
| +jq -e --arg n "$NO_INGRESS" --arg c "$CONN_QARN" '.ingressNetworkConnectors == [$n] and .egressNetworkConnectors == [$c] and .maximumDurationInSeconds == 900 and (.executionRoleArn == null) and (.idlePolicy == null)' "$T17/out/9.B-get.json" >/dev/null || die "VM_A settings differ: $(jq -c '{ingressNetworkConnectors,egressNetworkConnectors,maximumDurationInSeconds,executionRoleArn,idlePolicy}' "$T17/out/9.B-get.json")" |
| +for op in get list; do |
| + if [ "$op" = get ]; then try aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --debug; else try aws lambda-microvms list-microvms --image-identifier "$IMAGE_ARN" --debug; fi |
| + must |
| + d=$(printf '%s' "$ERR" | grep -m1 'Response headers' | grep -oE "'[Dd]ate': '[^']*'" || true) |
| + if [ -n "$d" ]; then rec "DATE_HEADER_$op" "present"; echo "$op: $d"; else rec "DATE_HEADER_$op" inconclusive; echo "$op: measurement inconclusive"; fi |
| + ERR="" |
| done |
| -aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '{state:state,startedAt:startedAt,ingress:ingressNetworkConnectors,egress:egressNetworkConnectors,max:maximumDurationInSeconds,role:executionRoleArn,idle:idlePolicy}' --output json |
| -aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --debug 2>&1 >/dev/null | grep -m1 'Response headers' | grep -o "'[Dd]ate': '[^']*'" |
| -aws lambda-microvms list-microvms --debug 2>&1 >/dev/null | grep -m1 'Response headers' | grep -o "'[Dd]ate': '[^']*'" |
| ``` |
| -- Expected: `startedAt` is present in the PENDING reply; record how it compares with the local |
| - before/after times of the run call and with the time the VM reached RUNNING, and whether it changes |
| - between PENDING and RUNNING. The VM reaches RUNNING within about 10 s (spike: first response 2.3 to |
| - 3.2 s). The read shows ingress exactly `["arn:aws:lambda:eu-west-1:aws:network-connector:aws-network-connector:NO_INGRESS"]`, |
| - egress `[CONN_QARN]`, max 1200, no role, no idle policy. Both Date greps print a `Date` header |
| - (record "present" or "absent" for Get and for List; absent means `AgeKnown` is always false and the |
| - controller never trusts provider age across a restart). |
| -- Only the `Date` value is kept from `--debug`; nothing else from the debug output is written down. |
| -- Abort if: the VM goes from PENDING to TERMINATING (the run hook failed; record `stateReason`), or |
| - the ingress literal is echoed differently. |
| +- Expected: `startedAt` is in the PENDING reply; record how it relates to the call window and to the |
| + first RUNNING read, and whether it changes. The VM shows exactly the `NO_INGRESS` literal, the |
| + qualified connector, 900 s, no role, no idle policy. Only the `Date` value is kept from the debug |
| + output (the debug text is never written to a file the run keeps). |
| +- If the grep finds nothing, the result is "measurement inconclusive" (U12), not "absent"; the |
| + method is not changed during the run. |
| -### 9.C Resume on RUNNING; suspend on SUSPENDED; resume twice |
| +### 9.C Resume on RUNNING; suspend on SUSPENDED; a second resume |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -echo "resume RUNNING:"; aws lambda-microvms resume-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -date -u +%T.%3N; aws lambda-microvms suspend-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -wait_vm "$VM_A" SUSPENDED 180 || exit 1 |
| -echo "suspend SUSPENDED:"; aws lambda-microvms suspend-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -date -u +%T.%3N; aws lambda-microvms resume-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -echo "second resume at once:"; aws lambda-microvms resume-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -wait_vm "$VM_A" RUNNING 180 || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VM_A |
| +r() { try aws lambda-microvms "$1" --microvm-identifier "$VM_A"; echo "$1: rc=$RC code=${ECODE:-none} ${ERR}"; } |
| +r resume-microvm |
| +if [ "$RC" = 0 ]; then rec RESUME_ON_RUNNING accepted; elif [ "$ECODE" = ConflictException ]; then rec RESUME_ON_RUNNING ConflictException; else vm_end "$VM_A"; die "resume on RUNNING: $ECODE"; fi |
| +rec SUSPEND_AT "$(date -u +%FT%T.%3NZ)"; r suspend-microvm; must |
| +vm_wait "$VM_A" SUSPENDED 180 RUNNING SUSPENDING |
| +r suspend-microvm |
| +if [ "$RC" = 0 ]; then rec SUSPEND_ON_SUSPENDED accepted; elif [ "$ECODE" = ConflictException ]; then rec SUSPEND_ON_SUSPENDED ConflictException; else vm_end "$VM_A"; die "suspend on SUSPENDED: $ECODE"; fi |
| +rec RESUME_AT "$(date -u +%FT%T.%3NZ)"; r resume-microvm; must |
| +vm_get "$VM_A"; before=$VST |
| +r resume-microvm |
| +case "$before" in SUSPENDED) when=during-first-resume;; RUNNING) when=after-first-resume;; *) when="unknown:$before";; esac |
| +if [ "$RC" = 0 ]; then rec SECOND_RESUME "accepted:$when"; elif [ "$ECODE" = ConflictException ]; then rec SECOND_RESUME "ConflictException:$when"; else vm_end "$VM_A"; die "second resume: $ECODE"; fi |
| +vm_wait "$VM_A" RUNNING 180 SUSPENDED |
| +echo "resume-on-running=$RESUME_ON_RUNNING suspend-on-suspended=$SUSPEND_ON_SUSPENDED second-resume=$SECOND_RESUME" |
| ``` |
| -- Expected: resume on RUNNING fails with `ConflictException` (doc.go, R4); record the exact message. |
| - Suspend reaches SUSPENDED in 2 to 4 s (spike). Suspend on SUSPENDED: record the result. The second |
| - resume, sent while the first is in progress (the VM stays SUSPENDED while `/resume` runs): record |
| - the result. The VM is RUNNING again within a few seconds. |
| -- If resume on RUNNING is not a `ConflictException`, the adapter's no-op mapping is wrong: record it; |
| - 6.1's `ResumeRunningIsNoop` will fail and that is a stop there. |
| -- Abort if: a wait times out. |
| +- Expected: resume on RUNNING is a `ConflictException` (R4; if accepted, the adapter's mapping is |
| + untested and 6.1's `ResumeRunningIsNoop` result decides). Suspend reaches SUSPENDED in about 2 to |
| + 4 s. The second resume's label says which state the VM was in just before it, measured by a Get; |
| + with a 200-returning hook the first resume may already be done, so "after-first-resume" is the |
| + likely label and the in-progress case may stay unmeasured. |
| -### 9.D Payload limit (4096 and 4097 bytes, ASCII) |
| +### 9.D Payload limit (ASCII) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -# (paste runvm here) |
| -for n in 4096 4097; do |
| - head -c "$n" /dev/zero | tr '\0' x > "$T17/out/payload-$n"; wc -c < "$T17/out/payload-$n" |
| - runvm "P$n" "t17-p$n-$(openssl rand -hex 3)" 120 "$T17/out/payload-$n" |
| - id=$(jq -r '.microvmId // empty' "$T17/out/9-P$n.json" 2>/dev/null) |
| - [ -n "$id" ] && { rec "VM_P$n" "$id"; aws lambda-microvms terminate-microvm --microvm-identifier "$id"; echo "terminated $id"; } |
| -done |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +probe() { local n=$1 |
| + head -c "$n" /dev/zero | tr '\0' x > "$T17/out/payload-$n"; [ "$(wc -c < "$T17/out/payload-$n")" = "$n" ] || die "payload file size" |
| + launch "P$n" "t17-p$n-$RUN" 120 "$T17/out/payload-$n" |
| + if [ "$L_RC" = 0 ]; then vm_end "$L_ID"; rec "PAYLOAD_$n" accepted |
| + elif [ "$L_CODE" = ValidationException ]; then rec "PAYLOAD_$n" "refused:ValidationException"; cat "$T17/out/launch-P$n.err" |
| + else die "payload $n: $L_CODE"; fi; } |
| +probe 4096; probe 4097 |
| +if [ "$PAYLOAD_4097" = accepted ]; then probe 16384; probe 16385; fi |
| +echo "4096=$PAYLOAD_4096 4097=$PAYLOAD_4097 16384=${PAYLOAD_16384:-not run} 16385=${PAYLOAD_16385:-not run}" |
| ``` |
| -- Expected: 4096 accepted (VM terminated at once); 4097 refused with a `ValidationException` naming |
| - the length. Both refusal and acceptance are results; record which. |
| -- If 4097 is accepted: run the same loop once more for `16384 16385` (the developer guide says 16 KB) |
| - and record those two results. Each accepted VM is terminated at once and has a 120 s backstop. |
| -- Abort if: a terminate fails. |
| +- Expected: 4096 accepted (ended at once); 4097 refused with a `ValidationException`. If 4097 is |
| + accepted, 16384 and 16385 are probed (the guide says 16 KB). These are ASCII payloads: they |
| + establish an ASCII boundary only, not whether AWS counts bytes or characters in general. |
| -### 9.E Replay the token after the VM has ended |
| +### 9.E End VM_A, then replay its token |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -# (paste runvm here) |
| -aws lambda-microvms terminate-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -wait_vm "$VM_A" TERMINATED 300 || exit 1 |
| -date -u +%FT%TZ > "$T17/out/9-A.terminated" |
| -echo "terminate again:"; aws lambda-microvms terminate-microvm --microvm-identifier "$VM_A" 2>&1; echo "exit $?" |
| -runvm E1 "$TOKEN_A" 1200 "$T17/out/payload-a" |
| -E1=$(jq -r '.microvmId // empty' "$T17/out/9-E1.json" 2>/dev/null) |
| -[ -n "$E1" ] && [ "$E1" != "$VM_A" ] && { rec VM_E1 "$E1"; aws lambda-microvms terminate-microvm --microvm-identifier "$E1"; echo "FINDING: replay after termination made a new VM"; } |
| -aws lambda-microvms get-microvm --microvm-identifier "$VM_A" --query '[state,stateReason,terminatedAt]' --output text 2>&1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VM_A TOKEN_A |
| +vm_end "$VM_A"; rec VM_A_ENDED "$(date -u +%FT%TZ)" |
| +try aws lambda-microvms terminate-microvm --microvm-identifier "$VM_A" |
| +if [ "$RC" = 0 ]; then rec TERMINATE_AGAIN ok; elif [ "$ECODE" = ResourceNotFoundException ]; then rec TERMINATE_AGAIN ResourceNotFoundException; else die "terminate again: $ECODE"; fi |
| +launch E1 "$TOKEN_A" 900 "$T17/out/payload-a" |
| +if [ "$L_RC" = 0 ] && [ "$L_ID" = "$VM_A" ]; then rec E1_RESULT same-ended-vm |
| +elif [ "$L_RC" = 0 ]; then vm_end "$L_ID"; rec E1_RESULT "new-vm:$L_ID" |
| +else case "$L_CODE" in ConflictException|ValidationException|ResourceNotFoundException) rec E1_RESULT "refused:$L_CODE";; *) die "E1: $L_CODE";; esac; fi |
| +settle_all |
| +echo "E1=$E1_RESULT" |
| ``` |
| -- Expected: terminate twice succeeds both times (documented idempotent). Record what the replay of |
| - the original token and request returns now: `VM_A` again (state `TERMINATED`), a new VM |
| - (terminated at once), or an error. This decides how a controller Replay after a long outage |
| - behaves. |
| +- Expected: both terminates succeed (documented idempotent). The replay of the original token and |
| + request after the VM ended returns the ended VM, a new VM (ended at once), or one of the listed |
| + errors; recorded. Then every facts VM is settled. |
| -### 9.F How long TERMINATED VMs stay visible (spans the run) |
| - |
| -Run this at the end of 9.E, after 6.2, after 7.5, after 8.3 and at the start of 10: |
| +### 9.F TERMINATED visibility (run at the end of 9.E, after 6.1, 7.4, 8.2 and before 10.1) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -for v in $VM_A ${VM_P4096:-}; do echo "$(date -u +%T) $v get: $(vm_state "$v")"; done |
| -aws lambda-microvms list-microvms --query "items[?state=='TERMINATED'] | length(@)" --output text |
| -cat "$T17/out/9-A.terminated" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need VM_A VM_A_ENDED IMAGE_ARN |
| +vm_get "$VM_A"; jw "VISIBILITY VM_A $VST since $VM_A_ENDED"; echo "$(date -u +%T) VM_A get: $VST (ended $VM_A_ENDED)" |
| +scan >/dev/null; echo "image list: $(wc -l < "$T17/last_scan.tsv") VMs, $(grep -c "^$VM_A " "$T17/last_scan.tsv" || true) of them VM_A" |
| ``` |
| -- Expected: record, at each checkpoint, whether Get still answers `TERMINATED` or not found, and |
| - how many TERMINATED VMs List still returns. The last checkpoint that sees `VM_A` gives a lower |
| - bound on the visibility window; the first that does not gives an upper bound. |
| +- Expected: at each checkpoint, record whether Get still answers TERMINATED or not found, and |
| + whether List still shows `VM_A`. The last sighting and the first miss bound the visibility window. |
| -### 9.G Final facts (after section 8, controller stopped) |
| +### 9.G Final token replay (after section 8) |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -# (paste runvm here) |
| -runvm G1 "$TOKEN_A" 1200 "$T17/out/payload-a" |
| -G1=$(jq -r '.microvmId // empty' "$T17/out/9-G1.json" 2>/dev/null) |
| -[ -n "$G1" ] && [ "$G1" != "$VM_A" ] && { rec VM_G1 "$G1"; aws lambda-microvms terminate-microvm --microvm-identifier "$G1"; wait_vm "$G1" GONE 300; } |
| -echo "hours since first use: $(( ( $(date +%s) - $(date -d "$(cat "$T17/out/9-A1.before")" +%s) ) / 3600 ))" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need TOKEN_A VM_A A1_BEFORE |
| +! ctl_alive || die "the controller is running" |
| +launch G1 "$TOKEN_A" 900 "$T17/out/payload-a" |
| +if [ "$L_RC" = 0 ] && [ "$L_ID" = "$VM_A" ]; then rec G1_RESULT same-ended-vm |
| +elif [ "$L_RC" = 0 ]; then vm_end "$L_ID"; rec G1_RESULT "new-vm:$L_ID" |
| +else case "$L_CODE" in ConflictException|ValidationException|ResourceNotFoundException) rec G1_RESULT "refused:$L_CODE";; *) die "G1: $L_CODE";; esac; fi |
| +settle_all |
| +echo "G1=$G1_RESULT, $(( ( $(date +%s) - $(date -d "$A1_BEFORE" +%s) ) / 60 )) minutes after the token's first use" |
| ``` |
| -- Expected: the replay of `TOKEN_A`, now 3 to 4 hours after its first use. If it still returns |
| - `VM_A`, the token window is at least that long; if it makes a new VM (terminated at once) or errors, |
| - the window is shorter. Record which, with the hours. |
| -- Then run 9.F once more. |
| +- Expected: a result 3 to 4 hours after first use; `same-ended-vm` means the token window is at |
| + least that long. Then run 9.F once more. |
| -**What gets recorded for R7** (copy into the progress file, one line each): client token: A2 result, |
| -A3 error, E1 result, G1 result with hours; Date header on Get and List; startedAt in PENDING and its |
| -relation to the call and to RUNNING; resume on RUNNING error; suspend on SUSPENDED result; second |
| -resume result; payload 4096/4097 (and 16384/16385 if run); the NO_INGRESS literal as echoed; the |
| -TERMINATED visibility bounds; and, from 6.1, the visibility and List lag the contract measured |
| -(the pre-flight's 60 s and 30 s are guesses). |
| +**R7 record** (one line each in the progress file): A2, A3 (with message), E1, G1 (with minutes); |
| +Date header for Get and List (present or inconclusive); startedAt in PENDING and its relation to the |
| +call and to RUNNING; resume on RUNNING; suspend on SUSPENDED; second resume with its label; payload |
| +results (ASCII); the NO_INGRESS literal as echoed; TERMINATED visibility bounds; contract visibility |
| +and List lag. |
| --- |
| -## 10. Teardown |
| +## 10. Teardown and verification |
| -Runs after 9.G, or on Paul's word after an abort. Dependency order. Every delete names an ID from |
| -the ledger; nothing else is deleted. Each step's "Expected" is the deletion confirmation; failures |
| -are a stop, except where a retry is written in. |
| +Runs after 9.G, or on Paul's word after a safe stop. Dependency order. Each deletion is confirmed by |
| +a direct read before the next dependency is touched, and recorded with `deleted`. |
| -### 10.1 No VM left, controller stopped |
| +### 10.1 No controller, no VM, then the image and both versions |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -ss -ltn '( sport = :18443 or sport = :18444 )' |
| -for v in $(our_live | cut -f1); do echo "terminating $v"; aws lambda-microvms terminate-microvm --microvm-identifier "$v"; done |
| -for v in $(our_live | cut -f1); do wait_vm "$v" GONE 300; done |
| -echo "ours live: [$(our_live)]"; echo "any live: [$(live_vms)]" |
| -``` |
| - |
| -- Expected: no listener; nothing to terminate (any VM terminated here is a leak and is recorded); |
| - both lists empty. |
| - |
| -### 10.2 Image (both versions) |
| - |
| -```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-microvms delete-microvm-image --image-identifier "$IMAGE_ARN" --output text 2>&1 | tee "$T17/out/10.2-delete.txt" |
| -if grep -q ConflictException "$T17/out/10.2-delete.txt"; then |
| - for v in "$VER_LARGE" "$VER_SMALL"; do aws lambda-microvms delete-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$v"; done |
| - sleep 30; aws lambda-microvms delete-microvm-image --image-identifier "$IMAGE_ARN" --output text |
| -fi |
| -for i in $(seq 1 40); do r=$(aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query state --output text 2>&1); echo "$(date -u +%T) $r"; case "$r" in DELETED|*ResourceNotFound*) break;; esac; sleep 15; done |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need IMAGE_ARN VER_SMALL VER_LARGE |
| +stop_ctl |
| +settle_all |
| +try aws lambda-microvms delete-microvm-image --image-identifier "$IMAGE_ARN" --output json |
| +[ "$RC" = 0 ] || die "delete image: ${ECODE:-rc$RC} $ERR (a ConflictException is a stop: U8)" |
| +_img() { try aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query state --output text |
| + if [ "$RC" = 0 ]; then echo "$(date -u +%T) $OUT"; case "$OUT" in DELETED) return 0;; DELETING) return 1;; esac; return 2; fi |
| + [ "$ECODE" = ResourceNotFoundException ] && return 0; return 3; } |
| +poll 900 15 "image deleted" _img |
| +for v in "$VER_SMALL" "$VER_LARGE"; do |
| + try aws lambda-microvms get-microvm-image-version --image-identifier "$IMAGE_ARN" --image-version "$v" --query state --output text |
| + if [ "$RC" = 0 ]; then [ "$OUT" = DELETED ] || die "version $v is $OUT"; else expect_err ResourceNotFoundException; fi |
| + deleted microvm-image-version "$IMAGE_ARN:$v" |
| +done |
| +deleted microvm-image "$IMAGE_ARN" |
| +try aws lambda-microvms list-microvms --output json; must |
| +printf '%s' "$OUT" | jq -e --arg a "$IMAGE_ARN" '[.items[] | select(.imageArn == $a and .state != "TERMINATED")] | length == 0' >/dev/null || die "a live VM of the deleted image" |
| ``` |
| -- Expected: `DELETING`, then `DELETED` or not found within 10 minutes. The version-by-version |
| - fallback runs only if AWS refuses to delete an image that has versions. |
| - |
| -### 10.3 Connector, then wait for its network interfaces to go |
| +### 10.2 Connector, then its network interfaces |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws lambda-core delete-network-connector --identifier "$CONN_ARN" 2>&1; echo "exit $?" |
| -for i in $(seq 1 60); do r=$(aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text 2>&1); echo "$(date -u +%T) $r"; case "$r" in *ResourceNotFound*) break;; DELETE_FAILED) break;; esac; sleep 15; done |
| -for i in $(seq 1 80); do n=$(aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC" --query 'length(NetworkInterfaces)' --output text); echo "$(date -u +%T) ENIs in VPC: $n"; [ "$n" = 0 ] && break; sleep 30; done |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need CONN_ARN VPC |
| +try aws lambda-core delete-network-connector --identifier "$CONN_ARN"; must |
| +_conn() { try aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text |
| + if [ "$RC" = 0 ]; then echo "$(date -u +%T) $OUT"; case "$OUT" in DELETING|ACTIVE|INACTIVE) return 1;; esac; return 2; fi |
| + [ "$ECODE" = ResourceNotFoundException ] && return 0; return 3; } |
| +poll 900 15 "connector deleted" _conn |
| +deleted connector "$CONN_ARN" |
| +_enis() { local n; n=$(aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC" --query 'length(NetworkInterfaces)' --output text) || return 3; echo "$(date -u +%T) interfaces in VPC: $n"; [ "$n" = 0 ]; } |
| +poll 2400 30 "connector interfaces gone" _enis |
| +for e in $(awk -F'\t' '$2 ~ /^SERVICE-ENI / {split($2, a, " "); print a[2]}' "$JOURNAL"); do |
| + try aws ec2 describe-network-interfaces --network-interface-ids "$e"; expect_err InvalidNetworkInterfaceID.NotFound |
| + deleted service-eni "$e" |
| +done |
| ``` |
| -- Expected: the connector goes `DELETING`, then not found within 15 minutes; then no network |
| - interface is left in the VPC within 40 minutes. |
| -- Abort if: `DELETE_FAILED`, or interfaces remain after 40 minutes. Do not delete Lambda's |
| - interfaces by hand; ask Paul. |
| +- Abort if: `DELETE_FAILED`, or interfaces remain after 40 minutes. Lambda's interfaces are never |
| + deleted by hand. |
| -### 10.4 Network, in order |
| +### 10.3 Network |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws ec2 delete-security-group --group-id "$SG" --query Return --output text |
| -aws ec2 disassociate-route-table --association-id "$RTB_ASSOC" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need SG RTB RTB_ASSOC SUBNET VPC DEF_SG MAIN_RTB DEF_ACL |
| +[ "$(aws ec2 delete-security-group --group-id "$SG" --query Return --output text)" = True ] || die "delete group" |
| +try aws ec2 describe-security-groups --group-ids "$SG"; expect_err InvalidGroup.NotFound; deleted security-group "$SG" |
| +aws ec2 disassociate-route-table --association-id "$RTB_ASSOC"; deleted route-table-association "$RTB_ASSOC" |
| aws ec2 delete-route-table --route-table-id "$RTB" |
| +try aws ec2 describe-route-tables --route-table-ids "$RTB"; expect_err InvalidRouteTableID.NotFound; deleted route-table "$RTB" |
| aws ec2 delete-subnet --subnet-id "$SUBNET" |
| +try aws ec2 describe-subnets --subnet-ids "$SUBNET"; expect_err InvalidSubnetID.NotFound; deleted subnet "$SUBNET" |
| aws ec2 delete-vpc --vpc-id "$VPC" |
| +try aws ec2 describe-vpcs --vpc-ids "$VPC"; expect_err InvalidVpcID.NotFound; deleted vpc "$VPC" |
| +try aws ec2 describe-security-groups --group-ids "$DEF_SG"; expect_err InvalidGroup.NotFound; deleted vpc-default-security-group "$DEF_SG" |
| +try aws ec2 describe-route-tables --route-table-ids "$MAIN_RTB"; expect_err InvalidRouteTableID.NotFound; deleted vpc-main-route-table "$MAIN_RTB" |
| +try aws ec2 describe-network-acls --network-acl-ids "$DEF_ACL"; expect_err InvalidNetworkAclID.NotFound; deleted vpc-default-network-acl "$DEF_ACL" |
| ``` |
| -- Expected: each call succeeds (the first prints `True`). The VPC's main route table, default |
| - security group and default network ACL go with the VPC. |
| -- Abort if: a `DependencyViolation`; list what still depends on it with |
| - `aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC"` and ask. |
| +- Abort if: a `DependencyViolation` or any read that is not the not-found answer. |
| -### 10.5 IAM roles |
| +### 10.4 IAM roles |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws iam detach-role-policy --role-name "$OPERATOR_ROLE" --policy-arn arn:aws:iam::aws:policy/AWSLambdaNetworkConnectorOperatorPolicy |
| -aws iam delete-role-policy --role-name "$OPERATOR_ROLE" --policy-name t17-eni-extra |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need OPERATOR_ROLE BUILD_ROLE |
| +aws iam delete-role-policy --role-name "$OPERATOR_ROLE" --policy-name t17-connector-eni |
| aws iam delete-role --role-name "$OPERATOR_ROLE" |
| +try aws iam get-role --role-name "$OPERATOR_ROLE"; expect_err NoSuchEntity; deleted iam-role "$OPERATOR_ROLE" |
| aws iam delete-role-policy --role-name "$BUILD_ROLE" --policy-name t17-build |
| aws iam delete-role --role-name "$BUILD_ROLE" |
| +try aws iam get-role --role-name "$BUILD_ROLE"; expect_err NoSuchEntity; deleted iam-role "$BUILD_ROLE" |
| ``` |
| -- Expected: each call succeeds. |
| - |
| -### 10.6 S3, logs, SNS |
| +### 10.5 S3 |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need BUCKET |
| aws s3api delete-object --bucket "$BUCKET" --key t17/app.zip |
| -aws s3api list-object-versions --bucket "$BUCKET" --query '[length(Versions || `[]`),length(DeleteMarkers || `[]`)]' --output text |
| +try aws s3api head-object --bucket "$BUCKET" --key t17/app.zip; expect_err 404; deleted s3-object "s3://$BUCKET/t17/app.zip" |
| +[ "$(aws s3api list-object-versions --bucket "$BUCKET" --output json | jq '((.Versions // []) + (.DeleteMarkers // [])) | length')" = 0 ] || die "objects left in the bucket" |
| aws s3api delete-bucket --bucket "$BUCKET" |
| -aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].logGroupName' --output text |
| +try aws s3api head-bucket --bucket "$BUCKET"; expect_err 404; deleted s3-bucket "$BUCKET" |
| +``` |
| + |
| +### 10.6 Log group |
| + |
| +```sh |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need LOG_GROUP |
| +got=$(aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].logGroupName' --output text) |
| +[ "$got" = "$LOG_GROUP" ] || die "log groups under the prefix: [$got]; any group the run did not create goes to Paul" |
| aws logs delete-log-group --log-group-name "$LOG_GROUP" |
| -aws sns delete-topic --topic-arn "$TOPIC_ARN" |
| +[ -z "$(aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].logGroupName' --output text)" ] || die "log group still listed" |
| +deleted log-group "$LOG_GROUP" |
| ``` |
| -- Expected: the bucket is empty (`0 0`; it was never versioned) and deleted; the log group list |
| - shows only `$LOG_GROUP`, which is deleted. If the list shows any other group under |
| - `/aws/lambda-microvms/equipo-hosted-dev-t17`, add it to the ledger with `rec` and delete it the same |
| - way (Lambda created it for this image); any other name is a stop. The topic is deleted. |
| +### 10.7 SNS topic |
| -### 10.7 Verify by type, then by tag, then clean local scratch |
| +```sh |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need TOPIC_ARN |
| +aws sns delete-topic --topic-arn "$TOPIC_ARN" |
| +try aws sns get-topic-attributes --topic-arn "$TOPIC_ARN"; expect_err NotFound NotFoundException; deleted sns-topic "$TOPIC_ARN" |
| +``` |
| -By type (each must answer "not found" or empty): |
| +### 10.8 Verify: every record classified, then the tag index as a cross-check |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -echo "any live VM: [$(live_vms)]" |
| -aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_ARN" --query state --output text 2>&1 | tail -1 |
| -aws lambda-microvms list-microvm-images --query "items[?starts_with(name, 'equipo-hosted-dev-t17')].name" --output text |
| -aws lambda-core get-network-connector --identifier "$CONN_ARN" --query State --output text 2>&1 | tail -1 |
| -aws ec2 describe-vpcs --filters Name=tag:purpose,Values=$TAGV --query 'Vpcs[].VpcId' --output text |
| -aws ec2 describe-vpcs --vpc-ids "$VPC" 2>&1 | tail -1 |
| -aws ec2 describe-subnets --subnet-ids "$SUBNET" 2>&1 | tail -1 |
| -aws ec2 describe-route-tables --route-table-ids "$RTB" 2>&1 | tail -1 |
| -aws ec2 describe-security-groups --group-ids "$SG" 2>&1 | tail -1 |
| -aws ec2 describe-network-interfaces --filters Name=vpc-id,Values="$VPC" --query 'NetworkInterfaces[].NetworkInterfaceId' --output text |
| -aws iam get-role --role-name "$OPERATOR_ROLE" 2>&1 | tail -1 |
| -aws iam get-role --role-name "$BUILD_ROLE" 2>&1 | tail -1 |
| -aws s3api head-bucket --bucket "$BUCKET" 2>&1 | tail -1 |
| -aws logs describe-log-groups --log-group-name-prefix /aws/lambda-microvms/equipo-hosted-dev-t17 --query 'logGroups[].logGroupName' --output text |
| -aws sns get-topic-attributes --topic-arn "$TOPIC_ARN" 2>&1 | tail -1 |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need RUN IMAGE_ARN |
| +echo "== confirmed creations without a confirmed deletion:" |
| +awk -F'\t' '$2 ~ /^DELETED / {split($2, a, " "); d[a[3]] = 1} $2 ~ /^CONFIRMED / {split($2, a, " "); c[a[3]] = a[2]} END {for (k in c) if (!(k in d)) print c[k], k}' "$JOURNAL" | sort |
| +echo "== VMs: recorded, and how each ended:" |
| +for id in $(vm_ids); do grep -q "VMGONE $id " "$JOURNAL" || die "VM $id has no confirmed end"; done |
| +echo "$(vm_ids | wc -l) VMs recorded, every one confirmed ended" |
| +echo "== intents without a confirmation:" |
| +awk -F'\t' '$2 ~ /^INTENT /' "$JOURNAL" |
| +echo "== tag index (lags; direct reads above decide):" |
| +for k in run purpose; do v=$([ "$k" = run ] && echo "$RUN" || echo "$TAGV") |
| + aws resourcegroupstaggingapi get-resources --tag-filters Key=$k,Values=$v --query 'ResourceTagMappingList[].ResourceARN' --output text | tr '\t' '\n'; done |
| ``` |
| -- Expected: no live VM; image not found (or `DELETED`); no image name left; connector not found; |
| - no tagged VPC; `InvalidVpcID.NotFound`, `InvalidSubnetID.NotFound`, |
| - `InvalidRouteTableID.NotFound`, `InvalidGroup.NotFound`; no interfaces; `NoSuchEntity` twice; |
| - `Not Found` (404) for the bucket; no log group; `NotFound` for the topic. |
| +- Expected: the first list holds only values that are not resources (the run's settings: `DIGEST`, |
| + `VER_*`, `CONN_VERSION`, `CONN_QARN`, `BASE_*`, tokens, times, results); every resource ID has a |
| + `DELETED` line. Every recorded VM has a confirmed end. Each intent has its confirmation (or, for |
| + `vm` intents, a VM ID or a recorded refusal). The tag index lists nothing with `run=<RUN>`, or |
| + only ARNs already confirmed deleted above ("index lag"); with `purpose`, only what 0.4 already |
| + observed. An ARN that is neither goes to Paul untouched. |
| -By tag (the Resource Groups Tagging index lags, sometimes by hours, so it can still list deleted |
| -resources; the direct lookups above decide): |
| +### 10.9 Evidence into the progress file, then remove scratch |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" && guard || exit 1 |
| -aws resourcegroupstaggingapi get-resources --tag-filters Key=purpose,Values=$TAGV --query 'ResourceTagMappingList[].ResourceARN' --output text | tr '\t' '\n' |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +! ctl_alive || die "the controller is running"; [ -z "$(listeners)" ] || die "listeners open" |
| +cut -f2- "$JOURNAL" | grep -vE '^(INTENT|CONTROLLER) ' > "$T17/journal-for-progress.txt" |
| +wc -l "$T17/journal-for-progress.txt" "$VMS" |
| ``` |
| -- Expected: empty, or only ARNs already confirmed deleted above. For each ARN listed, check it with |
| - its direct lookup above and record "index lag". An ARN that is not in the ledger is not touched and |
| - goes to Paul. |
| - |
| -Then record everything in the progress file, and remove local scratch: |
| +Paste `journal-for-progress.txt`, `vms.tsv`, the R7 lines and section 11.2's estimate into |
| +`HOSTED-SLICE1-PROGRESS.md` (they hold IDs, times and results only, no keys), then: |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -ss -ltn '( sport = :18443 or sport = :18444 )' |
| -cat "$T17/ledger.log" |
| +set -euo pipefail; : "${TMPDIR:?}"; rm -rf "$TMPDIR/equipo-t17"; [ ! -e "$TMPDIR/equipo-t17" ] && echo "scratch removed" |
| ``` |
| -Paste the ledger lines into `HOSTED-SLICE1-PROGRESS.md` (they hold IDs only, no keys), then: |
| +--- |
| + |
| +## S. Safe stop |
| + |
| +Run in this order after any abort. Each part is safe to run whatever phase the run reached. |
| + |
| +**S.1 Controller.** |
| ```sh |
| -. "$TMPDIR/equipo-t17/env.sh" || exit 1 |
| -rm -rf "$T17" && echo "scratch removed" |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +stop_ctl |
| ``` |
| -- Expected: no listener; the ledger is in the progress file; scratch removed (keys, certificate, |
| - database, binaries, zip). Nothing started by this run is still running. |
| +If `stop_ctl` aborts because the PID belongs to another process, or a port stays open while `/proc` |
| +hides the process, stop here and ask Paul: nothing is signalled that is not proven to be this run's |
| +controller. |
| -### 10.8 Spend record (at least 24 hours later, one call) |
| +**S.2 Reconcile uncertain creations.** For each `INTENT` without a `CONFIRMED` line, look the |
| +resource up by the run-specific name or `run` tag it was created with, and record it only if found |
| +that way. A resource is adopted only when its name carries this run's random ID (and 0.4 showed the |
| +name free) and, where taggable, it carries `run=<RUN>`. |
| -Billing data lags. The day after the run: |
| +```sh |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +awk -F'\t' '$2 ~ /^INTENT /' "$JOURNAL" |
| +for t in vpc subnet route-table security-group; do |
| + case $t in vpc) q='Vpcs[].VpcId'; c=describe-vpcs;; subnet) q='Subnets[].SubnetId'; c=describe-subnets;; |
| + route-table) q='RouteTables[].RouteTableId'; c=describe-route-tables;; security-group) q='SecurityGroups[].GroupId'; c=describe-security-groups;; esac |
| + echo "$t with run=$RUN: $(aws ec2 $c --filters Name=tag:run,Values=$RUN --query "$q" --output text)" |
| +done |
| +for r in "$OPERATOR_ROLE" "$BUILD_ROLE"; do try aws iam get-role --role-name "$r" --query Role.Arn --output text; echo "role $r: ${OUT:-$ECODE}"; done |
| +try aws lambda-core get-network-connector --identifier "$CONN_NAME" --query '[Arn,State]' --output text; echo "connector: ${OUT:-$ECODE}" |
| +try aws lambda-microvms get-microvm-image --image-identifier "$IMAGE_NAME" --query '[imageArn,state]' --output text; echo "image: ${OUT:-$ECODE}" |
| +try aws s3api head-bucket --bucket "$BUCKET"; echo "bucket: rc=$RC ${ECODE:-}" |
| +echo "log group: $(aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP" --query 'logGroups[].logGroupName' --output text)" |
| +try aws sns get-topic-attributes --topic-arn "arn:aws:sns:eu-west-1:$ACCOUNT:$TOPIC_NAME" --query 'Attributes.TopicArn' --output text; echo "topic: ${OUT:-$ECODE}" |
| +``` |
| + |
| +The agent then runs `rec <VAR> <ID>` for each resource found this way whose intent was unconfirmed |
| +(variable names as in the creating step), and records nothing else. |
| + |
| +**S.3 VMs.** If the image was never created (no `IMAGE_ARN` and S.2 found no image), no VM can |
| +exist and this part is skipped. Otherwise: |
| ```sh |
| -export AWS_PROFILE=kass AWS_PAGER="" |
| -aws sts get-caller-identity --query Account --output text |
| -aws ce get-cost-and-usage --time-period Start=2026-11-23,End=2026-11-26 --granularity DAILY --metrics UnblendedCost \ |
| - --group-by Type=DIMENSION,Key=SERVICE --query 'ResultsByTime[].[TimePeriod.Start,Groups[?Keys[0]==`AWS Lambda`].Metrics.UnblendedCost.Amount|[0]]' --output text |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh"; guard |
| +need IMAGE_ARN |
| +! ctl_alive || die "the controller is running" |
| +settle_all |
| +sleep 120 |
| +settle_all |
| ``` |
| -- Expected: account `640012953448`; the Lambda line for the run day. It is the whole account's |
| - Lambda spend, so it is an upper bound for this run. Adjust the dates to the actual run day. Record |
| - it next to the estimate in section 11. |
| +`settle_all` ends every recorded VM and every live VM an image-scoped List shows, accepts an end |
| +only as `TERMINATED` or two not-found reads at least 60 s apart, and finishes only after three |
| +consecutive scans 30 s apart show nothing live. The second run, at least 2 minutes after the |
| +controller stopped, covers the residual R21 accepts: a launch request AWS held after the client gave |
| +up can still create a VM late. A VM that appears even later is visible to any later scan of the |
| +image while the image exists, and its maximum duration (at most 1 hour for the drivers, 30 minutes |
| +for the orphan, 15 minutes for the contract) ends it. |
| + |
| +**S.4 What is left for Paul.** Everything else in the ledger stays in place, and the agent reports |
| +the ledger and this exposure: |
| + |
| +| Left in place | Cost while it stays | |
| +| --- | --- | |
| +| MicroVM image (two versions) | about $0.08 per GB-month (Ireland rate not printed), assumed 6 GB: about $0.50 a month; worst case 68 GB: about $5.40 a month; one-week minimum already paid | |
| +| Connector, VPC, subnet, route table, group, defaults | no listed charge (no NAT, gateway or Elastic IP) | |
| +| IAM roles, log group (1-day retention), SNS topic | none | |
| +| S3 bucket and one object under 10 MB | under $0.01 a month | |
| + |
| +Teardown (section 10) then runs only on Paul's word. |
| --- |
| -## 11. Expected spend and duration |
| +## 11. Spend |
| -Rates: Ireland x86_64 compute from spec §10 ($0.155 an hour at 2 GB, $0.310 at 4 GB; pause and resume |
| -$0.0057 per GB). The Lambda pricing page prints snapshot and image storage rates only for US East |
| -(write $0.0038 per GB, read $0.00155 per GB, storage $0.08 per GB-month, image storage with a 1-week |
| -minimum); Ireland may be a little higher. The page lists no charge for image builds or connectors. |
| +### 11.1 Estimate |
| -| Item | Basis | Expected | Worst case | |
| +Rates: Ireland x86_64 compute from spec §10 ($0.155 an hour at 2 GB baseline; above-baseline use up |
| +to 4x costs extra). The pricing page prints snapshot and storage rates for US East only (write |
| +$0.0038 per GB, read $0.00155 per GB, storage $0.08 per GB-month, image storage with a one-week |
| +minimum); the worst case adds 20 % to those for Ireland. It lists no charge for image builds or |
| +connectors; the worst case still allows for builds billed as VM time. |
| + |
| +| Item | Basis | Expected | Worst case, every approved branch | |
| | --- | --- | --- | --- | |
| -| VM compute, 9.A to 9.G | about 8 Small VMs, about 25 min in all; backstops 1200, 120 and 300 s | $0.07 | $0.11 (0.7 h) | |
| -| VM compute, contract (6) | about 7 Small VMs, 3 to 6 min each; backstop 15 min each | $0.09 | $0.31 (2 h) | |
| -| VM compute, controller (7) | 2 Small VMs, about 10 min each; backstop 1 h each | $0.05 | $0.31 (2 h) | |
| -| VM compute, orphan (8) | 1 Small VM, about 12 min; backstop 30 min | $0.03 | $0.08 (0.5 h) | |
| -| Use above baseline | idle hook server, so none expected | $0.00 | x4 on all compute: +$2.43 | |
| -| Pause and resume | 3 cycles (9.C, contract, driver), up to 4 GB each, $0.0057/GB | $0.07 | $0.46 (10 cycles at 8 GB) | |
| -| Launch snapshot reads | about 20 starts, 2 to 4 GB, $0.00155/GB | $0.12 | $0.37 (30 at 8 GB) | |
| -| Image storage | 2 versions, assume 3 GB each, 1-week minimum, $0.08/GB-month | $0.11 | $0.37 (20 GB) | |
| -| Image builds | 2 builds, a few minutes each, if billed as VM time | $0.05 | $0.30 | |
| -| Connector, VPC, subnet, group, routes | no listed charge; no NAT, internet gateway or Elastic IP | $0.00 | $0.00 | |
| -| S3 | one object under 10 MB for a few hours, a few requests | $0.01 | $0.01 | |
| -| SNS | a few publishes, no subscribers | $0.00 | $0.00 | |
| -| CloudWatch Logs | build logs under 1 MB, 1-day retention | $0.00 | $0.01 | |
| -| Data transfer | VMs have no route out; S3 to Lambda in-region | $0.00 | $0.01 | |
| -| Cost Explorer (10.8) | one request at $0.01 | $0.01 | $0.01 | |
| -| **Total** | | **about $0.60** | **about $4.80** | |
| - |
| -**Cap: $10.** No step can reach it: every VM has an AWS maximum duration of at most 1 hour, and the |
| -largest is the two driver VMs. If any VM is seen live outside its step, the safe stop terminates it. |
| - |
| -**Wall-clock:** about 4 to 4.5 hours from 0.1 to the end of 10.7, most of it waiting on the |
| -connector (up to 15 min), two image builds (up to 20 min each), the contract (about 30 min), the |
| -controller waits (each state change up to a 60 s reaper pass), the orphan grace (about 12 min) and |
| -connector interface cleanup in teardown (up to 40 min). 10.8 is one call the next day. |
| +| Facts VMs (9) | A1 about 12 min; payload VMs ended at once | $0.04 | A1, A2, A3, E1, G1 at 900 s each, 4 payload VMs at 120 s: 1.4 h, $0.22 | |
| +| Contract VMs (6) | about 7, 3 to 6 min each | $0.09 | 8 at their 15-min maximum: 2 h, $0.31 | |
| +| Controller VMs (7) | 2, about 10 min each | $0.05 | 2 at the 1-h maximum, plus one late R21 VM at 1 h: 3 h, $0.47 | |
| +| Orphan VM (8) | about 12 min | $0.03 | 1800 s: 0.5 h, $0.08 | |
| +| Above-baseline use | idle hook server, none expected | $0.00 | 4x on all 6.9 VM-hours: +$3.21 | |
| +| Pause and resume | 3 cycles at about 2 GB | $0.03 | 6 cycles at 40 GB (8 GB memory, 32 GB disk), x1.2: $1.64 | |
| +| Launch snapshot reads | about 22 starts at 2 GB | $0.07 | 30 starts at 40 GB, x1.2: $2.23 | |
| +| Image storage | 2 versions, assumed 3 GB each, one-week minimum | $0.11 | 68 GB, one-week minimum, x1.2: $1.51 | |
| +| Image builds | 2 builds, a few minutes | $0.05 | 2 builds of 20 min at 4 GB: $0.21 | |
| +| S3, CloudWatch Logs, SNS, data transfer | tiny object, under 1 MB of logs, a few publishes, no route out | $0.02 | $0.05 | |
| +| **Total** | | **about $0.50 to $0.55** | **about $9.90** | |
| + |
| +The worst case is the sum of every bound at once (every VM at its maximum, at 4x, with the largest |
| +snapshots), which cannot all happen in one run; it is still under the $10 approval ceiling. |
| +**Leftovers after an abort** are not in the total: retained image storage costs about $0.50 to |
| +$5.40 a month until teardown (S.4). |
| + |
| +### 11.2 The run's own estimate (stop rule) |
| + |
| +Computed from the journal at the end of every section, with no billing call: each VM counts from |
| +the time it was recorded to the time its end was confirmed (an upper bound on its life). |
| + |
| +```sh |
| +set -euo pipefail; . "${TMPDIR:?}/equipo-t17/env.sh" |
| +python3 -I - "$JOURNAL" <<'EOF' |
| +import sys, datetime as dt |
| +t = lambda s: dt.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S.%fZ") |
| +start, end, now = {}, {}, dt.datetime.utcnow() |
| +for line in open(sys.argv[1]): |
| + ts, msg = line.rstrip("\n").split("\t", 1) |
| + w = msg.split(" ") |
| + if w[0] == "VM" and w[1] not in start: start[w[1]] = t(ts) |
| + if w[0] == "VMGONE": end[w[1]] = t(ts) |
| +hours = sum(((end.get(v, now)) - s).total_seconds() for v, s in start.items()) / 3600 |
| +live = [v for v in start if v not in end] |
| +est = hours * 0.155 + 0.11 + 0.05 + 0.02 + 0.0057 * 2 * 3 |
| +print(f"VMs {len(start)}, not yet ended {len(live)}, VM-hours {hours:.2f}, estimate ${est:.2f}") |
| +sys.exit(3 if est >= 5 else 0) |
| +EOF |
| +``` |
| + |
| +- Stop rule: an exit status of 3 (estimate at $5 or more), or a VM live outside its step, means the |
| + safe stop. The estimate is compute at baseline plus fixed allowances; Paul reads the real bill |
| + himself (R33). |
| + |
| +**Wall-clock:** about 4.5 to 5 hours from 0.1 to 10.9. |
| --- |
| -## 12. UNCONFIRMED items and pre-flight values |
| - |
| -### UNCONFIRMED (written from docs or a secondary source, not confirmed in a model or the docs) |
| - |
| -1. **U1. Connector operator role trust.** The networking guide prints the operator role's |
| - permissions but not its trust policy. 2.1 uses `lambda.amazonaws.com` with `aws:SourceAccount`, |
| - from a third-party walkthrough (dev.classmethod.jp) and the build-role pattern in the security |
| - guide. |
| -2. **U2. Operator role permissions.** The SDK says the role needs `ec2:DeleteNetworkInterface` and |
| - describe calls; the managed policy `AWSLambdaNetworkConnectorOperatorPolicy` (v1) holds neither. |
| - 2.1 adds them inline. Whether they are needed is unconfirmed. |
| -3. **U3. Installed CLI is older than the SDK.** AWS CLI 2.36.10's `lambda-core` model has no |
| - `LatestVersionArn`, `VersionArn`, `ElasticIpConfiguration` or `list-network-connector-versions`; |
| - its `lambda-microvms` model lists only `ARM_64` for `architecture` and drops `status` and |
| - `supportedCpuConfigurations` from managed image versions; `list-network-connectors`' output key |
| - (`NetworkConnectors`) is read from that older model. The plan relies on the CLI passing |
| - `X86_64` through (botocore does not validate enum values) and builds the qualified connector ARN |
| - as `<Arn>:<Version>`; the controller's audit confirms the ARN live. |
| -4. **U4. Base image name and version in eu-west-1.** `al2023-1`, with a version of 3 or later that |
| - supports x86_64, is from the guide's us-east-1 examples. |
| -5. **U5. Container base image.** `public.ecr.aws/lambda/microvms:al2023-minimal` is named in the |
| - guide; that it has an x86_64 variant is unconfirmed. |
| -6. **U6. Hooks.** That the `ready` build hook on port 9000 answered with 200 is enough for the |
| - build, and that `runHookPayload` is accepted with the run hook enabled, follow the guide's hook |
| - pages; the exact `hooks` JSON is from the model. |
| -7. **U7. Build log group.** That `logging.cloudWatch.logGroup` accepts a group we pre-create, and |
| - that the build writes nowhere else, is unconfirmed (10.6 handles extra groups under the image's |
| - prefix). |
| -8. **U8. Image deletion.** Whether `delete-microvm-image` removes all versions or refuses while |
| - versions exist is not documented; 10.2 has the fallback. |
| -9. **U9. Connector interfaces on delete.** That Lambda deletes the connector's interfaces when the |
| - connector is deleted, and how long it takes, is from the SDK text and a secondary source. |
| -10. **U10. Availability zone.** That a connector accepts a subnet in `eu-west-1a` is unconfirmed. |
| -11. **U11. Malformed VM ID.** What `terminate-microvm` returns for an ID AWS never issued |
| - (`StopUnknownRef`) is undocumented. |
| -12. **U12. `--debug` format.** That botocore's debug log prints a `Response headers: {...}` line |
| - with `'Date'` (9.B) is from botocore's usual logging, not checked here. |
| -13. **U13. Tagging API coverage.** Whether Resource Groups Tagging lists MicroVM images and network |
| - connectors is unconfirmed; direct lookups decide in 10.7. |
| -14. **U14. Update keeps the first version active.** That `update-microvm-image` leaves the Small |
| - version ACTIVE is implied by the guide (new versions are ACTIVE; nothing says older ones change). |
| -15. **U15. Cost Explorer service name.** That MicroVM charges appear under `AWS Lambda` is |
| - unconfirmed. |
| -16. **U16. Ireland rates.** Snapshot, image storage and launch-read rates for Ireland are not |
| - printed; US East rates are used. Image build and connector charges are not listed. |
| - |
| -### Pre-flight values |
| - |
| -The pre-flight report (`task-17-preflight-report.md`, commits `d94d7454`, `1ebf6e61`, `60a06822`) |
| -was present when this plan was written, and its values are in the commands above: |
| - |
| -- Keygen: `EQUIPO_HOSTED_KEYGEN_DIR`, `TestLiveKeygen`, files `controller.key`, `controller.pub`, |
| - `instance.key`, `operator.key`, `verify_keys.json`, `tls.crt`, `tls.key`; key IDs |
| - `task17-instance` and `task17-operator`. |
| -- Contract: `EQUIPO_HOSTED_LIVE_CONFIG`; Visibility 60 s and ListLag 30 s are built in. |
| -- Controller: `EQUIPO_HOSTED_ENABLED=1`; crash switch `EQUIPO_HOSTED_CRASH_AFTER_LAUNCH=1` in a |
| - `-tags hostedlive` build only, exit status 137. |
| -- Drivers: `EQUIPO_HOSTED_LIVE_URL`, `EQUIPO_HOSTED_LIVE_CA_FILE`, `EQUIPO_HOSTED_LIVE_KEY_ID`, |
| - `EQUIPO_HOSTED_LIVE_KEY_FILE`, `EQUIPO_HOSTED_LIVE_CONTROLLER_KEY_FILE`, |
| - `EQUIPO_HOSTED_LIVE_IMAGE`, `EQUIPO_HOSTED_LIVE_ATTEMPT`, `EQUIPO_HOSTED_LIVE_CRASH_STEP` |
| - (`launch`, `recover`), `EQUIPO_HOSTED_LIVE_OPERATOR_KEY_ID`, `EQUIPO_HOSTED_LIVE_OPERATOR_KEY_FILE`; |
| - tests `TestLiveControllerSequence` and `TestLiveCrashRecovery`. |
| - |
| -Placeholders left: none. Two choices differ from the report's example on purpose: ports |
| -`127.0.0.1:18443` and `:18444` instead of `8443` and `9443` (checked free in 5.2, on a shared |
| -machine), and the config maps both sizes (`small` and `large`), since the image has both versions. |
| +## 12. UNCONFIRMED items and placeholders |
| + |
| +### Settled since revision 1 (Astra's dispositions) |
| + |
| +- **U1, connector role trust:** the Web Functions networking guide prints it for the same connector |
| + mechanism (`lambda.amazonaws.com`, `sts:AssumeRole`); the plan uses it with `sts:TagSession` added |
| + and no `aws:SourceAccount` condition. A trust failure is a stop. |
| +- **Build role trust:** granting `sts:AssumeRole` and `sts:TagSession` covers both versions of the |
| + page (the live page shows the first only). |
| +- **U6, hooks:** `/ready` returning 200 signals readiness; the hook fields fit the models; run |
| + payload delivery is documented. A runtime hook failure is a stop. |
| +- **U9, connector interfaces:** the pinned SDK documents asynchronous interface cleanup on delete, |
| + then not found. The 15 and 40 minute bounds are ours; exhausting them is a stop. |
| +- **U15, billing service name:** removed with the Cost Explorer call (R33). |
| + |
| +### Still unconfirmed (each is a stop point if it goes wrong; nothing is changed live) |
| + |
| +1. **U2. Operator role scoping.** That Lambda needs `ec2:DeleteNetworkInterface` and describe |
| + calls (the SDK says so; the documented policy lacks them), and that the `ec2:Subnet` condition |
| + is evaluated for `CreateNetworkInterface` and `DeleteNetworkInterface` on the interface resource. |
| +2. **U3. Old CLI model.** The installed CLI's models lack `X86_64`, `VersionArn`, connector |
| + versions and two managed-version fields (confirmed); that the CLI passes `X86_64` through |
| + unvalidated is not confirmed. No CLI upgrade or flag change live. |
| +3. **U4. Base image availability** of `al2023-1` version 3 or later for x86_64 in this account and |
| + region. |
| +4. **U5. Container base image** `public.ecr.aws/lambda/microvms:al2023-minimal` has an x86_64 |
| + variant. No other image is substituted. |
| +5. **U7. Build log group** used exclusively by the build; other groups are never deleted. |
| +6. **U8. Image deletion** with versions present: a `ConflictException` is a stop; there is no |
| + fallback. |
| +7. **U10. `eu-west-1a`** accepted for the subnet and connector. No other zone is tried. |
| +8. **U11. Malformed VM ID** on `terminate-microvm`: only the `ValidationException` branch is |
| + approved, and it is a recorded failure, not a pass. |
| +9. **U12. `--debug` output format** for the `Date` header; no match is "inconclusive". |
| +10. **U13. Tag index coverage** of MicroVM images and connectors; direct reads decide. |
| +11. **U14. Small version stays ACTIVE** after the update; checked as a gate in 3.9. |
| +12. **U16. Ireland rates** for snapshots, launch reads and image storage, and whether builds or |
| + connectors are billed; the worst case adds 20 % and counts builds as VM time. |
| +13. **U17. MicroVM ID format** (`mvm-` and the guide's pattern) for harvesting IDs from logs; the |
| + image-scoped scans are the authoritative inventory either way. |
| +14. **U18. Error codes** used in expected-failure branches that are taken from models or |
| + convention, not observed: `404` for `head-bucket` and `head-object`, `NotFound` (or |
| + `NotFoundException`) for SNS, `ResourceNotFoundException` for Lambda reads, and the |
| + `An error occurred (<code>)` text the `try` helper parses. A different code aborts. |
| +15. **U19. Image version tags:** whether versions carry the image's tags; recorded as read in 3.8, |
| + not required. |
| +16. **U20. Process survival:** that a controller started with `setsid nohup` survives between agent |
| + tool calls in the sandbox, and that `/proc/<pid>/cmdline` is readable for it. If not, abort; |
| + no other process mechanism is improvised. |
| + |
| +### Placeholders |
| + |
| +None. `PIN_SHA` is `3103334e2a3c8d4b20fc113c0310569f17087674`; the controller and contract log lines grepped |
| +above are the exact texts in that commit (`internal/hostedctl/logs.go`, |
| +`internal/isolatedjob/isolatedjobtest/contract.go`). |