Move the staged infra-repo copies out of the platform tree
They belong to carloku-infrastructure and platform-infrastructure and go there as their own branches; in this tree the census reads them as root sources.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+0
−806
infra-proposed/RATIONALE.md+0 −122infra-proposed/carloku-infra/bootstrap-box.sh+0 −152infra-proposed/carloku-infra/fence-flat-imds.CHANGES.md+0 −52infra-proposed/carloku-infra/fence-flat-imds.sh+0 −167infra-proposed/carloku-infra/region-ie.tf+0 −161infra-proposed/platform-infra/bootstrap-box.sh+0 −152
diff --git a/infra-proposed/RATIONALE.md b/infra-proposed/RATIONALE.md| deleted file mode 100644 |
| index 183242016..000000000 |
| --- a/infra-proposed/RATIONALE.md |
| +++ /dev/null |
| @@ -1,122 +0,0 @@ |
| -# 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. |
| - |
| ---- |
| - |
| -# Task 2 — deny the IE/region host role read of /carlos/release-key (H1-M2) |
| - |
| -Branch-diff only. The MODULE change is applied directly in this worktree at |
| -`infra/modules/region-host/{main.tf,variables.tf}`. This staged file is the |
| -PROPOSED carloku-infrastructure wiring; the real carloku-infrastructure repo |
| -is untouched. |
| - |
| -- `carloku-infra/region-ie.tf` → carloku-infrastructure/region-ie.tf |
| - |
| -## The hole |
| -`region-ie.tf` sets `ssm_parameter_arn = ".../parameter/carlos/*"`. The |
| -module's existing `host_ssm_parameter_scope` Deny uses `NotResource = |
| -[ssm_parameter_arn]`, so it denies only reads OUTSIDE that pattern — |
| -`/carlos/release-key` is INSIDE it, left to the managed |
| -AmazonSSMManagedInstanceCore Allow (`ssm:GetParameter*` on `*`). So the |
| -internet-facing IE box can read the root release-signing key. Same class as |
| -discussion #7; re-found as H1-M2 on the IE/region role. |
| - |
| -## Module change (this worktree) |
| -`infra/modules/region-host/main.tf`: new `aws_iam_role_policy |
| -"host_release_key_deny"` (count = `var.deny_release_key_reads ? 1 : 0`), |
| -inserted right after `host_ssm_parameter_scope` (its close was at :475; the |
| -new block sits between it and `aws_iam_instance_profile "host"`). Two explicit |
| -Deny statements, ported verbatim from `platform-infrastructure/dev/ |
| -release-key-deny.tf`: |
| - 1. `DenyReleaseKeyReads` — `ssm:GetParameter`, `GetParameters`, |
| - `GetParameterHistory` on |
| - `arn:aws:ssm:*:<account>:parameter/carlos/release-key`. |
| - 2. `DenyReleaseKeyAncestorPathReads` — `ssm:GetParametersByPath` on the four |
| - ancestor list paths `parameter/carlos`, `parameter/carlos/`, `parameter`, |
| - `parameter/`. |
| -Account id is `data.aws_caller_identity.current.account_id` (already declared |
| -in the module at main.tf:607). `infra/modules/region-host/variables.tf`: new |
| -`variable "deny_release_key_reads"` (bool, default true). |
| - |
| -## Why it composes |
| -Explicit Deny beats any Allow in IAM, including a managed policy's, so the key |
| -path is denied no matter how wide `ssm_parameter_arn` / the managed Allow are. |
| -The new Deny and the existing `NotResource` Deny never conflict: both are |
| -Deny, and adding a Deny can only subtract access. The GetParametersByPath deny |
| -names only the ANCESTOR list paths (`/carlos`, account root), so the box still |
| -reads deeper by-path prefixes (`/carlos/<app>/*`, pepper, smtp creds) — the |
| -other `/carlos/*` reads it needs are untouched. The four single-read actions |
| -cover only parameter reads; Session Manager's channel/inventory/association |
| -actions are not named, so the admin path is unchanged. |
| - |
| -## Promotion is not affected (Step 1) |
| -The console does NOT read the key from SSM at runtime: `cmd/console/main.go` |
| -reads `os.Getenv("CARLOS_RELEASE_KEY")` at serve() start (:312), populated by |
| -the `console.service` `release-key` env drop-in placed by hand over SSM |
| -(carloku README §"What's on the IE box", line 136). The promote/ship scripts |
| -(`promote-console.sh`, `promote-app.sh`, `ship-app.sh`, `promote-pending.sh`, |
| -`promote-platform-site.sh`) fetch `/carlos/release-key` with an operator |
| -`AWS_PROFILE` (keymail / titogo / passed-in), never the box instance role. No |
| -boot-time box-role read of the key exists in either infra repo. So the Deny |
| -cannot break signing or promotion. |
| - |
| -## Rollout (must flag to Paul) |
| -The carloku wiring needs the module `?ref=` bumped to the first platform tag |
| -that carries `host_release_key_deny` (placeholder `<RELEASE-KEY-DENY-TAG>` in |
| -the staged file). The module variable defaults ON, so the bump alone lands the |
| -Deny on the IE role; `deny_release_key_reads = true` is stated explicitly at |
| -the call site for visibility. Apply TARGETED at |
| -`module.host_ie.aws_iam_role_policy.host_release_key_deny` under scoped |
| -approval — a whole-module plan on this live box also carries its other drift. |
| -Expected targeted plan: 1 to add, 0 to change, 0 to destroy. The other three |
| -regions (us/uk/au, still v0.21.0) are not touched by this task; they pick up |
| -the Deny-on-by-default when they are rolled onto a tag that carries it. |
diff --git a/infra-proposed/carloku-infra/bootstrap-box.sh b/infra-proposed/carloku-infra/bootstrap-box.sh| deleted file mode 100644 |
| index 2b5a4e8d9..000000000 |
| --- a/infra-proposed/carloku-infra/bootstrap-box.sh |
| +++ /dev/null |
| @@ -1,152 +0,0 @@ |
| -#!/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 |
| -set -o pipefail |
| -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 the platform's own verify chain: release.GetSystemPointer -> |
| -# verifySystemPointer/parseSystemPointer checks the Ed25519 signature under the |
| -# root key (internal/release/systempointer.go), the artifact key is |
| -# bootstrap/router/<version>/carlos-<platform> (SystemArtifactKey, |
| -# systempointer.go:88), and the box self-update reads the sha from |
| -# p.Current.Artifacts[platform] of that verified pointer |
| -# (internal/host/systemleg.go:131, installchannel.go:297). Here platform is |
| -# linux-arm64 and channel is stable (the bytes a fresh box boots). |
| -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; } |
| -# Build the DER SubjectPublicKeyInfo (12-byte Ed25519 SPKI header + the 32-byte |
| -# raw key) in python. NOT shell printf: the box runs this under /bin/sh = dash, |
| -# whose printf does not honour \x hex escapes (it would emit the literal text), |
| -# so the DER would be garbage and verification would fail closed on a GENUINE |
| -# binary. python3 is already required above, so this adds no new dependency. |
| -python3 - "\$vdir/pub.raw" "\$vdir/pub.der" <<'PY' || { echo "bootstrap verify: cannot build the release pubkey DER" >&2; exit 1; } |
| -import sys |
| -raw = open(sys.argv[1], "rb").read() |
| -if len(raw) != 32: |
| - sys.exit("release pubkey is not 32 bytes") |
| -open(sys.argv[2], "wb").write(b"\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00" + raw) |
| -PY |
| -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/carloku-infra/fence-flat-imds.CHANGES.md b/infra-proposed/carloku-infra/fence-flat-imds.CHANGES.md| deleted file mode 100644 |
| index e1956f997..000000000 |
| --- a/infra-proposed/carloku-infra/fence-flat-imds.CHANGES.md |
| +++ /dev/null |
| @@ -1,52 +0,0 @@ |
| -# Proposed change to `carloku-infrastructure/scripts/fence-flat-imds.sh` (H1-M4) |
| - |
| -This is a STAGED replacement. Do not edit the live repo in place; apply this to |
| -`carloku-infrastructure` via its own review/merge, then redeploy the fence by |
| -SSM as usual. The file here is a full copy of the script with the box-side |
| -refresh rewritten; the SSM wrapper and the systemd unit are unchanged. |
| - |
| -## What changes, by line (against the live script at hunt snapshot) |
| - |
| -Line numbers below are the LIVE script's. |
| - |
| -- **Header comment, lines 12-16.** Reworded: a stale table still fails open for |
| - lockout-safety (startup/restart), but an agent that was confirmed in |
| - `supervise` and then LEFT it with the *same PID* now fails CLOSED. Names the |
| - `/run/carlos-imds-flat.confirmed` PID latch that tells the two apart. |
| - |
| -- **New line after 57 (`sup=$svc/supervise`).** Add `state=/run/carlos-imds-flat.confirmed` |
| - plus its comment. |
| - |
| -- **Lines 59-86 (the whole `{ … } > "$f"; nft -f "$f"` block).** Replaced. The |
| - old block always emitted `flush table` and only re-added the drop rules when |
| - the agent was confirmed in `supervise`; when it was not, the table flushed to |
| - empty — the drop removed, IMDS open to the flat tier (fail OPEN). The new |
| - block computes a three-way `mode` first: |
| - - `install` — agent confirmed in `supervise` (old positive branch, verbatim |
| - rules + chown/chmod), **plus** `printf '%s\n' "$main" > "$state"` to latch |
| - the confirmed PID. |
| - - `retain` — `$state` holds a PID equal to the current non-zero MainPID, but |
| - the agent is no longer in `supervise`. Same PID ⇒ not a restart (systemd |
| - would report a new MainPID) ⇒ a flat child moved the agent out (H1-M4). |
| - `exit 0` with **no nft call**, so the live table (the drop installed by the |
| - previous cycle) is retained: IMDS stays shut. This is the fix. |
| - - `open` — MainPID is 0, or a new PID not yet in `supervise` (startup or |
| - restart). Emits the empty-table flush exactly as the old code did: the |
| - deliberate carve-out, so the edge's own main process keeps its credentials |
| - while it comes up. A stale latch from a prior PID is dropped first. |
| - |
| -## Why the PID latch (not just "agent not in supervise -> keep drop") |
| - |
| -A blanket "keep the drop whenever the agent is absent from supervise" would |
| -lock the edge out of its own credentials on every restart: the restarted agent |
| -spends its startup window under `carlos-edge.service` (not yet in `supervise`), |
| -where the retained drop would deny it IMDS. The latch distinguishes the two |
| -cases by PID identity — a restart gets a new MainPID (carve-out, fail open), a |
| -child-driven move keeps the same MainPID (fail closed). `/run` is tmpfs, so the |
| -latch resets each boot and the first-boot startup window is always carve-out. |
| - |
| -## Proof |
| - |
| -Dash trace of the decision (mocking the supervise check and `nft`) is in the |
| -task report, all four cases: install / retain (H1-M4) / startup-open / |
| -restart-open. |
diff --git a/infra-proposed/carloku-infra/fence-flat-imds.sh b/infra-proposed/carloku-infra/fence-flat-imds.sh| deleted file mode 100644 |
| index 7d6151427..000000000 |
| --- a/infra-proposed/carloku-infra/fence-flat-imds.sh |
| +++ /dev/null |
| @@ -1,167 +0,0 @@ |
| -#!/bin/bash |
| -# 🤖 Keep flat-tier children of the edge (sidecars, flat and foreign exec |
| -# routes) away from the instance metadata service (security review |
| -# 2026-10-23, finding B1). Flat children run as uid carlos inside |
| -# carlos-edge.service's cgroup, so the carlos_imds uid gate |
| -# (harden-host.sh) lets them through; this table drops IMDS for every socket |
| -# in that cgroup except the edge agent's own `supervise` leaf (whose |
| -# cgroup.procs root takes over, so a child cannot move itself in) and an |
| -# explicit exempt list (empty). |
| -# |
| -# nft resolves a cgroup path to an id when the rule loads, and the edge |
| -# recreates its cgroups when it restarts, so a loop service reloads the table every |
| -# 5 s. A STALE table (an edge restart, or the agent still coming up) fails |
| -# open for lockout-safety: the drop is only installed once the edge's main |
| -# process is confirmed in `supervise`, so the edge can never be locked out of |
| -# its own credentials during startup or a restart. |
| -# |
| -# But an agent that was confirmed in `supervise` and then LEFT it with the |
| -# same PID is not a restart (systemd would report a new MainPID) — it is a |
| -# flat child that moved the agent out of `supervise` to make this refresh tear |
| -# its own drop down (hunt H1-M4). That case now fails CLOSED: the refresh keeps |
| -# the drop the previous cycle installed, so IMDS stays shut to the flat tier. |
| -# The PID latch (/run/carlos-imds-flat.confirmed) is what tells the two apart. |
| -# |
| -# Install on a box (via SSM send-command with this file as the payload), or: |
| -# fence-flat-imds.sh <aws-profile> <region> <instance-id> |
| -# Exempt cgroups (operator-owned flat apps that need the box role) go in |
| -# EXEMPT below, as names under carlos-edge.service. |
| -set -euo pipefail |
| - |
| -if [ $# -ge 3 ]; then |
| - profile=$1; region=$2; instance=$3 |
| - d=$(mktemp -d) |
| - sed -n '/^# ---- box-side ----$/,$p' "$0" > "$d/payload.sh" |
| - jq -n --rawfile s "$d/payload.sh" '{commands: ($s | split("\n"))}' > "$d/params.json" |
| - cmdid=$(aws --profile "$profile" --region "$region" ssm send-command --instance-ids "$instance" \ |
| - --document-name AWS-RunShellScript --parameters "file://$d/params.json" \ |
| - --comment "fence-flat-imds" --query Command.CommandId --output text) |
| - for i in $(seq 1 24); do sleep 5 |
| - s=$(aws --profile "$profile" --region "$region" ssm get-command-invocation --command-id "$cmdid" \ |
| - --instance-id "$instance" --query Status --output text 2>/dev/null || echo Pending) |
| - [ "$s" = Success ] || [ "$s" = Failed ] && break |
| - done |
| - echo "status: $s" |
| - aws --profile "$profile" --region "$region" ssm get-command-invocation --command-id "$cmdid" \ |
| - --instance-id "$instance" --query '[StandardOutputContent,StandardErrorContent]' --output text | tail -20 |
| - rm -rf "$d" |
| - [ "$s" = Success ] |
| - exit 0 |
| -fi |
| - |
| -# ---- box-side ---- |
| -set -e |
| -cat > /usr/local/sbin/carlos-imds-flat-refresh <<'REFRESH' |
| -#!/bin/bash |
| -# Reload table inet carlos_imds_flat (installed by fence-flat-imds.sh). |
| -set -euo pipefail |
| -# Empty since 2026-10-24: the forge app was exempt at first, but its binary |
| -# links no AWS client and never touches IMDS, and any exempt cgroup is one a |
| -# flat child (same uid, delegated cgroupfs) can move itself into. |
| -EXEMPT="" |
| -cg=/sys/fs/cgroup |
| -svc=carlos.slice/carlos-edge.service |
| -sup=$svc/supervise |
| -# state latches the PID we last confirmed in supervise this boot. /run is |
| -# tmpfs, so the latch clears on reboot and the startup carve-out applies afresh |
| -# each boot. It lets this refresh tell a flat child moving the agent OUT of |
| -# supervise (same PID, now absent — H1-M4) from the agent's own startup or a |
| -# restart (a new PID, or none, not yet moved in). |
| -state=/run/carlos-imds-flat.confirmed |
| -main=$(systemctl show -p MainPID --value carlos-edge.service 2>/dev/null || echo 0) |
| - |
| -if [ -d "$cg/$sup" ] && [ "$main" != 0 ] && grep -qx "0::/$sup" "/proc/$main/cgroup" 2>/dev/null; then |
| - mode=install |
| -elif [ -f "$state" ] && [ "$main" != 0 ] && [ "$(cat "$state" 2>/dev/null)" = "$main" ]; then |
| - mode=retain |
| -else |
| - mode=open |
| -fi |
| - |
| -case "$mode" in |
| -retain) |
| - # H1-M4 fail closed. The SAME process we confirmed in supervise this boot is |
| - # still MainPID but has LEFT supervise; a restart would have a new MainPID, |
| - # so a flat child moved the agent out to tear this drop down. Leave the live |
| - # table exactly as the last cycle installed it — the drop stays, IMDS stays |
| - # shut to the flat tier. No nft call: skipping the cycle retains the current |
| - # ruleset. The old script flushed to an empty table here (fail open). |
| - exit 0 |
| - ;; |
| -open) |
| - # Startup / restart carve-out (preserved). MainPID is 0 (stopped), or a NEW |
| - # process that has not yet moved into supervise. Keep the table empty so the |
| - # edge's own main process keeps its credentials while it comes up. Drop a |
| - # stale latch from a prior PID so the next confirmation re-latches the new one. |
| - if [ "$main" != 0 ] && [ -f "$state" ] && [ "$(cat "$state" 2>/dev/null)" != "$main" ]; then |
| - rm -f "$state" |
| - fi |
| - f=$(mktemp) |
| - trap 'rm -f "$f"' EXIT |
| - { |
| - echo "table inet carlos_imds_flat {}" |
| - echo "flush table inet carlos_imds_flat" |
| - } > "$f" |
| - nft -f "$f" |
| - ;; |
| -install) |
| - # The agent writes supervise/cgroup.procs once, to move itself in |
| - # (internal/cgroup/cgroup.go setupAt). After that nothing legitimate |
| - # needs to, so root takes the file: a flat child running as carlos |
| - # can no longer migrate itself into the exempt leaf. Moving OUT of |
| - # supervise (the start-and-move fallback) needs only the destination's |
| - # and the common ancestor's cgroup.procs, which stay carlos-owned — but |
| - # internal/cgroup now fails that fallback closed while the fence is on. |
| - chown root:root "$cg/$sup/cgroup.procs" "$cg/$sup/cgroup.threads" 2>/dev/null || true |
| - chmod 0644 "$cg/$sup/cgroup.procs" "$cg/$sup/cgroup.threads" 2>/dev/null || true |
| - f=$(mktemp) |
| - trap 'rm -f "$f"' EXIT |
| - { |
| - echo "table inet carlos_imds_flat {}" |
| - echo "flush table inet carlos_imds_flat" |
| - echo "table inet carlos_imds_flat {" |
| - echo " chain out {" |
| - echo " type filter hook output priority -1; policy accept;" |
| - for a in "$sup" $(for e in $EXEMPT; do [ -d "$cg/$svc/$e" ] && echo "$svc/$e"; done); do |
| - echo " ip daddr 169.254.169.254 socket cgroupv2 level 3 \"$a\" accept" |
| - echo " ip6 daddr fd00:ec2::254 socket cgroupv2 level 3 \"$a\" accept" |
| - done |
| - echo " ip daddr 169.254.169.254 socket cgroupv2 level 2 \"$svc\" counter drop" |
| - echo " ip6 daddr fd00:ec2::254 socket cgroupv2 level 2 \"$svc\" counter drop" |
| - echo " }" |
| - echo "}" |
| - } > "$f" |
| - nft -f "$f" |
| - # Latch the confirmed PID so a later same-PID exit from supervise is read as |
| - # the H1-M4 escape (retain), not a restart (open). |
| - printf '%s\n' "$main" > "$state" |
| - ;; |
| -esac |
| -REFRESH |
| -chmod 0755 /usr/local/sbin/carlos-imds-flat-refresh |
| - |
| -# A long-running loop rather than a 5 s timer: a timer writes two journal |
| -# lines per run (about 17,000 a day); the loop logs only nft errors. |
| -systemctl disable --now carlos-imds-flat.timer >/dev/null 2>&1 || true |
| -rm -f /etc/systemd/system/carlos-imds-flat.timer |
| -cat > /etc/systemd/system/carlos-imds-flat.service <<'UNIT' |
| -[Unit] |
| -Description=Keep the IMDS fence for flat-tier edge children current (reload every 5 s) |
| -After=nftables.service |
| - |
| -[Service] |
| -Type=simple |
| -ExecStart=/bin/sh -c 'while :; do /usr/local/sbin/carlos-imds-flat-refresh; sleep 5; done' |
| -Restart=always |
| -RestartSec=5 |
| - |
| -[Install] |
| -WantedBy=multi-user.target |
| -UNIT |
| - |
| -systemctl daemon-reload |
| -systemctl enable carlos-imds-flat.service >/dev/null 2>&1 |
| -systemctl restart carlos-imds-flat.service |
| -sleep 2 |
| -echo "service: $(systemctl is-active carlos-imds-flat.service) timer: $(systemctl is-enabled carlos-imds-flat.timer 2>&1 | head -1)" |
| -echo "fence:"; nft list table inet carlos_imds_flat |
diff --git a/infra-proposed/carloku-infra/region-ie.tf b/infra-proposed/carloku-infra/region-ie.tf| deleted file mode 100644 |
| index a9be3039c..000000000 |
| --- a/infra-proposed/carloku-infra/region-ie.tf |
| +++ /dev/null |
| @@ -1,161 +0,0 @@ |
| -# The IE region of the flagship: one Graviton box running `carlos agent`, |
| -# behind an Elastic IP. The box is disposable by construction — all |
| -# durable state is in the buckets — so there is no backup story for hosts |
| -# at all, only for buckets. Residency is enforced in the module: the host |
| -# role reaches the deployment bucket plus ITS OWN region's data bucket |
| -# and nothing else. |
| - |
| -module "host_ie" { |
| - # v0.28.8 for console_mail_from (below); v0.24.1 brought store_scanning. |
| - # The other three regions stay on v0.21.0 until they are rolled |
| - # deliberately. Apply this bump TARGETED at host_console_mail: a whole |
| - # module plan also carries the module's other changes since v0.24.1. |
| - # |
| - # TASK-2 (H1-M2): bump the ref to the first platform tag that carries the |
| - # module's aws_iam_role_policy.host_release_key_deny (TAG TBD — assigned |
| - # when the Task-2 module change is released; shown here as the placeholder |
| - # <RELEASE-KEY-DENY-TAG>). That module change defaults deny_release_key_reads |
| - # to true, so the Deny lands on this IE role on the bump; the line below |
| - # states it explicitly so the intent is visible at the call site. Apply it |
| - # TARGETED at module.host_ie.aws_iam_role_policy.host_release_key_deny — a |
| - # whole-module plan on this box also carries the module's other drift. |
| - source = "git::https://github.com/carlosframework/platform.git//infra/modules/region-host?ref=<RELEASE-KEY-DENY-TAG>" |
| - name = "carlos-flagship-ie" |
| - sg_description = "carlos flagship IE host" |
| - iam_name = "carlos-flagship-host" |
| - instance_type = "t4g.large" |
| - root_volume_size = 60 |
| - user_data = file("${path.module}/host-init.sh") |
| - deployment_bucket_arn = module.buckets.deployment_bucket_arn |
| - data_bucket_arn = module.buckets.data_bucket_arn |
| - ssm_parameter_arn = "arn:aws:ssm:eu-west-1:${local.account}:parameter/carlos/*" |
| - |
| - # Release-key deny (hunt H1-M2). ssm_parameter_arn above is .../carlos/*, |
| - # so /carlos/release-key sits INSIDE the allowed pattern and the managed |
| - # AmazonSSMManagedInstanceCore Allow lets this internet-facing IE box read |
| - # the root release-signing key. This explicit Deny (module default; named |
| - # here for visibility) names the key path by Resource and wins over that |
| - # Allow, leaving every other /carlos/* read the box needs untouched. The |
| - # console reads CARLOS_RELEASE_KEY from its service drop-in and the promote |
| - # scripts fetch the key with an operator profile, so no host loses the key. |
| - deny_release_key_reads = true |
| - |
| - # Object storage (#368/#381). Setting the prefix is what gives THIS box's |
| - # role the provisioning grant and creates the permissions boundary store |
| - # users are made under; the other three regions get none of it, because the |
| - # console is the only thing that provisions. |
| - # |
| - # The prefix is deliberately NOT "carlos-": that also matches this |
| - # deployment's own buckets (carlos-flagship-271376211898), and while the |
| - # module carries an explicit Deny for exactly that overlap, a prefix that |
| - # cannot collide in the first place is the better answer. |
| - store_bucket_prefix = "carlos-store-" |
| - |
| - # Object-storage virus scanning (platform spec 2026-10-04): lets THIS box's |
| - # role read and tag store objects. The console is the only thing that scans. |
| - store_scanning = true |
| - |
| - # Console email (platform spec 2026-10-21 console email sign-in): lets THIS |
| - # box's role send as exactly this address, the console's |
| - # CARLOS_CONSOLE_MAIL_FROM, through the ops account's SES tenant. The |
| - # console signs people in and delivers invitations with it. Paul enabled |
| - # it on 2026-10-21; the identity itself is made by the console (bab, |
| - # referrer console-mail) and its DKIM records live in dns-carloku.tf. |
| - console_mail_from = "noreply@carloku.com" |
| - console_mail_region = "eu-west-1" |
| - |
| - # Instance moves (#331): this box stages a moving instance's data into |
| - # the TARGET region's data bucket: Put/Delete on moves/* only, never |
| - # instances/* and never GetObject (module variable doc). |
| - # IE -> UK first (bdn/ips, 2026-10-01); add a region here before moving |
| - # anything into it. |
| - sibling_staging_arns = [aws_s3_bucket.data_uk.arn] |
| - |
| - # Wildcard-cert DNS-01 against the staged oncarlos.com Route53 zone |
| - # (dns53.tf). CHANGE TO EXISTING INFRASTRUCTURE — the rest of the region |
| - # work is pure addition, this line is not: it adds an inline policy |
| - # (`carlos-flagship-host-route53`) to the LIVE IE host role, so the plan |
| - # shows work inside module.host_ie. It is additive and bounded — the |
| - # module's conditions allow only _acme-challenge.* TXT UPSERT/DELETE in |
| - # this one zone — and it grants nothing until the box actually runs with |
| - # CARLOS_DNS_PROVIDER=route53 against an authoritative zone. The IE box |
| - # keeps issuing through DNSimple until then; this is staging, not a flip. |
| - route53_zone_ids = [aws_route53_zone.oncarlos.zone_id] |
| - |
| - # DNS-steering grant (multi-region ingress stage 5, platform PR #259): |
| - # latency A records + health checks for steered hosts in the oncarlos.com |
| - # zone, name-bound to *.oncarlos.com so the apex A stays out of reach. |
| - # Inert until CARLOS_STEERING_ZONE_ID is set on the box — the converger |
| - # duty is dormant without it. |
| - steering_zone_ids = [aws_route53_zone.oncarlos.zone_id] |
| - steering_record_names = ["*.oncarlos.com"] |
| - |
| - # Cost Explorer read for the economics dashboard's daily bill pull |
| - # (platform PR #171, internal/console/cepull.go): this is the box that |
| - # runs the flagship console, so it gets the account-level ce:GetCostAndUsage |
| - # grant. Per-box flag, off everywhere else; the grant lands on the shared |
| - # host role, so every process on this box can read the account's bill. |
| - enable_cost_explorer = true |
| - |
| - # Memory-low alarm recipient (memory-pressure spec §2.4); alerts.tf |
| - # says why it starts empty. |
| - alerts_email = local.memory_alerts_email |
| - |
| - # Keymail migration (plan K1): the inbound challenge-MX binds :25 directly on |
| - # the box — the edge doesn't speak SMTP. The SG uses in-line rules, so the |
| - # port comes through the module's extra_ingress, never a standalone rule |
| - # resource. Inert until a unit sets KEYMAIL_MX_ADDR; outbound :25 stays |
| - # blocked by AWS (keymail sends via the SES API). |
| - extra_ingress = [{ |
| - description = "smtp (keymail inbound mail bridge MX)" |
| - from_port = 25 |
| - to_port = 25 |
| - protocol = "tcp" |
| - cidr_blocks = ["0.0.0.0/0"] |
| - }] |
| - |
| - # Platform STUN/TURN relay (media roadmap stage 4a, platform spec |
| - # 2026-09-07-relay-stun-turn-design.md §6): opens udp+tcp 3478 and the |
| - # udp 49152-65535 allocation range, inline like extra_ingress above. The |
| - # unit itself only starts once /etc/carlos/relay-masters is staged on |
| - # the box (ConditionPathExists), so this line alone listens for nothing. |
| - # Ireland first; the other regions follow when a tenant needs them. |
| - relay = true |
| -} |
| - |
| -# State surgery from the pre-module layout (refactor 2026-08-01) — pure |
| -# bookkeeping, no real resource is touched. |
| -moved { |
| - from = aws_security_group.host_ie |
| - to = module.host_ie.aws_security_group.host |
| -} |
| - |
| -moved { |
| - from = aws_iam_role.host |
| - to = module.host_ie.aws_iam_role.host |
| -} |
| - |
| -moved { |
| - from = aws_iam_role_policy.host_buckets |
| - to = module.host_ie.aws_iam_role_policy.host_buckets |
| -} |
| - |
| -moved { |
| - from = aws_iam_role_policy_attachment.host_ssm |
| - to = module.host_ie.aws_iam_role_policy_attachment.host_ssm |
| -} |
| - |
| -moved { |
| - from = aws_iam_instance_profile.host |
| - to = module.host_ie.aws_iam_instance_profile.host |
| -} |
| - |
| -moved { |
| - from = aws_instance.host_ie |
| - to = module.host_ie.aws_instance.host |
| -} |
| - |
| -moved { |
| - from = aws_eip.host_ie |
| - to = module.host_ie.aws_eip.host |
| -} |
diff --git a/infra-proposed/platform-infra/bootstrap-box.sh b/infra-proposed/platform-infra/bootstrap-box.sh| deleted file mode 100644 |
| index 2b5a4e8d9..000000000 |
| --- a/infra-proposed/platform-infra/bootstrap-box.sh |
| +++ /dev/null |
| @@ -1,152 +0,0 @@ |
| -#!/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 |
| -set -o pipefail |
| -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 the platform's own verify chain: release.GetSystemPointer -> |
| -# verifySystemPointer/parseSystemPointer checks the Ed25519 signature under the |
| -# root key (internal/release/systempointer.go), the artifact key is |
| -# bootstrap/router/<version>/carlos-<platform> (SystemArtifactKey, |
| -# systempointer.go:88), and the box self-update reads the sha from |
| -# p.Current.Artifacts[platform] of that verified pointer |
| -# (internal/host/systemleg.go:131, installchannel.go:297). Here platform is |
| -# linux-arm64 and channel is stable (the bytes a fresh box boots). |
| -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; } |
| -# Build the DER SubjectPublicKeyInfo (12-byte Ed25519 SPKI header + the 32-byte |
| -# raw key) in python. NOT shell printf: the box runs this under /bin/sh = dash, |
| -# whose printf does not honour \x hex escapes (it would emit the literal text), |
| -# so the DER would be garbage and verification would fail closed on a GENUINE |
| -# binary. python3 is already required above, so this adds no new dependency. |
| -python3 - "\$vdir/pub.raw" "\$vdir/pub.der" <<'PY' || { echo "bootstrap verify: cannot build the release pubkey DER" >&2; exit 1; } |
| -import sys |
| -raw = open(sys.argv[1], "rb").read() |
| -if len(raw) != 32: |
| - sys.exit("release pubkey is not 32 bytes") |
| -open(sys.argv[2], "wb").write(b"\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00" + raw) |
| -PY |
| -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" ] |