Auditability
The per-organization hash chain, append-only enforcement in PostgreSQL, audit head exports, verified evidence bundles, and how to verify the record.
Every security-relevant change in AgentShield is written as an event in the same transaction as the change, and linked into a per-organization SHA-256 hash chain. The result is an audit trail where a silent edit or deletion is detectable.
What is recorded
| Source | Events |
|---|---|
| Gateway | authorization.decided, tool.executed, tool.failed, content.flagged |
| Control plane: agents | agent.registered, agent.suspended, agent.resumed, agent.revoked, credential.rotated |
| Control plane: approvals and alerts | approval.decided, alert.acknowledged, alert.resolved |
| Control plane: evidence | evidence.viewed, evidence.integrity_failed |
| Control plane: members | member.added, member.invited, member.invitation_accepted, member.role_changed, member.enabled, member.disabled, member.password_changed |
Payloads are redacted canonical JSON. An authorization.decided payload carries the tool, operation, resource, redacted arguments, outcome, and reason.
The hash chain
Each organization has its own chain. For each event:
payload_hash = sha256(canonical redacted payload)
header = canonical JSON of {
event_id, event_type, occurred_at, organization_id,
payload_hash, prev_hash
}
event_hash = sha256(header)- Keys are sorted, there is no insignificant whitespace, and strings use Go
encoding/jsonescaping (including<,>,&). occurred_atis UTC with nine fractional digits.- The first event's
prev_hashis 64 zero characters. - Duplicate JSON keys are rejected before hashing.
Enforcement in the database
agentshield_append_audit_linkis the supported insert path. The trigger assigns the sequence and requiresprev_hashto equal the organization's current head. Concurrent appends that lose the race retry.- Updates and deletes of
security_events,audit_chain,policy_versions, andauthorization_decisionsare rejected by triggers. - Events and links are written in the same transaction as the decision or change. A rolled-back change leaves no event.
Appends for one organization are serialized, which is inherent to a hash chain and acceptable for an audit log.
Audit head exports
A chain proves that links connect. It does not, by itself, prove that nobody rewrote an event and its link, which a database owner could do. The defense is a copy of the head kept outside the live head row:
curl -s -X POST http://127.0.0.1:8080/api/v1/audit/exports \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"destination":"security-archive/2026-11"}'{ "id": "…", "sequence": 18342, "head_hash": "4be1…", "exported_at": "2026-11-30T12:00:00Z", "destination": "security-archive/2026-11" }Owners, admins, and auditors can export the head and list exports. For the strongest guarantee, also copy the returned sequence and head_hash to a system the database owner cannot write: a ticket, a signed message, or write-once storage. A later chain that does not reproduce that hash at that sequence has been rewritten.
Verifying the chain
The console and GET /api/v1/audit show links for review. A full verification recomputes hashes from the stored rows, at full timestamp precision, with a read-only database connection:
- Read the organization's
audit_chainlinks insequenceorder, joined to theirsecurity_eventsrows. - Starting from the genesis
prev_hash, recomputepayload_hashfrompayload_redactedandevent_hashfrom the header, using the rules above. - Check each recomputed
event_hashequals the stored link, and that each link'sprev_hashequals the previousevent_hash. - Compare the hash at every exported sequence with your external copies.
runtime/gateway/internal/auditchain is the canonical implementation of the hash. Build verification tooling on it, or reproduce it exactly, rather than re-deriving the encoding.
Evidence bundles
For content.flagged and tool.failed, the event relay stores a JSON bundle in MinIO with the event, invocation, decision, execution, and alerts. Its SHA-256, size, and key are recorded in PostgreSQL. GET /api/v1/evidence/{id} recomputes the hash and returns 409 when the object no longer matches, appending evidence.integrity_failed. Every successful read appends evidence.viewed.
This detects tampering with stored evidence. It does not prevent deletion; enable object lock or bucket versioning on the evidence bucket if deletion is in your threat model.
Limits
- The chain does not protect against a database superuser who rewrites events, links, and every external copy of the head.
- In development, the Compose database user owns the tables and can disable triggers.
- Events written before migration
0006are not published to the stream, though they remain in the chain.
Implementation references
Was this page helpful?