canopy-security Data Model
For a contributor or security reviewer reading canopy_security: the tables in effect, the hash-chain and append-only posture, detection-rule semantics, retention, and the complete migration inventory. Routes live on canopy-security API Reference; source: migrations/.
Core tables
| Table | Purpose |
|---|---|
|
The system-wide audit log, one row per event received by the wildcard ( Actor derivation ( Chain input. |
|
The archive twin the #1208 archive runs move aged rows into. Same columns — |
|
Detection-rule firings: |
|
NIST SP 800-53 control coverage (seeded: AU-2/3/6/9/11, AC-2/6/7, SI-4, IR-4/5): |
|
Breach-detection rules (IRS Pub 1075 §9) as self-describing config: |
|
Legacy per-FTI-service chain-verification ledger (ADR-014 §7-8): |
|
The append-only public-key retention register for determination-signing keys: |
|
The async archive-run record: UUIDv7 PK, |
|
The due-state singleton for scheduled archival: |
|
JIT-populated worker directory keyed |
|
Generated ADR-018 / ADR-039 outbox and inbox — documented once on the data-models index. |
|
The fleet idempotency cache, created before the migrator runs by |
_sqlx_migrations (sqlx’s history table) is present as in every service.
chain-v2 objects (withdrawn, dormant until #1304 retires them)
Four migrations install the chain-v2 substrate. Because chain-v2 is withdrawn (ADR-041; ADR-014 Amendment 12), along with the #1279 cutover, every table stays empty and every runtime role NOLOGIN until #1304 retires the substrate; v1 writers are untouched and live. Every object is owned by canopy_chain_owner_security, and runtime identities get no direct DML. Functions, grants and the append-validation rules are specified by ADR-014 Amendments 6, 7 and 9 and the migration files; the archived plans chain-v2 anchor authority, chain-v2 append transport and chain-v2 verifiers carry the design.
| Migration | Tables | What they hold |
|---|---|---|
|
|
The registry (immutable instance history, the active-family pointer, fenced epoch states with a one-open partial unique, the trusted source→instance binding, per-shard heads); the audit family’s strict event store (BYTEA(32) hash CHECKs, five-tuple position UNIQUEs on live and archive, composite FK → heads; hashed columns derived from |
|
|
The durable ingress queue between "accepted" and "chained": |
|
reshapes |
Token-confidential leases ( |
|
|
The durable manual-verify job store (target, |
canopy-identity key registry (ADR-049 §9)
20261209000000_identity_signing_keys.sql (#2498) installs the registry each canopy-security replica publishes its in-memory ES256 public key into, and that the JWKS (#2500) reads (ADR-049 §9 and Amendment 1). Every object is owned by canopy_identity_owner (NOLOGIN). The runtime writes through the issuer pool, which logs in as canopy_identity_issuer: it owns nothing and holds exactly SELECT on both tables below plus INSERT on the five caller columns of identity_signing_keys; on the two stores below only their caller columns' INSERT and the purge’s EXECUTE; and on the subject and session tables below SELECT and EXECUTE on the six functions that write them. Its main-pool and issuer-pool boot probes, provisioning and the compromise runbook: Security Operations.
| Table | Purpose |
|---|---|
|
One row per published key. The caller supplies |
|
INSERT-only revocations: |
|
One row, |
identity_registry_immutable(), a statement-level trigger on both tables, refuses UPDATE, DELETE and TRUNCATE with 23514. None of the triggers has a bypass setting, and they bind every session while they are in place, a superuser included. They do not stop a member of canopy_identity_owner or a superuser from disabling or dropping a trigger or dropping a table, nor a superuser from setting session_replication_role = replica: the boot probes keep the issuer login from being either, and canopy-security’s main credential is the canopy_security_runtime login, which is neither (#2501, Security Operations). EXECUTE on the three functions is revoked from PUBLIC. The migration ends with an audit, scoped to its own schema, that refuses any privilege on these objects outside the issuer matrix, any grant option, and any issuer privilege beyond schema USAGE and database CONNECT.
The jti store and the issuance log (ADR-049 §10, §13)
20261210000000_identity_issuance_stores.sql (#2551) adds the token endpoint’s two stores, owned by canopy_identity_owner like the registry (ADR-049 Amendment 3); 20261213000000_identity_issuance_log_v2.sql (#2714) gives the log its version 2 layout, which records web-session events beside system-token mints, 20261215000000_identity_issuance_log_v3.sql (#2722) its version 3 layout, which records delegation mints too, and 20261218000000_identity_issuance_log_v4.sql (#2742) its version 4 layout, which records the native grants (ADR-049 Amendment 9). The issuer writes both and can read neither: it holds column-level INSERT on the columns below that a caller supplies, EXECUTE on the purge, and no SELECT, UPDATE, DELETE or TRUNCATE on either table.
| Table | Purpose |
|---|---|
|
The single-use record of every accepted |
|
One INSERT-only row per mint, per handled refusal and per web-session state change (Amendment 6). The issuer inserts |
Version 2 to 4 rows. The identity_issuance_log_v4_* CHECKs (delegation, device, events, refresh, session, token, revocation error) hold every version 2, 3 and 4 row to this table, a delegation row only from version 3 and a native grant’s only at version 4, and identity_issuance_log_error keeps error present exactly on a refusal. Each restates the version 3 CHECK of its name for versions 2 to 4: version 3’s bound only versions 2 and 3, so a version 4 row would have bypassed them. An approval’s device_id is admitted at version 4 alone too, so a version 2 or 3 row carries neither new column. A refresh’s version is a RotatedVersion, 2 or more, so the writer’s types cannot express a refresh row at redemption’s version. The table governs error, token_jti, kid, expires_at, subject_id, session_id, session_event, roles, programs, device_id and refresh_version: each one it does not name for a row is NULL there, and subject_token_jti is NULL on every row but a delegation one. On a delegation row it is present exactly onward, absent from a session; no column records the form, so that rule is the writer’s type’s (DelegationOrigin), not a CHECK’s. client, purpose, audience, scope, reason and peer_addr are outside the table; no version 2 to 4 CHECK reads them, and they carry what the column list above says.
grant_type |
outcome |
session_event |
carries |
|---|---|---|---|
|
|
none |
|
|
|
none |
|
|
|
|
|
|
|
none, or |
|
|
|
|
|
|
|
none |
|
|
|
none |
nothing else (an unknown, ended or revoked credential, answered 200) |
|
|
none |
|
|
|
none |
|
|
|
none |
|
|
|
none |
|
|
|
none |
|
|
|
none |
|
|
|
none |
as an issued |
|
|
none |
as an issued |
|
|
none, or |
|
|
|
none, or |
as a refused |
none |
|
none |
|
A session state change commits its row inside its own transaction through issuance_log::log_in, so the change and its row commit or roll back together; every other row goes through the group-commit writer. Both insert the same statement from the same IssuanceRecord, whose types admit only the rows above. The writer sends a delegation or native row’s roles and programs as one space-joined text each, which the insert splits with string_to_array: SQLx binds no array of arrays, and the join is lossless, since a role name or a program’s wire id holds no space. Version 1 rows, all issued or refused with none of the nine later columns and the token’s three identifiers exactly on a mint, are restated by the validated CHECK identity_issuance_log_v1_layout; version 2 and 3 rows by the validated identity_issuance_log_v4_* CHECKs, with the columns added since NULL. identity_issuance_log_v4_new_rows must never be validated: it would fail on them.
The row digest. row_digest is SHA-256 (32 bytes, a CHECK) over the UTF-8 text of the stored row as jsonb without its row_digest key, computed by the trigger after it stamps occurred_at:
sha256(convert_to((to_jsonb(NEW) - 'row_digest')::text, 'UTF8'))
It covers every other column the row’s schema_version defines, record_id and occurred_at included, a NULL column as JSON null: for a version 4 row that is every column of the table. The text is PostgreSQL’s canonical jsonb output: keys ordered by length and then bytewise, ", " and ": " separators, and every value in its jsonb rendering. to_jsonb renders a timestamptz in the session’s TimeZone, so the trigger function pins TimeZone = 'UTC', and the text depends on nothing a writer’s session sets ("2026-10-02T13:14:15.123456+00:00").
A version 1 row was digested before grant_type, subject_id, session_id, session_event, subject_token_jti, roles, programs, device_id and refresh_version existed; read now, its to_jsonb carries them as null, so its recompute removes those nine keys as well as row_digest. A version 2 row’s recompute removes the three version 3 keys and the two version 4 keys the same way, and a version 3 row’s the two version 4 keys. A migration that adds a column bumps the version and adds the older versions' removals likewise. An exporter recomputes each version’s digest and compares:
SET TimeZone = 'UTC';
SELECT record_id
FROM identity_issuance_log l
WHERE sha256(convert_to((to_jsonb(l) - CASE l.schema_version
WHEN 1 THEN ARRAY['row_digest', 'grant_type', 'subject_id',
'session_id', 'session_event',
'subject_token_jti', 'roles', 'programs',
'device_id', 'refresh_version']
WHEN 2 THEN ARRAY['row_digest', 'subject_token_jti', 'roles',
'programs', 'device_id', 'refresh_version']
WHEN 3 THEN ARRAY['row_digest', 'device_id', 'refresh_version']
ELSE ARRAY['row_digest']
END)::text, 'UTF8')) <> l.row_digest;
The purge. identity_purge_client_assertions(batch integer) RETURNS integer (SECURITY DEFINER, so it runs as the owner) deletes up to batch rows whose expires_at is before clock_timestamp(), oldest first, each selected FOR UPDATE SKIP LOCKED, and returns how many it deleted. Concurrent purges therefore take disjoint rows and never wait on each other. A batch that is NULL, below 1 or above 10000 is refused with 22023: the cap keeps one call’s row locks and WAL a bounded burst well inside the issuer’s 5 s statement_timeout. EXECUTE is revoked from PUBLIC and granted to the issuer, for its jti sweeper (#2552); EXECUTE on the stamp function is granted to nobody.
The migration ends with its own closing audit, over every identity object, the registry’s and these, with the same refusals as the registry’s audit and the extended matrix.
Subjects and web sessions (ADR-049 §3, §5, §8, §12)
20261214000000_identity_subjects_sessions.sql (#2715) adds canopy-identity’s subjects and its web sessions (ADR-049 Amendment 6), owned by canopy_identity_owner like the registry. The issuer reads all six tables and writes none of them directly: it holds SELECT on each and EXECUTE on the six owner functions below that write them, and no INSERT, UPDATE, DELETE or TRUNCATE, so every row goes through a function that keeps the invariants. Each state change commits its issuance-log row in the same transaction (identity/sessions.rs), so nothing takes effect unlogged. A session is stored by the SHA-256 of its credential, never the credential.
| Table | Purpose |
|---|---|
|
One canopy subject: |
|
The exact upstream pair a subject was minted for: |
|
INSERT-only suspension events: |
|
One session: |
|
A session’s validations: |
|
At most one per session: |
The functions. Each is SECURITY DEFINER with a pinned search_path. The open writes version 1 with its new session; each later validation is recorded under the session’s row lock (SELECT … FOR UPDATE) at the latest version plus 1. The open, the renewal and the grace judge the subject’s suspension themselves: each takes FOR KEY SHARE on the subject’s row, which conflicts with the suspension writers' FOR UPDATE, reads the subject’s latest suspension event (the highest version) under it, and answers suspended, writing nothing, before any other answer, so a suspension committed during an operation is never missed. Locks are taken subject before session, and no path takes them the other way. The open, the renewal, the grace and link-or-mint run only under READ COMMITTED, under which a statement after a lock wait reads what it waited for, and refuse any other isolation level with 25000 (invalid_transaction_state); the store begins every transaction at READ COMMITTED.
-
identity_link_or_mint_subject(p_iss, p_sub, p_candidate) RETURNS uuid: the subject the pair is effectively linked to (since20261217000000, its latest relink’s, else its link’s), elsep_candidate, minted and linked. It takes the pair’s shared advisory lock (Security administration (ADR-049 §12; Amendment 8)) first and holds it to the open’s commit. Concurrent first opens of a pair yield one subject: the loser’s link insert waits on the winner’s and then rereads its link, its own subject rolled back. A candidate that collides with a stored subject is refused with23505, never linked. -
identity_open_session(p_session, p_credential_hash, p_kind, p_client, p_subject, p_upstream_iss, p_upstream_client, p_upstream_sub, p_auth_time, p_nonce_digest, p_opened_at, p_ends_at, p_validation, p_validated_at, p_id_token_iat, p_id_token_digest, p_fresh_until, p_roles, p_programs, p_username) RETURNS text:suspended, writing nothing, when the subject’s latest suspension event suspends it; else the session (every column but none it stamps) and its version 1openvalidation, answeringopened. Refuses an unknown subject or an upstream pair not effectively linked to the subject (23503, under the pair’s shared lock since20261217000000), and a freshness past the session’s end (23514). -
identity_record_session_renewal(p_session, p_expected_version, p_validation, p_validated_at, p_id_token_iat, p_id_token_digest, p_fresh_until, p_roles, p_programs, p_username, p_now) RETURNS text: under the subject’s and then the session’s lock, answers in ordersuspended;revoked;ended(p_nowat or pastends_at);replayed(the presented digest is the latest id_token row’s: the highest version carrying an id_token, past grace rows and userinfo renewals);not_newer(the presentediatis not after that row’s, or the session recorded none);superseded(the latest version is notp_expected_version); else inserts the next version as arenewaland answersrecorded. A userinfo renewal presents no id_token and skips the two id_token answers. -
identity_record_session_grace(p_session, p_expected_version, p_validation, p_grace_seconds, p_now) RETURNS text: under the subject’s and then the session’s lock, answers in ordersuspended,revoked,ended,superseded, orexhaustedwhenleast(validated_at + 900 s + p_grace_seconds, ends_at)of the latest successful validation (the highest version that is not a grace) is not afterp_now; else inserts the next version as agracethat copies that validation’svalidated_at, roles, programs and username with that freshness, and answersrecorded. A second grace before the next success ends where the first did.p_grace_secondsoutside 0 to 3600 is refused with22023. -
identity_revoke_session(p_session, p_reason, p_client) RETURNS boolean: true when this call revoked the session, false when a revocation exists. Since20261216000000it refuses any reason but the issuer’s five with23514, so anadminorrelinkedrevocation comes only from the admin functions, with its action row. Its foreign-key check waits for a renewal or grace holding the session’s row lock, and holds a later one off until it commits. -
identity_purge_sessions(p_batch) RETURNS integer: deletes up top_batchsessions that ended, or were revoked, more than 30 days (720 hours) beforeclock_timestamp(), with their validations and revocation, each session lockedFOR UPDATE SKIP LOCKED, and returns how many sessions it deleted; a batch outside 1 to 1000 is refused with22023. Since20261219000000it first deletes a doomed session’s refresh credentials, its device decision and that decision’s device (Native sessions and the device flow (ADR-049 §7; Amendment 9)). The session sweeper calls it as the issuer, 100 at a time. -
identity_suspend_subject(p_subject, p_actor, p_reason)andidentity_lift_subject_suspension(p_subject, p_actor, p_reason), eachRETURNS uuid(the event’s id): an event at the subject’s next version, under the subject’s row lock; an unknown subject is refused withP0002. EXECUTE is granted to nobody.
identity_registry_immutable() refuses UPDATE, DELETE and TRUNCATE on the three subject tables, and UPDATE and TRUNCATE on the three session tables, with 23514; DELETE on those stays open to their owner alone, for the purge. EXECUTE on all eight functions is revoked from PUBLIC. The migration ends with its own closing audit over every identity object, the matrix extended by the six SELECTs and six EXECUTEs.
Security administration (ADR-049 §12; Amendment 8)
20261216000000_identity_admin.sql (#2729) adds the record of security administration, owned by canopy_identity_owner like the registry, and the NOLOGIN role canopy_identity_admin the admin routes' login connects as. A security administrator’s change reaches the identity tables only through the owner’s identity_admin_* functions, each making its change and its identity_admin_actions row in one transaction, so a change is never unaudited and an audit row never stands for a change that did not commit. The admin holds EXECUTE on the seven admin functions, SELECT on identity_signing_keys, identity_key_revocations, the six subject and session tables, identity_client_disablements and identity_subject_relinks, USAGE on the schema and CONNECT on the database, and nothing else; the issuer holds SELECT on identity_client_disablements and identity_subject_relinks and no admin function. 20261217000000_identity_relinks.sql (#2734) adds the re-links, and 20261220000000_identity_admin_create_subject.sql (#2766) the subject create; the admin now holds EXECUTE on eight admin functions. 20270125000000_identity_admin_actions_read.sql (#2737) grants the admin SELECT on identity_admin_actions, which GET /identity/admin/actions pages through; it still writes the record only through the admin functions.
| Table | Purpose |
|---|---|
|
INSERT-only, one row per admin change: |
|
INSERT-only runtime disablement events: |
|
INSERT-only re-links of an upstream pair: |
The functions. Each takes the target, then the actor’s subject, session, token jti, token kid and client, then the reason, and returns (action_id uuid, changed boolean). Each refuses to run outside READ COMMITTED with 25000 (identity_admin_isolation()), so a statement after a lock wait reads what the holder committed, and each records its action row (identity_admin_record, granted to nobody) whether or not the state changed.
-
identity_admin_suspendandidentity_admin_lift(p_subject, …): under the subject’s row lock (FOR UPDATE), the subject’s latest suspension event; when the state changes,identity_suspend_subjectoridentity_lift_subject_suspensionwith the actor’s subject asactor. An unknown subject isP0002. -
identity_admin_revoke_session(p_session, …): a revocation with reasonadminand the actor’s client,ON CONFLICT (session_id) DO NOTHING. An unknown session isP0002. -
identity_admin_disable_clientandidentity_admin_enable_client(p_client, …): underpg_advisory_xact_lock(2733, hashtext(p_client)), the client’s latest event; when the state changes, the next version. A malformed client is refused by the action row’s CHECK (23514). -
identity_admin_revoke_key(p_kid, …): under the key’s row lock (FOR UPDATE), so two revocations serialize; when unrevoked,identity_revoke_keywith the actor’s subject asactor(revoked_byis the admin login). An unknown kid isP0002. -
identity_admin_create_subject(p_subject, …)(20261220000000, Amendment 11): refuses the nil UUID (22023), then inserts the subjectON CONFLICT (subject_id) DO NOTHINGand records the actioncreate_subject(its only target the subject) either way,changedtrue only when it inserted. Two creates of one UUID serialize on the primary key and the second recordschangedfalse. It links nothing. -
identity_admin_link(p_iss, p_sub, p_subject, …)(20261217000000): under the pair’s exclusive advisory lock,pg_advisory_xact_lock(2734, hashtext(p_iss || ' ' || p_sub)), then the target and the pair’s current subjectFOR UPDATEin ascendingsubject_idorder, it reads the pair’s effective subject and the target’s effective links underp_iss. A pair already effectively linked to the target changes nothing. A target already effectively linked underp_issto another upstream subject is23505, an unknown targetP0002. An unlinked pair gets its base link, or relink version 1 when the target’s own base link underp_iss(since re-linked away) holds that issuer’s slot. A pair linked elsewhere gets its next relink, and its live sessions are revokedrelinked, with the actor’s client, in the same transaction. It creates no subject. Link-or-mint and the open take the same lock shared, so an open waits for an in-flight re-link of its pair and opens as the new subject, and a re-link waits for the pair’s in-flight opens and revokes their sessions; two pairs re-linked at once to one subject serialize on its row, and the second is refused.
identity_registry_immutable() refuses UPDATE, DELETE and TRUNCATE on the three tables with 23514. EXECUTE on all nine functions is revoked from PUBLIC. Each migration ends with a closing audit over every identity object holding the issuer’s matrix and the admin’s.
Native sessions and the device flow (ADR-049 §7; Amendment 9)
20261219000000_identity_native_sessions.sql (#2743) adds the store behind canopy-cli’s device flow, owned by canopy_identity_owner like the registry. identity_sessions admits a native session, kind native opened for canopy-cli; its credential_hash is the SHA-256 of the native revalidation credential, which canopy-web alone presents to renew, hold in grace or revoke it, and which mints nothing. The issuer reads the device, decision and refresh tables and writes them only through the owner’s functions below, holding SELECT on the three and EXECUTE on the eight functions; on the proof store it holds INSERT on its three columns and nothing else. The admin holds nothing on any of them. A code or credential is stored by its SHA-256, never itself.
| Table | Purpose |
|---|---|
|
One started device flow: |
|
At most one decision per device: |
|
A native session’s refresh credentials: |
|
The single-use record of every accepted DPoP proof, the shape of |
The functions. Each is SECURITY DEFINER with a pinned search_path, and answers the first of its list that holds, writing nothing unless its answer says so. Decisions on expiry and the session’s end compare the caller’s p_now; the purges read clock_timestamp(). Locks are taken subject before session, as everywhere: the redemption, the rotation and the unredeemed revocation take the subject’s FOR KEY SHARE, then the session FOR UPDATE, and read the subject’s latest suspension under them. The approval runs after link-or-mint and the open in one transaction, so it holds its subject before it claims the decision’s primary key, and the denial takes the denying subject’s FOR KEY SHARE before it claims the decision’s: no transaction waits on a subject while holding a decision another waits for. Every function that waits on a lock refuses any isolation but READ COMMITTED with 25000.
-
identity_start_device_authorization(p_device, p_device_code_hash, p_user_code_hash, p_client, p_created_at, p_expires_at) RETURNS text:user_code_taken, writing nothing, when a stored row holds the user code (ON CONFLICT (user_code_hash) DO NOTHING), so the caller may draw another (the device store draws at most three times); else the row andstarted. A colliding device code or id is23505. -
identity_approve_device(p_user_code_hash, p_session, p_now) RETURNS text:unknown,expired(p_nowat or pastexpires_at),decided, else the approval namingp_sessionand its subject andapproved. Two decisions on one device serialize on the decision’s primary key, the second answeringdecided. A session opened for another client than the device’s is23514, an unknown oneP0002. The caller must roll the approval’s whole transaction back on any answer butapproved, so a refused approval leaves behind no session, and no subject it minted. -
identity_deny_device(p_user_code_hash, p_subject, p_now) RETURNS text: an unknown subject isP0002; elseunknown,expired,decided, or the denial byp_subjectanddenied. -
identity_redeem_device(p_device_code_hash, p_credential, p_credential_hash, p_jkt, p_now), returning(answer text, session uuid, device uuid, did_revoke boolean), the session and device as found:unknown; undecided,expiredoncep_nowreachesexpires_at, elsepending;denied; then for an approval, under its locks,revoked,ended(p_nowat or pastends_at),suspended,reused(a refresh credential exists: the session is revokeddevice_code_reusedwith its client, anddid_revokeis whether that insert revoked it),expired(unredeemed pastexpires_at), else version 1 bound top_jktandredeemed. -
identity_rotate_native_refresh(p_session, p_presented_version, p_credential, p_credential_hash, p_now), returning(answer text, did_revoke boolean): under the session’s locks,revoked,ended,suspended,reused(the presented version is not the latest: the session is revokedrefresh_reusedwith its client,did_revokeas above), else the next version bound to the latest’sjkt, never one the caller names, androtated. The caller finds the presented credential by its hash and holds the proof’s thumbprint to itsjktfirst. An unknown session, or one holding no refresh credential, isP0002. Sincerevokedprecedesreused, a replay after any revocation revokes nothing and reportsdid_revokefalse. -
identity_revoke_unredeemed_native_session(p_session, p_now) RETURNS boolean: under the session’s locks, true, revoking itunredeemedwith canopy-web as the revoking client, exactly when it is native and unrevoked, holds no refresh credential, and its device’sexpires_atis at or beforep_now; else false. It and the redemption serialize on the session’s lock and compare the same instant, so at the expiry edge one redeems or the other revokes. An unknown session isP0002. -
identity_purge_devices(p_batch) RETURNS integer: deletes up top_batchdevices no approval names whose code expired more than 30 days (720 hours) ago, their denials first, each device lockedFOR UPDATE SKIP LOCKED; a batch outside 1 to 1000 is22023. An approved device leaves with its session throughidentity_purge_sessions. The session sweeper calls it afteridentity_purge_sessions(#2744). -
identity_purge_dpop_proofs(batch) RETURNS integer: asidentity_purge_client_assertions, up tobatchexpired proofs, oldest first,FOR UPDATE SKIP LOCKED, 1 to 10000 a call. The jti sweeper calls it afteridentity_purge_client_assertions(#2744).
identity_registry_immutable() refuses UPDATE and TRUNCATE on the device, decision and refresh tables with 23514; DELETE on them stays open to their owner alone, for the purges. The proof store, like the jti store, has no such trigger. EXECUTE on the eight functions is revoked from PUBLIC and the admin and granted to the issuer. identity_revoke_session still refuses the three native revocation reasons, which only these functions write. The migration ends with a closing audit over every identity object, the issuer’s matrix extended by its three SELECTs, the proof columns and the eight EXECUTEs.
Relationships
No Postgres foreign key exists among the core tables; the relationships below are by value. The chain-v2 family carries FKs internally (events → heads, jobs → incidents and runs, runs → jobs), and so do the identity registry (revocations → keys), the subject and session stores (links, suspensions and sessions → subjects; validations and revocations → sessions) the admin record (disablements → actions; relinks → subjects and actions) and the native store (decisions → devices, subjects and sessions; refresh credentials → sessions). nist_control_mappings, fti_chain_verifications, signing_key_history, worker_directory, the outbox, inbox and idempotency tables stand alone.
Cross-service FKs (ADR-001 boundary)
canopy-security holds no Postgres-level foreign key to another service. audit_events.event_id / user_id / resource_id / source_service and the metadata envelope are opaque values supplied by the publisher, never joined; fti_chain_verifications.broken_at_row_id points into fti_audit_log in canopy-tanf or canopy-medicaid and is resolved through the program service’s API. Per ADR-004, FTI never lands here — canopy-security persists only audit metadata about FTI access.
Retention
Rows are append-only and never deleted; the archive mover (#1208) only moves aged rows live → archive, and the chain spans both tables, so retention is archive ∪ live and audit_events_archive keeps rows indefinitely. archive_after_days is an age threshold, not a retention value (operator-set, no default). Retention policy — floors, legal hold, purge, per-family windows — is #1303. NIST SP 800-53 AU-11 is satisfied by the union of the two tables; the floors it must clear, checked 2026-09-16: 3 years from the month of origin for SNAP program records (7 CFR 272.1(f), LII mirror — the eCFR refused this host); 3 years from submission of the final expenditure report for Medicaid fiscal records (42 CFR 433.32(b), LII); and 7 years for FTI audit records — IRS Publication 1075 (Rev. 11-2021) AU-11: "Retain audit records seven (7) years". The state side, checked 2026-09-18: Georgia’s common schedule (Georgia Archives, State Government General Records Retention Schedules — https://www.georgiaarchives.org/records/state_print_all) has no series for an application audit trail; the nearest are GASC-07-020 "Security Access Records" ("Logs documenting when and who accessed restricted areas", 5 years) and GASC-04-001 "Computer System Documentation, Management, and Maintenance Records" (which lists "operations logs"; "Life of system, software, or component and all audit requirements have been met"), and the DHS schedule (agency 144 — https://www.georgiaarchives.org/records/agencyprint/144) carries no audit-log series. GASC-07-020 is shorter than the 7-year AU-11 floor and the indefinite archive already satisfies GASC-04-001’s life-of-system term, so the federal floors govern; a Georgia series specific to system audit logs is not established (#2139). The identity registry’s rows are never deleted either: its triggers refuse it to every session but a member of canopy_identity_owner or a superuser (canopy-identity key registry (ADR-049 §9)). A key stops counting toward the cap, and stops being published, once it is revoked or its publish_until passes. identity_issuance_log is INSERT-only by trigger and grows until #1303 sets its retention; its export is ADR-041’s (#1301). identity_client_assertions rows are useless once expired, and the purge removes them. Subjects, their links and their suspension events are never deleted (Subjects and web sessions (ADR-049 §3, §5, §8, §12)); a session, with its validations and revocation, is purged 30 days after it ended or was revoked, a native one with its refresh credentials, decision and device. A device no approval names is purged, with its denial, 30 days after its code expired, and identity_dpop_proofs rows once expired. breach_alerts and fti_chain_verifications are kept indefinitely as compliance evidence; nist_control_mappings and detection_rules are configuration-as-data.
Indexes
-
audit_events—idx_audit_events_event_type,idx_audit_events_source_service,idx_audit_events_action,idx_audit_events_user_id,idx_audit_events_resource_type,idx_audit_events_event_timestamp,idx_audit_events_metadata(GIN),idx_audit_events_event_hash;idx_audit_events_created_at_id((created_at DESC, id DESC)— the in-lock predecessor lookup andverify_chain's walk, #1197);idx_audit_events_received_at_id(the archive mover’s candidate scan);audit_events_household_idx(partial,WHERE household_id IS NOT NULL);audit_events_programs_gin(partial GIN,WHERE programs IS NOT NULL— theprograms && $scopearm);audit_events_dedup_key_uq(partial unique,WHERE dedup_key IS NOT NULL) -
audit_events_archive—idx_audit_events_archive_received_at_id(the keyset archive list),idx_audit_events_archive_event_timestamp_id(the FOIA-export union arm),idx_audit_events_archive_persons_metadata(partial GIN,WHERE source_service = 'canopy-persons'— the fact-history union arm) -
breach_alerts—idx_breach_alerts_rule_name,idx_breach_alerts_status,idx_breach_alerts_severity -
nist_control_mappings—idx_nist_control_mappings_control_id,idx_unique_nist_control(unique) -
detection_rules—idx_detection_rules_rule_type -
fti_chain_verifications—idx_fti_chain_verifications_service_verified_at((service, verified_at DESC)) -
signing_key_history—idx_signing_key_history_program((program, registered_at DESC)) -
audit_archive_runs—audit_archive_runs_active_uq(unique ontrue WHERE state IN ('queued','running')— one active run),audit_archive_runs_queued_idx,audit_archive_runs_reclaim_idx(partial claim and reclaim scans) -
worker_directory—worker_directory_last_seen_idx((last_seen_at DESC)) -
identity_signing_keys—identity_signing_keys_publish_until_idx(the cap count and the JWKS read) -
identity_client_assertions—identity_client_assertions_expires_at_idx(the purge’s oldest-first range scan) -
identity_admin_actions—identity_admin_actions_recorded_at_idx(reading the record by time, the action-log route’s pages included),identity_admin_actions_actor_token_kid_idx(the compromise response’s review by kid);identity_client_disablements—identity_client_disablements_version_key(unique(client, version): the latest event);identity_subject_relinks—identity_subject_relinks_version_key(unique(upstream_iss, upstream_sub, version): a pair’s latest relink),identity_subject_relinks_subject_idx(a subject’s effective links) -
identity_device_authorizations—identity_device_authorizations_device_code_hash_keyandidentity_device_authorizations_user_code_hash_key(unique: the lookups by code),identity_device_authorizations_expires_at_idx(the device purge’s scan);identity_device_decisions—identity_device_decisions_session_id_key(unique: an approval’s session);identity_native_refresh_credentials—identity_native_refresh_credentials_credential_hash_key(unique: the lookup by credential),identity_native_refresh_credentials_version_key(unique(session_id, version): the latest credential);identity_dpop_proofs—identity_dpop_proofs_expires_at_idx(the purge’s oldest-first range scan) -
identity_sessions—identity_sessions_credential_hash_key(unique: the lookup by credential),identity_sessions_ends_at_idx(the purge’s scan of ended sessions);identity_session_validations—identity_session_validations_version_key(unique(session_id, version): every "latest" read);identity_session_revocations—identity_session_revocations_revoked_at_idx(the purge’s scan of revoked sessions);identity_subject_links— the primary key andidentity_subject_links_subject_issuer;identity_subject_suspensions—identity_subject_suspensions_version_key -
chain-v2 —
chain_epochs_one_open_v2,audit_events_v2_shard_seq_idx,audit_events_v2_household_idx,audit_events_v2_event_id_uq,audit_events_v2_dedup_key_uq,audit_events_archive_v2_event_id_uq,chain_append_staging_claim_idx,chain_append_staging_unrouted_idx,chain_append_staging_parked_idx,chain_verification_runs_latest_idx,chain_incidents_latched_uq,chain_verify_jobs_queued_idx,chain_verify_jobs_reclaim_idx,chain_verify_jobs_reap_idx,chain_verify_jobs_active_target_uq -
event_outbox_*/event_inbox_*— the generated partial indexes, documented once on the data-models index;idx_idempotency_keys_created_at— runtime DDL beside its table
Migration files
The eight generated outbox/inbox files (20260508000000, 20260516000000, 20260518004851, 20260713000000, 20260720000000, 20260803000000, 20260815000000, 20260904000000) are documented once on the data-models index.
-
20260326000000_create_security_tables.sql—audit_events,breach_alerts,nist_control_mappings,detection_rules,audit_events_archive(LIKE audit_events INCLUDING ALL); the per-column indexes -
20260326000001_seed_nist_controls.sql— seeds the 11 NIST SP 800-53 control mappings -
20260326000002_seed_detection_rules.sql— seeds the four original rules (Failed Authentication, Bulk Data Access, Privilege Escalation, After Hours Access) -
20260402000000_add_constraints.sql— CHECKs onbreach_alerts.statusanddetection_rules.severity;idx_unique_nist_control -
20260402000001_add_hash_chain.sql—previous_hash+event_hashonaudit_events(ADR-014);idx_audit_events_event_hash -
20260409000000_align_archive_hash_columns.sql— the same hash columns onaudit_events_archive(theLIKEpredated the chain) -
20260425000001_create_fti_chain_verifications.sql— the per-FTI-service verification ledger -
20260601000010_add_household_id_to_audit_events.sql—household_idon both twins +audit_events_household_idx(#621) -
20260603120000_audit_events_append_only_guard.sql— #624:canopy_audit_append_only_guard()and the statement-level triggers on both twins -
20260621000000_add_audit_hash_version.sql— #686 (ADR-014 Amendment 1):hash_version SMALLINTon both twins -
20260624000000_create_signing_key_history.sql— #687 (ADR-036):signing_key_history,idx_signing_key_history_program, the append-only guard trigger -
20260624130000_drop_audit_hash_version.sql— #687 (ADR-014 Amendment 3): dropshash_versionfrom both twins (no v1 rows existed pre-1.0; the chain collapsed to one formula) -
20260811000000_audit_events_created_at_id_idx.sql— #1197:idx_audit_events_created_at_id(transactional, notCONCURRENTLY— the sqlx migrator lock deadlocks withCONCURRENTLY; operators pre-create it out of band on huge tables) -
20260910000000_chain_v2_substrate.sql— #1246 (ADR-014 Amendment 6): the chain-v2 substrate (table above) -
20260930000000_chain_append_staging.sql— #1207 (Amendment 7):chain_append_stagingand its functions -
20261010000000_chain_verification_hardening.sql— #1205/#1206 (Amendment 9): the chain-verification reshape -
20261015000000_chain_verification_projections.sql— #1205 (Amendment 9):chain_verify_jobs, the_appviews, the job functions -
20261101000000_audit_archive_runs.sql— #1208:audit_archive_runs,audit_archive_schedule, the four mover/read-path indexes, and a boot-time DO block that RAISEs unless each index is valid, on the right table and definition-matched -
20261102000000_detection_rule_predicates.sql— #1302: the four predicate columns; re-points the three inert seeds atevent_count; disables After Hours Access; adds FTI Access Volume and Reporting Extract Volume -
20261104000000_signing_key_registrant.sql— #1261:signing_key_history.registrant_service_id -
20261123000000_audit_ingest_dedup_key.sql— #1424:audit_events.dedup_key+audit_events_dedup_key_uq -
20261124000000_chain_v2_audit_dedup_key.sql— #1498:dedup_keyonaudit_events_v2and its archive twin,audit_events_v2_dedup_key_uq,chain_append_rows_auditreplaced to carry it -
20261128000000_add_programs_to_audit_events.sql— #1519 (ADR-044):programs TEXT[]on both twins +audit_events_programs_gin; no backfill -
20261202000000_reenable_after_hours_rule.sql— #1405: After Hours Access re-enabled onafter_hours_countwith theaccessed/ssnpredicate -
20261208000010_create_worker_directory.sql— #597 (ADR-046):worker_directory+worker_directory_last_seen_idx -
20261209000000_identity_signing_keys.sql— #2498 (ADR-049 §9): thecanopy_identity_owner/canopy_identity_issuerroles and their reconcile, the three registry tables, the stamp, immutability and revocation functions, the issuer grant matrix and the closing privilege audit -
20261210000000_identity_issuance_stores.sql— #2551 (ADR-049 §10, §13):identity_client_assertions+identity_client_assertions_expires_at_idx,identity_issuance_logwith its stamp and immutability triggers,identity_purge_client_assertions, the issuer’s grants on them and a closing privilege audit over every identity object -
20261211000000_identity_issuer_no_temporary.sql— #2571 (ADR-049 §9): revokes TEMPORARY on the database from PUBLIC, and TEMPORARY and CREATE on it fromcanopy_identity_issuer, so the issuer can create no temporary table and no schema of its own name to shadow a registry name; a closing audit refuses either privilege by any path -
20261213000000_identity_issuance_log_v2.sql— #2714 (ADR-049 §13, Amendment 6): the issuance log’s version 2 layout:grant_type,subject_id,session_idandsession_event, the widenedoutcome, the version 2 CHECKs, the validated version 1 layout and the NOT VALID refusal of new version 1 rows; the issuer’s log grant restated over seventeen columns and the closing privilege audit with the extended matrix -
20261214000000_identity_subjects_sessions.sql— #2715 (ADR-049 §3, §5, §8, §12; Amendment 6): the six subject and session tables, their eight owner functions and immutability triggers, the issuer’s SELECT and EXECUTE grants on them, and the closing privilege audit with the extended matrix -
20261215000000_identity_issuance_log_v3.sql— #2722 (ADR-049 §13, Amendment 7): the issuance log’s version 3 layout: thedelegationgrant,subject_token_jti,rolesandprograms, the version 2 CHECKs restated over versions 2 and 3 with the delegation rows' own, the version 1 layout restated with the new columns NULL, and the NOT VALID refusal of new version 2 rows; the issuer’s log grant restated over twenty columns and the closing privilege audit with the extended matrix -
20261216000000_identity_admin.sql— #2729 (ADR-049 §12; Amendment 8): thecanopy_identity_adminrole and its guards,identity_admin_actionsandidentity_client_disablements, the session-revocation reasonadmin,identity_revoke_sessionrefusing it, the eight admin functions, the admin’s and the issuer’s grants, and the closing audit holding both matrices -
20261217000000_identity_relinks.sql— #2734 (ADR-049 §8; Amendment 6; Amendment 8):identity_subject_relinks, the session-revocation reasonrelinked, the actionlinkand its target CHECKs,identity_admin_link,identity_link_or_mint_subjectandidentity_open_sessionreplaced to read the effective link under the pair’s shared lock, the admin’s and the issuer’s SELECT on the relinks and the admin’s EXECUTE on the re-link, and the closing audit with both matrices extended -
20261218000000_identity_issuance_log_v4.sql— #2742 (ADR-049 §13; Amendment 9): the issuance log’s version 4 layout:device_idandrefresh_version, the four native grant types and the outcomesdescribedanddenied, version 3’s CHECKs restated asidentity_issuance_log_v4_*for versions 2 to 4 with_v4_deviceand_v4_refreshadded, the validated version 1 layout and the NOT VALID refusal of new version 1 to 3 rows; the issuer’s log grant restated over twenty-two columns and the closing audit with the extended matrix -
20261219000000_identity_native_sessions.sql— #2743 (ADR-049 §7; Amendment 9): native sessions inidentity_sessions, the three native revocation reasons,identity_device_authorizations,identity_device_decisions,identity_native_refresh_credentialsandidentity_dpop_proofs, their eight owner functions and immutability triggers,identity_purge_sessionsreplaced to purge a native session’s rows, the issuer’s grants on them, and the closing audit with the extended matrix -
20261220000000_identity_admin_create_subject.sql— #2766 (ADR-049 §8; Amendment 11): the actioncreate_subjectand its target CHECK,identity_admin_create_subject, the admin’s EXECUTE on it, and the closing audit with the admin matrix extended -
20270124000000_main_pool_least_privilege.sql— #2501 (ADR-049 §9): the NOLOGIN rolecanopy_security_runtime, the main pool’s login, with the main pool’s grant matrix andcanopy_security_app's chain grants held directly; a closing check refuses a missing app grant, any privilege on an identity object, or ownership -
20270125000000_identity_admin_actions_read.sql— #2737 (ADR-049 §12; Amendment 8): the admin’s SELECT onidentity_admin_actionsfor the action-log route, and the closing audit with the admin matrix extended
All migrations are forward-only per ADR-016.