Skip to Content
AgentShield
Architecture

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

Identity, policy, and enforcement
Audit, detection, and the event pipeline

Tables by purpose

PurposeTables
Identityusers, organizations, memberships, user_sessions, member_invitations
Agentsagents, agent_credentials
Policysecurity_policies, policy_versions, agent_permissions (display projection only)
Enforcementexecutions, tool_invocations, authorization_decisions, approval_requests
Detectionsecurity_incidents, anomaly_alerts
Auditsecurity_events, audit_chain, audit_chain_heads, audit_head_exports
Pipelineevent_outbox, evidence_objects, reliability_metrics, reliability_cursor
Resilience testingchaos_scenarios, chaos_executions
Housekeepingschema_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:

FunctionUsed for
agentshield_lookup_agentGateway agent lookup by id
agentshield_login_candidates, agentshield_create_session, agentshield_resolve_sessionHuman sign-in and session resolution
agentshield_open_invitationLooking up an invitation before sign-in
agentshield_claim_events, agentshield_ack_events, agentshield_event_backlog, agentshield_compute_reliabilityEvent relay

The schema owner bypasses RLS. Production mode refuses to start unless services connect as agentshield_app.

What is stored, and what is not

DataStored as
Agent private keysNever stored
Agent public keysRaw 32 bytes plus SHA-256 fingerprint
Human passwordsArgon2id hash
Session and invitation tokensSHA-256 only
Tool argumentsRedacted canonical JSON plus SHA-256 of the canonical form
Tool resultsRedacted
Approval bindingSHA-256 of the raw authorize body
Event payloadsRedacted 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:

FileAdds
0001_init.sqlCore schema, triggers, audit chain
0002_user_sessions.sqlHuman sessions
0003_chaos_scenarios.sqlChaos catalog
0004_app_role_rls.sqlagentshield_app, row level security, SECURITY DEFINER helpers, audit head exports
0005_invitations.sqlInvitations and forced password change
0006_event_pipeline.sqlOutbox 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

StoreKeys or subjectsRetention
Redisagentshield:v1:nonce:*, :rate:*, :tool:*, :tokens:*, :circuit:*, :circuit-fail:*30–130 seconds
NATS JetStreamStream AGENTSHIELD_EVENTS, subjects agentshield.events.>Seven days
MinIOBucket agentshield-evidence, <org>/<yyyy>/<mm>/<dd>/<event id>.jsonOperator-defined

Redis holds no durable state. Losing it resets budgets and the replay window; the 60-second timestamp check still rejects old signatures.

Was this page helpful?

On this page