Data Storage Architecture
The PostgreSQL schema, how tenant isolation and append-only guarantees are enforced in the database, and what lives in Redis, NATS, and MinIO.
PostgreSQL is the transactional source of truth. Redis holds short-lived counters and nonces. NATS carries events after commit. MinIO stores evidence objects. No analytical database is deployed; PostgreSQL remains authoritative for every decision.
Schema overview
Tables by purpose
| Purpose | Tables |
|---|---|
| Identity | users, organizations, memberships, user_sessions, member_invitations |
| Agents | agents, agent_credentials |
| Policy | security_policies, policy_versions, agent_permissions (display projection only) |
| Enforcement | executions, tool_invocations, authorization_decisions, approval_requests |
| Detection | security_incidents, anomaly_alerts |
| Audit | security_events, audit_chain, audit_chain_heads, audit_head_exports |
| Pipeline | event_outbox, evidence_objects, reliability_metrics, reliability_cursor |
| Resilience testing | chaos_scenarios, chaos_executions |
| Housekeeping | schema_migrations |
Invariants enforced by the database
Tenant integrity. Composite foreign keys tie agent-scoped rows to (agent_id, organization_id), so a row can never reference an agent in another organization. A trigger rejects changing an agent's organization. Nullable agent references are checked by trigger.
Append-only records. Triggers reject UPDATE and DELETE on security_events, audit_chain, policy_versions, and authorization_decisions.
Audit chain. agentshield_append_audit_link is the supported insert path. The trigger assigns the sequence and requires prev_hash to equal the current head. See Auditability.
Decision consistency. A trigger checks that a decision's policy reference agrees with the policy it names.
Shape constraints. CHECK constraints bound statuses, roles, severities, hash formats (64 lowercase hex), key lengths (32-byte public keys), and JSON types.
Row level security
Migration 0004_app_role_rls.sql creates the agentshield_app role and enables RLS on tenant tables. Services set app.organization_id for each transaction after authentication, and policies filter rows by it. Operations that must happen before the organization is known use narrow SECURITY DEFINER functions:
| Function | Used for |
|---|---|
agentshield_lookup_agent | Gateway agent lookup by id |
agentshield_login_candidates, agentshield_create_session, agentshield_resolve_session | Human sign-in and session resolution |
agentshield_open_invitation | Looking up an invitation before sign-in |
agentshield_claim_events, agentshield_ack_events, agentshield_event_backlog, agentshield_compute_reliability | Event relay |
The schema owner bypasses RLS. Production mode refuses to start unless services connect as agentshield_app.
What is stored, and what is not
| Data | Stored as |
|---|---|
| Agent private keys | Never stored |
| Agent public keys | Raw 32 bytes plus SHA-256 fingerprint |
| Human passwords | Argon2id hash |
| Session and invitation tokens | SHA-256 only |
| Tool arguments | Redacted canonical JSON plus SHA-256 of the canonical form |
| Tool results | Redacted |
| Approval binding | SHA-256 of the raw authorize body |
| Event payloads | Redacted canonical JSON |
Redaction replaces the value of any key matching password, passwd, secret, token, credential, authorization, api_key, private_key, or access_key (case-insensitive, - or _ separators) with "[REDACTED]". The matcher is deliberately aggressive.
Migrations
infrastructure/docker/postgres/migrations/ is the schema source of truth:
| File | Adds |
|---|---|
0001_init.sql | Core schema, triggers, audit chain |
0002_user_sessions.sql | Human sessions |
0003_chaos_scenarios.sql | Chaos catalog |
0004_app_role_rls.sql | agentshield_app, row level security, SECURITY DEFINER helpers, audit head exports |
0005_invitations.sql | Invitations and forced password change |
0006_event_pipeline.sql | Outbox trigger, evidence records, relay functions |
Each file is safe to run twice. No service creates or alters tables at runtime. See PostgreSQL setup.
Other stores
| Store | Keys or subjects | Retention |
|---|---|---|
| Redis | agentshield:v1:nonce:*, :rate:*, :tool:*, :tokens:*, :circuit:*, :circuit-fail:* | 30–130 seconds |
| NATS JetStream | Stream AGENTSHIELD_EVENTS, subjects agentshield.events.> | Seven days |
| MinIO | Bucket agentshield-evidence, <org>/<yyyy>/<mm>/<dd>/<event id>.json | Operator-defined |
Redis holds no durable state. Losing it resets budgets and the replay window; the 60-second timestamp check still rejects old signatures.
Implementation references
Was this page helpful?
Event Processing Architecture
The transactional outbox, the event relay, NATS JetStream delivery, evidence bundles in MinIO, and reliability metrics.
Observability Architecture
Prometheus metrics on dedicated ports, tenant-safe labels, structured logs, the Grafana dashboard, alert rules, and benchmarks.