#119 [Feature]: Audit log export, retention and tamper evidence
Originally created by: bosd
We are evaluating Dopbase as a lightweight self-hosted secrets manager for a small consultancy and want to work towards the access-control and audit-logging expectations of NIS2 (and similar frameworks such as ISO 27001). The current audit log (docs/reference/audit-events.md) already covers the right events. What is missing, and listed as roadmap there, is what makes it usable as evidence.
Proposal
- Export / forwarding: stream audit records as JSON lines to stdout or a file, and optionally to syslog or a webhook, so an operator can ship them to external, write-once storage.
- Retention: a configurable retention period, with a clear rule for what happens at expiry (archive then delete).
- Tamper evidence: each record carries a hash of the previous record (hash chain), plus a
dopbase audit verifycommand that checks the chain. An optional periodic signed checkpoint would let an operator anchor it externally. - Read access: a read-only auditor role that can view and export the log but cannot read secrets.
Out of scope: SIEM-specific integrations.
Happy to contribute a PR for the export part if the direction fits. Which of these would you accept, and in which order?
See also [#24] (browse audit events from the CLI).
Related
Tickets: #123
Tickets: #124
Tickets: #125
Tickets: #126
Tickets: #131
Tickets: #135
Tickets: #24
Originally posted by: bosd
Implemented and proposed in this order, as four stacked PRs. Each branch builds on the previous one and each PR targets
main; until a predecessor merges its diff shows the whole stack, so the per-PR commit noted below is the one to review.#123 — Tamper evidence (hash chain + verify) —
0015_audit_chainaddsseq,prev_hash,record_hashwith a unique sequence index. Appends stay atomic under SQLite's existing write lock, so no new locking.GET /api/v1/audit-events/verifyanddopbase audit verifyrecompute the chain in sequence order and stop at the first break (exit0intact,2broken;--jsonincludes the head sequence/hash for external anchoring). Records written before the chain are sealed during the next startup migration pass and during backup restore.#124 — Export —
dopbase audit exportstreams one JSON object per line to stdout or--output <FILE>(written atomically, mode0600, never replaced without--force), with--action/--project/--environment/--actorfilters and--limit; pagination is followed to the end, so a full export never stops at one API page. The audit list API now carriesseq/prevHash/recordHashadditively, so every exported line remains externally verifiable. Syslog/webhook forwarding is deferred: reliable forwarding (backpressure, retries, durability) is a separate problem from exporting, and file/stdout already covers shipping to write-once storage.#125 — Retention —
audit_retention_daysinserver.tomlorDOPBASE_AUDIT_RETENTION_DAYS; unset (the default) keeps the whole log,0is rejected as a misconfiguration. The expiry rule is exactly archive, then delete: expired records are written toaudit-archive/as JSON lines (every stored column, chain fields included) and only then deleted in the same transaction, together with an anchor (0016_audit_chain_anchor) recording where the chain continues.dopbase audit verifypicks up at the anchor and reportsPruned through: sequence N, so retention never reads as tampering, and appends after a full prune continue the sequence instead of restarting. Only the oldest contiguous run is pruned — a record timestamped behind a retained one (clock step) would leave a hole no anchor can describe, so it waits. Retention runs at startup and on each audit write, the same opportunistic pattern as the existing 30-day session pruning, since the codebase has no scheduler. Archives live outsidedopbase backup snapshot(database only) and the docs say to back them up separately.#126 — Read-only auditor role — a new
AdminRole::Auditorthatrequire_audit_readeradmits to the audit list and verify endpoints only;require_metadata_accessandrequire_read_accessexplicitly refuse it, so secret metadata, project/environment data, instance status, mutations, and account administration all return403. Members keep their existing access and still cannot read the log. Migration0017rebuildsadmins(SQLite cannot alter a check constraint) and rebuildssessionsafter the swap so foreign keys follow the new table — no session is revoked. The Admin UI role picker is not included (API-created accounts, same API-first scope as [#120]).Signed checkpoint: not included as a periodic signer — the verify response already exposes
headSeq/headHashfor anchoring in external write-once storage, so a periodic signed checkpoint can be a focused follow-up on top of [#123]. SIEM integrations remain out of scope per the issue.All four are implemented and green on
fmt,clippy -D warnings, the full test suite,test:docs, andtest:github(the 3 pre-existingcommands::export::*failures in this environment need the util-linuxscriptbinary and are unrelated).Related
Tickets: #120
Tickets:
#123Ticket changed by: dopbase
Originally posted by: dopbase
@bosd Thanks for the contribution!
I’ll cherry-pick the changes that are required and leave out anything unnecessary, such as the dual secret keys. We can work around that for now. I’ll focus on adding tamper evidence, as I think it’s a valuable improvement.