carlos / platform Public

bootstrap-box: verify carlos.new against root-signed system pointer (H1-M1/H6-M1)

Proposed replacements for carloku+platform bootstrap-box.sh: before install/
run, fetch control/system/router/stable.json, verify its Ed25519 signature
under CARLOS_RELEASE_PUBKEY ($pub, already written to host.env), and require
sha256(carlos.new) == stable.Current.Artifacts[linux-arm64].SHA256. Any
failure (unreachable/absent pointer, missing tool, bad signature, sha
mismatch) exits 1 without installing — fail closed. Mirrors console
apisystemupdate.go bootstrapState. Branch-diff only; real infra repos
untouched; update-platform-binary.sh left intact.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude Opus (hunt fix) pushed by claude agent, operated by paul@keymail.dev 5ce7e2a7c4739956f43f0df227b675edf0b89c3f parent bcae2a7
3 files changed, +319 −0
  • infra-proposed/RATIONALE.md +51 −0
  • infra-proposed/carloku-infra/bootstrap-box.sh +134 −0
  • infra-proposed/platform-infra/bootstrap-box.sh +134 −0
diff --git a/infra-proposed/RATIONALE.md b/infra-proposed/RATIONALE.md
new file mode 100644
index 000000000..91a29a7cb
--- /dev/null
+++ b/infra-proposed/RATIONALE.md
@@ -0,0 +1,51 @@
+# Task 1 — bootstrap verifies the binary before running it as root (H1-M1 / H6-M1)
+
+Branch-diff only. These two files are the PROPOSED replacements for the real
+`scripts/bootstrap-box.sh` in each infra repo (which are byte-identical today,
+sha `46aa1642…`). Nothing is applied; the real infra repos are untouched.
+
+- `carloku-infra/bootstrap-box.sh` → carloku-infrastructure/scripts/bootstrap-box.sh
+- `platform-infra/bootstrap-box.sh` → platform-infrastructure/scripts/bootstrap-box.sh
+
+## What changed
+One block of 54 lines inserted into the on-box heredoc, between the
+`aws s3 cp … bootstrap/carlos … carlos.new` line and the `install` line. No
+other line changes. The two copies stay identical.
+
+## Why this chain
+The box already receives `CARLOS_RELEASE_PUBKEY` (`$pub`) in the same heredoc,
+so the root public key is in hand before any binary runs. The platform's own
+trust chain (console `apisystemupdate.go` `bootstrapState`) treats
+`bootstrap/carlos` as current only when its sha256 equals
+`stable.Current.Artifacts["linux-arm64"].SHA256`, where `stable` is the system
+pointer `control/system/router/stable.json` verified under the root key
+(`release.GetSystemPointer` → `verifySystemPointer`). The bootstrap reuses
+exactly that: fetch the signed pointer, verify its Ed25519 signature with
+`$pub`, read the sha256 from the verified payload, compare to the downloaded
+bytes. The sha is never taken from an unsigned object.
+
+The signature covers the base64 payload STRING (`signRootPayload`:
+`ed25519.Sign(key, []byte(base64(payload)))`), so the script verifies over the
+exact base64 string and only decodes afterwards — no JSON canonicalisation.
+
+Tools used on the box (Debian arm64; `awscli` + cloud-init's python3 + base
+openssl 3.x present): `aws`, `openssl pkeyutl -rawin` (Ed25519), `python3`
+(stdlib JSON extraction only — never the trust gate), `sha256sum`. Missing tool
+→ exit 1 (fail closed).
+
+## Fail-closed
+Every failure path — pointer unreachable/absent, non-32-byte key, grant on the
+wire, bad signature, missing/!router/!stable pointer, sha mismatch, missing
+openssl/python3 — prints a reason to stderr and `exit 1` BEFORE `install`, so
+`carlos.new` is never installed or run. There is deliberately no fallback to
+running unverified bytes.
+
+## Rollout precondition (must flag to Paul)
+This requires `control/system/router/stable.json` to be published (via
+`carlos system update --channel stable`) before the new bootstrap is rolled.
+If it is absent, every new box FAILS CLOSED and will not bootstrap — which is
+the intended security posture, but it means the pointer must exist first. This
+is branch-diff only; rolling it is a later scoped step (re-bootstrap / AMI
+refresh), per the plan.
+
+`update-platform-binary.sh` (operator-sha path) is intentionally untouched.
diff --git a/infra-proposed/carloku-infra/bootstrap-box.sh b/infra-proposed/carloku-infra/bootstrap-box.sh
new file mode 100644
index 000000000..f50b4fca1
--- /dev/null
+++ b/infra-proposed/carloku-infra/bootstrap-box.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+# 🤖 Bootstrap a carlos host over SSM: install the binary from the
+# deployment bucket, run `carlos bootstrap`, write host.env, start the
+# edge. Idempotent — safe to re-run.
+# Usage: bootstrap-box.sh <aws-profile> <instance-id> <deployment-bucket> \
+# <data-bucket> <pubkey-file> [aws-region] [carlos-region] [status-box-region]
+#
+# aws-region (default eu-west-1) is the box's own region — it sets
+# CARLOS_HIBERNATE_REGION (which data bucket region the box wakes from).
+# AWS_REGION is pinned to the DEPLOYMENT bucket's region (eu-west-1): the
+# Go SDK does not follow S3 cross-region redirects, so a region box whose
+# AWS_REGION named its own region got PermanentRedirect 301 on every
+# deployment-bucket call (status, metrics, adoption, provision — learned
+# 2026-08-11 standing up us/uk/au). The hibernate store has its own region
+# var precisely so these can differ.
+#
+# carlos-region is CARLOS_REGION, the placement scope this box serves
+# ("us"|"uk"|"au"; unset = serves ""-scoped records only). status-box-region
+# is STATUS_BOX_REGION, the free-text region word the status page and the
+# console's shared-fleet chips display ("US · N. Virginia"). Both may come
+# from the environment instead of the argument, and both are OMITTED from
+# host.env when empty — an unset region is a legal state on this box, not a
+# blank one.
+set -euo pipefail
+profile=$1; instance=$2; depbucket=$3; databucket=$4; pubfile=$5
+region=${6:-eu-west-1}
+carlosregion=${7:-${CARLOS_REGION:-}}
+boxregion=${8:-${STATUS_BOX_REGION:-}}
+pub=$(cat "$pubfile")
+
+# Appended inside the host.env heredoc below; empty keeps the file exactly as
+# it was before regions existed.
+extra=""
+if [ -n "$carlosregion" ]; then
+ extra="$extra
+CARLOS_REGION=$carlosregion"
+fi
+if [ -n "$boxregion" ]; then
+ extra="$extra
+STATUS_BOX_REGION=\"$boxregion\""
+fi
+d=$(mktemp -d)
+
+cat > "$d/bootstrap.sh" <<EOF
+set -e
+aws s3 cp s3://$depbucket/bootstrap/carlos /opt/carlos/carlos.new --no-progress
+
+# --- H1-M1 / H6-M1: verify the downloaded binary against the ROOT-SIGNED
+# system pointer BEFORE installing or running it as root. The deployment
+# bucket is writable by more principals than the root release key, so
+# bootstrap/carlos is NOT trusted on its own: a bucket writer who replaces
+# it would otherwise have the next box run attacker bytes as root. We trust
+# only bytes whose sha256 is named by control/system/router/stable.json,
+# whose signature verifies under CARLOS_RELEASE_PUBKEY (already in hand as
+# \$pub). ANY failure here — unreachable or absent pointer, missing tool,
+# bad signature, sha mismatch — exits non-zero and leaves carlos.new
+# UNINSTALLED. Fail closed: a box that cannot verify never runs the binary.
+# (Mirrors console apisystemupdate.go bootstrapState: sha256(bootstrap/carlos)
+# must equal stable.Current.Artifacts["linux-arm64"].SHA256.)
+command -v openssl >/dev/null 2>&1 || { echo "bootstrap verify: openssl not found; refusing to install unverified carlos" >&2; exit 1; }
+command -v python3 >/dev/null 2>&1 || { echo "bootstrap verify: python3 not found; refusing to install unverified carlos" >&2; exit 1; }
+vdir=\$(mktemp -d)
+trap 'rm -rf "\$vdir"' EXIT
+aws s3 cp s3://$depbucket/control/system/router/stable.json "\$vdir/pointer.json" --no-progress || { echo "bootstrap verify: cannot fetch control/system/router/stable.json (publish it with 'carlos system update --channel stable' before rolling this bootstrap); refusing to install" >&2; exit 1; }
+# Reconstruct the root public key PEM from the raw 32-byte key already in hand.
+printf '%s' '$pub' | base64 -d > "\$vdir/pub.raw"
+[ "\$(wc -c < "\$vdir/pub.raw")" -eq 32 ] || { echo "bootstrap verify: CARLOS_RELEASE_PUBKEY is not a 32-byte Ed25519 key" >&2; exit 1; }
+{ printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; cat "\$vdir/pub.raw"; } > "\$vdir/pub.der"
+openssl pkey -pubin -inform DER -in "\$vdir/pub.der" -out "\$vdir/pub.pem" 2>/dev/null || { echo "bootstrap verify: cannot load the release pubkey" >&2; exit 1; }
+# Split the signed wrapper into the EXACT base64 payload string and the signature.
+# (This only extracts; the signature over that exact string is the gate below.)
+python3 - "\$vdir/pointer.json" "\$vdir/payload.b64" "\$vdir/sig.bin" <<'PY' || { echo "bootstrap verify: system pointer is not a valid signed wrapper" >&2; exit 1; }
+import base64, json, sys
+w = json.load(open(sys.argv[1]))
+if w.get("grant") is not None:
+ sys.exit("system pointer carries a grant; the platform takes the root key only")
+open(sys.argv[2], "w").write(w["payload"])
+open(sys.argv[3], "wb").write(base64.b64decode(w["sig"]))
+PY
+# The signature covers the base64 payload STRING, verified under the root key.
+openssl pkeyutl -verify -pubin -inkey "\$vdir/pub.pem" -rawin -in "\$vdir/payload.b64" -sigfile "\$vdir/sig.bin" >/dev/null 2>&1 || { echo "bootstrap verify: system pointer signature does not verify under CARLOS_RELEASE_PUBKEY" >&2; exit 1; }
+# Only now decode the VERIFIED payload and read the sha256 for this platform.
+want=\$(python3 - "\$vdir/payload.b64" <<'PY'
+import base64, json, sys
+p = json.loads(base64.b64decode(open(sys.argv[1]).read()))
+if p.get("component") != "router" or p.get("channel") != "stable":
+ sys.exit("system pointer is not router/stable")
+cur = p.get("current") or {}
+art = (cur.get("artifacts") or {}).get("linux-arm64") or {}
+sha, key, ver = art.get("sha256"), art.get("key"), cur.get("version")
+if not sha or key != "bootstrap/router/%s/carlos-linux-arm64" % ver:
+ sys.exit("system pointer names no linux-arm64 artifact for its version")
+print(sha)
+PY
+) || { echo "bootstrap verify: could not read the signed linux-arm64 sha256 from the pointer" >&2; exit 1; }
+got=\$(sha256sum /opt/carlos/carlos.new | cut -d' ' -f1)
+[ "\$got" = "\$want" ] || { echo "bootstrap verify: carlos.new sha256 \$got does not match the root-signed pointer \$want; refusing to install" >&2; exit 1; }
+echo "bootstrap verify: carlos.new matches stable's root-signed linux-arm64 artifact (\$want)"
+# --- end verify ---
+
+install -m755 -o carlos -g carlos /opt/carlos/carlos.new /opt/carlos/carlos && rm /opt/carlos/carlos.new
+/opt/carlos/carlos bootstrap
+cat > /etc/carlos/host.env <<ENV
+CARLOS_DATA_DIR=/data
+CARLOS_DEPLOYMENT_BUCKET=$depbucket
+CARLOS_RELEASE_PUBKEY=$pub
+CARLOS_HIBERNATE_BUCKET=$databucket
+CARLOS_HIBERNATE_REGION=$region
+CARLOS_HIBERNATE_PREFIX=instances
+AWS_REGION=eu-west-1$extra
+ENV
+chmod 600 /etc/carlos/host.env
+chown carlos:carlos /etc/carlos/host.env
+systemctl start carlos-edge
+sleep 3
+systemctl is-active carlos-edge
+/opt/carlos/carlos version
+EOF
+
+jq -n --rawfile s "$d/bootstrap.sh" '{commands: ($s | split("\n"))}' > "$d/params.json"
+cmdid=$(aws --profile "$profile" ssm send-command --instance-ids "$instance" \
+ --document-name AWS-RunShellScript --parameters "file://$d/params.json" \
+ --query Command.CommandId --output text)
+echo "command $cmdid sent; polling..."
+for i in $(seq 1 30); do
+ sleep 5
+ status=$(aws --profile "$profile" ssm get-command-invocation --command-id "$cmdid" \
+ --instance-id "$instance" --query Status --output text 2>/dev/null || echo Pending)
+ [ "$status" = "Success" ] || [ "$status" = "Failed" ] && break
+done
+echo "status: $status"
+aws --profile "$profile" ssm get-command-invocation --command-id "$cmdid" \
+ --instance-id "$instance" --query StandardOutputContent --output text | tail -8
+[ "$status" = "Success" ]
diff --git a/infra-proposed/platform-infra/bootstrap-box.sh b/infra-proposed/platform-infra/bootstrap-box.sh
new file mode 100644
index 000000000..f50b4fca1
--- /dev/null
+++ b/infra-proposed/platform-infra/bootstrap-box.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+# 🤖 Bootstrap a carlos host over SSM: install the binary from the
+# deployment bucket, run `carlos bootstrap`, write host.env, start the
+# edge. Idempotent — safe to re-run.
+# Usage: bootstrap-box.sh <aws-profile> <instance-id> <deployment-bucket> \
+# <data-bucket> <pubkey-file> [aws-region] [carlos-region] [status-box-region]
+#
+# aws-region (default eu-west-1) is the box's own region — it sets
+# CARLOS_HIBERNATE_REGION (which data bucket region the box wakes from).
+# AWS_REGION is pinned to the DEPLOYMENT bucket's region (eu-west-1): the
+# Go SDK does not follow S3 cross-region redirects, so a region box whose
+# AWS_REGION named its own region got PermanentRedirect 301 on every
+# deployment-bucket call (status, metrics, adoption, provision — learned
+# 2026-08-11 standing up us/uk/au). The hibernate store has its own region
+# var precisely so these can differ.
+#
+# carlos-region is CARLOS_REGION, the placement scope this box serves
+# ("us"|"uk"|"au"; unset = serves ""-scoped records only). status-box-region
+# is STATUS_BOX_REGION, the free-text region word the status page and the
+# console's shared-fleet chips display ("US · N. Virginia"). Both may come
+# from the environment instead of the argument, and both are OMITTED from
+# host.env when empty — an unset region is a legal state on this box, not a
+# blank one.
+set -euo pipefail
+profile=$1; instance=$2; depbucket=$3; databucket=$4; pubfile=$5
+region=${6:-eu-west-1}
+carlosregion=${7:-${CARLOS_REGION:-}}
+boxregion=${8:-${STATUS_BOX_REGION:-}}
+pub=$(cat "$pubfile")
+
+# Appended inside the host.env heredoc below; empty keeps the file exactly as
+# it was before regions existed.
+extra=""
+if [ -n "$carlosregion" ]; then
+ extra="$extra
+CARLOS_REGION=$carlosregion"
+fi
+if [ -n "$boxregion" ]; then
+ extra="$extra
+STATUS_BOX_REGION=\"$boxregion\""
+fi
+d=$(mktemp -d)
+
+cat > "$d/bootstrap.sh" <<EOF
+set -e
+aws s3 cp s3://$depbucket/bootstrap/carlos /opt/carlos/carlos.new --no-progress
+
+# --- H1-M1 / H6-M1: verify the downloaded binary against the ROOT-SIGNED
+# system pointer BEFORE installing or running it as root. The deployment
+# bucket is writable by more principals than the root release key, so
+# bootstrap/carlos is NOT trusted on its own: a bucket writer who replaces
+# it would otherwise have the next box run attacker bytes as root. We trust
+# only bytes whose sha256 is named by control/system/router/stable.json,
+# whose signature verifies under CARLOS_RELEASE_PUBKEY (already in hand as
+# \$pub). ANY failure here — unreachable or absent pointer, missing tool,
+# bad signature, sha mismatch — exits non-zero and leaves carlos.new
+# UNINSTALLED. Fail closed: a box that cannot verify never runs the binary.
+# (Mirrors console apisystemupdate.go bootstrapState: sha256(bootstrap/carlos)
+# must equal stable.Current.Artifacts["linux-arm64"].SHA256.)
+command -v openssl >/dev/null 2>&1 || { echo "bootstrap verify: openssl not found; refusing to install unverified carlos" >&2; exit 1; }
+command -v python3 >/dev/null 2>&1 || { echo "bootstrap verify: python3 not found; refusing to install unverified carlos" >&2; exit 1; }
+vdir=\$(mktemp -d)
+trap 'rm -rf "\$vdir"' EXIT
+aws s3 cp s3://$depbucket/control/system/router/stable.json "\$vdir/pointer.json" --no-progress || { echo "bootstrap verify: cannot fetch control/system/router/stable.json (publish it with 'carlos system update --channel stable' before rolling this bootstrap); refusing to install" >&2; exit 1; }
+# Reconstruct the root public key PEM from the raw 32-byte key already in hand.
+printf '%s' '$pub' | base64 -d > "\$vdir/pub.raw"
+[ "\$(wc -c < "\$vdir/pub.raw")" -eq 32 ] || { echo "bootstrap verify: CARLOS_RELEASE_PUBKEY is not a 32-byte Ed25519 key" >&2; exit 1; }
+{ printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; cat "\$vdir/pub.raw"; } > "\$vdir/pub.der"
+openssl pkey -pubin -inform DER -in "\$vdir/pub.der" -out "\$vdir/pub.pem" 2>/dev/null || { echo "bootstrap verify: cannot load the release pubkey" >&2; exit 1; }
+# Split the signed wrapper into the EXACT base64 payload string and the signature.
+# (This only extracts; the signature over that exact string is the gate below.)
+python3 - "\$vdir/pointer.json" "\$vdir/payload.b64" "\$vdir/sig.bin" <<'PY' || { echo "bootstrap verify: system pointer is not a valid signed wrapper" >&2; exit 1; }
+import base64, json, sys
+w = json.load(open(sys.argv[1]))
+if w.get("grant") is not None:
+ sys.exit("system pointer carries a grant; the platform takes the root key only")
+open(sys.argv[2], "w").write(w["payload"])
+open(sys.argv[3], "wb").write(base64.b64decode(w["sig"]))
+PY
+# The signature covers the base64 payload STRING, verified under the root key.
+openssl pkeyutl -verify -pubin -inkey "\$vdir/pub.pem" -rawin -in "\$vdir/payload.b64" -sigfile "\$vdir/sig.bin" >/dev/null 2>&1 || { echo "bootstrap verify: system pointer signature does not verify under CARLOS_RELEASE_PUBKEY" >&2; exit 1; }
+# Only now decode the VERIFIED payload and read the sha256 for this platform.
+want=\$(python3 - "\$vdir/payload.b64" <<'PY'
+import base64, json, sys
+p = json.loads(base64.b64decode(open(sys.argv[1]).read()))
+if p.get("component") != "router" or p.get("channel") != "stable":
+ sys.exit("system pointer is not router/stable")
+cur = p.get("current") or {}
+art = (cur.get("artifacts") or {}).get("linux-arm64") or {}
+sha, key, ver = art.get("sha256"), art.get("key"), cur.get("version")
+if not sha or key != "bootstrap/router/%s/carlos-linux-arm64" % ver:
+ sys.exit("system pointer names no linux-arm64 artifact for its version")
+print(sha)
+PY
+) || { echo "bootstrap verify: could not read the signed linux-arm64 sha256 from the pointer" >&2; exit 1; }
+got=\$(sha256sum /opt/carlos/carlos.new | cut -d' ' -f1)
+[ "\$got" = "\$want" ] || { echo "bootstrap verify: carlos.new sha256 \$got does not match the root-signed pointer \$want; refusing to install" >&2; exit 1; }
+echo "bootstrap verify: carlos.new matches stable's root-signed linux-arm64 artifact (\$want)"
+# --- end verify ---
+
+install -m755 -o carlos -g carlos /opt/carlos/carlos.new /opt/carlos/carlos && rm /opt/carlos/carlos.new
+/opt/carlos/carlos bootstrap
+cat > /etc/carlos/host.env <<ENV
+CARLOS_DATA_DIR=/data
+CARLOS_DEPLOYMENT_BUCKET=$depbucket
+CARLOS_RELEASE_PUBKEY=$pub
+CARLOS_HIBERNATE_BUCKET=$databucket
+CARLOS_HIBERNATE_REGION=$region
+CARLOS_HIBERNATE_PREFIX=instances
+AWS_REGION=eu-west-1$extra
+ENV
+chmod 600 /etc/carlos/host.env
+chown carlos:carlos /etc/carlos/host.env
+systemctl start carlos-edge
+sleep 3
+systemctl is-active carlos-edge
+/opt/carlos/carlos version
+EOF
+
+jq -n --rawfile s "$d/bootstrap.sh" '{commands: ($s | split("\n"))}' > "$d/params.json"
+cmdid=$(aws --profile "$profile" ssm send-command --instance-ids "$instance" \
+ --document-name AWS-RunShellScript --parameters "file://$d/params.json" \
+ --query Command.CommandId --output text)
+echo "command $cmdid sent; polling..."
+for i in $(seq 1 30); do
+ sleep 5
+ status=$(aws --profile "$profile" ssm get-command-invocation --command-id "$cmdid" \
+ --instance-id "$instance" --query Status --output text 2>/dev/null || echo Pending)
+ [ "$status" = "Success" ] || [ "$status" = "Failed" ] && break
+done
+echo "status: $status"
+aws --profile "$profile" ssm get-command-invocation --command-id "$cmdid" \
+ --instance-id "$instance" --query StandardOutputContent --output text | tail -8
+[ "$status" = "Success" ]