diff --git a/changelog.d/3894.documentation.md b/changelog.d/3894.documentation.md new file mode 100644 index 000000000..bf8f88f1f --- /dev/null +++ b/changelog.d/3894.documentation.md @@ -0,0 +1 @@ +- **Runbook: "The audit database was recreated or restored"** (#3772). Step by step recovery with `containarium audit anchor new-epoch`, what it writes, what `audit verify-anchor` shows afterwards, and what the recovery does not protect against. The "daemon refuses to anchor" section now describes startup detection. diff --git a/docs/security/OPERATOR-SECURITY-RUNBOOK.md b/docs/security/OPERATOR-SECURITY-RUNBOOK.md index 416353647..3cb0ad116 100644 --- a/docs/security/OPERATOR-SECURITY-RUNBOOK.md +++ b/docs/security/OPERATOR-SECURITY-RUNBOOK.md @@ -1525,17 +1525,109 @@ acting on it: history, and editing it is exactly what the refusal guards against. Anchoring resumes on its own once the chain passes the last anchored -checkpoint. A recorded recovery that starts a new anchor epoch, so that -`verify-anchor` treats the break as a documented break and not as -tampering, is tracked in #3549. The state is held in memory, so after a -daemon restart the signals above reappear at the first refused tick, within -one anchor interval (`CONTAINARIUM_AUDIT_ANCHOR_INTERVAL`, 15 minutes by -default), not at startup. A conflict (a checkpoint already anchored with a -different root) that persists across ticks is not the "database recreated" -case: run `containarium audit verify-anchor` and treat a mismatch as a -possible rewrite. A single conflict that clears on the next tick can happen -when a recreated chain lands exactly on the last anchored checkpoint while -it climbs past it. +checkpoint. If the database was recreated or restored on purpose, do not +wait for that: record the break with the steps in +[The audit database was recreated or restored](#the-audit-database-was-recreated-or-restored). + +A chain that is already behind the anchor when the daemon starts is +reported at startup (`DEGRADED (found at startup)` in the daemon log, and +the readiness entry goes NOT_SERVING at once), not after the first anchor +interval (`CONTAINARIUM_AUDIT_ANCHOR_INTERVAL`, 15 minutes by default). The +state is held in memory, so a restart reports it again. A conflict (a +checkpoint already anchored with a different root) that persists across +ticks is not the "database recreated" case: run +`containarium audit verify-anchor` and treat a mismatch as a possible +rewrite. A single conflict that clears on the next tick can happen when a +recreated chain lands exactly on the last anchored checkpoint while it +climbs past it. + +### The audit database was recreated or restored + +Use this when the platform Postgres was recreated, or restored from an older +copy, you have confirmed that is what happened (see the checks above), and the +daemon refuses to anchor the new chain. `new-epoch` does not reset the anchor. +It ends the old anchor history on the record and starts a new one, and +`verify-anchor` shows the break. + +1. **Stop anchoring.** Stop the daemon, or run the command while it is + refusing. A publish that lands while the command works makes it abort and + change nothing. + +2. **Start the new epoch**, as root, with a reason and the confirmation flag: + + ```bash + sudo containarium audit anchor new-epoch \ + --reason "audit database restored from the backup" \ + --confirm-new-epoch + ``` + + `--anchor-path` defaults to `CONTAINARIUM_AUDIT_ANCHOR_PATH`, then the + daemon's default. The command refuses, before it touches the file or the + database, when `--confirm-new-epoch` or `--reason` is missing or the caller + is not root. The actor is the user behind `sudo` (`$SUDO_USER`), else the + current user. + +3. **What it did.** It prints the archive path, the archive's sha256 and the + last anchor the old file held, and: + - copied the old anchor file, whole, to `.archived-` + (mode 0600, never over an existing file). The old file is archived, never + deleted: keep the archive, with the rest of your evidence, for as long as + you keep the audit log; + - replaced the anchor file, atomically, with a new one whose first line is + a break record: when, who, why, the archive and its sha256, the last + checkpoint and root, and the epoch number (the first break starts epoch + 2); + - recorded the same in the audit chain, as action + `audit_anchor_new_epoch` (`containarium audit query --action + audit_anchor_new_epoch`). If the database write fails the command says the + file was changed, names the archive and sha256, and the break record in the + file still names the actor. + +4. **Start the daemon.** The next tick publishes at the chain's current + checkpoint and anchoring resumes. Rollback protection applies again from + there. + +With `CONTAINARIUM_AUDIT_ANCHOR_BUCKET` or a timestamp authority configured, +the objects are keyed by checkpoint, and a new epoch restarts at low +checkpoints. Epoch 1 keeps its original names. Epoch *n* after it publishes +under `epoch-/` in the bucket and under +`.tsa/epoch-/` for tokens, so nothing already written moves or +is overwritten. The daemon follows the anchor file's epoch, so a break made +while it runs takes effect on the next publish. + +#### What `verify-anchor` shows afterwards + +`containarium audit verify-anchor` prints each recorded break as a break (when, +who, why, the archive and its sha256) and says the archive is present and +unchanged. This is not a failure. It checks, for every break including those +recorded inside archives: + +| Result | Meaning | Exit | +| --- | --- | --- | +| ⚠ | A recorded break. The archive is present, matches its recorded sha256 and ends at the last anchor the break records. | 0 | +| ✗ | The archive is missing, has changed, or does not end at the anchor the break records. Deleting the old history after a break does not pass as a clean break. | non-zero | +| ✗ | With `--anchor-bucket`: an earlier epoch's bucket prefix holds an object the epoch's archive does not hold, or one with a different root. | non-zero | +| ✗ | With `--anchor-tsa-trust-bundle`: an earlier epoch's token is for a record the archive does not hold, is stamped over a different record, or is not signed by a trusted TSA. | non-zero | +| ⚠ | An earlier epoch's archive holds checkpoints the bucket does not (an upload that never succeeded, or a different prefix). | 0 | +| ✗ | A drop in the anchor with **no** break record. This is the unexplained case and still fails, exactly as before. | non-zero | + +The current epoch is checked against the database as always. Earlier epochs +are not: their rows are gone with the old database, so they are compared with +their archive, and the archive with the sha256 in the break record. + +#### What this does not protect against + +- The break record is written by whoever runs the command as root. It makes + the break visible and attributable; it does not prove the reason is true. + Review `audit_anchor_new_epoch` entries, and the archive, when you audit. +- A host-root attacker can still stop the daemon, run `new-epoch`, and start a + new history. What they cannot do is make it unrecorded: the break record, + the archive with its sha256, the audit entry, and any bucket or timestamp + copy of the earlier epoch remain. Keep an off-host copy of the anchor file + and the archives; the bucket copy of the earlier epochs is what a host-root + attacker cannot edit. +- A rollback is not a recovery. If the database was *not* recreated or + restored, do not run this: verify first (`containarium audit verify-anchor`). ### Anchoring to a bucket