Architecture / Decision records / ADR-HIS-050
ADR-HIS-050 The audit unit: one intake path, a hash-chained append-only store, the catalogue and access to audit¶
| Status | Accepted |
| Decided | 2026-11-25 by session RC-1-S04 |
| Record | Drafted 2026-11-25; approved 2026-11-25 by the Enterprise Architecture Board |
| Where the rule lives | services/ess-audit/ (its README.md; module mod-ess-006, migrations db/mod_ess_006/) |
Context¶
RC-1-S04 builds the D10 audit service, MOD-ESS-006, as the unit services/ess-audit. It covers FR-ESS-AUD-001 and FR-ESS-AUD-002, behind the contract audit.v1 of ADR-HIS-048. Every unit emits audit to this one through the service kit. Every later session that reads audit (D06 access review, D08 security indicators, the ESS screens, the gate's evidence) depends on what it stores and how. The specification leaves five choices to the implementation:
- the integrity mechanism (ASM-ESS-006: "the requirement is detectability");
- where the registered audit event catalogue lives (CFG-ESS-017). The configuration service (RC-1-S05) is not built, and
audit.v1has no operation to register a type; - how the minimum catalogue's category fields are enforced;
- how intake is authorized when the decision point may be the thing that is down;
- where an export's file lives before the D02 storage channel (RustFS, RC-2) exists.
Options considered¶
- Integrity: a digest per event; a hash chain; digested batches anchored outside the store; database permissions alone.
- Catalogue: read from the configuration service; a file in the jar; a table of the unit, seeded from the specifications.
- Category fields: not enforced (stored as sent); enforced as written in D10-ESS 9.5 and 7.3; enforced with the patient reference made mandatory for every patient-related category.
- Intake authorization: a policy decision per event; a local rule (only a service identity appends).
- Export file: the database of the unit; a local disk; waiting for D02 storage.
Decision¶
- One intake path. The API, the batch form, the backbone channel
his.ess.auditintake.v1and the service's own audit events all go throughAuditStore, in this order: - schema validation against the contract's own file (
AuditEventSubmission.v1.schema.json, copied into the jar at build time); - the catalogue: an unregistered type is quarantined;
- the category fields;
- deduplication on
eventId; - the privacy rules;
- the append, in one transaction with the AuditEventRecorded announcement.
An event is acknowledged only once it is stored or quarantined. Quarantine keeps what was received, byte for byte, and the store refuses to delete it.
- A hash chain. Each event is stored as its canonical JSON (content: members sorted, no whitespace, RFC 8785 for the value types audit holds). Its digest is sha256(previousDigest + "\n" + content). There is one chain per UTC day of recorded time, each starting at sequence 1 and linking to the last digest before it. One head row, under an advisory lock, gives the chain one order.
- Verification walks the chain and finds changed content, index columns that disagree with the content, sequence gaps, broken links, removals at the end (against the head), and reordering.
- Answers and exports are built from content, never from the index columns.
- Triggers refuse UPDATE, DELETE and TRUNCATE of stored events, of quarantined content and of incident evidence, so no application function can alter them (BR-ESS-020).
- The catalogue is the table event_type of the unit. It is seeded by a generated migration from section 9.5 of all ten domain specifications: 205 types, each in one of the nine categories. A later registration is a new migration (scripts/catalogue-migration.py). It moves to the configuration service as the item CFG-ESS-017 once RC-1-S05 offers it.
- Category fields are enforced as D10-ESS 9.5 and DE-ESS-013 in 7.3 state them, and failures are quarantined as schema-invalid with the field named.
- A field the table makes conditional ("where used", "for signing", "where the change needed approval") is required only in that case.
- The patient reference is required only for event types marked patient_scoped (FR-ESS-AUD-001 part 7). No published catalogue says which types are, so none is marked yet. The question is on the session's issue.
- Intake is authorized locally: only a service identity appends, and a person who tries is refused and audited. No policy decision is asked, so that audit intake never depends on the decision point and an outage of it stays auditable (BR-ESS-022, DEC-ESS-018). Reading is decided by the decision point as for any resource (ess.AuditEvent, ess.AuditExport, ess.AuditIntegrityVerification, ess.AuditCompletenessReport, ess.AuditQuarantineEntry), with the stated purpose and a self-review flag as attributes. A service identity never reads.
- The service audits itself directly, in the transaction of the read or action, as ess.aud.access, ess.aud.integrity and ess.aud.integrity-failure with criteria and purpose. The kit's enforcement point gained a variant whose refusals the caller audits (PolicyEnforcer.require(check, RefusalAudit)), because the audit-access category needs the criteria and purpose that only the caller knows.
- The export file is kept in the unit's database (audit_export_content) and its location names the D02 storage channel. It is removed when the location expires. It moves to RustFS with object lock when D02 storage exists (RC-2).
- This unit's copy of the kit sends the audit payload of the contract: no nulls, beforeAfter, no emittedTime, no empty resource identifier, schemaversion 1.0. It also gained DomainEventPublisher.publishUnsequenced for an event the contract declares not sequenced. The template itself is unchanged.
Rationale¶
- One path means one set of rules, whoever submits, so the API, the channel and the service itself cannot disagree. The contract's own schema file keeps the unit and the contract from drifting.
- A chain detects removal and reordering, which per-event digests cannot. A canonical text column makes the digest reproducible by an independent consumer of an export (AC-05) without the service's code. Triggers make "no function permits it" (AC-01) true of the store as well as the API. Only the table's owner, acting outside the application, can get past them, and verification detects what it changed (AC-02).
- A seeded table gives the unit a complete, governed catalogue now, without a dependency on an unbuilt service. A table, unlike a jar file, is what a later registration changes.
- Enforcing the category fields as written follows the specification; the emitters are told so in
contracts/ess/CONTRACT-POINTS.md(emitter point 4). Making the patient reference mandatory for a whole category would quarantine legitimate events: tasks, escalations and bed changes are Record change events without a patient. Part 7 conditions it on the type, so the type carries the flag. - A decision call per audit event would make audit unavailable exactly when the decision point is, and would add a dependency to the busiest path of the system.
Consequences¶
- Every unit made from the template must send the contract's payload before its audit is stored. Until the template is changed, its provisional fields (
details,emittedTime, JSON nulls) fail the schema. Its codesrecord-created,access-deniedandaccess-check-unavailableare not registered. Such events are quarantined and alerted, never lost (handover follow-up for the template). - Each domain checks its 9.5 types and registers new ones through a migration of this unit, until the catalogue moves to configuration. A domain marks a type
patient_scopedonce the question is answered. - The chain serializes appends on one lock. If NFR-ESS-005 measures more than one chain can take, the chain is split by partition, with the head kept per partition. The verification walks each chain the same way.
- The scheduled verification runs daily over the last two days (
his.audit-service.verification-window). The jobs are safe on several instances. - The forwarding to security monitoring (FR-ESS-AUD-003) builds on AuditEventRecorded and the Security category events this unit already stores.