Content Versioning & Audit Trail
Overview
OpenRegister provides a complete content versioning and immutable audit trail system for all register objects. Every mutation is recorded as a versioned snapshot in a tamper-evident, hash-chained log with a minimum 10-year retention guarantee. The system satisfies Dutch government compliance requirements including Archiefwet 1995, BIO, and AVG/GDPR Article 30.
Tender demand: 56% of analyzed government tenders require immutable audit trail capabilities.
Content Versioning
Semantic Versioning
Every object carries a _version field following semantic versioning (MAJOR.MINOR.PATCH):
| Event | Version Change |
|---|---|
| Object created | 1.0.0 |
| Normal save/update | PATCH increment (1.0.1, 1.0.2, …) |
| Draft promoted to published | MINOR increment (1.1.0) |
| Schema-breaking change or explicit user action | MAJOR increment (2.0.0) |
| Bulk update (each object independently) | PATCH increment per object |
Version History
Every version is stored as a full snapshot in the audit trail. Users can:
- List all versions of an object:
GET /api/objects/{register}/{schema}/{id}/audit - Compare any two versions with field-level diffs
- Roll back to any previous version:
POST /api/objects/{register}/{schema}/{id}/revert/{version}
Draft / Published Lifecycle
A record can have named drafts beside its published version. A draft stores only the changed fields, is visible to its creator and to users who may change the record, and becomes the published version when it is promoted, after a per-field conflict check against the version it was made from. See Draft Versions.
Immutable Audit Trail
Hash Chaining
Every audit trail entry is cryptographically chained to the previous entry. From the keyed-from row on, the link is an HMAC under a chain key:
entry_hash = HMAC-SHA256(chain_key, previous_entry_hash + entry_json)
The chain key is a tenant key held by TenantKeyService: it is generated on first use and stored encrypted with Nextcloud's ICrypto, so it is not in the audit table and a database write alone cannot recompute a link. Rows written before the chain was keyed keep their unkeyed link, SHA-256(previous_entry_hash + entry_json). The repair step KeyAuditHashChain runs on upgrade and on install. It verifies those rows, keeps the verdict under the app config key audit_chain_unkeyed_verdict, and starts the keyed chain at the next row, linked onto the last unkeyed one. The keyed-from row is stored together with an HMAC of it, so moving it is detected.
This tamper-evident chain allows independent verification: if any entry is modified or deleted, the chain breaks at that point. The chain can be verified via:
GET /apps/openregister/api/audit-trails/verify?from={entryId}&to={entryId}
from and to are audit entry IDs, not timestamps, and both are optional — omit them to walk the whole trail. The endpoint is admin-only. It returns:
{ "valid": true, "entriesVerified": 309036, "brokenAt": null, "skippedNullHashes": 0, "unkeyedEntries": 309000, "keyedFrom": 309001, "keyBoundaryIntact": true }
unkeyedEntries counts the verified rows before keyedFrom that carry the older unkeyed link. A keyBoundaryIntact of false means the stored keyed-from row was altered, and the chain is then reported as not valid.
brokenAt is the ID of the first entry whose recomputed hash disagreed with the hash stored against it; verification stops there, so entriesVerified counts only the entries confirmed before the break.
Sealing
Chaining an entry is called sealing, and it is a separate step from writing it. An entry is inserted first and sealed immediately afterwards, because its hash depends on the entry before it — so sealing has to be serialised, while writing does not.
Serialisation uses an exclusive advisory lock (openregister/audit-seal). Without it, two concurrent seal passes can each read the same predecessor and then write, leaving many entries chained onto one predecessor. That is a fan-out rather than a chain, and verification correctly reports it as broken even though nobody tampered with anything.
Sealing is fail-soft. If the lock cannot be acquired within three attempts, the write still succeeds and the entry is simply left unsealed — an audit entry with no hash. Refusing the write instead would mean a lock contention could lose audit data, which is worse than a gap.
That makes a sweeper necessary rather than optional:
| Job | OCA\OpenRegister\BackgroundJob\AuditSealJob |
| Interval | every 5 minutes |
| Work per tick | up to 10 passes × 500 entries |
| Order | oldest unsealed first, so it is resumable by construction |
A backlog after heavy write activity is normal and drains on its own. A backlog that never shrinks is not: it means sealing is failing on the write path and in the sweep, and the job logs a warning saying so.
An unsealed entry is not a tampered entry. It is an entry the chain cannot vouch for either way. Verification skips unsealed entries and carries the last sealed hash forward, so gaps weaken the guarantee without producing false alarms.
Seal coverage is shown under Administration settings → Open Register → Log integrity, alongside a button that runs the full verification on demand. The two numbers answer different questions and the page keeps them apart deliberately: coverage says whether the sweeper is keeping up, and says nothing about whether the stored hashes still agree with their rows. Only verification answers that.
Repairing a broken chain
If verification reports valid: false, read the entry at brokenAt before doing anything else. There are two causes and they are not equally serious:
- The entry was altered after it was written — the case the chain exists to expose.
- It was sealed by a historical concurrent pass and chained onto the wrong predecessor — a bookkeeping fault, with the entry itself intact.
Only once you have established which, repair with:
occ openregister:rechain-audit-trail
This recomputes every hash from genesis, in ID order, under the seal lock — so the result is a single chain by construction. It also seals any entry that never had a hash, so one run repairs both failure modes.
It is a command rather than a background job on purpose. Rewriting stored audit hashes is precisely the event the chain is built to make suspicious, so it must be asked for by a person; it prompts for confirmation unless given --force, supports --dry-run, and logs its start and completion at warning level so the rewrite is itself part of the record.
Audit Entry Structure
Every create, update, and delete produces an audit trail entry containing:
| Field | Description |
|---|---|
id | Auto-incrementing sequence number |
timestamp | Server-side UTC timestamp (not client-provided) |
user | Nextcloud user ID of the actor |
action | create, update, delete, read (for sensitive data) |
objectUuid | UUID of the affected object |
schemaUuid | UUID of the schema |
registerUuid | UUID of the register |
changed | JSON diff: { "fieldName": { "old": "...", "new": "..." } } |
snapshot | Full object state at this point in time (for create) |
hash | SHA-256 hash of this entry |
previousHash | Hash of the preceding entry in the chain |
ipAddress | Client IP address |
sessionId | Nextcloud session or API token identifier |
Which rule allowed a read
A read entry records who opened an object and when. When one of the schema's read
rules let the reader see it, the entry also records which rule:
| Field | Meaning |
|---|---|
ruleDigest | SHA-256 (64 hex characters) of the canonical JSON of the matched rule entry, as declared on the schema |
ruleVersion | The schema version that rule belonged to at the time of the read |
The rule named is the first entry in the schema's read list the reader matched, with its
group and match as declared, not as resolved for this reader: two handlers reading their
own meldingen under the same rule get the same digest. A read no rule mediated (an
administrator, the object's owner, or a schema without read rules) has both fields null.
Proving which rule was in force. Take the schema as it stood at ruleVersion, find the
rule entry the reader matched, and compute its digest: sort the keys of every map
(recursively; list order is kept), encode as compact JSON with unescaped slashes and unicode,
and take SHA-256. A bare group name ("behandelaars") is digested as the JSON string. The
result equals ruleDigest. The rule may have changed since; the digest still names the one
that applied.
Both fields are part of the hash chain when present, so a digest cannot be altered, removed
or added after sealing without GET /api/audit-trails/verify reporting the entry. When they
are absent they are left out of the sealed form entirely, so entries written before the fields
existed verify exactly as before.
Retention
- Audit trail entries have a minimum 10-year retention requirement
- Entries cannot be modified or deleted via the API
- Background jobs enforce the minimum retention period before any physical removal
- Audit trail is included in e-Depot SIP packages for permanent archival
Schema, Register and Organisation Edits
Every create, update and delete of a schema, a register or an organisation writes one sealed row on the same hash-chained audit trail, whichever door the write came through: the API, updateFromArray, a tool provider, a configuration import or a repair step. The row is written by a listener on the entity's own event, so a door added later is covered without changes.
Actions
| Action | Written when |
|---|---|
schema.created, schema.updated, schema.deleted | A schema is stored, changed or removed. |
register.created, register.updated, register.deleted | A register is stored, changed or removed. |
organisation.created, organisation.updated, organisation.deleted | An organisation is stored, changed or removed. |
A save that changes nothing writes no row. Derived fields (updated, created, facets, version) never count as a change on their own.
Row shape
Each row carries the actor (user, userName, or system without a session), the organisationId (the entity's organisation, or the organisation itself for organisation.*), the cause and causeRun of the write (person, import, migration, scheduled, ...) and a changed block:
- created:
slug,title,versionand, for a schema, the property names. - updated:
slug, for a schema or registerversionBeforeandversionAfter, andfields: one{path, old, new}per changed path, for exampleproperties.age.maxLengthorauthorization.read. - deleted:
slug,title,version, the property count and asha256of the definition as it was; the definition itself is not kept.
A value longer than 2 KB is stored as its hash and length instead of the value.
Masking
A value under a key that names a credential (password, secret, token, apiKey, clientSecret, privateKey, in any case) is never stored: the row shows ******** for it, old and new. A changed credential is still visible as a changed path.
Reading the edits
GET /api/schemas/{id}/changes?_page=1&_limit=20
GET /api/registers/{id}/changes?_page=1&_limit=20
Both are for administrators only (403 otherwise) and answer {results, page, limit, hasMore}, newest first. _limit defaults to 20 and is at most 100. Organisation edits are read from the audit trail list, GET /api/audit-trails?action=organisation.updated.
Deletion Audit Trail
The deletion audit trail documents the full lifecycle of every deletion:
Soft Delete
All API deletions are soft by default:
_deletedfield is set withdeletedBy,deletedAt, and optionalreason- Object remains in the database and is excluded from normal queries
- Retrievable via
?_deleted=trueor the trash endpoint - Deletion audit entry is created
Restore
- Soft-deleted objects can be restored:
POST /api/objects/{register}/{schema}/{id}/restore - Restore creates an audit entry with action
restore - Version is incremented on restore
Cascade Delete Tracking
When an object is deleted and other objects reference it:
- Configured
onDelete: cascadereferences are deleted transitively - Each cascaded deletion gets its own audit entry with
reason: cascade_from:{uuid} - Cascade chains are tracked to prevent circular reference loops
Physical Purge
Physical purge (permanent removal) happens only:
- After the configured
archive.purgeAfterretention period has elapsed - Via the destruction workflow with multi-step approval (see Archiving)
- A purge audit entry is written before physical deletion
GDPR Compliance
For GDPR (AVG) compliance, the audit trail supports:
- Right of access (Article 15): Export all audit entries for a specific user
- Right to erasure (Article 17): Pseudonymization of user identifiers in audit entries (the data itself may be deleted, but the audit record of deletion is retained)
- Article 30 Register: Processing activities are linked to objects via the verwerkingsregister integration
- Data minimization: Read auditing only activates for properties marked as sensitive (
sensitivity: high)
API
GET /api/objects/{register}/{schema}/{id}/audit List all versions/audit entries for an object
GET /api/objects/{register}/{schema}/{id}/audit/{n} Get a specific audit entry
POST /api/objects/{register}/{schema}/{id}/revert/{v} Revert object to version v
GET /api/audit/verify Verify hash chain integrity
GET /api/audit/export Export audit trail (CSV/JSON)
Standards
| Standard | Role |
|---|---|
| Archiefwet 1995 | 10-year minimum audit retention |
| BIO (Baseline Informatiebeveiliging Overheid) | Audit logging requirements for government systems |
| AVG / GDPR Article 30 | Processing activity documentation |
| NEN-ISO 16175-1:2020 | Records management principles |
Related Features
- Object Storage & Lifecycle — objects being versioned and audited
- Archiving & Records Management — long-term retention and e-Depot transfer
- Access Control (RBAC) — audit entries record access decisions
- Event-Driven Architecture — audit entries are created from lifecycle events