CR65: snapshot restore bestimmt das Verzeichnis selbst (D038) #70

Merged
oliver.maklott merged 2 commits from cr65-restore-target into main 2026-11-27 21:08:33 +01:00

Code-Review 3, Befunde S30 (hoch) und S37 (mittel). Schließt die Lücke, die D028/D030 offen ließen.

  • S30: restore nahm das Zielverzeichnis aus der unsignierten snapshot.json, fragte bei leerem oder fehlendem Verzeichnis nichts, und der Vergleich ließ gewöhnliche Zusatzdateien durch. Ein gefälschtes Abbild landete so als root z. B. in /usr/local/sbin, mit eigenem docker.
  • S37: Auf einem Rechner mit einer Instanz nahm das Abbild einer anderen Instanz deren Verzeichnis.

Akzeptanz:

  • Das Verzeichnis kommt nie aus dem Manifest: Wahl der Betreiber:in (--dir …), sonst das Verzeichnis der Instanz auf diesem Rechner, sonst /opt/<name> wie bei install. manifest.instance wird geprüft.
  • Jede Datei, die weder zum Bundle gehört noch auf der Liste der Dateien steht, die apcmd selbst schreibt, ist eine Abweichung.
  • Auf einem Rechner ohne die Instanz werden Name und Verzeichnis immer gezeigt und gefragt (--yes beantwortet es).
  • Ein Verzeichnis mit einer Installation anderen Projektnamens beendet die Wiederherstellung, mit und ohne --replace.
  • database, created und format aus snapshot.json werden geprüft, bevor restore sie weitergibt oder zeigt; snapshot create lehnt ein POSTGRES_DB ab, das restore nicht annähme.
  • Tests: gefälschtes Manifest, zusätzliche ausführbare Datei, Rechner mit einer Instanz, gefälschte Felder; Wiederherstellung auf leerem Rechner und über die eigene Instanz laufen weiter (deno test: 191 bestanden).

Zusätzlich: snapshot create lehnt einen Instanznamen ab, den restore nicht annähme. Folge für Betreiber:innen: eigene Dateien im Installationsverzeichnis führen bei restore zur Rückfrage (--trust-snapshot für Skripte).

Bleibt offen: Der Inhalt der Dateien, die apcmd selbst schreibt, wird nicht verglichen (.apcmd/previous vor rollback); Abbilder sind weiterhin nicht signiert.

Kein Versionssprung in diesem PR: Die Veröffentlichung folgt mit eigenem PR.

Entscheidung: D038 (ändert Sätze in D015, D028, D030).

🤖 Generated with Claude Code

Code-Review 3, Befunde S30 (hoch) und S37 (mittel). Schließt die Lücke, die D028/D030 offen ließen. - S30: `restore` nahm das Zielverzeichnis aus der unsignierten `snapshot.json`, fragte bei leerem oder fehlendem Verzeichnis nichts, und der Vergleich ließ gewöhnliche Zusatzdateien durch. Ein gefälschtes Abbild landete so als root z. B. in `/usr/local/sbin`, mit eigenem `docker`. - S37: Auf einem Rechner mit einer Instanz nahm das Abbild einer anderen Instanz deren Verzeichnis. Akzeptanz: - [x] Das Verzeichnis kommt nie aus dem Manifest: Wahl der Betreiber:in (`--dir` …), sonst das Verzeichnis der Instanz auf diesem Rechner, sonst `/opt/<name>` wie bei `install`. `manifest.instance` wird geprüft. - [x] Jede Datei, die weder zum Bundle gehört noch auf der Liste der Dateien steht, die apcmd selbst schreibt, ist eine Abweichung. - [x] Auf einem Rechner ohne die Instanz werden Name und Verzeichnis immer gezeigt und gefragt (`--yes` beantwortet es). - [x] Ein Verzeichnis mit einer Installation anderen Projektnamens beendet die Wiederherstellung, mit und ohne `--replace`. - [x] `database`, `created` und `format` aus `snapshot.json` werden geprüft, bevor `restore` sie weitergibt oder zeigt; `snapshot create` lehnt ein `POSTGRES_DB` ab, das `restore` nicht annähme. - [x] Tests: gefälschtes Manifest, zusätzliche ausführbare Datei, Rechner mit einer Instanz, gefälschte Felder; Wiederherstellung auf leerem Rechner und über die eigene Instanz laufen weiter (`deno test`: 191 bestanden). Zusätzlich: `snapshot create` lehnt einen Instanznamen ab, den `restore` nicht annähme. Folge für Betreiber:innen: eigene Dateien im Installationsverzeichnis führen bei `restore` zur Rückfrage (`--trust-snapshot` für Skripte). Bleibt offen: Der Inhalt der Dateien, die apcmd selbst schreibt, wird nicht verglichen (`.apcmd/previous` vor `rollback`); Abbilder sind weiterhin nicht signiert. Kein Versionssprung in diesem PR: Die Veröffentlichung folgt mit eigenem PR. Entscheidung: D038 (ändert Sätze in D015, D028, D030). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`snapshot restore` took the target directory from the unsigned
snapshot.json and asked nothing when it was empty or missing; the
comparison of the installation part passed ordinary extra files. A forged
snapshot could so be unpacked as root into an empty directory on root's
PATH with a `docker` of its own (S30). On a host with one instance, the
snapshot of another instance took that instance's directory (S37).

- The directory is the operator's choice, else where this host has the
  instance, else /opt/<name> as `install` derives it; never the manifest's.
- `instance` in snapshot.json is validated (name as `install` takes one,
  version); `snapshot create` refuses a name `restore` would not take.
- Name and directory are always shown; on a host without the instance they
  are asked (`--yes` answers, no terminal is a no).
- A directory that holds an installation or Compose project of another
  name ends the run, with and without --replace.
- Every file that is neither the bundle's nor one apcmd writes itself is a
  difference in the comparison.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
CR65: validate the other snapshot.json fields restore hands on or shows (D038)
All checks were successful
check / check (pull_request) Successful in 12s
check / check (push) Successful in 13s
release / release (push) Successful in 1s
0fd375fa22
`database` went unvalidated to `ops restore-prepare --confirm` and into a
line on the terminal, `created` into apcmd.log and the result, and a
`format` that is no number into the message about an unknown format.
`readSnapshot` now takes a database name as POSTGRES_DB of an instance can
be, the time as `create` writes it and an integer format, before the host
is looked at; anything else is no snapshot. `snapshot create` refuses a
POSTGRES_DB `restore` would not take.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
aivopod/apcmd!70
No description provided.