Skip to content

feat(bin): add HPlan world-readable inventory-copy guard - #2941

Closed
swippipp wants to merge 2 commits into
kunchenguid:mainfrom
swippipp:fm/hplan-bestandskopien-waechter
Closed

swippipp wants to merge 2 commits into
kunchenguid:mainfrom
swippipp:fm/hplan-bestandskopien-waechter

Conversation

@swippipp

Copy link
Copy Markdown

Ziel

Ein Wächter gegen die Fehlerfamilie der letzten Tage: weltlesbare Kopien der echten HPlan-Bestandsdaten - 229 Hallenbelegungen mit Klarnamen und Rufnummern echter Übungsleiter. Vier Vorkommen am 23./24.08., dazu am 24.08. die laufende Produktionsdatenbank selbst auf 644 als sechstes Vorkommen und Grund für den Serverblick.

Der Vorschlag: die Signatur hängt am Inhalt

Die Signatur ist die Form des Bestands selbst, nie der Name: Tabelle belegung mit gefülltem uebungsleiter-Feld. Drei Stufen:

  • sqlite-struktur: SQLite schreibfrei geöffnet (immutable - keine Sperren, kein Journal), Tabelle und Spalte nachgewiesen, mindestens 100 Zeilen mit gefülltem Feld. Schwellwert per Umgebungsvariable; der bekannte Bestand misst 229/229.
  • byte-signatur: wenn keine Struktur lesbar ist - beide Schema-Token in NUL-haltigen Binärdaten oberhalb von 32 KiB. Trifft lebende und verwaiste WAL-Begleiter.
  • dump-signatur: SQL-Text mit beiden Token plus INSERT nach belegung. Prosa, die die Wörter nur erwähnt, meldet nicht.

Warum das auch die nächste Kopie trifft: Jede künftige Kopie - docker cp, Skript, Handkopiervorgang, anderer Name, WAL-Abbild, Textabzug - trägt die Struktur ihres eigenen Inhalts mit, und genau darauf wird geprüft. Die Gegenprobe in der Batterie schiebt eine Kopie unter einem Namen unter, der mit keinem der bekannten Fälle etwas teilt.

Ehrlich gezogene Grenzen: Extrakte unter dem Zeilenschwellwert, komprimierte Container, gepackte Git-Objekte (komprimiert - ein committetes Leck ist eine andere Familie), Symlinks, und umbenannte Textabzüge ohne SQL-Form im Kopf.

Kosten (gemessen, nicht geschätzt)

  • typischer Gesamtaufruf check inklusive Serverbein: 8,7 s bei einer Budgetgrenze von 20 s, automatisch auf das Watcher-Zeitlimit (30 s) zugeschnitten
  • davon /tmp 2,6 s, der .treehouse-Pool nach Putsatz (~23k Dateien) 5,7 s, Serverbein über ssh rund 1 s
  • Chaoslauf mit unlesbarer Datei, hängendem Server und gerissener Zeitgrenze gleichzeitig: endet begrenzt, Exit 0, genau eine Zeile und benennt jeden Teilausfall namentlich - der Aufsichtszyklus läuft unbeschadet weiter
  • unveränderte Funde werden je Pfad entnervt (Ledger in state/.hplan-guard, nur Hashes und Epochenn); Re-Nag standardmäßig täglich

Was er nie tut

Kein Inhalt verlässt ihn - weder Meldung noch Protokoll noch Datensatz; der Test weist Sentinel-Werte in allen Ausgaben und State-Dateien nach. Er ändert nichts an gefundenen Dateien (Checksummen-Gegenprobe), repariert nichts und setzt keine Musterbefehle ab. Auf dem Server wird nur gelesen: ein Shell-Schnipsel per bash -s gereicht, nichts hinterlassen, nichts neu gestartet; /root/backups/hplan bleibt ausgenommen und gegentestet.

Abnahme Punkt für Punkt

  • Gegenmessung rot vor grün: Batterie fiel gegen den Stummel aus, bevor die Erkennung implementiert war
  • anders benannte Kopie: test_finds_differently_named_copy
  • still bei Rechte 600 und ohne Signatur: test_silent_on_600_signed_copy, test_silent_on_unsigned_world_readable, plus Wort-Schergegenprobe
  • Server samt WAL, Sicherungsordner stumm: test_remote_leg_respects_backup_exclusion, zusätzlich live gegen gex gefahren
  • kein Inhalt anywhere: test_no_content_leaves_the_scanner
  • ändert nichts: test_scanner_changes_nothing
  • Kosten: Zahlen oben, im Test grob abgesichert durch test_scan_stays_fast
  • im Zyklus dieses Heims: arm/disarm im vertrauten Shim-Muster, test_arm_disarm_roundtrip
  • Chaos-Nachforderung: test_chaos_run_names_partials_and_stays_bounded
  • alle Tore: 19 von 19 Fällen grün (bin/fm-test-run.sh tests/fm-hplan-guard.test.sh), shellcheck sauber

