Skip to content

Audit

Who did what. Each root owns a log, and so does each user, for their user routes. The gateway records each audited request with the chain of nodes it addressed; the audit service stores it and serves it back by node, or by user.

An audit event is one request, not one change. It says who called which route, on which nodes and ids, from where, and how the request ended. A service may add what changed (details). Nothing else.

Piece Says Owner
Actor The member (or, on a user route, the user) whose credential was admitted, and which credential Gateway (admission)
Nodes The chain the route addressed, root first Gateway (admission)
Action Service, method, route template, path params Gateway (route match)
Origin IP, user agent Gateway
Outcome How the request ended Gateway
Details What changed The service, on X-Plat5-Audit-Details
Created The id a create produced The service, on X-Plat5-Audit-Created
Named nodes The chain a user route changed The service, on X-Plat5-Audit-Nodes and X-Plat5-Audit-Member
Store and read API audit service

Two settings, independent of each other:

  • Whether and how the gateway writes events is wiring, in the gateway’s env: AUDIT_MODE (sync, async, or off, default sync) and AUDIT_URL (env). It stays out of the config, so the admin token can’t turn audit off or weaken its delivery mode. Events already written mean the same either way.
  • Whether audit’s read routes are published at the gateway is services/audit.yml, like any service file (generated routes). Leaving it out of services hides the reads; the gateway still writes events.
AUDIT_MODE=sync (default) AUDIT_MODE=async AUDIT_MODE=off
Gateway AUDIT_URL Required to boot Required to boot Ignored
audit service Runs Runs Need not run. If services/audit.yml stays in the config, its read routes answer as an unreachable upstream does
Audited request Intent written before forward. 503 if it can’t be Forwarded immediately; one completed event queued after the response Forwarded like any other
Route audit fields Applied Applied Accepted at apply, ignored
X-Plat5-Audit-* Read, stored, stripped Read, stored, stripped Stripped

The gateway logs the mode at boot. Turning audit on doesn’t backfill.

Audit is for reporting and compliance. A product feature never reads it: audit can be off, it’s behind a permission, and it may get retention. A feature that needs to know who did something records the member id itself (concepts/model.md).

An event is in the log of every node in its chain, so reading a node returns its events and everything below it.

Scope Event Logs
public Never —
A kind When audited Each node in the chain, and the node a create produced (created_id), so a node’s log shows its own creation
user When audited The user’s own, by user id. Also each node the service names, on a success

The user’s log holds what they did on their own routes: personal keys, account deletion, invite redeems. Only the user and other front doors read it. An account deletion is in no other log: an org sees only that the user’s member is now removed.

A user route that changes a tree (creating an org, redeeming an invite) is in that tree’s logs too. The tree isn’t taken from the path: the service names the chain on X-Plat5-Audit-Nodes, and the user’s member in that tree on X-Plat5-Audit-Member (below). The service is trusted; the caller is not.

Method decides the default: POST, PUT, PATCH, DELETE audited; GET, HEAD not. The route audit field overrides it.

An event exists once the gateway knows the actor and the node, and the route is audited:

Gateway result Event
401 None. There’s no trusted actor
403 at admit (node not found, not in the tree) None. There’s no tree to log into
429 None. Nothing ran, including a 429 from the failed-auth IP limiter in place of a permission 403
403 permission check rejected, one background write
400 on a param rejected, one background write
503, intent not written None, or rejected if the intent landed unseen (delivery)
Forwarded responded or no_response

Audit runs inside the gateway’s pipeline (access): the intent is written after the permission check and before forward, and the outcome after the service answers. So during an audit outage a 503 comes only after the permission check, and never says whether a node exists. The failed-auth IP limiter counts the permission 403 (access), which bounds how many rejected events a member without the permissions can cause.

Two writes per forwarded audited request, both keyed by request_id.

Intent. Before forward, and the client waits on it. It carries every event field except outcome, status, and details. Each attempt times out at 500ms; up to 3 attempts within 1s. If none succeeds, the gateway answers 503 and doesn’t call the service. It then sends a rejected / 503 outcome in the background, because the intent may have landed without the gateway seeing it.

Outcome. After the upstream answers, or fails. The client doesn’t wait on it. It runs in the gateway’s logging phase, so an upstream failure or a client disconnect still produces one. The gateway queues it in process and retries with backoff. The queue is bounded; an outcome that overflows it is dropped, logged and counted.

