From 44ee3cd38e0e1e096784b8c105e041721c6239c0 Mon Sep 17 00:00:00 2001 From: David Hunt Date: Sun, 1 Nov 2026 22:12:13 +0100 Subject: [PATCH] chore: move private-network ops material out of this public repo The VM runbook, migration plan and design, provisioning script, host LaunchAgents and NIC service described a private network (internal addresses, VLAN layout, firewall rules, pg_hba, jump host, SSH users). They now live in the private ops repo (openclaw-config: docs/fos-showcase/ and deploy/fos-showcase/). deploy/deploy.sh no longer carries the VM or jump host as defaults; it reads VM_HOST, JUMP_HOST and VM_PATH from ~/.foscs/fosshowcase/deploy.env next to the secrets it already delivers. env.example and docker-compose.yml no longer embed the database host. The README's Deploying section points at the ops repo for everything VM-specific. --- README.md | 53 +- deploy/com.foscs.postgres-stale-lock.plist | 38 - ...m.foscs.tart-fos-showcase-checkpoint.plist | 33 - deploy/com.foscs.tart-fos-showcase.plist | 24 - deploy/deploy.sh | 27 +- deploy/env.example | 2 +- deploy/nic-offload-off.service | 20 - deploy/postgres-clear-stale-lock.sh | 43 - deploy/provision-vm.sh | 43 - docker-compose.yml | 2 +- docs/runbook-pi-to-vm.md | 790 ------------------ .../plans/2026-06-22-pi-to-vm-migration.md | 483 ----------- .../2026-06-22-pi-to-vm-migration-design.md | 227 ----- 13 files changed, 39 insertions(+), 1746 deletions(-) delete mode 100644 deploy/com.foscs.postgres-stale-lock.plist delete mode 100644 deploy/com.foscs.tart-fos-showcase-checkpoint.plist delete mode 100644 deploy/com.foscs.tart-fos-showcase.plist delete mode 100644 deploy/nic-offload-off.service delete mode 100755 deploy/postgres-clear-stale-lock.sh delete mode 100755 deploy/provision-vm.sh delete mode 100644 docs/runbook-pi-to-vm.md delete mode 100644 docs/superpowers/plans/2026-06-22-pi-to-vm-migration.md delete mode 100644 docs/superpowers/specs/2026-06-22-pi-to-vm-migration-design.md diff --git a/README.md b/README.md index e901f15..a105489 100644 --- a/README.md +++ b/README.md @@ -48,53 +48,36 @@ FOSShowcaseiOSApp is a cross-platform [SwiftUI](https://developer.apple.com/xcod ## Deploying -The public web service (Vapor backend + Ignite web app, behind nginx) runs as a -Docker Compose stack on an **isolated Tart Linux VM** (`fos-showcase`, `10.1.3.10`) -on the `fos-openclaw` host, on the UniFi "Public Servers" VLAN-3 DMZ. The repo is -the source of truth and the VM is disposable. Full architecture, network rules, and -the rebuild procedure are in [`docs/runbook-pi-to-vm.md`](docs/runbook-pi-to-vm.md). +The public web service (Vapor backend + Leaf web app, behind nginx) runs as a +Docker Compose stack on a small private Linux VM. The repo is the source of +truth and the VM is disposable: rebuilding from the repo is the recovery path. + +Where the VM is, how it is reached, how it was built, and the network rules +around it are **not in this repository**. They live in the private ops repo +(`openclaw-config`: `docs/fos-showcase/runbook-pi-to-vm.md` and +`deploy/fos-showcase/`). ### Routine deploy (code / config change) -Run from a machine that has the canonical secrets at `~/.foscs/fosshowcase/{.env,ssl/}`: +Run from a machine that has the canonical secrets at `~/.foscs/fosshowcase/` +(`.env`, `ssl/`, and `deploy.env` naming the VM): ```bash git commit ... # commit your change first ./deploy/deploy.sh ``` -`deploy/deploy.sh` ProxyJumps through the `fos-openclaw` host (the VM's DMZ VLAN is -reachable only via the host), then: - -1. rsyncs the repo to `/opt/fosshowcase` on the VM, -2. delivers `.env` + `ssl/` (mode 600), and -3. runs `docker compose up -d --build` and prints `docker compose ps`. +`deploy/deploy.sh` rsyncs the repo to the VM, delivers `.env` + `ssl/` +(mode 600), builds the three images one at a time (the VM is small), and runs +`docker compose up -d`. Notes: -- A deploy **rebuilds both Swift apps** (~20–40 min) — the Dockerfiles `COPY` the - whole repo, so any change invalidates the shared build cache. -- Secrets and TLS certs are **not** in git; they live at `~/.foscs/fosshowcase/` and - are pushed at deploy time. `deploy/env.example` documents the required variables. -- Override targets via env: `VM_HOST`, `JUMP_HOST` (set `JUMP_HOST=""` to deploy - directly when already on the internal network), `SRC_SECRETS`. - -### Full VM rebuild (disposable VM) - -If the VM is lost, rebuild from the runbook: - -1. `deploy/provision-vm.sh` — create the Tart VM on VLAN 3 (`VLAN_IFACE=vlan1`), -2. in-guest provisioning (static IP, Docker, NTP, `deploy/nic-offload-off.service`, SSH hardening), -3. install the host LaunchAgent (`deploy/com.foscs.tart-fos-showcase.plist`) so the VM - auto-starts on reboot, then -4. `deploy/deploy.sh`. - -Network and database authorization (UDM port-forward + firewall, Postgres `pg_hba`) -is permanent and managed in the `openclaw-config` repo — it does not need redoing -per deploy. - -The VM keeps **no backups by design** — rebuilding from the repo *is* the recovery path, -and the `fos-openclaw` host is covered by Time Machine. See runbook Section 7. +- A deploy **rebuilds both Swift apps** (the Dockerfiles `COPY` the whole repo, + so any change invalidates the build cache); expect 30+ minutes. +- Secrets, TLS certs and the VM address are **not** in git. `deploy/env.example` + documents the required application variables; `deploy.env` holds `VM_HOST` + and optionally `JUMP_HOST` / `VM_PATH`. ## Maintainers diff --git a/deploy/com.foscs.postgres-stale-lock.plist b/deploy/com.foscs.postgres-stale-lock.plist deleted file mode 100644 index f7c2a78..0000000 --- a/deploy/com.foscs.postgres-stale-lock.plist +++ /dev/null @@ -1,38 +0,0 @@ - - - - - Label - com.foscs.postgres-stale-lock - - - ProgramArguments - - /bin/bash - /Users/david/.foscs/scripts/postgres-clear-stale-lock.sh - - - RunAtLoad - - - StartInterval - 300 - - StandardOutPath - /Users/david/.foscs/postgres-stale-lock.log - - StandardErrorPath - /Users/david/.foscs/postgres-stale-lock.log - - EnvironmentVariables - - PATH - /usr/bin:/bin:/usr/sbin:/sbin - HOME - /Users/david - - - diff --git a/deploy/com.foscs.tart-fos-showcase-checkpoint.plist b/deploy/com.foscs.tart-fos-showcase-checkpoint.plist deleted file mode 100644 index 03f2b9c..0000000 --- a/deploy/com.foscs.tart-fos-showcase-checkpoint.plist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - Label - com.foscs.tart-fos-showcase-checkpoint - ProgramArguments - - /Users/david/.foscs/scripts/tart-daily-checkpoint.sh - fos-showcase - - EnvironmentVariables - - PATH - /opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin - RETENTION_COUNT - 7 - - StartCalendarInterval - - Hour - 2 - Minute - 30 - - StandardOutPath - /tmp/tart-fos-showcase-checkpoint.out.log - StandardErrorPath - /tmp/tart-fos-showcase-checkpoint.err.log - RunAtLoad - - - diff --git a/deploy/com.foscs.tart-fos-showcase.plist b/deploy/com.foscs.tart-fos-showcase.plist deleted file mode 100644 index b763eda..0000000 --- a/deploy/com.foscs.tart-fos-showcase.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - Label - com.foscs.tart-fos-showcase - ProgramArguments - - /opt/homebrew/bin/tart - run - fos-showcase - --net-bridged=REPLACE_WITH_VLAN3_INTERFACE - --no-graphics - - KeepAlive - - RunAtLoad - - StandardOutPath - /tmp/tart-fos-showcase.out.log - StandardErrorPath - /tmp/tart-fos-showcase.err.log - - diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 8a812b3..206c17c 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -2,15 +2,26 @@ set -euo pipefail # Deliver secrets/certs/repo to the fos-showcase VM and (re)deploy the stack. -# The VM is on the isolated "Public Servers" VLAN (zone Web Servers), reachable -# only via the fos-openclaw host — so we ProxyJump through it. Set JUMP_HOST="" -# to connect directly (e.g. from a machine already in the Internal zone). +# +# Where the VM is, and how to reach it, is private network detail and is NOT +# in this public repo. It comes from $SRC_SECRETS/deploy.env (mode 600), next +# to the .env and ssl/ this script already delivers: +# +# VM_HOST=user@vm-address # required +# JUMP_HOST=user@bastion-address # optional; empty = connect directly +# VM_PATH=/opt/fosshowcase # optional +# +# The runbook (VM build, network rules, recovery) lives in the private ops repo. + +SRC_SECRETS="${SRC_SECRETS:-$HOME/.foscs/fosshowcase}" # canonical .env + ssl/ + deploy.env +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" -VM_HOST="${VM_HOST:-admin@10.1.3.10}" +[ -f "$SRC_SECRETS/deploy.env" ] || { echo "Missing $SRC_SECRETS/deploy.env (VM_HOST, optional JUMP_HOST/VM_PATH)"; exit 1; } +# shellcheck disable=SC1091 +. "$SRC_SECRETS/deploy.env" +: "${VM_HOST:?deploy.env must set VM_HOST}" VM_PATH="${VM_PATH:-/opt/fosshowcase}" -SRC_SECRETS="${SRC_SECRETS:-$HOME/.foscs/fosshowcase}" # canonical .env + ssl/ source -REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" -JUMP_HOST="${JUMP_HOST:-david@10.1.2.158}" # fos-openclaw; set "" to disable ProxyJump +JUMP_HOST="${JUMP_HOST:-}" SSH_OPTS=(-o StrictHostKeyChecking=accept-new) [ -n "$JUMP_HOST" ] && SSH_OPTS+=(-J "$JUMP_HOST") SSH_CMD="ssh -o StrictHostKeyChecking=accept-new${JUMP_HOST:+ -J $JUMP_HOST}" @@ -37,7 +48,7 @@ rsync -az -e "$SSH_CMD" "$SRC_SECRETS/.env" "$VM_HOST:$VM_PATH/.env" rsync -az -e "$SSH_CMD" "$SRC_SECRETS/ssl/" "$VM_HOST:$VM_PATH/ssl/" ssh "${SSH_OPTS[@]}" "$VM_HOST" "chmod 600 $VM_PATH/.env && chmod 600 $VM_PATH/ssl/*.key" -# Build the images ONE AT A TIME. The VM has 2 vCPUs / 3.9 GB; `up --build` +# Build the images ONE AT A TIME. The VM is small (2 vCPUs / 4 GB); `up --build` # compiles both Swift apps in parallel and each release build spawns ~1.6 GB # swift-frontend processes, so the kernel OOM-killer took the build (and sshd) # out on 2026-11-01. Sequential builds fit; the swap of running containers is diff --git a/deploy/env.example b/deploy/env.example index a234a9d..9525dd3 100644 --- a/deploy/env.example +++ b/deploy/env.example @@ -8,7 +8,7 @@ # lines, like these. LOG_LEVEL=info -DATABASE_HOST=10.1.2.158 +DATABASE_HOST= # openclaw_webhook role password (= OPENCLAW_WEBHOOK_PASSWORD in ~/.openclaw/.env) POSTGRES_WEBHOOK_PASSWORD=__set_me__ diff --git a/deploy/nic-offload-off.service b/deploy/nic-offload-off.service deleted file mode 100644 index f82369e..0000000 --- a/deploy/nic-offload-off.service +++ /dev/null @@ -1,20 +0,0 @@ -[Unit] -# Tart bridged-VLAN throughput fix. -# The virtio NIC's TX segmentation offload (TSO/GSO) produces oversized/bad -# segments on the bridged tagged-VLAN path, collapsing UPLOAD throughput -# (~0.7 MB/s) while download stays fast — so served images/pages crawl. -# Disabling offloads forces in-guest segmentation and restores full speed -# (tested: 55-75 MB/s up, 23 MB/s down). Install on the fos-showcase VM: -# sudo cp deploy/nic-offload-off.service /etc/systemd/system/ -# sudo systemctl enable --now nic-offload-off.service -Description=Disable TSO/GSO/GRO on enp0s1 (Tart bridged-VLAN TX throughput fix) -After=network-online.target -Wants=network-online.target - -[Service] -Type=oneshot -ExecStart=/usr/sbin/ethtool -K enp0s1 tso off gso off gro off -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target diff --git a/deploy/postgres-clear-stale-lock.sh b/deploy/postgres-clear-stale-lock.sh deleted file mode 100755 index f11e783..0000000 --- a/deploy/postgres-clear-stale-lock.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# Remove a stale PostgreSQL postmaster.pid left behind by an unclean host -# shutdown, so the Homebrew launchd service can start on the next retry. -# -# Why: on 2026-10-06 a macOS upgrade reboot killed postgres mid "smart -# shutdown". After reboot the PID recorded in postmaster.pid belonged to an -# unrelated Apple XPC service, so postgres refused to start ("lock file -# already exists") every 10 s until the file was removed by hand. The -# showcase server container crash-looped on "connection refused" meanwhile. -# -# Safe by construction: the file is only moved aside when -# 1. no process with that PID exists, OR the process is not postgres, AND -# 2. nothing is listening on the cluster's port. -# The file is renamed, not deleted, so it can be inspected afterwards. -# -# Installed on fos-openclaw as ~/.foscs/scripts/postgres-clear-stale-lock.sh, -# run by ~/Library/LaunchAgents/com.foscs.postgres-stale-lock.plist. - -PGDATA="${PGDATA:-/opt/homebrew/var/postgresql@18}" -PIDFILE="$PGDATA/postmaster.pid" - -log() { printf '%s %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"; } - -[ -f "$PIDFILE" ] || exit 0 - -PID="$(sed -n 1p "$PIDFILE" | tr -d '[:space:]')" -PORT="$(sed -n 4p "$PIDFILE" | tr -d '[:space:]')" -PORT="${PORT:-5432}" - -if [[ "$PID" =~ ^[0-9]+$ ]] && ps -p "$PID" -o comm= 2>/dev/null | grep -q 'postgres'; then - exit 0 # live postmaster owns the lock -fi - -if lsof -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1; then - log "postmaster.pid PID $PID is not postgres but port $PORT is in use; leaving the file alone" - exit 0 -fi - -STALE="$PIDFILE.stale-$(date '+%Y%m%d-%H%M%S')" -mv "$PIDFILE" "$STALE" -log "moved stale postmaster.pid (PID $PID not a running postgres) to $STALE; launchd will retry postgres" diff --git a/deploy/provision-vm.sh b/deploy/provision-vm.sh deleted file mode 100755 index a5d6019..0000000 --- a/deploy/provision-vm.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -set -euo pipefail - -# Provision the fos-showcase Tart VM on the VLAN-3 "Public Servers" DMZ. -# Run ON fos-openclaw (Tart host). Idempotent where practical. -# -# Prereqs handled in the runbook BEFORE this runs: -# - VLAN 3 trunked to the host's switch port -# - DHCP reservation OR pool-exclusion for 10.1.3.10 on the UDM Pro - -VM_NAME="${VM_NAME:-fos-showcase}" -BASE_IMAGE="${BASE_IMAGE:-ghcr.io/cirruslabs/ubuntu:24.04}" -VM_CPU="${VM_CPU:-2}" -VM_MEM="${VM_MEM:-6144}" # MB; headroom for the Swift release build -VM_DISK="${VM_DISK:-32}" # GB -# REQUIRED: the exact interface token from `tart run --net-bridged=list` on the host. -# A VLAN-3 tagged interface is NOT a friendly name — discover/create it first (runbook §1). -VLAN_IFACE="${VLAN_IFACE:?set VLAN_IFACE to the exact token from 'tart run --net-bridged=list'}" -TART_BIN="${TART_BIN:-tart}" - -command -v "$TART_BIN" >/dev/null || { echo "tart not found"; exit 1; } - -if "$TART_BIN" list --quiet | grep -qx "$VM_NAME"; then - echo "VM $VM_NAME already exists — skipping clone." -else - echo "Cloning $BASE_IMAGE -> $VM_NAME" - "$TART_BIN" clone "$BASE_IMAGE" "$VM_NAME" -fi - -"$TART_BIN" set "$VM_NAME" --cpu "$VM_CPU" --memory "$VM_MEM" -# --disk-size only GROWS a disk; setting it <= the base image's size errors. Apply -# best-effort, then verify+grow the guest filesystem in-guest (Task 9: growpart/resize2fs). -"$TART_BIN" set "$VM_NAME" --disk-size "$VM_DISK" \ - || echo " (disk already >= ${VM_DISK}G or set skipped — verify with 'df -h' in-guest)" - -echo "Starting $VM_NAME bridged to '$VLAN_IFACE' (run under launchd/tmux for persistence in prod)" -echo " $TART_BIN run \"$VM_NAME\" --net-bridged=\"$VLAN_IFACE\" --no-graphics &" -echo "" -echo "After boot, finish in-guest provisioning via SSH (see provision-guest snippet in runbook):" -echo " - netplan static 10.1.3.10/24 gw 10.1.3.1" -echo " - Docker CE + docker-compose-plugin from download.docker.com (arm64)" -echo " - enable systemd-timesyncd (clock-sensitive HMAC/TLS)" -echo " - 8 GB swapfile (Swift release builds OOM the 4 GB guest without it; runbook 3b step 4b)" diff --git a/docker-compose.yml b/docker-compose.yml index 2f2e818..943ed46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,7 +62,7 @@ services: dockerfile: Dockerfile-server environment: <<: *shared_environment - DATABASE_HOST: ${DATABASE_HOST:-10.1.2.158} + DATABASE_HOST: ${DATABASE_HOST:?set in .env} DATABASE_PORT: 5432 DATABASE_NAME: foscs DATABASE_USER: openclaw_webhook diff --git a/docs/runbook-pi-to-vm.md b/docs/runbook-pi-to-vm.md deleted file mode 100644 index f4a75eb..0000000 --- a/docs/runbook-pi-to-vm.md +++ /dev/null @@ -1,790 +0,0 @@ -# Runbook: Pi → VM Cutover (FOSShowcase) - -**Branch:** `migration/pi-to-vm` -**Date:** 2026-06-22 -**Spec:** `docs/superpowers/specs/2026-06-22-pi-to-vm-migration-design.md` -**Plan:** `docs/superpowers/plans/2026-06-22-pi-to-vm-migration.md` - -## Summary - -Move the FOSShowcase Docker Compose stack (nginx/client/server) off the decommissioned Raspberry Pi -onto an isolated Tart Linux VM on fos-openclaw (`10.1.2.158`). The VM sits on VLAN 3 "Public Servers" -(`10.1.3.10`), connects directly to the `foscs` Postgres database (no SSH tunnel), and is exposed -publicly on ports 80/443 only. - -**There is no Pi fallback.** The Pi is gone. Do not flip the WAN port-forward until internal -validation on `10.1.3.10` passes in full. - -### Quick-reference: key values - -| Item | Value | -|---|---| -| Tart host | fos-openclaw, `10.1.2.158` (Apple Silicon Mac Mini) | -| VM name | `fos-showcase` | -| VM OS | Ubuntu 24.04 (noble) arm64 | -| VM IP | `10.1.3.10/24`, gateway `10.1.3.1` | -| VLAN | 3 "Public Servers", UDM Pro zone "Web Servers" (Isolate Network = on) | -| DHCP pool | `10.1.3.6–254` — EXCLUDE `.10` (VM is static; reservation is not enough) | -| Database | `foscs` on `10.1.2.158:5432` | -| DB runtime role | `openclaw_webhook` | -| DB migration role | `openclaw_admin` | -| psql binary | `/opt/homebrew/opt/postgresql@18/bin/psql` | -| Cert filenames | `foscomputerservices.com.crt` / `foscomputerservices.com.key` (hardcoded in nginx.conf) | -| Canonical secrets/certs | `~/.foscs/fosshowcase/{.env,ssl/}` on the dev Mac (mode 600) | -| VM repo path | `/opt/fosshowcase` | -| VM admin user | `admin` | - ---- - -## Section 1: Infra Prerequisites (UDM Pro) - -### 1a. VLAN 3 trunk to the host switch port - -VLAN 20 is already trunked to fos-openclaw's switch port (proven by `openclaw-vm`). VLAN 3 is -**not** confirmed. Trunk it before provisioning — if the VM can't ARP `10.1.3.1`, it has no network -and all subsequent steps fail silently. - -**UDM Pro steps:** -1. In the UniFi Network UI, go to Settings → Networks and verify "Public Servers" exists as VLAN 3. -2. Go to Devices → fos-openclaw's switch → Port configuration. Ensure the port profile includes - VLAN 3 as a tagged (trunk) VLAN. -3. Apply and wait for the switch to update. - -**Discover the VLAN-3 interface token on fos-openclaw** (run this on the host, not in the VM): - -```bash -# On fos-openclaw: -tart run --net-bridged=list -``` - -Look for an interface tagged with VLAN 3. If it does not appear, create a macOS VLAN interface: - -```bash -# On fos-openclaw — create a VLAN 3 interface on the NIC (replace en0 with the actual NIC name): -# Find the real NIC: networksetup -listallhardwareports -sudo networksetup -createVLAN "VLAN3-PublicServers" en0 3 -# Verify it appears: -tart run --net-bridged=list -``` - -Record the **exact** token (it may look like `en0.3` or the VLAN service name). You will use this -value in every subsequent command that references `VLAN_IFACE`. - -```bash -# Set it for the rest of this session: -export VLAN_IFACE="" # e.g. en0.3 -``` - -### 1b. DHCP pool exclusion for 10.1.3.10 - -The VM uses a **static** netplan address (`10.1.3.10`). A DHCP reservation is not sufficient — -another device could receive `.10` before the reservation kicks in. You must exclude `.10` from the -pool. - -**UDM Pro steps:** -1. Go to Settings → Networks → "Public Servers" (VLAN 3). -2. Change the DHCP start address from `10.1.3.6` to `10.1.3.11` (shrinking the pool so `.10` is - never leased). - — **or** — configure a static IP exclusion for `10.1.3.10` if your UDM Pro firmware supports it. -3. Apply. - -**Confirm `.10` is free before bringing up the VM:** - -```bash -# From any host on the VLAN-3 segment or from the UDM Pro: -ping -c 3 10.1.3.10 # must be 100% packet loss -arping -c 3 10.1.3.10 # must show "no reply" -``` - -If either responds, find and shut down whatever owns that address before proceeding. - -### 1c. SAN cert generation - -The current cert is wildcard-only (`*.foscomputerservices.com`); it does **not** cover the apex -`foscomputerservices.com`. Reissue a SAN cert covering **both** the apex and the wildcard. The cert -expires 2026-07-20 — reissue now. - -**Required filenames (hardcoded in nginx.conf — do not rename):** -- `foscomputerservices.com.crt` -- `foscomputerservices.com.key` - -**Generate with Let's Encrypt (certbot DNS challenge, run on the dev Mac or any internet-connected -host):** - -```bash -# Replace YOUR_EMAIL with your actual email: -certbot certonly \ - --manual \ - --preferred-challenges dns \ - -d foscomputerservices.com \ - -d '*.foscomputerservices.com' \ - --agree-tos \ - -m YOUR_EMAIL - -# After issuance, copy to the canonical location with the exact required names: -mkdir -p ~/.foscs/fosshowcase/ssl -cp /etc/letsencrypt/live/foscomputerservices.com/fullchain.pem \ - ~/.foscs/fosshowcase/ssl/foscomputerservices.com.crt -cp /etc/letsencrypt/live/foscomputerservices.com/privkey.pem \ - ~/.foscs/fosshowcase/ssl/foscomputerservices.com.key -chmod 600 ~/.foscs/fosshowcase/ssl/foscomputerservices.com.key -``` - -**Verify the SAN before proceeding (both entries must appear):** - -```bash -openssl x509 \ - -in ~/.foscs/fosshowcase/ssl/foscomputerservices.com.crt \ - -noout -ext subjectAltName -# Expected output must include both: -# DNS:foscomputerservices.com -# DNS:*.foscomputerservices.com -``` - ---- - -## Section 2: Firewall Rules (Web Servers Zone — Exactly Three Holes) - -Configure these in the UDM Pro before deploying, but **leave the WAN port-forward OFF** until -internal validation (Section 5) passes. - -### Hole 1: Egress — VM to PostgreSQL only - -Allow the VM to reach the database and nothing else internally. - -**UDM Pro: Settings → Firewall & Security → Rules → LAN** - -Create a rule in the "Web Servers" zone (or as a traffic rule from VLAN 3): - -| Field | Value | -|---|---| -| Action | Accept | -| Source | `10.1.3.10/32` | -| Destination | `10.1.2.158`, port `5432`, protocol TCP | -| Description | `fos-showcase → foscs PostgreSQL` | - -Then add a default-deny rule for all other VM egress to internal zones (VLAN 3's "Isolate Network" -setting handles this, but explicitly confirm that inter-VLAN traffic from `10.1.3.0/24` is blocked -by default. If you have a catch-all LAN→LAN block rule, the accept rule above must be ordered -**above** it). - -### Hole 2: Ingress — WAN 80/443 only (NO 8081) - -This is a two-part configuration: a port-forward and a firewall allow. - -**Stage the port-forward — but do NOT enable it yet:** - -| Field | Value | -|---|---| -| Enabled | OFF (enable only after internal validation) | -| Protocol | TCP | -| WAN port(s) | 80, 443 | -| Forward IP | `10.1.3.10` | -| Forward port(s) | 80, 443 | -| Description | `FOSShowcase public ingress` | - -**Firewall allow (WAN → Web Servers zone):** - -| Field | Value | -|---|---| -| Action | Accept | -| Source | WAN / any | -| Destination | `10.1.3.10`, ports `80, 443` | -| Description | `WAN → fos-showcase HTTP/HTTPS` | - -Port 8081 is deliberately excluded. The 8081 listener runs inside the VM (reachable on the VLAN) -but is not forwarded to the internet — the native-app backend API is out of scope for this migration. - -### Hole 3: Management — Local LAN(s) to VM SSH only - -Allow SSH from your administrative LAN(s) to the VM. **Never expose port 22 to the WAN.** - -| Field | Value | -|---|---| -| Action | Accept | -| Source | Local LAN CIDR(s) (e.g. `10.1.2.0/24`, `10.1.20.0/24`) | -| Destination | `10.1.3.10`, port `22`, protocol TCP | -| Description | `Local LAN → fos-showcase SSH management` | - ---- - -## Section 3: In-Guest Provisioning - -### 3a. First-boot access - -After Tart clones and starts the VM with bridged networking (`--net-bridged=$VLAN_IFACE`), the VM -boots with a default Ubuntu 24.04 image. Find its initial IP (DHCP, not yet static) from the Tart -console or the UDM Pro DHCP leases, then SSH in: - -```bash -# Default credentials for the ghcr.io/cirruslabs/ubuntu:24.04 image: -# user: admin password: admin -ssh admin@ -``` - -Once you're in, run the following provisioning block. The commands are ordered and can be pasted as -one block into the SSH session. - -### 3b. In-guest provisioning commands (copy-paste block) - -```bash -# ============================================================ -# FOSShowcase VM in-guest provisioning -# Run as: admin@ -# ============================================================ - -# --- 1. Static network (netplan) --- -# Discover the primary NIC name (Tart Ubuntu guests are often enp0s1, not eth0): -IFACE=$(ip -o link show | awk -F': ' '$2 != "lo"{print $2; exit}') -echo "Primary interface: $IFACE" # substitute this name in the netplan below - -# Replace in the heredoc with the value printed above before applying: -sudo tee /etc/netplan/01-static.yaml > /dev/null </dev/null || true - -sudo netplan apply -# After this, your SSH session may drop. Reconnect on 10.1.3.10: -# ssh admin@10.1.3.10 - -# --- 2. NTP (clock-sensitive: HMAC signatures + TLS certificates) --- -sudo systemctl enable --now systemd-timesyncd -timedatectl set-ntp true -timedatectl status # confirm: "System clock synchronized: yes" - -# --- 2b. NIC offload fix (REQUIRED for throughput) --- -# On the Tart bridged tagged-VLAN path, the virtio NIC's TX segmentation -# offload collapses UPLOAD throughput (~0.7 MB/s) — served pages/images crawl -# while downloads stay fast. Disable offloads via a persistent unit. -# (deploy/nic-offload-off.service in this repo; ethtool ships with Ubuntu.) -sudo apt-get install -y ethtool -sudo cp /opt/fosshowcase/deploy/nic-offload-off.service /etc/systemd/system/ -sudo systemctl daemon-reload -sudo systemctl enable --now nic-offload-off.service -ethtool -k enp0s1 | grep -E 'tcp-segmentation-offload:|generic-segmentation-offload:' # both: off -# Verify upload speed from another LAN host (expect tens of MB/s, not ~0.7): -# curl -s --resolve foscomputerservices.com:443:10.1.3.10 -o /dev/null \ -# -w '%{speed_download}\n' 'https://foscomputerservices.com/Images/Landing%20Page/About@3x.png' - -# --- 3. Docker CE + docker-compose-plugin (official repo, arm64) --- -# Ubuntu's docker.io package does NOT ship docker compose v2 — use Docker's own repo. -sudo apt-get update -sudo apt-get install -y ca-certificates curl gnupg - -sudo install -m 0755 -d /etc/apt/keyrings -curl -fsSL https://download.docker.com/linux/ubuntu/gpg \ - | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg -sudo chmod a+r /etc/apt/keyrings/docker.gpg - -echo \ - "deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.gpg] \ - https://download.docker.com/linux/ubuntu \ - $(lsb_release -cs) stable" \ - | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null - -sudo apt-get update -sudo apt-get install -y \ - docker-ce \ - docker-ce-cli \ - containerd.io \ - docker-buildx-plugin \ - docker-compose-plugin - -# Add admin user to the docker group (no sudo needed for docker commands): -sudo usermod -aG docker admin -newgrp docker # applies in this session; new sessions pick it up automatically - -# Verify: -docker compose version # must print v2.x - -# --- 4. Disk expansion (if rootfs didn't auto-expand to the full 32 GB) --- -df -h / -# If /dev/sda or /dev/vda shows < 30 GB, expand it: -# (adjust /dev/sda1 to the actual root partition from 'lsblk') -sudo apt-get install -y cloud-guest-utils -sudo growpart /dev/sda 1 -sudo resize2fs /dev/sda1 -df -h / # should now show ~30 GB - -# --- 4b. Swap (REQUIRED for deploys) --- -# The VM has 4 GB RAM and a Swift release build (whole-module optimization) -# runs swift-frontend processes above that; on 2026-11-01 the kernel -# OOM-killer ended the build, sshd and DNS. 8 GB of swap lets the build -# finish (slower while it spills, but it completes). deploy.sh also builds -# the images one at a time and the Dockerfiles pass --jobs 1. -sudo fallocate -l 8G /swapfile -sudo chmod 600 /swapfile -sudo mkswap /swapfile -sudo swapon /swapfile -echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab > /dev/null -swapon --show # expect /swapfile 8G - -# --- 5. SSH hardening --- -# Install your public key: -mkdir -p ~/.ssh && chmod 700 ~/.ssh -# Paste your public key (from the dev Mac: cat ~/.ssh/id_ed25519.pub or similar): -echo "PASTE_YOUR_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys -chmod 600 ~/.ssh/authorized_keys - -# Disable password authentication and root login. -# DO NOT edit /etc/ssh/sshd_config with sed: Ubuntu's `Include sshd_config.d/*.conf` -# runs first and cloud-init writes a root-only 50-cloud-init.conf that says -# "PasswordAuthentication yes". sshd keeps the FIRST value it reads, so a -# drop-in that sorts before it is the only edit that sticks. (On 2026-11-01 -# the VM was found with password login still enabled for this reason.) -sudo rm -f /etc/ssh/sshd_config.d/50-cloud-init.conf -printf 'PasswordAuthentication no\nPermitRootLogin no\n' \ - | sudo tee /etc/ssh/sshd_config.d/00-hardening.conf > /dev/null -sudo sshd -t && sudo systemctl reload ssh - -# Verify the EFFECTIVE policy, not the file you wrote: -sudo sshd -T | grep -iE '^(passwordauthentication|permitrootlogin) ' -# expect: passwordauthentication no / permitrootlogin no - -# Replace the base image's default password (admin/admin, documented in 3a, -# and this runbook is public). Keep a password so the Tart console still -# works for recovery; store it at ~/.foscs/fosshowcase/vm-admin-password on -# the dev Mac (mode 600). -sudo passwd admin - -# Verify SSH key auth before closing this session: -# Open a second terminal: ssh admin@10.1.3.10 -# Confirm it logs in without a password prompt, and that -# ssh -o PubkeyAuthentication=no admin@10.1.3.10 -# is refused with "Permission denied (publickey)". Then close this window. - -# --- 6. Create repo directory --- -sudo mkdir -p /opt/fosshowcase -sudo chown admin:admin /opt/fosshowcase - -echo "=== In-guest provisioning complete ===" -echo "Reconnect via: ssh admin@10.1.3.10" -``` - -### 3c. Post-provisioning checks (run from the VM) - -```bash -# Run these from inside the VM after reconnecting on 10.1.3.10: - -# Network identity: -ip a show # must show 10.1.3.10/24 (replace with the discovered NIC name, e.g. enp0s1) -ping -c 2 10.1.3.1 # gateway reachable (ARP works) -ping -c 2 1.1.1.1 # internet reachable - -# Clock: -timedatectl | grep -E "synchronized|NTP" - -# Docker: -docker compose version # must print v2.x - -# Disk: -df -h / # must show ~30 GB available -``` - -### 3d. Install the VM run LaunchAgent on fos-openclaw (host) - -The VM must start automatically and stay up across host reboots. The LaunchAgent lives in this repo -at `deploy/com.foscs.tart-fos-showcase.plist`. Before installing it, substitute the real VLAN-3 -interface token you discovered in Section 1a. - -```bash -# On fos-openclaw (run from the dev Mac via SSH, or directly on the host): - -# 1. Edit the plist to insert the real interface token: -# Replace REPLACE_WITH_VLAN3_INTERFACE with $VLAN_IFACE (e.g. en0.3) -# in deploy/com.foscs.tart-fos-showcase.plist (already cloned here) - -# 2. Copy to LaunchAgents: -cp /path/to/FOSShowcase/deploy/com.foscs.tart-fos-showcase.plist \ - ~/Library/LaunchAgents/ - -# 3. Load (starts immediately and survives reboots): -launchctl load ~/Library/LaunchAgents/com.foscs.tart-fos-showcase.plist - -# 4. Confirm the VM is running: -tart list | grep fos-showcase # shows "running" -``` - -### 3e. Install the Postgres stale-lock LaunchAgent on fos-openclaw (host) - -An unclean host shutdown (an OS upgrade reboot, a power cut) can kill postgres mid-shutdown and leave `postmaster.pid` behind. After reboot the recorded PID may belong to an unrelated process, so Homebrew's `postgresql@18` service refuses to start ("lock file already exists") every 10 s forever, and the showcase `server` container crash-loops on `connection refused`. This happened on 2026-10-06 after the macOS 27.0.1 upgrade. - -`deploy/postgres-clear-stale-lock.sh` moves the lock aside only when the PID is not a running postgres **and** nothing is listening on the cluster port. `deploy/com.foscs.postgres-stale-lock.plist` runs it at login/boot and every 5 minutes; it is a silent no-op while postgres is healthy. - -```bash -# On fos-openclaw: -cp /path/to/FOSShowcase/deploy/postgres-clear-stale-lock.sh ~/.foscs/scripts/ -chmod +x ~/.foscs/scripts/postgres-clear-stale-lock.sh -cp /path/to/FOSShowcase/deploy/com.foscs.postgres-stale-lock.plist ~/Library/LaunchAgents/ -launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.foscs.postgres-stale-lock.plist - -# Confirm (exit status 0, and the log is empty while postgres is healthy): -launchctl list | grep com.foscs.postgres-stale-lock -cat ~/.foscs/postgres-stale-lock.log -``` - -Manual recovery, if you ever need it before the agent runs: - -```bash -pgrep -x postgres || mv /opt/homebrew/var/postgresql@18/postmaster.pid{,.stale} -brew services restart postgresql@18 -tail /opt/homebrew/var/log/postgresql@18.log # expect "database system is ready to accept connections" -``` - ---- - -## Section 4: Live pg_hba Apply (No Restart) - -The production `foscs` database on fos-openclaw must accept connections from `10.1.3.10`. Do this -with a **reload** — not a restart, and do **not** run `setup-postgres.sh` on the production database -(its step 4 does `brew services restart postgresql@18`, which bounces production). - -```bash -# On fos-openclaw (the database host): -PG_HBA="$(psql_bin -U postgres -t -c "SHOW hba_file;" | tr -d ' ')" -# Or find it manually — typically: -# /opt/homebrew/var/postgresql@18/pg_hba.conf - -# Use the full psql path (not in PATH by default): -PSQL=/opt/homebrew/opt/postgresql@18/bin/psql - -# 1. Confirm the line isn't already there: -grep "10.1.3.10" /opt/homebrew/var/postgresql@18/pg_hba.conf || true - -# 2. Append the new /32 grant: -echo "host foscs all 10.1.3.10/32 scram-sha-256" \ - >> /opt/homebrew/var/postgresql@18/pg_hba.conf - -# 3. Reload (NOT restart) — applies immediately, zero downtime: -$PSQL -U postgres -c "SELECT pg_reload_conf();" -# Expected output: pg_reload_conf -# ---------------- -# t - -# 4. Verify it was accepted: -$PSQL -U postgres -c "SELECT type, database, user_name, address, auth_method FROM pg_hba_file_rules WHERE address = '10.1.3.10/32';" -# Must show one row for foscs / scram-sha-256 -``` - ---- - -## Section 5: Cutover Sequence - -Execute in strict order. **Do not advance to the next step if the current one fails.** - -``` -Step 1: Infra prerequisites (Section 1) - ├── VLAN 3 trunked → host switch port - ├── DHCP pool excludes 10.1.3.10 - └── SAN cert generated, filenames correct, at ~/.foscs/fosshowcase/ssl/ - -Step 2: Firewall staged (Section 2) - ├── Egress pinhole: 10.1.3.10 → 10.1.2.158:5432 TCP - ├── Management: local LAN(s) → 10.1.3.10:22 - └── WAN port-forward: STAGED BUT DISABLED - -Step 3: VM provisioned (Sections 3a–3c) - ├── tart run fos-showcase --net-bridged=$VLAN_IFACE --no-graphics - ├── In-guest block run (netplan, Docker, NTP, SSH hardening) - ├── VM answers on 10.1.3.10, clock synced, docker compose v2 available - └── Run LaunchAgent installed on host (Section 3d) - -Step 4: pg_hba applied (Section 4) - ├── 10.1.3.10/32 line appended to pg_hba.conf - └── pg_reload_conf() returned t - -Step 5: Deploy (from dev Mac) - └── ./deploy/deploy.sh - # Syncs repo + .env + ssl/ to 10.1.3.10, runs docker compose up -d --build - -Step 6: Internal validation ← GATE: do not advance until ALL pass - └── See Section 6 (internal checks only, against 10.1.3.10 directly) - -Step 7: Enable WAN port-forward (UDM Pro) - └── Set port-forward 80/443 → 10.1.3.10 to ENABLED - -Step 8: External validation - └── See Section 6 (external checks) - -Step 9: Post-cutover - └── Section 7 (backup/recovery posture — nothing to install) + SYSTEM-MAP update -``` - -### Step 5 expanded: running deploy.sh - -```bash -# From the dev Mac: -cd /path/to/FOSShowcase -./deploy/deploy.sh - -# Expected output ends with all three containers Up: -# NAME IMAGE STATUS -# nginx ... Up X seconds -# client ... Up X seconds -# server ... Up X seconds -``` - -If the build fails (Swift compiler OOM), the 6 GB VM sizing should prevent this, but if it happens: -check `docker stats` on the VM and confirm no other heavy process is competing. - ---- - -## Section 6: Verification - -Run the internal checks (Steps I1–I4) **before** flipping the WAN port-forward. Run external checks -(Steps E1–E3) after. - -### Internal verification (against 10.1.3.10 directly) - -**I1. Stack health:** - -```bash -# From dev Mac: -ssh admin@10.1.3.10 "cd /opt/fosshowcase && docker compose ps" -# All three containers must show State=Up (not Restarting, not Exit) -``` - -**I2. TLS — website loads, cert is correct:** - -```bash -# From dev Mac (via management SSH): -# Use openssl, NOT curl — curl can silently tolerate bad TLS. -openssl s_client \ - -connect 10.1.3.10:443 \ - -servername foscomputerservices.com \ - &1 | head -30 -# Look for: -# subject=CN=foscomputerservices.com (or similar) -# issuer=... -# Verify return code: 0 (ok) ← critical; any other code = cert problem -``` - -Check both apex and wildcard SAN by varying -servername: - -```bash -openssl s_client -connect 10.1.3.10:443 -servername foscomputerservices.com &1 | \ - grep -E "subject|Verify return" - -openssl s_client -connect 10.1.3.10:443 -servername www.foscomputerservices.com &1 | \ - grep -E "subject|Verify return" -``` - -**I3. DB connection (direct, no tunnel):** - -```bash -# From inside the VM: -ssh admin@10.1.3.10 -docker compose -f /opt/fosshowcase/docker-compose.yml logs server | grep -i "database\|connect\|error" | tail -20 -# Expect a successful direct connection to 10.1.2.158:5432 — NOT via host-gateway or tunnel. -# "Connection established" or equivalent from the Vapor startup. -``` - -**I4. Webhook round-trip (simulated POST):** - -```bash -# From dev Mac — replace WEBHOOK_SECRET with the value from ~/.foscs/fosshowcase/.env: -WEBHOOK_SECRET="" -PAYLOAD='{"ticker":"TEST","action":"buy","price":100}' -SIG=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -hex | awk '{print $2}') - -curl -sk -X POST \ - -H "Content-Type: application/json" \ - -H "X-Webhook-Signature: $SIG" \ - -d "$PAYLOAD" \ - https://10.1.3.10/webhooks/ \ - --resolve foscomputerservices.com:443:10.1.3.10 -# Expected: HTTP 200 or 204 (server accepted the alert) -``` - -Then confirm the row was inserted — use the `webhook_read_alerts` MCP tool or: - -```bash -# On fos-openclaw (the DB host): -/opt/homebrew/opt/postgresql@18/bin/psql -U openclaw_webhook -d foscs \ - -c "SELECT * FROM webhook.tv_alerts ORDER BY created_at DESC LIMIT 3;" -# The TEST row must appear. -``` - -### Isolation tests - -**Positive — VM can reach Postgres:** - -```bash -# Inside the VM: -nc -vz 10.1.2.158 5432 -# Must succeed: "Connection to 10.1.2.158 5432 port [tcp/postgresql] succeeded!" -``` - -**Negative (host-scope, authoritative) — VM cannot reach a different internal host:** - -```bash -# Inside the VM — pick any internal host that is NOT 10.1.2.158: -# e.g. fos-dev at 10.1.2.201 -nc -vz -w5 10.1.2.201 22 -# Must FAIL: "Connection timed out" or "Connection refused" -# This proves the egress allow is host+port scoped, not host-wide. -``` - -**Negative (port-scope, secondary/weak) — VM refused to port 3300:** - -```bash -# Inside the VM: -nc -vz -w5 10.1.2.158 3300 -# Expected: refused or timed out -# NOTE: This is weak evidence if fos-db MCP binds loopback-only on 10.1.2.158 -# (it would be refused regardless of the firewall). Lean on the cross-host test above. -# Confirm whether 3300 actually binds the LAN interface before treating this as a firewall proof: -# On fos-openclaw: sudo lsof -iTCP:3300 -sTCP:LISTEN -``` - -### External verification (after WAN port-forward is enabled) - -**E1. TLS — apex and a subdomain via real DNS:** - -```bash -# From ANY external host (not on the LAN), or use a phone on cellular: -openssl s_client \ - -connect foscomputerservices.com:443 \ - -servername foscomputerservices.com \ - &1 | grep -E "subject|SAN|Verify return" -# Verify return code: 0 (ok) - -openssl s_client \ - -connect www.foscomputerservices.com:443 \ - -servername www.foscomputerservices.com \ - &1 | grep -E "subject|SAN|Verify return" -``` - -**E2. HTTP → HTTPS redirect:** - -```bash -curl -I http://foscomputerservices.com/ -# Expected: HTTP/1.1 301 Moved Permanently Location: https://... -``` - -**E3. TradingView test alert (real webhook path):** - -Send a test alert from TradingView pointing to `https://foscomputerservices.com/webhooks/`. Then -confirm it landed using the `webhook_read_alerts` MCP tool: - -``` -webhook_read_alerts(limit: 5) -``` - -The test ticker must appear as the most recent row. - ---- - -## Section 7: Backup & Recovery Posture - -**Nothing to install. The VM is disposable by design.** - -`fos-showcase` keeps **no Tart checkpoints**, and that is deliberate — not an oversight. The -recovery story is: - -1. **The repo is the source of truth.** Rebuild the VM per Section 3, then `deploy/deploy.sh`. -2. **The host is backed up via Time Machine.** `fos-openclaw` itself is covered. -3. **The only VM-resident state is secrets + certs**, and those are pushed at deploy time from - `~/.foscs/fosshowcase/{.env,ssl/}` on the dev Mac. Nothing unique lives on the VM. - -So `tart list` showing no `fos-showcase-checkpoint-*` entries is **expected state**. Do not flag -it as a gap. (Contrast with `openclaw-vm`, which *does* keep daily checkpoints — it holds state -that isn't reproducible from a repo.) - -`deploy/com.foscs.tart-fos-showcase-checkpoint.plist` remains in the repo as an unused option. If -you ever decide this VM does warrant checkpoints, install it on the host with `launchctl load` -after `plutil -lint`; it calls `~/.foscs/scripts/tart-daily-checkpoint.sh fos-showcase` at 02:30 -(offset from `openclaw-vm`'s 02:00 to avoid I/O collision) and honours `RETENTION_COUNT=7`. - -### What DOES need to survive a reboot - -Two host-side LaunchAgents matter: `deploy/com.foscs.tart-fos-showcase.plist` (`KeepAlive` + `RunAtLoad`), which restarts the VM itself, and `deploy/com.foscs.postgres-stale-lock.plist` (Section 3e), which lets Homebrew postgres recover from an unclean shutdown. Confirm both are loaded: - -```bash -# On fos-openclaw: -launchctl list | grep -E "com.foscs.tart-fos-showcase|com.foscs.postgres-stale-lock" -tart list | grep fos-showcase # State should be "running" -lsof -nP -iTCP:5432 -sTCP:LISTEN # postgres must be listening -``` - -Inside the VM, all three Compose services declare `restart: unless-stopped`, so Docker brings the -stack back after a VM reboot or docker-daemon restart. - -> **Regression note (2026-07-25 → 2026-08-05, ~10.7 days of downtime):** `client` and `server` -> originally had **no** restart policy — only `nginx` did. A host reboot left both app containers -> `Exited (255)` permanently, while nginx crash-looped 15,418 times on -> `host not found in upstream "server"`, so nothing bound :443. Fixed by adding -> `restart: unless-stopped` to both services in `docker-compose.yml`. If you ever see this shape -> again, note that nginx's exponential backoff will have maxed out and it will **not** pick up -> revived upstreams on its own: -> -> ```bash -> ssh -J david@10.1.2.158 admin@10.1.3.10 \ -> 'cd /opt/fosshowcase && docker compose up -d && docker compose restart nginx' -> ``` - ---- - -## Section 8: Rollback - -**There is no Pi fallback.** The Pi is decommissioned and unavailable. - -The only rollback available is: - -1. **Disable the WAN port-forward** (UDM Pro → port-forward for 80/443 → set Enabled = OFF). - The site goes dark externally. Internal services (trading pipeline, DB) are unaffected — they - read `webhook.tv_alerts` directly from the DB, not from FOSShowcase. - -2. **Debug on the direct VM IP** (`10.1.3.10`). The management SSH hole (local LAN → :22) remains - open. You can `docker compose logs`, `docker compose restart`, redeploy, or fix config and - re-run `./deploy/deploy.sh` — all over the management channel. - -3. **Re-enable the WAN port-forward** once the issue is resolved and internal validation passes - again. - -### Rollback decision tree - -``` -Site down externally after WAN flip? -├── TLS error → cert issue (wrong filename? SAN mismatch?) -│ └── Check: openssl x509 -in ~/.foscs/fosshowcase/ssl/foscomputerservices.com.crt -noout -ext subjectAltName -├── Connection refused / timeout → port-forward or firewall misconfiguration -│ └── Check: nc -vz 443 from external; confirm port-forward target IP -├── HTTP 502/503 → container down -│ └── Check: ssh admin@10.1.3.10 "docker compose ps && docker compose logs --tail 50" -├── DB connection error in server logs -│ └── Check pg_hba grant is present; check egress firewall rule; nc -vz 10.1.2.158 5432 from VM -└── Webhook POST fails → HMAC secret mismatch or env var missing - └── Check .env on VM: ssh admin@10.1.3.10 "grep WEBHOOK_SECRET /opt/fosshowcase/.env" -``` - ---- - -## Appendix: Placeholder Reference - -The following values must be substituted with your actual environment values before running commands: - -| Placeholder | How to obtain | -|---|---| -| `` / `$VLAN_IFACE` | `tart run --net-bridged=list` on fos-openclaw after trunking VLAN 3 | -| `` | UDM Pro DHCP leases table, or `tart run` console output, immediately after VM boot | -| `PASTE_YOUR_PUBLIC_KEY_HERE` | `cat ~/.ssh/id_ed25519.pub` on the dev Mac (or whichever key you use for SSH) | -| `` | `grep WEBHOOK_SECRET ~/.foscs/fosshowcase/.env` | -| `YOUR_EMAIL` | Your email address for Let's Encrypt registration | -| `/path/to/FOSShowcase` | Absolute path where the FOSShowcase repo is checked out on fos-openclaw | diff --git a/docs/superpowers/plans/2026-06-22-pi-to-vm-migration.md b/docs/superpowers/plans/2026-06-22-pi-to-vm-migration.md deleted file mode 100644 index ab7f84b..0000000 --- a/docs/superpowers/plans/2026-06-22-pi-to-vm-migration.md +++ /dev/null @@ -1,483 +0,0 @@ -# FOSShowcase Pi → fos-openclaw VM Migration — Implementation Plan - -> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. - -**Goal:** Move the FOSShowcase Docker stack off the decommissioned Raspberry Pi onto an isolated Tart Linux VM on fos-openclaw (VLAN 3 "Public Servers", `10.1.3.10`), preserving the `docker compose` deploy model, with a direct firewall-pinholed Postgres connection and exactly three firewall holes. - -**Architecture:** A dedicated Ubuntu 24.04 arm64 Tart VM on fos-openclaw runs the existing 3-container compose stack (nginx/client/server) unchanged. Images build in the VM (`docker compose up -d --build`, no registry). The VM sits on the isolated UniFi DMZ VLAN 3; it reaches `foscs` Postgres on `10.1.2.158:5432` directly through a single egress firewall pinhole plus a `pg_hba` `/32` grant (the Pi's SSH tunnel is retired). Public ingress is WAN 80/443 only. - -**Tech Stack:** Tart (macOS Apple-Silicon VM tool), Docker + compose v2, Ubuntu 24.04 arm64, netplan, nginx, Vapor/Swift, PostgreSQL 18, UniFi UDM Pro firewall, macOS `launchd`. - -**Spec:** `docs/superpowers/specs/2026-06-22-pi-to-vm-migration-design.md` - ---- - -## Repos & surfaces - -This plan touches **two repos and live infra**: - -- **FOSShowcase** (this repo, branch `migration/pi-to-vm`): `docker-compose.yml` edit, new `deploy/` scripts, checkpoint plist, runbook. -- **openclaw-config**: `deploy/postgres/setup-postgres.sh` `pg_hba` grant, `docs/SYSTEM-MAP.md` topology update. Commit these on a matching branch (e.g. `feat/fosshowcase-vlan3`). -- **Live infra (runbook-driven, Phase 2):** UniFi UDM Pro (VLAN-3 trunk, DHCP reservation, firewall rules, port-forward), fos-openclaw host (Tart provisioning), the production `foscs` DB (live `pg_reload_conf`). These require host/UDM access and are executed from the runbook, not committed. - -## File structure - -| Path | Repo | Responsibility | -|---|---|---| -| `docker-compose.yml` (modify) | FOSShowcase | Make `DATABASE_HOST` `.env`-overridable; drop dead `extra_hosts` | -| `deploy/env.example` (create) | FOSShowcase | Document required runtime env vars | -| `deploy/provision-vm.sh` (create) | FOSShowcase | Create + network + base-provision the Tart VM | -| `deploy/com.foscs.tart-fos-showcase.plist` (create) | FOSShowcase | Keep `tart run fos-showcase` alive across host reboots (mirrors openclaw-vm) | -| `deploy/deploy.sh` (create) | FOSShowcase | Deliver secrets/certs/repo to VM; `compose up -d --build` | -| `deploy/com.foscs.tart-fos-showcase-checkpoint.plist` (create) | FOSShowcase | Daily Tart checkpoint LaunchAgent (host) | -| `docs/runbook-pi-to-vm.md` (create) | FOSShowcase | Operational runbook: infra prereqs, firewall, cutover, verification, rollback | -| `deploy/postgres/setup-postgres.sh` (modify) | openclaw-config | Idempotent `pg_hba` grant for `10.1.3.10/32` | -| `docs/SYSTEM-MAP.md` (modify) | openclaw-config | FOSShowcase → `10.1.3.10`/VLAN 3; DB firewall row | - -## Conventions for this plan - -These are infra scripts, not unit-testable application code. "Verify" steps use `bash -n` (syntax), `shellcheck` (lint), `plutil`/`docker compose config` (artifact validation), and idempotency re-runs. **Live behavior is validated in Phase 2 against the running VM** — there is no Pi fallback, so Phase 2 validates fully on the direct VM IP before any WAN exposure. - -**Commit policy:** every `git commit` in this plan must end with the trailer -`Co-Authored-By: Claude Opus 4.8 (1M context) ` (omitted from the snippets below for brevity). - -Decided parameters (from spec): -- VM name `fos-showcase`; Ubuntu 24.04 arm64; ~2 vCPU / 6 GB / 32 GB disk. -- Static IP `10.1.3.10/24`, gw `10.1.3.1`, VLAN 3, zone "Web Servers". -- VM repo path `/opt/fosshowcase`; VM admin user `admin` (Tart Ubuntu default — harden with SSH key, disable password). -- Canonical secret/cert source on dev Mac: `~/.foscs/fosshowcase/{.env,ssl/}` (mode 600). - ---- - -## Phase 1 — Repo artifacts (offline, committable) - -### Task 1: Retarget DB connection in compose - -**Files:** -- Modify: `docker-compose.yml` (server `environment` + `extra_hosts`) -- Create: `deploy/env.example` - -- [ ] **Step 1: Edit `docker-compose.yml`** — make `DATABASE_HOST` overridable and remove the dead tunnel mapping. - -Change: -```yaml - DATABASE_HOST: host.docker.internal -``` -to: -```yaml - DATABASE_HOST: ${DATABASE_HOST:-10.1.2.158} -``` -Delete the `extra_hosts` block from the `server` service: -```yaml - extra_hosts: - - "host.docker.internal:host-gateway" -``` - -- [ ] **Step 2: Create `deploy/env.example`** - -```bash -# FOSShowcase runtime environment (copy to the canonical source ~/.foscs/fosshowcase/.env, mode 600) -LOG_LEVEL=info -DATABASE_HOST=10.1.2.158 -DATABASE_PORT=5432 -DATABASE_NAME=foscs -DATABASE_USER=openclaw_webhook -DATABASE_PASSWORD=__set_me__ # POSTGRES_WEBHOOK_PASSWORD -MIGRATION_DATABASE_USER=openclaw_admin -MIGRATION_DATABASE_PASSWORD=__set_me__ # POSTGRES_ADMIN_PASSWORD -WEBHOOK_SECRET=__set_me__ # TradingView HMAC -``` - -- [ ] **Step 3: Validate compose parses with the override** - -Run: `DATABASE_HOST=10.1.2.158 POSTGRES_WEBHOOK_PASSWORD=x POSTGRES_ADMIN_PASSWORD=x WEBHOOK_SECRET=x docker compose config | grep -A2 'DATABASE_HOST'` -Expected: resolved value shows `DATABASE_HOST: 10.1.2.158` and **no** `extra_hosts` under `server`. - -- [ ] **Step 4: Commit** - -```bash -git add docker-compose.yml deploy/env.example -git commit -m "feat(deploy): direct DB host via DATABASE_HOST env; drop SSH-tunnel extra_hosts" -``` - ---- - -### Task 2: VM provisioning script - -**Files:** -- Create: `deploy/provision-vm.sh` - -- [ ] **Step 1: Write `deploy/provision-vm.sh`** (runs ON fos-openclaw, where Tart lives) - -```bash -#!/bin/bash -set -euo pipefail - -# Provision the fos-showcase Tart VM on the VLAN-3 "Public Servers" DMZ. -# Run ON fos-openclaw (Tart host). Idempotent where practical. -# -# Prereqs handled in the runbook BEFORE this runs: -# - VLAN 3 trunked to the host's switch port -# - DHCP reservation OR pool-exclusion for 10.1.3.10 on the UDM Pro - -VM_NAME="${VM_NAME:-fos-showcase}" -BASE_IMAGE="${BASE_IMAGE:-ghcr.io/cirruslabs/ubuntu:24.04}" -VM_CPU="${VM_CPU:-2}" -VM_MEM="${VM_MEM:-6144}" # MB; headroom for the Swift release build -VM_DISK="${VM_DISK:-32}" # GB -# REQUIRED: the exact interface token from `tart run --net-bridged=list` on the host. -# A VLAN-3 tagged interface is NOT a friendly name — discover/create it first (runbook §1). -VLAN_IFACE="${VLAN_IFACE:?set VLAN_IFACE to the exact token from 'tart run --net-bridged=list'}" -TART_BIN="${TART_BIN:-tart}" - -command -v "$TART_BIN" >/dev/null || { echo "tart not found"; exit 1; } - -if "$TART_BIN" list --quiet | grep -qx "$VM_NAME"; then - echo "VM $VM_NAME already exists — skipping clone." -else - echo "Cloning $BASE_IMAGE -> $VM_NAME" - "$TART_BIN" clone "$BASE_IMAGE" "$VM_NAME" -fi - -"$TART_BIN" set "$VM_NAME" --cpu "$VM_CPU" --memory "$VM_MEM" -# --disk-size only GROWS a disk; setting it <= the base image's size errors. Apply -# best-effort, then verify+grow the guest filesystem in-guest (Task 9: growpart/resize2fs). -"$TART_BIN" set "$VM_NAME" --disk-size "$VM_DISK" \ - || echo " (disk already >= ${VM_DISK}G or set skipped — verify with 'df -h' in-guest)" - -echo "Starting $VM_NAME bridged to '$VLAN_IFACE' (run under launchd/tmux for persistence in prod)" -echo " $TART_BIN run \"$VM_NAME\" --net-bridged=\"$VLAN_IFACE\" --no-graphics &" -echo "" -echo "After boot, finish in-guest provisioning via SSH (see provision-guest snippet in runbook):" -echo " - netplan static 10.1.3.10/24 gw 10.1.3.1" -echo " - Docker CE + docker-compose-plugin from download.docker.com (arm64)" -echo " - enable systemd-timesyncd (clock-sensitive HMAC/TLS)" -``` - -> Note: the **in-guest** steps (netplan, Docker install, NTP) are documented as a copy-paste block in the runbook (Task 7) rather than baked here, because they run inside the VM over SSH and depend on the VM's first-boot credentials. Keeping them in the runbook keeps `provision-vm.sh` host-side and idempotent. - -- [ ] **Step 2: Lint** - -Run: `bash -n deploy/provision-vm.sh && shellcheck deploy/provision-vm.sh` -Expected: no errors (shellcheck: no warnings above info). - -- [ ] **Step 3: Commit** - -```bash -chmod +x deploy/provision-vm.sh -git add deploy/provision-vm.sh -git commit -m "feat(deploy): Tart VM provisioning for fos-showcase on VLAN 3" -``` - ---- - -### Task 2b: VM run-persistence LaunchAgent - -**Files:** -- Create: `deploy/com.foscs.tart-fos-showcase.plist` - -`provision-vm.sh` deliberately does not start the VM (startup needs a persistent supervisor, not a one-shot). The VM must survive host reboots like `openclaw-vm` does. - -- [ ] **Step 1: Confirm the openclaw-vm run mechanism on fos-openclaw** and mirror it. - -Run (on fos-openclaw): `ls ~/Library/LaunchAgents/ | grep -i tart; launchctl list | grep -i openclaw` -Expected: identify the LaunchAgent (or other supervisor) that keeps `openclaw-vm` running. If it differs from a `tart run` LaunchAgent, mirror that mechanism instead of the plist below. - -- [ ] **Step 2: Write `deploy/com.foscs.tart-fos-showcase.plist`** (KeepAlive supervisor for `tart run`; substitute the real `--net-bridged` token). - -```xml - - - - - Label - com.foscs.tart-fos-showcase - ProgramArguments - - /opt/homebrew/bin/tart - run - fos-showcase - --net-bridged=REPLACE_WITH_VLAN3_INTERFACE - --no-graphics - - KeepAlive - - RunAtLoad - - StandardOutPath - /tmp/tart-fos-showcase.out.log - StandardErrorPath - /tmp/tart-fos-showcase.err.log - - -``` - -- [ ] **Step 3: Validate** — `plutil -lint deploy/com.foscs.tart-fos-showcase.plist` → `OK`. - -- [ ] **Step 4: Commit** - -```bash -git add deploy/com.foscs.tart-fos-showcase.plist -git commit -m "feat(deploy): KeepAlive LaunchAgent to keep fos-showcase VM running" -``` - -> Like the checkpoint plist, this is **not** deployed by openclaw-config's `deploy-all.sh` — it is installed manually on the host (runbook §3). The `--net-bridged` token must match the interface discovered in Task 8. - ---- - -### Task 3: Deploy script - -**Files:** -- Create: `deploy/deploy.sh` - -- [ ] **Step 1: Write `deploy/deploy.sh`** (runs from the dev Mac on the local LAN → VM:22) - -```bash -#!/bin/bash -set -euo pipefail - -# Deliver secrets/certs/repo to the fos-showcase VM and (re)deploy the stack. -# Run from the dev Mac (local LAN — allowed by the management firewall pinhole). - -VM_HOST="${VM_HOST:-admin@10.1.3.10}" -VM_PATH="${VM_PATH:-/opt/fosshowcase}" -SRC_SECRETS="${SRC_SECRETS:-$HOME/.foscs/fosshowcase}" # canonical .env + ssl/ source -REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" -SSH_OPTS=(-o StrictHostKeyChecking=accept-new) - -# Cert/key filenames MUST match nginx.conf's hardcoded paths -# (ssl_certificate foscomputerservices.com.crt / ssl_certificate_key foscomputerservices.com.key). -# The reissued SAN cert must keep these exact names or nginx won't start. -[ -f "$SRC_SECRETS/.env" ] || { echo "Missing $SRC_SECRETS/.env"; exit 1; } -[ -f "$SRC_SECRETS/ssl/foscomputerservices.com.crt" ] || { echo "Missing cert in $SRC_SECRETS/ssl"; exit 1; } -[ -f "$SRC_SECRETS/ssl/foscomputerservices.com.key" ] || { echo "Missing key in $SRC_SECRETS/ssl"; exit 1; } - -echo "==> Ensuring remote path" -ssh "${SSH_OPTS[@]}" "$VM_HOST" "sudo mkdir -p '$VM_PATH' && sudo chown \$(id -un) '$VM_PATH'" - -echo "==> Syncing repo (excluding build/vcs/secrets)" -rsync -az --delete \ - --exclude '.git' --exclude '.build' --exclude 'ssl' --exclude '.env' \ - -e "ssh ${SSH_OPTS[*]}" \ - "$REPO_ROOT/" "$VM_HOST:$VM_PATH/" - -echo "==> Delivering secrets + certs (mode 600)" -rsync -az -e "ssh ${SSH_OPTS[*]}" "$SRC_SECRETS/.env" "$VM_HOST:$VM_PATH/.env" -rsync -az -e "ssh ${SSH_OPTS[*]}" "$SRC_SECRETS/ssl/" "$VM_HOST:$VM_PATH/ssl/" -ssh "${SSH_OPTS[@]}" "$VM_HOST" "chmod 600 '$VM_PATH/.env' '$VM_PATH'/ssl/*.key" - -echo "==> Building + starting stack" -ssh "${SSH_OPTS[@]}" "$VM_HOST" "cd '$VM_PATH' && docker compose up -d --build" - -echo "==> Container status" -ssh "${SSH_OPTS[@]}" "$VM_HOST" "cd '$VM_PATH' && docker compose ps" -``` - -- [ ] **Step 2: Lint** - -Run: `bash -n deploy/deploy.sh && shellcheck deploy/deploy.sh` -Expected: no errors. - -- [ ] **Step 3: Commit** - -```bash -chmod +x deploy/deploy.sh -git add deploy/deploy.sh -git commit -m "feat(deploy): deploy.sh — sync repo+secrets to VM and compose up --build" -``` - ---- - -### Task 4: Daily checkpoint LaunchAgent - -**Files:** -- Create: `deploy/com.foscs.tart-fos-showcase-checkpoint.plist` - -- [ ] **Step 1: Write the plist** (mirrors `com.foscs.tart-openclaw-checkpoint.plist`; calls the openclaw-config-deployed checkpoint script by its host path; offset to 02:30 so it doesn't collide with openclaw-vm's 02:00). - -```xml - - - - - Label - com.foscs.tart-fos-showcase-checkpoint - ProgramArguments - - /Users/david/.foscs/scripts/tart-daily-checkpoint.sh - fos-showcase - - EnvironmentVariables - - PATH - /opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin - RETENTION_COUNT - 7 - - StartCalendarInterval - - Hour - 2 - Minute - 30 - - StandardOutPath - /tmp/tart-fos-showcase-checkpoint.out.log - StandardErrorPath - /tmp/tart-fos-showcase-checkpoint.err.log - RunAtLoad - - - -``` - -> Cross-repo dependency (documented): `tart-daily-checkpoint.sh` lives in openclaw-config and is deployed to `~/.foscs/scripts/` on fos-openclaw by `openclaw-config/deploy/deploy-all.sh`. It is already parameterized by source VM name, so `fos-showcase` works with no script change. `tart clone` of a running VM yields a crash-consistent checkpoint; acceptable here (same as openclaw-vm). -> -> **This plist is NOT auto-deployed.** `openclaw-config/deploy/deploy-all.sh` only ships `com.foscs.tart-openclaw-checkpoint.plist`. Both this checkpoint plist and the run plist (Task 2b) are installed manually on the host (runbook §3/§7). Optionally, a follow-up can extend `deploy-all.sh` to also ship the two `fos-showcase` plists so they're not orphaned at the next deploy-all run. - -- [ ] **Step 2: Validate plist** - -Run: `plutil -lint deploy/com.foscs.tart-fos-showcase-checkpoint.plist` -Expected: `OK`. - -- [ ] **Step 3: Commit** - -```bash -git add deploy/com.foscs.tart-fos-showcase-checkpoint.plist -git commit -m "feat(deploy): daily Tart checkpoint LaunchAgent for fos-showcase" -``` - ---- - -### Task 5: pg_hba grant (openclaw-config repo) - -**Files:** -- Modify: `deploy/postgres/setup-postgres.sh` (after the `10.1.2.0/24` LAN block, ~line 99) - -- [ ] **Step 1: Add an idempotent `/32` block** matching the existing style. - -```bash -# FOSShowcase VM (VLAN 3 DMZ) — webhook ingester, least-privilege /32 -# NOTE: fixed-string grep. The existing blocks above grep ".*foscs.*scram" -# but write "host foscs all scram" — foscs precedes the CIDR, so their -# guard NEVER matches and they append a duplicate on every run (confirmed bug). -# Do not copy that pattern. -if grep -qF "10.1.3.10/32" "$PG_HBA"; then - echo " FOSShowcase entry (10.1.3.10/32) already present — skipping." -else - echo "host foscs all 10.1.3.10/32 scram-sha-256" >> "$PG_HBA" - echo " Added FOSShowcase entry (10.1.3.10/32)." -fi -``` - -> Optional hardening (note for the executor): the three existing guards (loopback, -> `10.1.20.0/24`, `10.1.2.0/24`) share the same idempotency bug. Fixing them is out of -> scope for this migration but worth a follow-up ticket; do not silently rewrite them here. - -- [ ] **Step 2: Lint** - -Run: `bash -n deploy/postgres/setup-postgres.sh` -Expected: no errors. - -- [ ] **Step 3: Commit (openclaw-config branch)** - -```bash -git add deploy/postgres/setup-postgres.sh -git commit -m "feat(postgres): authorize FOSShowcase VM 10.1.3.10/32 in pg_hba" -``` - -> ⚠️ Live application is **not** done by re-running this script on prod (its step 4 does `brew services restart postgresql@18`, which bounces the production DB). The runbook applies just the new line to the live `pg_hba.conf` and calls `SELECT pg_reload_conf();`. This script edit is for durable rebuilds. - ---- - -### Task 6: SYSTEM-MAP.md topology update (openclaw-config repo) - -**Files:** -- Modify: `docs/SYSTEM-MAP.md` - -- [ ] **Step 1: Update FOSShowcase references** — replace `10.1.2.213` / "VLAN 2" / "Docker" host context with `10.1.3.10` on VLAN 3 "Public Servers" (Tart VM on fos-openclaw). Update the services/firewall tables: the FOSShowcase row (~line 469) and the PostgreSQL endpoint row (~line 966). **The endpoint row's access column currently reads "Loopback + VLAN 20" — this is already stale** (the live `pg_hba` also authorizes `10.1.2.0/24`). Correct it to reflect loopback + `10.1.20.0/24` + `10.1.2.0/24` **and** add the new `10.1.3.10/32`. Update the relevant mermaid topology blocks (FOSShowcase subgraph ~line 73) and the prose reference at ~line 330. - -- [ ] **Step 2: Sanity check** there are no remaining stale `10.1.2.213` FOSShowcase references. - -Run: `grep -n "10.1.2.213" docs/SYSTEM-MAP.md` -Expected: no FOSShowcase matches (or none at all). - -- [ ] **Step 3: Commit (openclaw-config branch)** - -```bash -git add docs/SYSTEM-MAP.md -git commit -m "docs(system-map): FOSShowcase now on VLAN 3 (10.1.3.10) Tart VM" -``` - ---- - -### Task 7: Cutover runbook - -**Files:** -- Create: `docs/runbook-pi-to-vm.md` - -- [ ] **Step 1: Write the runbook** with these sections (full commands, copy-paste ready): - -1. **Infra prerequisites (UDM Pro):** - - Trunk VLAN 3 to the fos-openclaw switch port; confirm the host can present a `VLAN 3` bridged interface for Tart. - - **Exclude `10.1.3.10` from the DHCP pool** (pool is `10.1.3.6–254`; shrink the start to `.11` or otherwise carve out `.10`). A DHCP *reservation* is **not** sufficient here because the guest uses a **static** netplan address — the goal is to guarantee no other host is ever leased `.10`. Confirm `.10` is unused (`arping`/ping) before bringing up the static config. - - Generate the new SAN cert (apex + `*.foscomputerservices.com`). It **must** be written with the exact filenames `foscomputerservices.com.crt` and `foscomputerservices.com.key` (nginx.conf hardcodes these). Place at `~/.foscs/fosshowcase/ssl/` on the dev Mac. -2. **Firewall rules ("Web Servers" zone) — exactly three holes:** - - Egress: `10.1.3.10` → `10.1.2.158:5432` TCP allow; default-deny rest to internal zones. - - Ingress: WAN port-forward `80,443` → `10.1.3.10`; WAN→Web Servers allow for 80/443. **No 8081.** - - Management: local LAN(s) → `10.1.3.10:22` allow; never WAN. -3. **In-guest provisioning block** (SSH into the VM after first boot): netplan static `10.1.3.10/24` gw `10.1.3.1`; Docker CE + `docker-compose-plugin` from `download.docker.com/linux/ubuntu` (arm64); add `admin` to `docker` group; enable `systemd-timesyncd`; SSH-key auth + disable password. -4. **Live pg_hba apply (no restart):** append `host foscs all 10.1.3.10/32 scram-sha-256` to the prod `pg_hba.conf`, then `psql -c "SELECT pg_reload_conf();"` (psql at `/opt/homebrew/Cellar/postgresql@18/18.2/bin/psql`). -5. **Cutover sequence** (mirrors spec §8): provision → pg_hba+egress → deploy → internal validation on `10.1.3.10` → flip WAN port-forward → external validation → checkpoint install + SYSTEM-MAP. -6. **Verification** (spec §9): `openssl s_client -connect :443 -servername foscomputerservices.com` for apex AND a subdomain; TradingView test alert → `webhook.tv_alerts` via `webhook_read_alerts`; isolation negatives — VM refused to `10.1.2.158:3300` and to a non-Postgres internal host; positive — VM reaches `10.1.2.158:5432`. -7. **Checkpoint install:** copy the plist to `~/Library/LaunchAgents/` on fos-openclaw and `launchctl load` it. -8. **Rollback:** no Pi fallback — rollback = revert the WAN port-forward (site goes dark) and debug on the direct IP. Emphasize: do not flip WAN until internal validation passes. - -- [ ] **Step 2: Commit** - -```bash -git add docs/runbook-pi-to-vm.md -git commit -m "docs(runbook): Pi -> VM cutover runbook (firewall, provisioning, verification)" -``` - ---- - -## Phase 2 — Execution (live infra, runbook-driven) - -> These tasks run against the UDM Pro, the fos-openclaw host, and the production DB. They require host/UDM access and are gated on a human. Follow `docs/runbook-pi-to-vm.md`. **No WAN exposure until internal validation (Task 10) passes** — there is no Pi to fall back to. - -### Task 8: Pre-flight -- [ ] VLAN 3 trunked to host port. Run `tart run --net-bridged=list` on the host and record the **exact** VLAN-3 interface token (create the macOS VLAN interface if absent). This token feeds `VLAN_IFACE` (Task 9) and both run/checkpoint plists. -- [ ] **DHCP pool excludes `10.1.3.10`** (not just a reservation — the guest is static); confirm `.10` is unused (ping/arping) before Task 9. -- [ ] New SAN cert (apex + wildcard) generated and placed at `~/.foscs/fosshowcase/ssl/`; `~/.foscs/fosshowcase/.env` populated (mode 600). -- [ ] Firewall rules staged (egress pinhole, management pinhole) — WAN port-forward left OFF for now. -- [ ] Verify cert: `openssl x509 -in ~/.foscs/fosshowcase/ssl/foscomputerservices.com.crt -noout -ext subjectAltName` shows **both** apex and wildcard. - -### Task 9: Provision VM -- [ ] On fos-openclaw: `VLAN_IFACE="" deploy/provision-vm.sh`. -- [ ] Install + load the run LaunchAgent (`com.foscs.tart-fos-showcase.plist`, with the real `--net-bridged` token) so the VM starts and stays up; run the in-guest provisioning block (netplan static `10.1.3.10`, Docker CE + compose plugin, NTP, SSH-key auth). -- [ ] Verify: from the VM, `ip a` shows `10.1.3.10`; `ping -c1 10.1.3.1` succeeds (ARPs gateway); `timedatectl` shows synced clock; `docker compose version` prints v2; `df -h /` shows the full ~32 GB (run `growpart`/`resize2fs` if the rootfs didn't auto-expand). - -### Task 10: pg_hba + deploy + internal validation -- [ ] Apply live `pg_hba` `/32` + `pg_reload_conf()`; enable the egress pinhole. -- [ ] From dev Mac: `deploy/deploy.sh`; `docker compose ps` shows all three healthy. -- [ ] Verify (internal, against `10.1.3.10` directly, no WAN): website loads; server logs show a successful **direct** DB connect (not tunnel); a signed `/webhooks/` POST INSERTs a row visible via `webhook_read_alerts`. -- [ ] Isolation tests (authoritative test is cross-host): - - Positive: from the VM, `nc -vz 10.1.2.158 5432` succeeds. - - Negative (host-scope, authoritative): from the VM, a connection to a **different** internal host on any port is refused/filtered (proves the egress rule is host+port-scoped, not just relying on a service not listening). - - Negative (port-scope, secondary): `nc -vz 10.1.2.158 3300` is refused. ⚠️ Treat as weak evidence — if fos-db MCP binds loopback-only this is refused regardless of the firewall. Confirm 3300 actually listens on `10.1.2.158`'s LAN interface before relying on it; otherwise lean on the cross-host test. - -### Task 11: WAN cutover + external validation -- [ ] Enable WAN port-forward `80,443` → `10.1.3.10` + WAN→Web Servers allow. -- [ ] Verify externally: `openssl s_client` clean for apex and subdomain; a real TradingView test alert lands in `tv_alerts`; HTTP→HTTPS redirect works. - -### Task 12: Post-cutover -- [ ] Install + load the checkpoint LaunchAgent on fos-openclaw; confirm one manual run produces a `fos-showcase-checkpoint-*` clone. -- [ ] Land the openclaw-config SYSTEM-MAP + pg_hba commits (merge branch). -- [ ] Monitor host load and the webhook path for 24h. - ---- - -## Execution order - -Phase 1 tasks 1–7 are independent of live infra and can be done/committed first (tasks 5–6 in openclaw-config). Phase 2 tasks 8→9→10→11→12 are strictly sequential. diff --git a/docs/superpowers/specs/2026-06-22-pi-to-vm-migration-design.md b/docs/superpowers/specs/2026-06-22-pi-to-vm-migration-design.md deleted file mode 100644 index 394d6f0..0000000 --- a/docs/superpowers/specs/2026-06-22-pi-to-vm-migration-design.md +++ /dev/null @@ -1,227 +0,0 @@ -# FOSShowcase — Raspberry Pi → fos-openclaw VM Migration - -**Date:** 2026-06-22 -**Status:** Design (revised after spec review; pending implementation plan) -**Author:** David Hunt (with Claude) - -## 1. Context & Goal - -FOSShowcase is the public-facing Swift full-stack web service for `foscomputerservices.com` -(nginx + Ignite `client` + Vapor `server`). It has been running as a Docker Compose stack on a -Raspberry Pi at `10.1.2.213`. **The Pi is no longer available.** - -Goal: move the stack onto an **isolated Tart Linux VM on fos-openclaw (`10.1.2.158`)** while: - -- preserving the existing `docker compose` deployment model, -- rebuilding the network isolation the standalone Pi provided for free (FOSShowcase faces the - public internet; fos-openclaw is the most sensitive host on the network), -- removing any Docker registry (Docker Hub) from the deploy loop. - -This is **not** a database migration. The `foscs` PostgreSQL database already lives on -fos-openclaw (`10.1.2.158:5432`); the Pi only ran the application stack. - -## 2. Current State (Pi) - -- Host: Raspberry Pi, `10.1.2.213`, internal VLAN 2, arm64, bare-metal Docker + `docker compose up`. -- Stack (`docker-compose.yml`): three services — `nginx` (publishes 80/443/8081), `client` - (internal 8082), `server` (internal 8083). Vapor services run `serve --env production`. -- nginx (`nginx.conf`): - - `:80` → 301 redirect to `:443` - - `:443` → `/` to `client:8082`, `/webhooks/` to `server:8083` (rate-limited) - - `:8081` → `/` and `/webhooks/` to `server:8083` (backend / native-app API) -- **DB access (important — corrected after review):** `docker-compose.yml` **hardcodes** - `DATABASE_HOST: host.docker.internal` (a literal, not a `${VAR}` substitution) plus - `extra_hosts: host.docker.internal:host-gateway`. The Pi reached `foscs` on `10.1.2.158:5432` - **via an SSH tunnel** (commit `961ef54`, "PostgreSQL via SSH tunnel"): the container hit the Pi - host gateway, where a tunnel forwarded `:5432` to `10.1.2.158`. Runtime role `openclaw_webhook`; - migrations role `openclaw_admin`. -- Images tagged `foscompsvcs/fos-showcase-{client,server}:latest`; every service has a `build:` - section, so images build locally without a registry. -- TLS: cert mounted from `ssl/` into nginx. **The cert SAN is `*.foscomputerservices.com` only — - it does NOT cover the apex `foscomputerservices.com`**, which nginx `server_name` nonetheless - serves (pre-existing gap, see §7.1). -- Public ingress: `foscomputerservices.com` (WAN IP) → port-forward → the Pi. - -## 3. Target Architecture - -- **Host:** fos-openclaw (`10.1.2.158`, Apple Silicon, already a Tart host — runs `openclaw-vm` - plus a daily Tart checkpoint service). -- **VM:** new Tart Linux VM. - - Name: `fos-showcase` - - OS: Ubuntu 24.04 (noble) **arm64** — matches the image bases; native arm64, no emulation. - - Resources: ~2 vCPU / **6 GB RAM** (headroom for the Swift `--static-swift-stdlib` release - build; idles far lower at runtime). Disk ~32 GB. - - Static IP: **`10.1.3.10/24`**, gateway `10.1.3.1`, DNS via the VLAN's auto DNS. - - Network attach: bridged onto **VLAN 3 "Public Servers"**. -- **Inside the VM:** Docker engine + compose plugin, running the existing 3-container stack - (nginx 80/443/8081, client 8082 internal, server 8083 internal). -- **Disposability:** VM provisioning is fully scripted and committed; the VM is added to a Tart - checkpoint service. The repo (plus the named secret/cert source in §7.1) is the source of truth. - -### 3.1 Host prerequisite — VLAN 3 trunk (do this first) - -Tart bridged networking attaches the VM to a host interface. For the VM to land on VLAN 3, the -**switch port feeding fos-openclaw's NIC must trunk VLAN 3** and the host must present the -VLAN-3-tagged bridge. The `openclaw-vm`/VLAN-20 precedent proves VLAN 20 is trunked to that port — -it does **not** prove VLAN 3 is. Verify/trunk VLAN 3 to the port before provisioning, and confirm -the VM can ARP its gateway `10.1.3.1` as the first post-boot check. This is the most likely -silent first-boot failure. - -## 4. Network & Security Model - -VLAN 3 "Public Servers" (`10.1.3.0/24`, gateway `10.1.3.1`, UDM Pro, zone **"Web Servers"**) has -**Isolate Network = on** and **Allow Internet Access = on**. The design punches **exactly three -holes**: - -| Direction | Rule | Purpose | -|---|---|---| -| Ingress (WAN → VM) | port-forward **80, 443 only** → `10.1.3.10`; WAN→Web Servers allow | Public website (443) + TradingView webhooks (`443 /webhooks/`), HTTP→HTTPS redirect (80) | -| Egress (VM → internal) | **`10.1.3.10` → `10.1.2.158:5432` TCP only** | PostgreSQL (direct; no SSH tunnel) — nothing else internal reachable | -| Management | **local LAN(s) → `10.1.3.10:22`** (internal only; never WAN) | Deploy / admin over SSH (option A), restricted to local LANs | - -- Internet egress remains open (VLAN already allows it) for base-image pulls, apt, SPM fetches, NTP, - and DNS resolution — all outbound-to-internet, requiring **no** inter-VLAN holes. -- Nothing internal initiates to the VM (the trading pipeline reads `webhook.tv_alerts` from the DB, - not from FOSShowcase). Inbound from internal trust zones stays default-deny. - -### 4.1 Companion change in `openclaw-config` (outside this repo) - -`deploy/postgres/setup-postgres.sh` currently authorizes only `10.1.2.0/24` and `10.1.20.0/24` in -`pg_hba.conf`. Add an **idempotent block authorizing `10.1.3.10/32`** (least privilege; `/32` not -`/24`) with `scram-sha-256`, *in the script* — a manual `pg_hba` edit would be clobbered on the next -infra run (openclaw-config rule #10). Apply with `pg_reload_conf()` / `pg_ctl reload` — **reload, -not restart**. Without this, Postgres rejects the VM even with the firewall open. - -### 4.2 Port 8081 — decided: not publicly forwarded - -Both 443 and 8081 are nginx TLS listeners (same cert, same `/webhooks/` rate-limiting) — 8081 is -**not** a raw/un-fronted port. They split only by upstream-at-root: `:443 /` → `client:8082` -(website), `:8081 /` → `server:8083` (backend API for native apps). - -**Decision:** native apps are out of scope for this migration, so **8081 gets no WAN port-forward.** -The website and TradingView webhooks both arrive on 443. The 8081 listener still runs inside the VM -(reachable on the VLAN if ever needed) but is not exposed to the internet — one fewer public hole. -If native-app support over the internet is needed later, add the forward then, or serve the API -under a path on 443 (e.g. `/api/`) for a single public port. - -## 5. Database (connection retargeted, DB unchanged) - -`foscs` stays on `10.1.2.158:5432`. The SSH tunnel is retired; the VM connects **directly** over the -firewall egress + `pg_hba` pinhole. This requires a small, deliberate **compose change** (see §11 — -this is in scope, contrary to a naive "no app changes" reading): - -- Change `DATABASE_HOST: host.docker.internal` → `DATABASE_HOST: ${DATABASE_HOST:-10.1.2.158}` so - `.env` can set it, and put `DATABASE_HOST=10.1.2.158` in `.env`. -- Remove the now-dead `extra_hosts: host.docker.internal:host-gateway`. - -Roles unchanged: `openclaw_webhook` (runtime, INSERT+SELECT on `webhook.tv_alerts`), `openclaw_admin` -(migrations). Both the egress firewall rule and `pg_hba` must authorize `10.1.3.10`. - -## 6. Image Build — No Registry - -Deploy is **`docker compose up -d --build` inside the VM** — images build locally, never pushed or -pulled from a registry. Docker Hub is eliminated as a *distribution* dependency; `foscompsvcs/*` -tags become plain local tags (optionally retagged `fos-showcase-{server,client}:local`). The only -residual registry touch is **base-image pulls at build time** (`swift:6.2.3-noble`, `ubuntu:noble`, -`nginx:1.28.0`) — build-time only, cached, not a runtime dependency. The 6 GB VM sizing covers the -transient Swift build spike. - -## 7. Provisioning & Deploy (lives in FOSShowcase repo) - -New `deploy/` directory in the FOSShowcase repo (repo is source of truth, VM disposable): - -- `deploy/provision-vm.sh` — create the `fos-showcase` Tart VM, attach the VLAN-3 bridge, set static - IP `10.1.3.10`, install Docker, enable NTP. Docker install uses **Docker's official apt repo** - (`download.docker.com/linux/ubuntu`, arm64) installing `docker-ce docker-ce-cli containerd.io - docker-compose-plugin` (the Ubuntu `docker.io` package does **not** ship `docker compose` v2), and - adds the deploy user to the `docker` group. Enable `chrony`/`systemd-timesyncd` — HMAC and TLS are - clock-sensitive and a fresh VM can boot skewed. -- `deploy/deploy.sh` — pull `.env` + `ssl/` from their canonical source (§7.1), sync the repo to the - VM over the management SSH channel, run `docker compose up -d --build`. -- Daily checkpoints: a host LaunchAgent `com.foscs.tart-fos-showcase-checkpoint.plist` that invokes - the existing `openclaw-config/deploy/tart-daily-checkpoint.sh` **by absolute path** with - `SOURCE_VM=fos-showcase` (cross-repo call, documented — preferred over duplicating the script). - Note `tart clone` of a live VM may need a brief stop/snapshot for a consistent checkpoint; confirm - how the existing `openclaw-vm` service handles this and mirror it. -- `docs/runbook-pi-to-vm.md` — operational runbook covering the UDM Pro firewall/port-forward - changes, the `openclaw-config` `pg_hba` change, and the SYSTEM-MAP.md update (§8). - -### 7.1 SSL & Secrets (named source, not "out of band") - -`.env` and `ssl/` are gitignored, so "VM rebuildable from scratch" requires a **named canonical -source**, mirroring the openclaw-config `~/.openclaw/.env` + `init-env.sh` doctrine: - -- Define a master location on the dev Mac for FOSShowcase's `.env` and `ssl/` (e.g. - `~/.foscs/fosshowcase/{.env,ssl/}`); `deploy.sh` pulls from there. Deliver with modes **600** for - the cert key and `.env`. -- **Cert (decided — reissue):** the current cert is wildcard-only (`*.foscomputerservices.com`, - expires **2026-07-20**) and does not cover the apex. A **new SAN cert covering both the apex - `foscomputerservices.com` and `*.foscomputerservices.com`** will be generated and placed in `ssl/` - (and at the canonical source above) as part of the migration. Verification (§9) tests the exact - production hostnames over TLS. - -## 8. Migration / Cutover Sequence - -The Pi is **gone — there is no live fallback** — so the VM is validated in full before public -traffic is flipped. - -1. **Prereq:** trunk VLAN 3 to the host port (§3.1). -2. Provision the `fos-showcase` VM on VLAN 3 (`10.1.3.10`); confirm it ARPs `10.1.3.1` and has - correct clock. -3. Apply the `openclaw-config` `pg_hba` change (`10.1.3.10/32`) and **reload** Postgres; add the UDM - egress pinhole (`10.1.3.10` → `10.1.2.158:5432`). -4. Apply the compose `DATABASE_HOST` change (§5); deliver `.env` + `ssl/`; deploy - (`docker compose up -d --build`). -5. **Internal validation against `10.1.3.10` directly** (before WAN exposure): website loads; DB - connects directly (no tunnel); a simulated authenticated `/webhooks/` POST INSERTs into - `webhook.tv_alerts`. -6. Add the WAN port-forwards (**80/443 only** — no 8081, per §4.2) + WAN→Web Servers allow. DNS - already resolves to the WAN IP (no change unless it was a LAN-mapped record). -7. **External validation:** a real TradingView test alert lands in `tv_alerts`; the native-app - endpoint responds; TLS verified with `openssl s_client` against the *exact* production hostnames. -8. Add the VM to the Tart checkpoint service; update **SYSTEM-MAP.md** (FOSShowcase now - `10.1.3.10` / VLAN 3; DB firewall row gains VLAN 3) per openclaw-config rule #8. - -## 9. Verification - -- TLS via `openssl s_client` (not curl) against each production hostname — catches the apex/SAN gap. -- End-to-end TradingView alert → `webhook.tv_alerts` round-trip, confirmed via `webhook_read_alerts`. -- **Isolation tests (both directions of the egress rule):** - - Positive: VM reaches `10.1.2.158:5432`. - - Negative (scope): VM is **refused** to `10.1.2.158:3300` (fos-db MCP) and other internal ports — - proving the egress allow is port-scoped to 5432, not host-wide. - - Negative (host): VM cannot reach a non-Postgres internal host at all. - -## 10. Risks & Mitigations - -- **No rollback to the Pi.** Mitigated by full pre-cutover validation against the direct VM IP. -- **`DATABASE_HOST` retarget / tunnel removal** is a behavior change. Mitigated by step 5 internal - validation confirming a direct (non-tunnel) DB connection before WAN exposure. -- **Cert apex/SAN gap + 2026-07-20 expiry.** Mitigated by reissuing a SAN cert during the window. -- **VLAN 3 not trunked to the host port.** Mitigated by the §3.1 prerequisite + ARP check. -- **Resource pressure on the Mac Mini.** Mitigated by local-build-only and modest steady-state - footprint; the 6 GB is a deploy-time spike. Watch host load. -- **Clock skew on a fresh VM.** Mitigated by NTP enablement + clock check (step 2). - -## 11. Decisions Made - -- Runtime: **Tart Linux VM** (Docker-on-host rejected for blast-radius; Lima rejected — Tart matches - existing tooling). -- Network: **VLAN 3 "Public Servers"**, static `10.1.3.10`, three firewall holes only. -- Public ingress: **80/443 only** — 8081 (native-app backend API) is not WAN-forwarded; native - apps are out of scope for this migration. -- Management access: **option A** — SSH pinhole to `10.1.3.10:22` allowed **only from local LAN(s)**, - never WAN. -- Cert: **reissue a SAN cert covering apex + wildcard** (replaces the wildcard-only cert). -- Deploy model: **build-in-VM, no registry** (`docker compose up -d --build`). -- DB connection: **direct to `10.1.2.158:5432`**, SSH tunnel retired (requires the §5 compose edit). -- VM sizing: ~2 vCPU / 6 GB / ~32 GB disk. -- Provisioning scripts + runbook: **in the FOSShowcase repo**; `pg_hba` change in openclaw-config. - -## 12. Scope - -**In scope (app repo):** a minimal `docker-compose.yml` edit (`DATABASE_HOST` → `${...:-10.1.2.158}`, -remove dead `extra_hosts`); possible cert reissue; new `deploy/` scripts + runbook. -**In scope (openclaw-config):** `pg_hba` `/32` authorization; SYSTEM-MAP.md update. -**Out of scope:** migrating `foscs` PostgreSQL (already on fos-openclaw); FOSShowcase application -logic; re-architecting public ingress beyond retargeting port-forwards.