Skip to main content
sec0-sdk/audit provides Sec0Appender, the audit log writer used by middleware, gateway, and instrumentation packages. It writes append-only, signed NDJSON audit files with daily rotation and optional presigned uploads to the Sec0 control plane.

How Audit Works

Every hop in the Sec0 runtime produces an audit envelope, a structured JSON record that captures:
  • Timing: Timestamp, latency
  • Identity: Tenant, server, tool, node ID, agent reference
  • Tracing: Trace ID, span ID, cause trace/span
  • Integrity: SHA-256 hashes of inputs and outputs
  • Policy: Decision (allow/deny), retention class
  • Signature: Ed25519 signature over the canonicalized envelope
  • Agent state: Variables, metadata, risk tags, findings

Setting Up the Appender

Writing Audit Envelopes

File Layout

Given config.dir = ".sec0", the appender writes:

Audit Envelope Schema

Presigned Uploads

When config.presign is provided, the appender automatically uploads only new bytes since the last successful upload to the Sec0 control plane:
presign.auditKey is the exact value sent as the Authorization header to the control plane. For Sec0 API keys, include the Bearer prefix (for example: Bearer ${process.env.SEC0_API_KEY}), not the raw key by itself. If you use an OIDC access token instead of an API key, set tenant, environment, clientName, and clientVersion explicitly because /api/auth/validate-key only accepts API keys.

Control-Plane Endpoints

Raw Payload Capture

Write a separate dataset for payload analysis pipelines:
Raw payload recording requires config.presign so the appender can enforce canonical tenant/env/client metadata.

Signing

Every audit envelope is signed with Ed25519 using sec0-sdk/signer:

Signer Interface

Helpers

Always use canonicalize() before signing JSON objects. Without deterministic key ordering, signatures break across serialization boundaries.