Skip to content

feat(audit): add the audit trail core - #188

Merged
fog-workflows[bot] merged 1 commit into
masterfrom
feat/audit-core
Nov 10, 2026
Merged

fog-workflows[bot] merged 1 commit into
masterfrom
feat/audit-core

Conversation

@mastacontrola

Copy link
Copy Markdown
Member

What

fog-node now keeps an append-only audit trail, like FOG 1.6 (its ADR 0021). The decisions are in docs/adr/0003-audit-trail.md. The brief is 2026-11-10-audit-core.

  • AuditLog model. Its indexes come from audit/ensure-indexes at bootstrap (migrate: 'safe'). It has no stock.auditlog CRUD routes.
  • sails.helpers.audit.record writes one row and never throws into a request.
  • Request seam (api/hooks/audit). Each request gets a correlationId. The middleware in config/http.js attaches the finish listener, so the seam also records a 403 from Sails' own CSRF check. It records every 401/403 and every authenticated POST/PUT/PATCH/DELETE.
    • It skips allowed reads and /agent/v1/.
    • It skips the sign-in and sign-out routes, assets and /csrfToken.
    • It skips the read-only POST actions: general/datatable, general/columns, task-history, auth/token, and also host/pending-datatable.
  • sails.helpers.audit.can(req, perm) replaces the inline permission checks in the policies and controllers. A denial row then names the permission. Group refusals name group.update or group.create. A refused or failed page save is recorded as denied or failed, not as its 302.
  • Auth events: auth.login, auth.login.failed, auth.logout and auth.token.rejected. A JWT request now reports authVia: 'jwt'.
  • Agent events: agent.enroll and agent.token, with the 1.6 texts.
  • http.trustProxy defaults to false. npm run setup carries it forward. docs/install.md explains when to set it.

Known gaps

  • Each npm test run leaves a few rows that the cleanup cannot attribute to the suite: anonymous denied requests and auth.token.rejected. They have no test name to match. The ADR says which rows the cleanup deletes.
  • Plugin permission checks (printer, snapin) still record an empty permission, as the brief allows.

Test

  • npm test: 382 passing. The new test/integration/audit.test.js covers the seam, the auth and agent events, the outcome overrides and the CSRF refusal. The seam, CSRF, page-save and sign-in tests were each made to fail with their feature removed.
  • npm run test:ui, npm run test:ui:prod, npm run test:install: green.

🤖 Generated with Claude Code

…th and agent events)

fog-node now keeps an append-only audit trail, like FOG 1.6 (ADR 0021
there, ADR 0003 here):

- AuditLog model, with indexes from audit/ensure-indexes at bootstrap.
- audit.record writes one row and never throws into a request.
- Each request gets a correlationId. The middleware in config/http.js
  attaches the response finish listener, so the seam also sees a 403
  from Sails' own CSRF check.
- The seam records every 401/403 and every authenticated write. It
  skips allowed reads, the read-only POSTs (datatables, columns, task
  history, token), /agent/v1/, sign-in/out and assets.
- audit.can records the permission that a check consulted, so a
  denial row names it. Group refusals name group.update or group.create.
  A refused or failed page save is recorded as denied or failed, not as
  its 302.
- auth.login, auth.login.failed, auth.logout and auth.token.rejected.
  A JWT request now reports authVia 'jwt'.
- agent.enroll and agent.token rows with the 1.6 texts.
- http.trustProxy defaults to false, and setup carries it forward.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot enabled auto-merge November 10, 2026 16:19
@fog-workflows
fog-workflows Bot added this pull request to the merge queue Nov 10, 2026
Merged via the queue into master with commit 52dc322 Nov 10, 2026
6 checks passed
@fog-workflows
fog-workflows Bot deleted the feat/audit-core branch November 10, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant