Aller au contenu principal

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 id is 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 to audit.records.v1.dlq with an error header.

Read path​

  • GET /v1/audit/records: filters actor_id, resource, action (exact match), from / to (RFC 3339, from inclusive, to exclusive). 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 order actor_id, resource, action.
  • GET /v1/audit/records/{id}: reads the row then calls immudb VerifyRow against the server state. A verified record is returned with "verified": true; a verification failure answers 409 audit_verification_failed; a missing record 404 audit_record_not_found.
  • Both routes require audit.record.read on atl:audit:*:record/* (checked through authz before the handler; see authorization). immudb errors answer 503.

Dependencies​

  • Services: authz (Check through authzclient).
  • Infrastructure: immudb, Kafka.
  • Libraries: audit, authzclient, httpx, kafkax, pagination, principal, problem, arn, config, logging, telemetry (see libraries).

Inputs and outputs​

KindNameNotes
HTTPGET /v1/audit/records, GET /v1/audit/records/{id}API reference; routed by the gateway under /v1/audit
RPC outauthz.v1.AuthzService/Checkaudit.record.read
Kafka inaudit.records.v1every audit.Record (consumer group audit)
Kafka outaudit.records.v1.dlqrecords still failing after 5 attempts

Data (immudb)​

Database IMMUDB_DATABASE (default defaultdb), one SQL table created at startup (CREATE TABLE IF NOT EXISTS):

ColumnTypeContent
idVARCHAR[32], primary keyrecord ULID
timeTIMESTAMPUTC
service, actionVARCHAR[32], VARCHAR[96]e.g. files, files.file.upload
resourceVARCHAR[256]resource ARN (may be empty)
outcomeVARCHAR[16]success, denied, failure
actor_kind, actor_idVARCHAR[16], VARCHAR[64]principal kind and ID
owner_kind, owner_idVARCHAR[16], VARCHAR[64]API key owner
admin_modeBOOLEANadmin mode of the request
ip, request_id, trace_idVARCHAR[64], VARCHAR[64], VARCHAR[32]correlation
refsVARCHAR[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​

VariableDefaultDescription
HTTP_ADDR:8080 (compose: :8083)Listen address; the service has no own default, set it locally
PRINCIPAL_PUBLIC_KEYrequiredBase64 Ed25519 public key verifying X-Atl-Principal
AUTHZ_URLhttp://localhost:8081authz ConnectRPC endpoint
KAFKA_BROKERSlocalhost:19092Source of audit records
IMMUDB_ADDRESS, IMMUDB_PORTlocalhost, 3322immudb gRPC endpoint
IMMUDB_USER, IMMUDB_PASSWORDimmudb, requiredimmudb credentials (compose: IMMUDB_ADMIN_PASSWORD, default immudb-dev)
IMMUDB_DATABASEdefaultdbimmudb database

Plus the common APP_ENV, LOG_LEVEL, METRICS_ADDR (default :9090), OTEL_EXPORTER_OTLP_ENDPOINT (see environment variables).