Aktivierung nach Merge

Im Heim einmal bin/fm-hplan-guard.sh arm - danach ruft der Watcher ihn je Prüfzyklus auf, und die Meldung landet dort, wo der Kapitän sie sieht. disarm nimmt Shim, Vertrauensbindung und Datensatz komplett zurück. Das Ausrollen selbst bleibt bewusst dieser Entscheidung vorbehalten.

Live-Befund des ersten Laufs (nur Metadaten)

Der erste echte Lauf fand acht weltlesbare Bestandskopien - die Familie lebt:

  • /tmp/claude-1000/-home-fridjof--treehouse-HPlan-c6c586-3-HPlan/…/scratchpad/wegwerf.sqlite samt -wal - 644, strukturiert bestätigt
  • /tmp/claude-1000/-home-fridjof--treehouse-HPlan-c6c586-1-HPlan/…/scratchpad/voll/quelle.sqlite - 644, 688 KB
  • …/scratchpad/walprobe/sicherung.sqlite und …/walprobe/hplan.sqlite - 644, je 8 KB
  • .treehouse/firstmate-7bab20/4/firstmate/data/hplan-ausrollen-2026-08-23/db-sicherung-vor-u4-2026-08-23.sqlite - 644, 348 KB
  • .treehouse/HPlan-00fd4e/1/HPlan/daten/hplan.sqlite und …/2/HPlan/daten/hplan.sqlite - 644, je 312-348 KB

Die Produktionsdatenbank im Docker-Volumen steht inzwischen auf 600 (nachgemessen), die Sicherungen dort liegen richtig. Über die obigen Funde entscheidet ein Mensch - der Wächter hat sie nur laut gemeldet.

Webrecherche: 0 Suchen verwendet.

Content-signed detection of world-readable copies of the real HPlan
inventory (table belegung with a filled uebungsleiter column), in three
tiers: structured SQLite proof, raw-byte markers for NUL-bearing blobs
such as WAL images, and SQL text dumps. Scans /tmp, home, repo root,
the ~/.treehouse pool, and the service's Docker volume on the server
over a bounded ssh read-only sweep; backup folders are excluded.

Reports only path, mode, size, tier, and row counts - never content.
Repairs nothing. Every failure mode lands as a named partial state
while the run exits 0 inside a hard budget cut to the watcher's check
timeout, so the supervision cycle survives even a fully failing sweep.
Per-path suppression keeps an unchanged fleet silent; arm/disarm follow
the trusted-check-shim pattern.
@greptile-apps

greptile-apps Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Confidence Score: 2/5

The PR does not yet appear safe to merge because three previously reported suppression-state failures remain in the current implementation.

Invalid configuration can replace an unloaded ledger, mutable finding metadata changes suppression identities during ordinary database updates, and concurrent checks can overwrite each other's entries; together these behaviors cause repeated alerts and loss of persisted suppression state.

Files Needing Attention: bin/fm-hplan-guard.sh

Reviews (2): Last reviewed commit: "fix(bin): guard server leg drops size fl..." | Re-trigger Greptile

Comment thread bin/fm-hplan-guard.sh
Comment on lines +499 to +505
if ! resolve_config; then
# A bad configuration is a named partial state like any other: reported
# once through the same suppression ledger, never a crash.
PARTIALS+=("falsch konfiguriert: $CONFIG_ERROR")
emit_suppressed_or_line
return 0
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Configuration failure discards suppression state

When any HPLAN_GUARD_* setting is invalid, this branch emits and writes suppression state before record_read loads the existing ledger, causing the configuration alert to repeat every cycle and previously suppressed leak findings to be reported again after configuration is repaired.

Suggested change
if ! resolve_config; then
# A bad configuration is a named partial state like any other: reported
# once through the same suppression ledger, never a crash.
PARTIALS+=("falsch konfiguriert: $CONFIG_ERROR")
emit_suppressed_or_line
return 0
fi
if ! resolve_config; then
# A bad configuration is a named partial state like any other: reported
# once through the same suppression ledger, never a crash.
record_read
PARTIALS+=("falsch konfiguriert: $CONFIG_ERROR")
emit_suppressed_or_line
return 0
fi

