#134 feat(audit): browse audit events with dopbase audit list
Originally created by: thomijasir
Summary
Adds dopbase audit list, a one-page-at-a-time table of audit events for administrators. Closes [#24].
audit export from [#131] already had the filters, name resolution and cursor handling, so the first commit moves them into a shared AuditFilters and list reuses them:
audit
+ list --action --project --environment --actor --limit 1..200 (default 50) --cursor
verify --anchor
export --action --project --environment --actor --limit N --output --force
\___________ AuditFilters (shared) _____/
:::text
dopbase audit list --limit 2
stdout TIME SEQ ACTOR ACTION RESOURCE PROJECT ENVIRONMENT (+ "2 event(s)")
stderr Info: More events match. Next page: dopbase audit list --limit 2 --cursor <C>
dopbase --json audit list
stdout the API page unchanged: {"items": [...], "nextCursor": ...}
stderr (nothing)
Where this differs from the original issue text:
- The next-page command goes to stderr and repeats the original filters. The server doesn't tie a cursor to a filter set, so reusing a cursor with different filters would skip or repeat events. Keeping the hint off stdout also leaves the table clean for
grepandless. - A
SEQcolumn shows each event's chain position, so it can be matched againstaudit verifyoutput. Legacy rows show-. - Table cells replace control characters and bidirectional overrides with
?. Since [#131] we assume someone may write rows directly, and a plantedactorLabellikeevil\e[2K\rforgedcould otherwise erase or rewrite rows on an investigator's screen.--jsonkeeps the stored value. --limitis checked by clap before any request.exportnow fails on a page without anitemsarray instead of stopping quietly and reporting a short export as a success.
The issue body has been updated to match.
Compatibility
No compatibility impact. audit export keeps the same flags and output, and the server is unchanged. The only behavior change outside the new command is that export now errors on a malformed API response.
Merge risk: a two-way door. The change is CLI only, with no migrations or server changes, so reverting the branch removes the command and nothing else. Blast radius: the audit subcommands. The shared output::printable helper is new and only audit list uses it.
Known gap, left out on purpose: a runner or agent token running audit list is refused before any audit request, but the message comes from the shared sign-in check (the configured Dopbase credential is invalid or expired) and is misleading for a valid token. Fixing it changes every administrator command, so it belongs in its own PR. Members get the server's This operation requires an administrator.
Verification
cargo fmt --checkandcargo clippy --locked --all-targets --all-features -- -D warningspass. While working,cargo test --test cli auditandcargo test --test cli argspassed after each commit.bash ./scripts/verify-backend.shpasses in a cleanapp/Dockerfile.testcontainer on the final branch: fmt, clippy, the full test suite with--test-threads=1(CLI suite: 218 passed, 1 ignored), release build, and the CLI and server smoke checks.- An end-to-end script ran 8 checks against the release binary in the same container, with a real server, a bootstrapped admin, and
sqlite3used to plant a record. All passed:
| Check | Result |
|---|---|
audit list default table |
headers and 9 events, newest first |
audit list --limit 2 \| cat |
stdout holds only the table; the next-page command is on stderr |
| Run the printed next-page command | returns sequences 7 and 6, no overlap with page 1 |
--project storefront --environment storefront/production --action secret.created |
only secret.created rows |
--json --limit 2 |
page JSON with nextCursor, empty stderr |
--limit 201, --project nope |
rejected |
Planted actor_label with ESC, [2K, CR |
table shows evil?[2K?forged, JSON keeps \u001b[2K\rforged |
| Runner token | refused, nothing on stdout |
- New tests in
app/tests/cli/commands/audit.rs, run against the in-processFixtureserver: paging through the printed commands, including a filter value with a space and a quote checked by a realsh;--jsonequal to a direct API call; every filter alone and combined, plus empty results; local limit errors and a server-rejected cursor; planted escape codes; agent token and member refusal.app/tests/cli/args.rsgains parse cases, and the export test's seeding loop is now a shared helper. bun run test:docsandbunx prettier --checkpass 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.mdwhen public behavior changed, or explained why they are not needed. - [x] I updated relevan documentation inside
/docs
Ticket changed by: dopbase