The guarantee in sync mode: an audited request doesn’t reach its service unless its intent is recorded. If the gateway dies or drops the outcome between forward and outcome, the event stays pending. Pending is not success, and nothing turns it into one.

One write per forwarded audited request, sent after the response in the gateway’s logging phase through the same bounded background queue and retry loop as outcomes. occurred_at is still captured at request arrival, and the client never waits on audit. During an audit outage or gateway crash, events that cannot be drained or overflow the queue are dropped, logged, and counted—trading the sync durability guarantee for lower write latency and half the audit database writes.

In either mode, a gateway refusal after admit is one write, in the background, queued like an outcome.

Every write is idempotent. An outcome is applied once, pending → final.

Audit stores what it’s sent. It doesn’t repeat the gateway’s or identity’s rules, and ignores fields it doesn’t know, so a newer gateway or identity never makes audited requests fail.

Headers on the upstream response. The gateway reads them only on audited routes, and strips them always, on every route.

Header Says Read on
X-Plat5-Audit-Details What changed Any audited route
X-Plat5-Audit-Created The id a create produced Any audited route
X-Plat5-Audit-Nodes, X-Plat5-Audit-Member The chain of nodes a user route changed, and the member in that tree Audited user routes, 2xx responses, both or neither

None of them can create an event, or change its outcome or status. They’re trusted as sent: the gateway checks their shape, not what they name.

Format One JSON object. Visible ASCII only: escape the rest as \u. At most 4096 bytes
Invalid or over the cap The event is recorded with details: null; the gateway logs a warning
Meaning The service’s. The gateway stores it as sent and never reads inside it

What goes in: what changed, with old and new values where the service has them ({ "role": { "from": "developer", "to": "admin" } }). A create names what it created. What stays out: secrets, and anything the caller couldn’t read from that route. Each service documents its own shapes; identity’s are in reference/api/identity.md.

One id: visible ASCII, one path segment, at most 128 bytes. Invalid → ignored, with a warning.

Any id the service returns is added as a log key, unchecked: the event is in the log of whatever node has that id. The service is trusted to return an id from the request’s own tree; if it returns another tree’s node id, the event goes into that tree’s log.

X-Plat5-Audit-Nodes is the node ids of the chain the route changed, root first, comma-separated, at most 32. X-Plat5-Audit-Member is the user’s member in that tree. Each id has the same rules as Created. On a 2xx to an audited user route, they become named_node_ids and named_member_id, and the event is in each named node’s log too: a read of one returns it, with the named member as the actor and no user id. Anywhere else, or one without the other, they’re ignored, with a warning.

So on a user route the service names the chain and the member, and that member is who acted in a read of those nodes’ logs. The gateway checks neither that the ids form a chain nor that the member is in that tree: the service is trusted, as it is with Created.

The event’s fields and the read API: reference/api/audit.md. Deployment-wide pull export (GET /internal/events): reference/api/internal.md. Storage, Owner/Writer DB roles, and partition pruning (audit prune): internals/audit-storage.md.

  • Export. audit exposes a deployment-wide long-polled cursor feed (GET /internal/events) on its INTERNAL_PORT returning finalized events in strictly monotonic commit order (seq), waiting up to 25 seconds and answering 204 when caught up. Plat5 ships no SIEM or object-storage push connectors; run a small shipper/relay against this feed to archive to WORM storage (e.g., S3 Object Lock) or forward to Datadog, Splunk, or BigQuery.
  • Retention. The live audit serve process runs as a non-deleting Postgres Writer role and cannot delete or truncate events. To enforce hot-store retention and GDPR storage limitation after archival, run audit prune --before YYYY-MM (or --older-than <N>m) from a scheduled job under the schema Owner role, which drops expired whole monthly partitions without touching live or future months.
  • Bodies, query strings, permissions, roles, or slugs in an event
  • Events from public routes, or a log chosen by a path param
  • 401s, 429s, or not-found 403s in the log
  • The gateway reading inside details, or a service header creating or re-outcoming an event
  • A product feature that reads audit
  • Changing an event after its outcome, deleting individual events through an API, or running audit serve as a role that can delete
  • Audit for some trees or services and not others
  • Built-in SIEM, S3, or webhook push connectors
  • Other front doors’ events. Each keeps its own log