audit
Role: consumes every audit record published on audit.records.v1, stores it in immudb (tamper-evident SQL)
and serves a read-only query API with cryptographic verification of single records.
Limits: no business logic, no MongoDB, no outbox. It produces no events (only dead letters) and does not audit reads of the audit log itself. Records only contain identifiers (no PII); the service does not check that, producers are responsible for it.
Write path
Every service builds records with pkg/audit and publishes them through its outbox
(the gateway publishes directly). The audit consumer (group audit) decodes each Kafka value as a JSON
audit.Record:
- malformed JSON or a record without
idis logged and skipped (offset committed); - valid records are inserted with
ON CONFLICT DO NOTHING, so replays are idempotent (primary key = record ID); - an immudb error is retried by
kafkax(5 attempts, linear backoff from 500 ms); after that the record goes toaudit.records.v1.dlqwith anerrorheader.
Read path
GET /v1/audit/records: filtersactor_id,resource,action(exact match),from/to(RFC 3339,frominclusive,toexclusive). Newest first (ORDER BY id DESC, ULIDs are time ordered); the cursor carries the last ID and the next page asks for lower IDs. Standard limit (default 25, max 200). When several filters are set, the immudb index is chosen in the orderactor_id,resource,action.GET /v1/audit/records/{id}: reads the row then calls immudbVerifyRowagainst the server state. A verified record is returned with"verified": true; a verification failure answers 409audit_verification_failed; a missing record 404audit_record_not_found.- Both routes require
audit.record.readonatl:audit:*:record/*(checked through authz before the handler; see authorization). immudb errors answer 503.
Dependencies
- Services: authz (
Checkthroughauthzclient). - Infrastructure: immudb, Kafka.
- Libraries:
audit,authzclient,httpx,kafkax,pagination,principal,problem,arn,config,logging,telemetry(see libraries).
Inputs and outputs
| Kind | Name | Notes |
|---|---|---|
| HTTP | GET /v1/audit/records, GET /v1/audit/records/{id} | API reference; routed by the gateway under /v1/audit |
| RPC out | authz.v1.AuthzService/Check | audit.record.read |
| Kafka in | audit.records.v1 | every audit.Record (consumer group audit) |
| Kafka out | audit.records.v1.dlq | records still failing after 5 attempts |
Data (immudb)
Database IMMUDB_DATABASE (default defaultdb), one SQL table created at startup (CREATE TABLE IF NOT EXISTS):
| Column | Type | Content |
|---|---|---|
id | VARCHAR[32], primary key | record ULID |
time | TIMESTAMP | UTC |
service, action | VARCHAR[32], VARCHAR[96] | e.g. files, files.file.upload |
resource | VARCHAR[256] | resource ARN (may be empty) |
outcome | VARCHAR[16] | success, denied, failure |
actor_kind, actor_id | VARCHAR[16], VARCHAR[64] | principal kind and ID |
owner_kind, owner_id | VARCHAR[16], VARCHAR[64] | API key owner |
admin_mode | BOOLEAN | admin mode of the request |
ip, request_id, trace_id | VARCHAR[64], VARCHAR[64], VARCHAR[32] | correlation |
refs | VARCHAR[2048] | JSON object of related IDs / ARNs (empty when none) |
Indexes: actor_id, resource, action. Records are never updated or deleted (kept after account erasure).
Health
/readyz checks the immudb session (immudb check, a SELECT ... LIMIT 1). Kafka is not part of readiness.
Configuration
| Variable | Default | Description |
|---|---|---|
HTTP_ADDR | :8080 (compose: :8083) | Listen address; the service has no own default, set it locally |
PRINCIPAL_PUBLIC_KEY | required | Base64 Ed25519 public key verifying X-Atl-Principal |
AUTHZ_URL | http://localhost:8081 | authz ConnectRPC endpoint |
KAFKA_BROKERS | localhost:19092 | Source of audit records |
IMMUDB_ADDRESS, IMMUDB_PORT | localhost, 3322 | immudb gRPC endpoint |
IMMUDB_USER, IMMUDB_PASSWORD | immudb, required | immudb credentials (compose: IMMUDB_ADMIN_PASSWORD, default immudb-dev) |
IMMUDB_DATABASE | defaultdb | immudb database |
Plus the common APP_ENV, LOG_LEVEL, METRICS_ADDR (default :9090), OTEL_EXPORTER_OTLP_ENDPOINT
(see environment variables).