Files
felhom.eu/documentation/audits/new-app-securo-2026-11-15/tools/securo_undo.py
T
adminandClaude Opus 5.5 c616727d84
gates / gates (push) Successful in 2m8s
Securo onboarding: the audit evidence and R-1399 (the website lists fewer apps than the catalog)
documentation/audits/new-app-securo-2026-11-15/: source and image reads, bench (negative control, the
0.17.0 -> 0.18.0 move, memory from birth, storage), 9202 on the drill catalog (the guarded Update, the
undo on a real failure, the setup gate against a stranger's poll, accounts, the visitor's address and
lock-out through the simulated tunnel, receipt upload, backup -> remove -> restore), card pictures and
the guide label check. R-1399 (P4, Apps & catalog): wger and Securo have no card on the apps page and
the count says 63. The catalog commit follows after the operator's yes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012qRErfCoiTkvDK9N5XHbzb
2026-11-15 15:08:22 +01:00

132 lines
6.6 KiB
Python

#!/usr/bin/env python3
"""securo_undo.py — checklist 6.3 for Securo: the box's UNDO on a real failure, on scratch 9202 through the product's own
guarded Update. Adapted from security-app-updates-2026-10-27/part3/tools/undo_proof.py (Jellyfin).
Securo 0.17.0 -> 0.18.0 migrates its database (alembic 102 -> 105); the bench's abort put 0.17.0 back on the migrated
schema and the backend REFUSED to start („Can't locate revision identified by '105'", bench/evidence/MV-securo). So the
box's undo must bring back the DATA, not only the old image. The proof:
1. the drill's securo at FROM (a temporary drill commit), install, seed the first user, read it back (C1);
2. a temporary drill commit moves the images to 0.18.0 AND makes its checks fail (compose healthcheck `false`, the
.felhom.yml probe on a path that does not exist) — so 0.18.0 starts, migrates the database, and the Update fails
in its check;
3. press the guarded Update: the final phase must be `undone`; while it verifies, 0.18.0's own log is saved (the
conversion is seen, not assumed);
4. after the undo: the running image is 0.17.0 and the seeded account and transaction read back (a wrong password refused);
5. the two temporary drill commits are reverted, the app removed.
usage: SC=<dir with .ctlpw> TARGET=9202 EV=<dir> python3 undo_proof.py
"""
import json, os, re, subprocess, sys, threading, time
sys.path.insert(0, "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu/scripts")
import box_walk as w
import upgrade_fixtures_box28 as f28
APP, SUB = "securo", "finance"
FROM, TO = "0.17.0", "0.18.0" # securo-frontend and securo-backend (x3) move together
D = w.DRILL
EV = os.environ["EV"]
os.makedirs(EV, exist_ok=True)
rec = {"app": APP, "from": FROM, "to": TO, "started": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())}
def git(*a):
return subprocess.run(["git", "-C", D] + list(a), capture_output=True, text=True, timeout=120)
def drill_commit(msg, edit):
git("pull", "-q", "--rebase", "origin", "main")
comp, fy = f"{D}/templates/{APP}/docker-compose.yml", f"{D}/templates/{APP}/.felhom.yml"
c, y = open(comp).read(), open(fy).read()
c, y = edit(c, y)
open(comp, "w").write(c)
open(fy, "w").write(y)
git("add", f"templates/{APP}")
git("commit", "-q", "-m", msg)
r = git("push", "-q", "origin", "main")
h = git("rev-parse", "--short=12", "HEAD").stdout.strip()
w.say(f" drill commit {h}: {msg} (push rc={r.returncode})")
w.refresh_box_mirror()
return h
def finish(verdict, why):
rec["verdict"], rec["why"] = verdict, why
rec["log"] = w.LOG
json.dump(rec, open(os.path.join(EV, "undo-proof-securo.json"), "w"), indent=2)
w.say(f"RESULT {verdict} — {why}")
w.login()
head0 = git("rev-parse", "HEAD").stdout.strip()
rec["drill_head_before"] = head0
fx = f28.FIXTURES28[APP]
commits = []
try:
def to_from(c, y):
return c.replace(f":{TO}\n", f":{FROM}\n"), y
commits.append(drill_commit("UNDO-PROOF setup: securo at FROM (temporary, reverted at the end)", to_from))
if w.stack(APP).get("deployed"):
w.remove(APP)
w.sync_rescan(APP, "ghcr.io/securo-finance/securo-backend:" + FROM, tries=40, delay=10)
if not w.deploy(APP, SUB):
finish("inconclusive", "the install at FROM did not complete"); raise SystemExit(1)
w.wait_app(SUB, "/api/health", want=("200",), tries=60)
tok = fx.seed(w, SUB, w.say)
if not tok or not fx.verify(w, SUB, tok, w.say):
finish("inconclusive", "C1: the seed did not read back before the update"); raise SystemExit(1)
def failing_to(c, y):
c = c.replace(f":{FROM}\n", f":{TO}\n")
c = c.replace('test: ["CMD-SHELL", "wget -qO - http://127.0.0.1:8080/api/health | grep -q healthy"]', 'test: ["CMD", "false"]')
y = y.replace('path: "/api/health"', 'path: "/api/undo-proof-no-such-path"', 1)
assert 'test: ["CMD", "false"]' in c and "undo-proof" in y
return c, y
commits.append(drill_commit("UNDO-PROOF: securo 0.18.0 whose checks fail (temporary, reverted at the end)", failing_to))
w.sync_rescan(APP, "ghcr.io/securo-finance/securo-backend:" + TO, tries=40, delay=10)
seen = {"lines": []}
stop = threading.Event()
def watch():
while not stop.is_set():
out = w.guest("docker inspect -f '{{.Config.Image}}' securo-backend 2>/dev/null; "
"docker logs --tail 400 securo-backend 2>&1 | grep -iE 'Running upgrade|alembic|revision' | tail -40")
if TO in out.split("\n")[0]:
seen["lines"] = out.strip().split("\n")
time.sleep(5)
th = threading.Thread(target=watch, daemon=True)
th.start()
rec["update"] = u = w.press_update(APP, poll=1.0, cap_s=1800)
stop.set()
th.join(timeout=30)
rec["to_log_while_verifying"] = seen["lines"][-40:]
time.sleep(15)
rec["observables_after"] = obs = w.observables(APP)
running = w.guest("docker inspect -f '{{.Config.Image}}' securo-backend 2>/dev/null").strip()
rec["running_image_after"] = running
if u.get("final_phase") != "undone":
finish("failed", f"the update ended {u.get('final_phase')!r}, not 'undone'"); raise SystemExit(1)
if running != "ghcr.io/securo-finance/securo-backend:" + FROM:
finish("failed", f"after the undo the running image is {running!r}, not {FROM}"); raise SystemExit(1)
if not any(re.search(r"Running upgrade", l) for l in seen["lines"]):
w.say(" note: no migration line was captured from 0.18.0 while it verified")
rec["seed_after_undo"] = ok = fx.verify(w, SUB, tok, w.say)
if not ok:
finish("failed", "the undo put the old image back but the seeded user does not sign in"); raise SystemExit(1)
finish("proven", "0.18.0 started on the data, migrated it, and failed its check; the box undid it: 0.17.0 runs again "
"and the seeded account and transaction read back (a wrong password refused)")
finally:
if w.stack(APP).get("deployed"):
w.remove(APP)
for h in reversed(commits):
git("pull", "-q", "--rebase", "origin", "main")
r = git("revert", "--no-edit", h)
w.say(f" drill revert {h}: rc={r.returncode}")
if commits:
git("push", "-q", "origin", "main")
w.refresh_box_mirror()
rec["drill_head_after"] = git("rev-parse", "HEAD").stdout.strip()
rec["drill_tree_equal_to_before"] = git("diff", "--quiet", head0, "HEAD", "--", f"templates/{APP}").returncode == 0
w.say(f" drill templates/{APP} equal to before: {rec['drill_tree_equal_to_before']}")
json.dump({k: v for k, v in rec.items() if k != "log"} | {"log": w.LOG},
open(os.path.join(EV, "undo-proof-securo.json"), "w"), indent=2)