patchwise-agent-studio / docs /OPERATIONS-HARDENING.md
EnergyVenom's picture
Astra: AR and gap business actions, usage fixes, client report coverage, health check, backups and alerts, cancel_invoice fix (d52c9b976774)
cdfb5de verified
|
Raw History Blame Contribute Delete
6.55 kB

Operations hardening (OCI app server and browser runner)

Audit of where Astra's state lives on the OCI server, what protects it, and what was added. Read with DEPLOYMENT.md, RUNBOOK.md and REMOTE_RUNNER.md.

Audit

Question Finding
Where state lives One folder, FPT_HOME=/data in the container, bind-mounted from /home/ubuntu/astra-data on the VM's own disk (deploy/oci/update-app.sh): fpt.sqlite (runs, users, audit, schedules, kv), checkpoints.sqlite, secrets/ (vault), evidence/ (encrypted), runs/, tickets/, screens/, library/, logs/, fusion_areas.json. Settings and secrets of the container are in /etc/astra/app.env on the VM (root), outside the repo and outside /data.
Survives a container rebuild Everything in /data (bind mount), /etc/astra/app.env, the previous image tag (one rollback). The runner VM keeps ~/astra, ~/astra.prev.
Backed up today Only if OCI_STATE_PAR_URL and FPT_STATE_KEY are in app.env (not visible from the repo: verify on the server). Then statesync.py saves an encrypted archive (SQLite copied with the online backup API) to the bucket: when data changed, at most every 5 min on OCI, at once on run events, on shutdown. Kept: latest.bin, previous.bin, the newest 5 history/ copies. Over 45 MB it leaves out evidence, then finished runs' folders. Not in it: logs/ (except audit anchors), app.env, the runner.
Lost if the VM disk dies With the bucket: everything saved there (at most the last few minutes), minus left-out evidence and logs. Without it, everything. Always lost: app.env (including FPT_STATE_KEY: without it the bucket's archives cannot be decrypted), the TLS proxy setup, the runner's systemd unit and token. The runner's code is rebuilt by sync.sh.
Gaps found 1. The rolling history is the last 5 saves, minutes to a few hours: damage noticed a day later could not be undone. 2. FPT_STATE_KEY and app.env have no copy anywhere. 3. update-app.sh removed the container with docker rm -f (SIGKILL), skipping the app's shutdown save and letting a run stop cleanly. 4. The container log was unbounded (docker default). 5. Alerts existed only for run events, state.left_out and Agent Studio dead letters. A dead runner or pod sign-in, a full disk, a stuck run, a failing save or a failing schedule showed up only when someone opened the app (pre-flight at the next run). The trio_backup_ok metric needs a scraper that is not set up.

What was added (all off or inert until switched on)

  • Dated backups (platform/backup.py): one encrypted archive per FPT_BACKUP_INTERVAL_H (24), same archive and key as the state save, to state/daily/<time>.bin in the same bucket (with state/daily/index.json, since the PAR address may not list) and, when FPT_BACKUP_DIR is set, to that folder (a mounted volume on another disk). The newest FPT_BACKUP_KEEP (14) are kept. Nothing is backed up while saving is paused (failed start-up restore, newer instance), so good copies never age out in favour of an empty one. Costs three bucket requests a day.
  • Alerts (platform/watchdog.py) through the existing notification channels (app bell, webhook, Telegram), every FPT_OPS_CHECK_INTERVAL_S (300): runner unreachable or not ready (same check as pre-flight), default pod sign-in fails, data disk below FPT_OPS_DISK_MIN_FREE_PCT (10) free, a run "running" with no step or update for FPT_OPS_RUN_STUCK_MINUTES (300), the dated backup or the state save failing, saving paused after a failed restore. A condition alerts after FPT_OPS_ALERT_AFTER_FAILURES (2) failed checks in a row (a deploy leaves the runner on the old commit for a few minutes), then stays quiet until it clears, and sends one "fixed" notice. State is in the database, so a restart does not repeat an alert. Network checks wait while the emergency stop is on.
  • Pod sign-in check is a real sign-in. Off unless FPT_OPS_POD_CHECK_MINUTES is set; a rejected password is not tried again for 6 hours, because Fusion locks a user after a few bad sign-ins.
  • Deploy script: the old container is stopped with SIGTERM and up to 60 s (it makes its last save, a run stops at its next step) before removal; the container log is capped at 5 x 10 MB.
  • CLI: python -m coworker backup run | list | restore <name> [--force].

To do on the server at deploy time

  1. In /etc/astra/app.env: OCI_STATE_PAR_URL and FPT_STATE_KEY (if not there already), then FPT_BACKUP=1, FPT_OPS_ALERTS=1, and optionally FPT_BACKUP_DIR=/data/backups (that is the same disk: for another disk mount a volume and bind it into the container, e.g. add -v /mnt/backup:/backups and FPT_BACKUP_DIR=/backups). Set a notification channel (FPT_NOTIFY_WEBHOOK_URL, or Telegram in Settings) or the alerts only appear in the app's bell.
  2. Copy app.env (at least FPT_STATE_KEY, OCI_STATE_PAR_URL, the secrets) to a password manager. Nothing else holds the key.
  3. Optional, not done by the repo: cap the runner's journal (SystemMaxUse=500M in /etc/systemd/journald.conf).
  4. After the first deploy: docker exec astra python -m coworker backup run, then backup list.

Restore

Tested by coworker/tests/test_ops_hardening.py (backup, restore into an empty home from the bucket name and from the folder).

  1. Stop the app (docker stop astra) so it cannot save over what you restore.
  2. docker run --rm --env-file /etc/astra/app.env --entrypoint python -v /home/ubuntu/astra-restore:/data astra:<rev> -m coworker backup list shows the copies, newest first; ... -m coworker backup restore state/daily/<time>.bin unpacks one into the empty folder. (From a folder copy: pass its path, mounted into the container.)
  3. Check it, then mv /home/ubuntu/astra-data /home/ubuntu/astra-data.bad && mv /home/ubuntu/astra-restore /home/ubuntu/astra-data and start the container (or run update-app.sh). It takes the next bucket generation at start.
  4. A new VM: do the same on an empty disk after recreating /etc/astra/app.env with the old FPT_STATE_KEY; or simply start the container on an empty disk, which restores latest.bin (RUNBOOK "Restore").

Not done

A schedule that turns itself off after 3 failed starts is still only in the audit log and on the schedules page; the runner VM's own disk and the proxy's certificates are not watched from the app (the runner's /healthz does not report disk).