audit anchor: a chain reset behind its anchor file leaves anchoring refused forever, with only a log line and no recovery path
Problem
When the audit database is recreated (or restored from an older copy) while the host's anchor file survives, the chain in Postgres restarts at a low checkpoint and the daemon's anchor sink refuses to anchor it, every tick, indefinitely. The only signal is one ERROR log line per tick. There is no health signal, no metric, no doctor finding and no documented recovery.
[audit-anchor] ERROR: publish anchor at checkpoint 106: audit: refusing to anchor checkpoint 106,
older than the last anchored checkpoint 1036 — tamper-evidence against a privileged rewrite is degraded until this succeeds
Observed on a self-hosted (BYOC) host on v0.125.0 and unchanged on v0.129.1. It went unnoticed for days: the daemon stayed healthy, the tunnel stayed up, and nothing alerted.
How it happens
FileSink.PublishRoot (internal/audit/anchor.go) is rollback protection: it returns an error for any checkpoint below the last record in /var/lib/containarium/audit-anchors.jsonl. That is the right default, and it is what stops a privileged writer from presenting an older chain. But the same check fires when the chain is legitimately reset:
- The anchor file lives on the host disk and survives.
- The platform Postgres LXC is recreated (or its data is restored from an older point), so
audit_logsstarts again near checkpoint 1. - The first anchor tick after the daemon comes back logs the refusal, and every tick after it logs it again.
The chain in this report advanced about 2 checkpoints an hour, so it would take roughly 19 days to pass the old anchor's 1036 (and the daemon cannot tell a legitimate reset from a rewrite while it waits).
What the evidence looked like
- Anchor file: ~500 records, strictly monotonic, no unparseable lines, last checkpoint 1036 and its timestamp days before the database was recreated.
- Platform Postgres LXC created a few minutes before the first refusal (the first anchor tick), which fixes the cause.
- 0 refusals on four other hosts of the same fleet, whose anchor files kept advancing, so this is an event on one host, not a general defect in the sink.
- Whether the old audit rows survive after such a reset is unknowable from the daemon: with no backup, the old anchors in the local file are the only remaining evidence of that period.
Proposal
- Surface a refusing anchor. Report it in
/health(a degraded reason), incontainarium doctor, and as a metric (for example a gaugecontainarium_audit_anchor_degradedplus a refusals counter), so the existing alerting can page on it. Say in the log line what the operator can do about it. - A first-class recovery command, for example
containarium audit anchor new-epoch(name tentative), instead of moving files by hand:- archives the old anchor file under a timestamped name and records its sha256, last checkpoint and the reason;
- writes a break record into the new file and into the audit log itself, so the break is permanent evidence and not a silent reset;
- requires an explicit confirmation flag and a root-level caller.
audit verify-anchorunderstands epochs: a documented, recorded break verifies as a break, not as tampering; an unexplained drop still fails as it does today.- Detect a reset chain at startup (chain length or base behind the last anchored checkpoint) and report it once, clearly, instead of a silent per-tick loop.
- Keep a second copy of the anchor file off the host by default, or have
doctorwarn when only a local file is configured. Once the database is gone, that file is the only evidence. - Runbook section: "the audit database was recreated or restored", covering how to confirm what happened and when
new-epochis the right answer.
Security considerations
The refusal exists to defeat rollback, so the recovery path must not become the way to launder one. new-epoch must (a) never delete the old file, (b) leave a break record that verify-anchor and the proof pack show, (c) be recorded in the audit chain with the actor, and (d) be impossible to run without an explicit flag. An unexplained jump should keep failing verification.
Acceptance
- [ ] With an anchor file whose last checkpoint is N and a chain at checkpoint k < N:
/healthis degraded with a reason,doctorreports it, the metric is set, and the log line names the fix. - [ ]
new-epocharchives the old file (sha256 recorded), writes the break record, and the next tick publishes successfully. - [ ]
verify-anchorpasses across a recorded break and still fails on an unrecorded drop (extend the planted-checkpoint test from #2980). - [ ] A test or doc covers the "database recreated" scenario end to end.
Related
#2560 (external immutable anchor sink), #2784 (tracking: audit evidence stays verifiable), #2878 (retention prefix purge and chain base), #2980 (planted checkpoint below the chain base), #2728 (RFC3161 anchor sink), #2880 and #2881 (GCS anchor bucket and verify-anchor).
🤖 Generated with Claude Code
Verify on dev: plant an anchor file ahead of the chain → /health is degraded with a reason, containarium doctor reports it, and the metric is set.
Blocked by: none
Sprint: #3725
Part of #3725
Starting on proposal item 1 only (surface a refusing anchor), as a Part of PR. A refused checkpoint (the chain is behind the anchor file, or conflicts with an anchored root) will set a new readiness entry containarium.audit_anchor to NOT_SERVING; containarium doctor reads that entry. /health turns degraded with the fixed reason audit anchor refused. There will be an OTel gauge containarium.audit.anchor.degraded, a refusal counter, a log line that explains the state when it starts, and a runbook section. The next successful publish clears it. new-epoch, epoch-aware verify-anchor, the off-host copy and the startup detection stay open for later PRs.
Decision recorded on #3725 (2026-11-17): the default is accepted by @hsinatfootprintai, so the issue is ready to implement against it.
Routed model:opus: surfaces a refusing anchor across health, doctor and metrics. Multi-file, inside the existing design; the open question (surfacing only) is answered on #3725.
Surfacing shipped in #3649 (merged 2026-11-12): /health degraded reason, containarium doctor readiness entry, the anchor gauge and refusals counter, and the log line with a runbook section. Items 2–6 moved to #3772, with the constraints from this issue carried over. Closing #3549 with surfacing as its agreed scope.