Language

Why the audit chain is verifiable

An HMAC append-only digest chain: what changing a row, deleting a row, and recomputing the whole chain each leave behind, why pruning is also recorded, and what content is deliberately kept out of the audit.

Many systems have an "operation log". MISI CMS's audit is not a log table; it is a digest chain whose tampering can be verified — and the difference between the two only shows on the day something goes wrong.

How it is linked. Each audit row carries, besides its own content, two fields: the previous row's digest (prev_hash) and this row's digest (chain_hash). The algorithm for this row's digest is HMAC-SHA256(key, prev_hash ‖ key_gen ‖ row_fields), where row_fields is every column of this row. The key point is that the key is unreachable by an attacker: only digest outputs cannot be reversed into the key, so "recomputing the whole chain" requires the key itself, not database write permission.

So the three kinds of tampering each expose themselves differently. Change the content of any row → that row's digest changes, and the prev_hash recorded by the next row no longer matches. Delete a row in the middle → the next row's prev_hash points at a digest that does not exist, and that number vanishes without a trace — a mark that cannot be patched over. Recompute the whole chain → impossible without the key; recompute with a different key → the key generation is inside the digest, and a mismatched generation is read out. The keyed and unkeyed forms also each have their own digest domain prefixes, so "downgrading a keyed row to an unkeyed recomputation" likewise does not match.

Verification has an exit. GET /api/v1/audit/verify walks the chain and gives a conclusion; both audit addresses require the kernel audit permission — it is not something any logged-in user can read.

What happens when retention expires. Audit does not grow without limit; pruning is a recorded event: how many rows were cut and which number ranges, written in that row's own fields on the chain (pruned_count / pruned_ranges), and one audit.chain.pruned entry is left. So "this stretch has no records" has two answers — it never happened, or it happened but was cleaned up by the rules — and the two are different shapes on the chain, not the same blank.

What is recorded and what is not has a boundary. Recorded: who (from a verified session, not self-reported by the client), which address, what action, which object number, the result, and the input parameters. Not recorded: the output of commands, the body of theme files, and the plaintext of model passwords. The reason is one and the same — audit is retained long-term, queryable by many people in the backend, and also moves away with whole-site archives, which is a second storage location, and "a person who can change the archive bytes" can also change the archive and its manifest together. So sensitive content does not enter the audit, and changing an archive is proven by a fingerprint: creating and taking an archive each record a fingerprint pressed from per-cell digests, and that fingerprint sits on the HMAC chain — someone who changes both the archive bytes and the manifest cannot change the audit chain.

Redaction happens in exactly one place. The rule for masking by key name (passwords, tokens, api_key and the like) has a single implementation, and call sites do not each mask again — two sets of rules will always drift, and the drifted form is "this field looks empty, but actually it was missed by masking". Rejected writes leave nothing: the failed validation does not land in the audit, otherwise any account with write permission could use an infinitely replayable 400 to pile up a long-retained store.

What questions it answers. "Who changed the model password last Wednesday" (whether it changed, when, which host, whether it was changed — the password itself is not recorded), "has this archive been touched since it was created", "who published this content and based on which revision", "who revoked, and when, a role's permission to download the whole-site archive". It does not answer "what the assistant did after receiving the output" — that is the question for the model-call records surface; the two sides each have their own readers and do not impersonate each other.