Runbook — deploying migration 224 (chain_seq) without paging a false tamper
Target of the runbook_url on AuditChainBroken and AuditChainRolloutSkew in
deploy/alerts/audit-chain.yaml.
Owner: platform / devops. Issues: #2968 (this runbook) · #2949 (the column) · #2963 (its review) · #2915 (the alerts).
TL;DR for a deployer
Deploy migration 224 and the binaries that write audit rows together, in one change. Do not run the migration ahead of the rollout and let old replicas drain behind it.
If you do split them, expect AuditChainRolloutSkew (warning) for every affected
org until the rollout completes and the next nightly verifier pass runs. That
alert is not a security incident. AuditChainBroken (critical) still is.
If this is an UPGRADE of a live cluster rather than a fresh install, the ArgoCD sync-wave order works against you — wave 0 runs the migration while pre-224 replicas are still serving. Roll the writers first, then the migration: see "A fresh install and an upgrade need opposite orders" below. On a fresh install the wave order is correct as-is and there is nothing to do.
Why the order matters
Migration 224 added agent_audit_log.chain_seq and made it — not created_at —
the key the audit hash chain is ordered on. created_at is stamped by the
caller, before it contends for the append path's advisory lock, so under a
burst rows commit in lock order while carrying contention-order timestamps and
the chain forks. chain_seq is assigned inside the lock and is monotone in
commit order by construction. (#2949; the measurement is in the migration
header — 40 concurrent appends produced 16 distinct prev_hash values where 1
was correct.)
The column is NOT NULL DEFAULT 0, and the migration backfills every existing
chained row with its position in the current walk order. So after the migration:
| writer | chain_seq it writes | effect |
|---|---|---|
| post-224 binary | tail + 1, inside the lock | correct |
| pre-224 binary | 0, the column default | sorts before every backfilled row |
Zero sorts first. The walk therefore starts at a row whose prev_hash is not
the 32-zero chain root, invariant 1 fails, and the chain reports as broken.
The break is real and the loud posture is correct — for an audit chain a false alarm beats silent acceptance, and the window is bounded by the rollout. What #2968 fixed is that the alert used to describe it as tampering.
What the on-call sees now
The verifier classifies each break. A link/order failure (invariants 1, 2
and 4) at a row carrying chain_seq = 0 is the rollout signature and nothing
else can produce it; a content-hash failure (invariant 3) recomputes from the
row's own columns, is independent of walk order, and is never a rollout
artefact. That classification is exported as
audit_chain_verifier_unsequenced_break, and the alert rules route on it:
| you see | means | severity |
|---|---|---|
AuditChainRolloutSkew | break at chain_seq = 0 | warning |
AuditChainBroken | anything else | critical |
The two partition audit_chain_verifier_status == 0 per
(org_id, epoch, chain_scope): no broken chain is silent, and no broken chain
pages twice. A rollout on one org or one grain does not excuse a genuine
break on another.
If the discriminator series is missing entirely — an old verifier binary, i.e.
a mixed-version rollout of the thing doing the reporting — the join matches
nothing and AuditChainBroken fires exactly as it did before #2968. Absence
fails loud.
Deploying 224 correctly
- Ship the migration and the writer binaries in one release. The writers of
chained rows are the session-chain path and the org-grain path, both in
internal/runtime/audit/pgstore.go. Anything that callsaudit.EnableChain(...)is a writer. - Roll the writers before or with the migration, never long after. A post-224 binary running against a pre-224 schema is safe — the column does not exist, and the code paths that use it are the ones the migration adds. The unsafe direction is the other one.
- If a canary or a partial rollout is unavoidable, say so in the deploy channel
before starting, so the resulting
AuditChainRolloutSkewis expected rather than investigated. - The window closes when every writing replica is post-224 and the next
nightly pass has re-walked the chains. The verifier runs at 02:00 UTC
(
deploy/cron/audit-verify.yaml), and the gauge holds its last value for a full day, so the warning will not clear before then.
A FRESH INSTALL AND AN UPGRADE NEED OPPOSITE ORDERS (#2968)
This is the part that was missing, and it is the reason step 2 above reads as a contradiction of the manifests if you only look at one of them.
The ArgoCD sync-wave ordering in deployments/overlays/mnet/kustomization.yaml
is designed for a fresh install:
| wave | resource | why it is first |
|---|---|---|
| 0 | upsquad-migrate | creates the schema |
| 1 | upsquad-db-roles | GRANTs over what migrate made |
| 2 | upsquad-platform-flags | writes a row into it |
| 3 | every Deployment | connects as a role that now exists |
That order is correct for an install and unsafe for an upgrade, and both readings are right at the same time:
- Fresh install — there is no pre-224 binary anywhere, so there is no
mixed-version window to order. Schema-then-workloads is the only order that
works: reverse it and the app starts against an empty schema, or
db-rolesGRANTs over nothing and every query fails on permissions. - Upgrade of a live cluster — there are running replicas, they are pre-224,
and wave 0 applies the migration while they are still serving. That is the
window: every chained row those replicas write lands with
chain_seq = 0.
So on an upgrade, do not let a single ArgoCD sync do both. Roll the writer Deployments first, wait for the rollout to complete, and only then let the migration Job run:
# 1. writers first — image tag only, no migration in this sync
kubectl -n platform rollout status deploy/context-engine --timeout=10m
kubectl -n platform rollout status deploy/agent-orchestrator --timeout=10m
kubectl -n platform rollout status deploy/model-gateway --timeout=10m
# 2. then the migration
kubectl -n platform wait --for=condition=complete job/upsquad-migrate --timeout=10m
The writer set is derived, not copied: anything calling audit.EnableChain(...)
is a writer. Today that is cmd/context-engine, cmd/agent-orchestrator and the
model gateway (internal/modelgateway/auditchain.go). Re-derive it with
grep -rn 'EnableChain' --include='*.go' . rather than trusting this list —
a service added later will not update this line.
If you cannot split the sync, the fallback is step 3 above: announce it, and
expect AuditChainRolloutSkew (warning) rather than treating it as a breach.
What is enforced, and what is only written here
scripts/check-sync-wave-order.py fails CI if the declared order regresses:
the db Jobs must carry explicit, strictly increasing waves, and every workload
must carry an explicit wave strictly after them. It also fails if a comment
claims a wave the render does not have — which is how this went wrong for months:
the overlay's comment asserted "the Deployments (wave 3)" while no Deployment
carried a sync-wave at all, so ArgoCD placed all eleven of them in wave 0,
alongside the migration.
Two things that check cannot enforce, so they stay your responsibility:
kubectl apply -kignores sync-wave entirely. Kubernetes does not read those annotations; only ArgoCD does. The manual path's ordering is thekubectl waitcalls above and nothing else.- The install/upgrade asymmetry itself. No single wave ordering expresses
both, so the upgrade deviation is a procedure, not a constraint. The migrate
Job carries
upsquad.io/rollout-runbook: docs/runbooks/audit-chain-224-rollout.mdso that a deployer reading the manifest is pointed here; the check asserts that annotation exists, that this file exists, and that it still mentionschain_seq.
Triaging AuditChainRolloutSkew
-
Confirm a rollout is actually in flight.
kubectl get pods -n platform -o \jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'Every replica that writes audit rows must be on a post-224 image.
-
If no rollout is in flight, this is not skew. Nothing else legitimately writes
chain_seq = 0to a chain that already has sequenced rows. Treat it exactly asAuditChainBrokenand follow that runbook, including the escalation.This matters because
chain_seqis deliberately not part of the row hash (see the migration header for why), so someone who canUPDATEthe table can zero a row's sequence and choose which alert they trip.The verifier checks the breaking row's own content hash before it will classify an unsequenced row as an artefact, so they cannot edit a row's content and zero that row's sequence to hide it. They can hide behind a different row, and it takes two statements and no hash recomputation:
1. edit row K's content -> K now fails the content check2. zero row J's chain_seq, J after K -> J sorts to the front of the walkJ is untouched and self-consistent, so it passes the guard, fires the first-row invariant at
chain_seq = 0, and the walk stops there without ever reaching K. That is inherent to "the walk stops at the first failure" plus "chain_seqis not hashed"; it is a severity downgrade, never a silencing; and step 1 is what catches it. A skew alert with no rollout in flight is the only signal you get for this class — treat it accordingly.Pinned by
TestAuditChain2968_ATamperCanHideBehindALaterZeroedSequence_KnownLimit, which will fail if the limit is ever closed. -
Read the evidence.
kubectl logs -n platform job/audit-verify-<n> | jq 'select(.ok == false)'Each line carries
broken_at_unsequenced_row,broken_row_id,broken_at_rowandbroken_reason. -
Complete the rollout and wait for the next pass. Do not re-run the 224 backfill to "repair" the rows: it is idempotent and numbers only rows that need it, but re-running it while a pre-224 replica is still writing simply re-creates the condition one row later.
What NOT to do
- Do not silence either alert to make a dashboard green.
AuditChainBrokenwas named as a live control in six code comments and existed in zero rules files for four years (#2873). Silencing restores that state. - Do not relax the
AuditChainBrokenpredicate because it is noisy. If it is firing on something that is not tampering, the fix is a discriminator like this one, computed at the source — not a wider threshold. - Do not re-chain, truncate or "repair" a chain that has broken for any reason other than confirmed rollout skew. The broken link is the evidence.
Related
deploy/alerts/audit-chain.yaml— the five rules and the reasoning behind each predicate.internal/context/store/migrations/224_audit_log_chain_seq.up.sql— the column, the indexes and the backfill.test/integration/context/audit_chain_2968_test.go— the classification, proved both ways against a real database.deploy/alerts/tests/audit-chain_test.yamlT10–T13 — the routing, proved both ways in promtool.