Menu ▾ ▴

#124 Audit log export as JSON lines

closed
nobody
None
2026-10-23
2026-10-17
Anonymous
No

Originally created by: bosd

Implements the second slice of [#119]: exporting the audit log. dopbase audit export streams records as JSON lines to standard output or a file, so an operator can ship them to external, write-once storage.

Stacked on [#123]: this branch builds on feat/audit-chain, so the PR currently shows that commit too. Once [#123] merges (or on a rebase) only the export commit remains; review 8e9eae3 for this change. Retention and the read-only auditor role from [#119] follow in separate PRs.

Summary

  • dopbase audit export writes one JSON object per line to standard output, or to a file with --output <FILE>. Files are written atomically with owner-only permissions (0600) through the same path as secret export, and an existing file is never replaced without --force.

  • The export follows pagination to the end, so a full export never silently stops at the 200-record API page limit. --limit <N> caps the stream when a partial export is wanted, and --action, --project (name or ID), --environment (reference or ID), and --actor (email or actor ID) narrow it. Without filters the whole log is exported.

  • The audit list API now carries the chain fields seq, prevHash, and recordHash on every item, so each exported line keeps the evidence needed to check and anchor the copy outside Dopbase. The fields are absent only for records that predate the chain and have not been sealed yet.

  • Standard output stays raw JSON lines in every mode so it can be piped directly (dopbase audit export | jq ...); with --output and --json the count and path are printed as an object instead.

Compatibility

  • Additive only: the three chain fields join the audit list response, older clients ignore them, and all existing filters, endpoints, and clients are unchanged.
  • Export reads the audit log through the existing list API, so it is administrator-only exactly like reading the log, and it reads no secret values.
  • The new audit::collection path builder replaces no existing route; GET /api/v1/audit-events is unchanged apart from the added response fields.

Verification

  • cargo fmt --check
  • cargo clippy --locked --all-targets --all-features -- -D warnings
  • cargo test: cli 211 (new tests cover one JSON line per record with chain fields and newest-first order, action/project/environment/actor filters, a failed project lookup, a zero limit, a capped stream, 205 records flowing past one API page through the cursor, private file output that refuses to overwrite without --force, and the --json summary), constants 4 (encoding of the new filter builder), main 27, services 21, users 15, backups 9. The 3 pre-existing commands::export::* failures need the util-linux script binary and are unrelated to this change.
  • bun run test:docs, bun run test:github (17/17), bunx prettier --check on the changed Markdown.

Checklist

  • [x] I kept this pull request focused on one problem.
  • [x] I added or updated tests for behavior changes, or explained why tests are not needed.
  • [x] I updated the documentation and CHANGELOG.md when public behavior changed, or explained why they are not needed.
  • [x] I updated relevan documentation inside /docs

Related

Tickets: #119
Tickets: #123
Tickets: #125
Tickets: #131

Discussion

  • Anonymous

    Anonymous - 2026-10-23

    Originally posted by: bosd

    Superseded by [#131], which merged this work (rebased onto main, with review hardening on top). Closing.

     

    Related

    Tickets: #131

  • Anonymous

    Anonymous - 2026-10-23

    Ticket changed by: bosd

    • status: open --> closed
     

Log in to post a comment.