Comment thread bin/fm-hplan-guard.sh Resolved
Comment thread bin/fm-hplan-guard.sh
Comment on lines +448 to +494
record_write() { # <keys-reported-space-list>: persist the ledger atomically
local reported=$1 now cutoff keep='' tmp
local entry ekey eepoch key found i
mkdir -p "$STATE" 2>/dev/null || true
now=$(real_epoch)
cutoff=$((now - 604800))
local -a ks=()
local -a es=()
local IFS=';'
for entry in $REC_SEEN; do
[ -n "$entry" ] || continue
ekey=${entry%%:*}
eepoch=${entry##*:}
case "$eepoch" in ''|*[!0-9]*) continue ;; esac
[ "$eepoch" -ge "$cutoff" ] || continue
ks+=("$ekey")
es+=("$eepoch")
done
unset IFS
for key in $reported; do
found=0
for i in ${ks[@]+"${!ks[@]}"}; do
[ "${ks[$i]}" = "$key" ] && { es[i]=$now; found=1; break; }
done
[ "$found" = 1 ] || { ks+=("$key"); es+=("$now"); }
done
# One field per entry; printf adds the newline per argument, because a
# command-substitution accumulator would strip it and glue entries together.
local -a lines=()
for i in ${ks[@]+"${!ks[@]}"}; do
lines+=("$(printf '%010d %s' "${es[$i]}" "${ks[$i]}")")
done
local sorted e k
sorted=$(printf '%s\n' ${lines[@]+"${lines[@]}"} | sort -r | head -n 128)
while read -r e k; do
[ -n "$k" ] || continue
keep="${keep:+$keep;}${k}:${e}"
done <<< "$sorted"
tmp=$(mktemp "$RECORD.XXXXXX" 2>/dev/null) || return 1
chmod 0600 "$tmp" 2>/dev/null || { rm -f -- "$tmp"; return 1; }
{
printf '%s\n' "$RECORD_SCHEMA"
printf 'seen=%s\n' "$keep"
} > "$tmp" || { rm -f -- "$tmp"; return 1; }
mv -f -- "$tmp" "$RECORD" || { rm -f -- "$tmp"; return 1; }
return 0
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Concurrent checks lose suppression entries

If a manual check overlaps a watcher check, both runs can read the same ledger snapshot and independently replace it; the last writer drops keys recorded by the other run, causing unchanged findings to be reported again on the next sweep.

The remote sweep applied the 32 KiB byte-tier floor to the service's
own data location, so a small signed extract - a real 150-row copy is
about 16 KiB - passed silently, and a clean-empty result was
indistinguishable from a leg that never ran. The floor belongs to the
generic local binary tier, not to a dedicated volume where any
world-readable signature carrier is news regardless of size.

The leg now always surfaces in scan's coverage: COVER with candidate
counts when it ran, leer when the configured roots are absent, a named
PARTIAL when unreachable or torn. Verified live against gex in both
directions: a planted world-readable signed probe at the volume path is
found and reported; an equally signed probe under /root/backups/hplan
stays unreported. Both probes removed afterwards.
@swippipp

Copy link
Copy Markdown
Author

Abnahmerunde 3a - Ursache gefunden, gezogen, live gegengeprobt (2da543a):

Ursache: Das Serverbein wendete die 32-KiB-Größenuntergrenze der lokalen Byte-Spur auch im Volumen an. Eine echte 150-Zeilen-Kopie ist aber nur ~16 KiB groß - sie fiel durch den Vorfilter, und ein leerer Erfolg war von einem Lauf, der nie geschah, nicht zu unterscheiden. Beides war der Defekt: die Grenze gehört in die allgemeine lokale Suche, nicht in das dedizierte Datenverzeichnis des Dienstes, und der Server musste sich in jeder Ausgabe zeigen.

Jetzt:

  • Keine Größenuntergrenze mehr im Serverbein: dort ist jede weltlesbare Signaturträgerin ein Fund, egal wie klein.
  • Der Server erscheint immer in der Abdeckung von scan: COVER server:gex:<pfad> ok <Kandidatenzahl> <Lesefehler> bei Lauf, leer 0 0 bei fehlenden Wurzeln, PARTIAL mit Grund bei Nichterreichbarkeit oder gerissener Frist.
  • check bleibt ereignisgetrieben (sauber = still, damit der Watcher nicht je Zyklus durch eine Alles-Gut-Meldung geweckt wird); Abweichungen landen weiter in der Ein-Zeilen-Meldung.

Gegenmessung live am echten Ort, beide Richtungen: signierte synthetische Probe (150 Zeilen, erfundene Namen, 644) unter _data/abnahme-probe-silenz.dat -> FINDING ... 644 16384 byte-signatur marker plus COVER server:... ok 1 0; equally signed Probe unter /root/backups/hplan/manuell/ -> keine Zeile. Beide Proben danach entfernt, Volumen führt nur seine drei echten Dateien.

Batterie steht bei 20/20 grün inklusive dreier neuer Fälle (Lauf mit Zahl, fehlende Wurzeln als leer, Ausfall als PARTIAL ohne ok-Behauptung); shellcheck sauber.

@swippipp

Copy link
Copy Markdown
Author

Landed locally in the operating fleet's local main (cherry-picked as d60fbbc + 3e28f35, colocated test green). This guard is domain-specific to one deployment's HPlan data handling, so it does not belong in the shared upstream; closing rather than merging. Apologies for the noise - our delivery mode for firstmate-repo tasks is local-only, and this branch was opened upstream by mistake.

@swippipp swippipp closed this Aug 24, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Scheduled 3:10am PT 8/24 pass. VISION.md read in full from current main 8fa0505e48a155da78a9aeeb50911719dc558710 (#2939). First look at this unstamped PR. No captain comment authorizing a merge. No competing PR.

VISION (inspected bin/fm-hplan-guard.sh arm/disarm/check/scan, case "${1:-check}", default HPLAN_GUARD_SERVER=on / REMOTE_HOST=gex / docker volume hplan_hplan-daten, world-read bit st_mode & 0o0004, SQLite immutable=1, remote bash -s find+grep, ledger chmod 0600, shim 0700, and bin/fm-hplan-guard-analyze.py content tiers). Per-rule:

  • One captain, one interface: aligns (reports path/mode/size/tier only; never content; check is silent when clean).
  • Authority is explicit and never inferred: aligns as opt-in — watcher registration requires arm; disarm removes shim, trust, and ledger. After arm, server-leg default is on (gex + that volume).
  • Scripts own the mechanics: aligns (content signature, budget, suppression are deterministic).
  • A restart is a non-event: aligns (ledger in state/.hplan-guard; named partials; exit 0 so the watcher cycle survives).
  • Delegation with a spine: aligns (a refusal/report path; repairs nothing).
  • The fleet outlives any vendor: cannot tell (no harness adapter).
  • Scope: does not align — table belegung / column uebungsleiter, host gex, and the HPlan docker volume are one home's project, shipped into the shared distro. VISION: the shared surface stays generic and captain-agnostic; personal projects stay private to the home that owns them.

Class: opt-in (must arm). Not auto-eligible: no no-mistakes-pipeline-attestation:v1, CI did not stay available to approve, and the generic-surface question is a captain decision after that. Not default-behavior of the fleet (the binary is not auto-registered).

Security (file-mode/permissions, full diff): no .github / secrets / workflow injection. Guard only considers world-readable regular files, opens SQLite immutable, does not chmod/repair finds, and prints no inventory content. Remote leg is a bounded read-only find -perm -0004 + grep over HPLAN_GUARD_SSH_CMD (default BatchMode ssh). Ledger/shim modes 0600/0700. Default server-on after arm would ssh to gex on any home that arms it. Greptile 2/5 on suppression-ledger races is not a merge gate. First-time fork swippipp (no prior PRs). No security reason to withhold CI.

Workflow-approval this pass (captain gh):

  • Listed at start as action_required: 32714590731 CI and 32714590766 Require no-mistakes on HEAD 2da543aeb0a311bf2d5c5e38bc93191117be892a
  • Approve POST returned 404; runs then absent (gh run list --commit empty; only Greptile check-suite remains)
  • Could not approve this pass

CI / NM: HEAD 2da543aeb0a311bf2d5c5e38bc93191117be892a. MERGEABLE / UNSTABLE, ahead 2 / behind 2. Body has no no-mistakes-pipeline-attestation:v1. GitHub NM check never landed on this HEAD.

Overlap / HOLD: none of the standing spawn/herdr/lock files. Unique bin/fm-hplan-guard.sh + analyzer + tests.

Waiting on the author for a HEAD-matching attestation (and for fork CI to actually exist so it can be approved). The HPlan-in-distro question is a captain decision that would still block after that — not flagging NOW because author/CI blockers remain. Do not rebase.

Land-eligible: NO. Captain-flag NOW: no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants