#24 [Feature]: Browse audit events from the CLI
Originally created by: thomijasir
Originally owned by: thomijasir
Feature description
Add dopbase audit list, an administrator command that shows one page of audit events at a time in a readable table.
Current behavior
Since [#131] the CLI has dopbase audit verify and dopbase audit export. Export already takes the action, project, environment, and actor filters, resolves names to IDs, and follows cursors to the end of the log, but it writes JSON lines. There is still no quick way to look at the latest events from a terminal.
Why we need this
Administrators need a quick way to investigate secret access, configuration changes, authentication events, and operational actions from a terminal or script, without exporting the whole log or opening the Admin UI.
Proposed CLI interface
dopbase audit listdopbase audit list --project storefront --environment storefront/productiondopbase audit list --action secret.updated --actor admin@example.com --limit 100dopbase --json audit list --cursor <CURSOR>
list and export share the same filter flags and the same name resolution, so the two commands cannot drift apart.
Expected behavior
- Filters for project, environment, action, and actor, alone or combined. Project and environment names resolve to IDs before the audit request.
--limitaccepts 1 through 200 and defaults to 50, the server default. The CLI rejects other values before sending a request.- The table shows time, chain sequence (
seq), actor, action, resource, project ID, and environment ID. Legacy records with no chain position show-. The sequence lets an event found while browsing be matched againstdopbase audit verifyoutput. - When more events match, the command for the next page is printed to standard error, with the original filters and the
--cursorvalue. Standard output holds only the table, so it can be piped. The server does not tie a cursor to a filter set, so the printed command repeats the filters to keep a cursor from being reused with different ones. --jsonprints the API page unchanged (itemsandnextCursor) and nothing on standard error.- Control characters and bidirectional overrides in stored fields are shown as
?in the table. After [#131] the threat model includes someone with write access to the database, and a planted actor label with terminal escape codes could otherwise erase or rewrite rows on an investigator's screen. JSON output keeps the stored value. - The command uses administrator authentication. A member gets the server's authorization error (
This operation requires an administrator.). Runner and agent tokens are refused by the CLI's sign-in check before any audit request. Today that check saysthe configured Dopbase credential is invalid or expired, which is misleading for a valid runner token. Fixing that message affects every administrator command, so it is tracked as a follow-up.
Security and compatibility
- Never reveal secret values. Metadata is left out of the table and shown as received under
--json; the CLI never fetches related plaintext. - Keep cursors opaque and pass them unchanged.
- Send filters with proper URL encoding (the existing
api_paths::audit::collectionhelper). audit exportkeeps its flags and output. It now fails on a malformed page instead of stopping quietly.
Out of scope
- Fetching a single event by ID, since no item endpoint exists.
- Secret history or rollback.
- Changing audit retention or server authorization.
Possible follow-ups:
- A clearer CLI message when a runner or agent token runs an administrator command.
--since/--untiltime filters (server change).- A
--resource-typefilter (server change). GET /api/v1/audit-events/{id}for anaudit showcommand (server change).
Acceptance criteria
- [ ] Administrators can list the newest events and fetch the next page with the printed command.
- [ ] All filters work alone and in combination, and
listandexportshare them. - [ ] Names resolve to IDs before the audit request.
- [ ] Invalid limits are rejected locally.
- [ ] The next-page command goes to standard error, and JSON mode prints only the API page.
- [ ] Planted control characters cannot reach the terminal through the table.
- [ ] Members receive the server's authorization failure, and runner and agent tokens never reach the audit endpoint.
Test scenarios
- Extend
app/tests/cli/commands/audit.rs, which runs the CLI against the in-processFixtureserver; no separate fake server is needed. - Cover paging through the printed commands (including filter values that need shell quoting), JSON fidelity against the API, each filter alone and combined, empty results, local limit errors, a rejected cursor, planted escape codes, and authorization failures.
- Add parsing cases to
app/tests/cli/args.rs.
Documentation
Document the administrator requirement, filters, page size, cursor paging, JSON scripting versus audit export, and the fact that events do not expose secret values.
Dependencies
Builds on [#131]. Uses the existing GET /api/v1/audit-events endpoint; no server change is required.
Ticket changed by: dopbase