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

audit_events

The system-wide audit log, one row per event received by the wildcard (#) RabbitMQ subscriber and the HTTP intake arms. Columns: event_id, event_type (routing key), source_service, action, resource_type, resource_id, user_id, user_role, ip_address, household_id (the worker-portal household filter), metadata JSONB, event_timestamp, received_at, created_at, the ADR-014 chain pair previous_hash / event_hash, programs TEXT[] (the ADR-044 program-scope assertion — NULL = no assertion, dropped from scoped reads; '{}' = program-neutral, visible to every scoped reader; slugs = visible on overlap) and dedup_key (the retired jti-keyed idempotency of auth.token_exchange rows, #1424: historical rows keep their keys, and no append writes the column since the exchange audit’s intake arm went). Appends are serialised by the audit chain’s transaction-scoped advisory lock, held until the appending transaction commits. Its key is derived on the locking connection from current_schema() (#2467): in public it is the literal 1, frozen (a rolling deploy runs old and new binaries against one database, and two keys for one chain would fork it — the #1245 failure); in any other schema it is the #1913 per-schema key advisory_lock_id(schema, "canopy-security.audit_chain"), so an ephemeral-schema test’s chain never waits on the live consumer’s lock or on another test’s. One append chains a slice of events (#2469): the wildcard consumer appends up to 32 buffered deliveries in the transaction that also stamps their event_inbox rows, the HTTP ingest arm one event per request. Under the lock it reads the predecessor once, then mints each row’s id (UUID v7) in chain order, so the (created_at, id) order the predecessor read and verification walk equals chain order even when two rows share a created_at. The statement-level trigger canopy_audit_append_only_guard blocks UPDATE / DELETE / TRUNCATE unless the transaction sets canopy.audit_maintenance = 'on'.

Actor derivation (event_parsing::extract_actor). A fact event’s nested author object gives user_id (its sub) and user_role (its author_type). Otherwise the first usable top-level actor field wins, in the order user_id, created_by, updated_by, requested_by, accessed_by, overridden_by, then the #1008 actor fields last_edited_by, consent_recorded_by, recorded_by, completed_by, cancelled_by, referred_by, action_by, discovered_by, actor and composition’s actor_user_id, and last worker_id. A typed Actor object there (#1008: {"actor_type":"human","subject":…} or {"actor_type":"service","service":…}) records the subject or service principal as user_id and its class, human or service, as user_role, over any payload role. A bare string records itself as user_id, with user_role from the author object’s author_type, else the payload’s role / user_role. A malformed Actor object is skipped like any other non-string value. human and service are reserved for the Actor arm: a payload, author_type or POST /v1/security/audit/ingest role spelled either way is dropped, so the row records no role. canopy-web renders the actor from these two columns: an empty user_id is the system, a service role shows the principal, and any other row is a human.

Chain input. event_hash is SHA-256 over the RFC 8785 (JCS) canonical bytes of the frozen AuditChainInputs struct (services/canopy-security/src/store/mod.rs; the field set ADR-014 Amendment 1 fixed): previous_hash, event_id, event_type, the canonical timestamp (event_timestamp at fixed microsecond precision), user_id, user_role, action, resource_type, resource_id, source_service, household_id and metadata — the last hashed exactly as stored, so sealed PII enters as ciphertext and a redaction in canopy-persons leaves the row byte-identical. ip_address, received_at, created_at, programs and dedup_key are outside the hash. dedup_key is outside deliberately, not by omission: verification reproduces the stored hash from exactly these fields, so widening the struct would change the value every existing row must reproduce and invalidate the whole chain. The column was an operational idempotency handle only; the jti it was derived from (metadata→>'jti') sits inside the hashed metadata, so its tamper evidence rides there. programs follows the same precedent (the 20261128000000 migration header records that column’s tamper-evidence posture).

audit_events_archive

The archive twin the #1208 archive runs move aged rows into. Same columns — previous_hash / event_hash, household_id and programs were added in lock-step so the positional move and the export union keep working; dedup_key stays live-only — and the same append-only trigger. The chain extends across the live ↔ archive boundary, so archived rows remain verifiable.

breach_alerts

Detection-rule firings: rule_name, severity (CHECK low / medium / high / critical), description, user_id, source_service, evidence JSONB, status (CHECK open / in_progress / resolved / false_positive), resolved_by / resolved_at.

nist_control_mappings

NIST SP 800-53 control coverage (seeded: AU-2/3/6/9/11, AC-2/6/7, SI-4, IR-4/5): control_id (unique), control_name, control_family, event_types[], description, implementation_status.

detection_rules

Breach-detection rules (IRS Pub 1075 §9) as self-describing config: rule_name (UNIQUE), rule_type, the sliding window (threshold, window_minutes), severity (CHECK), enabled / active, notify_webhook, and the typed predicate columns event_type_pattern / action_pattern / resource_type_pattern / source_service_pattern (NULL = wildcard, AND-combined, ILIKE containment, bound as parameters). Two evaluators exist (detection.rs): event_count, and after_hours_count — the same predicate count restricted to events whose jurisdiction-local hour falls outside the configured business-hours window (#1405). Both count across audit_events ∪ audit_events_v2. Seeded rules: Failed Authentication (auth_failed, 5 / 10 min), Bulk Data Access (export, 100 / 5 min), Privilege Escalation (role_changed, 1 / 60 min), FTI Access Volume (ssn / accessed, 100 / 10 min), Reporting Extract Volume (source canopy-reporting, 50 / 10 min), and After Hours Access — disabled by 20261102000000 and re-enabled by 20261202000000 on after_hours_count with the non-aliasing predicate accessed / ssn, threshold 1 per 1440 minutes.

fti_chain_verifications

Legacy per-FTI-service chain-verification ledger (ADR-014 §7-8): service, verified_at, rows_verified, broken, broken_at_row_id, broken_reason, duration_ms. No writers since #1245; the only reader is the latched-breach bit behind GET /v1/security/chain/status. Drops when #1304 retires the chain (the #1279 cutover that was to drop it was withdrawn with chain-v2, ADR-041).

signing_key_history (ADR-036)

The append-only public-key retention register for determination-signing keys: kid (PK, canopy-{program}-{YYYYqN}), program, public_key_pem (SPKI, public key only), registered_at, and registrant_service_id (the authenticated registering service, #1261; NULL on earlier rows, never backfilled). "Current" is derived from registration order. The trigger canopy_signing_key_append_only_guard blocks UPDATE / DELETE / TRUNCATE unless canopy.signing_key_maintenance = 'on'. Never private material, never FTI.

audit_archive_runs (#1208)

The async archive-run record: UUIDv7 PK, state (queued / running / done / error), requested_by, the frozen config snapshot (archive_after_days 1..=36500, chunk_size 100..=20000, max_chunks_per_pass 1..=1000), the token-fenced lease (lease_owner, lease_token, lease_expires_at, heartbeat_at), attempts, chunks_committed, rows_archived, more, error_code (CHECK duplicate_overlap / upgrade_state_unrepaired / statement_timeout / db_error / crashed), error_detail, started_at / finished_at, with state-consistency CHECKs (running ⇔ leased, terminal ⇔ finished, error ⇔ error_code, queued ⇒ pristine). One active run total. Not append-only-guarded — operational state.

audit_archive_schedule (#1208)

The due-state singleton for scheduled archival: singleton (PK, CHECK true), next_due_at, last_claimed_at; the due-claim is one UPDATE … WHERE next_due_at ⇐ now() RETURNING (Skip semantics — a week of downtime is one claim).

worker_directory (ADR-046)

JIT-populated worker directory keyed (issuer, subject) (opaque OIDC sub): display_name, email, role, first_seen_at, last_seen_at. Rows arrive only from BFF-reported validated logins (POST /v1/security/workers/observed) and the seeder. Plain upsert table — outside the chain, no append-only trigger, no archive twin.

event_outbox / event_inbox

Generated ADR-018 / ADR-039 outbox and inbox — documented once on the data-models index.

idempotency_keys (runtime DDL)

The fleet idempotency cache, created before the migrator runs by canopy_db::ensure_idempotency_schema (canopy_api::bootstrap::apply_migrations_on; canopy-manage migrate apply makes the same call); shape owned by crates/canopy-db/src/idempotency_schema.rs.

_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

20260910000000_chain_v2_substrate.sql (Amendment 6)

chain_instances, chain_topology, chain_epochs, chain_sources, chain_heads, audit_events_v2, audit_events_archive_v2, chain_anchors, chain_anchor_heads, chain_verification_checkpoints, chain_verification_runs, chain_incidents

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 canonical_event_payload by chain_append_rows_audit; ip_address and — since 20261124000000 — dedup_key ride unhashed); the anchor store (canonical manifest bytes + hash, monotonic CAS append, one-way notarization_state); the chain verification state; six NOLOGIN roles; the status and preimage views.

20260930000000_chain_append_staging.sql (Amendment 7)

chain_append_staging

The durable ingress queue between "accepted" and "chained": event_id (UUIDv7 PK), canonical_event_payload, payload_digest, the unhashed ingress, the router-stamped placement trio, the park quarantine (parked_at / park_reason, attempts). chain_staging_dequeue / chain_staging_park are the only delete and park paths; audit_events_v2_event_id_uq is the permanent replay identity.

20261010000000_chain_verification_hardening.sql (Amendment 9)

reshapes chain_verification_checkpoints, chain_verification_runs, chain_incidents

Token-confidential leases (lease_token, readable only through chain_checkpoints_verify_v), the family loop kind and cycle stamps, shard_id / mode / job_id on runs, the stored detected_loop_kind, the closed 22-kind incident vocabulary, bounded evidence (≤ 16 KiB) readable only by canopy_chain_incident_admin, and the guarded functions (chain_checkpoint_acquire / _advance, chain_run_record, chain_incident_latch / _resolve, chain_anchor_transition_emit / _confirm with the canopy_chain_anchor_emitter role).

20261015000000_chain_verification_projections.sql (Amendment 9)

chain_verify_jobs

The durable manual-verify job store (target, requested_loop, state, the captured work definition, the DB-minted claim token, run_id, error_code; one active job per target), the five token-free app views, the runs mode ⇔ job constraint, and the chain_job* SECURITY DEFINER functions. Terminal (done / error) rows are the table’s only exit: the audit verifier task calls chain_job_reap on its first pass and then daily, deleting rows finished more than CANOPY_SECURITY__CHAIN_JOB_REAP_DAYS ago (default 7, the SQL floor; 7..=90) unless they reference a still-latched incident, in batches of 1 000 jobs, each call committing on its own (#2963); the run rows they point at survive with job_id severed to NULL (#2148).

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

identity_signing_keys

One row per published key. The caller supplies kid (PK), x, y, replica_id (UUID) and requested_sign_seconds; the BEFORE INSERT trigger identity_signing_keys_stamp (SECURITY DEFINER) stamps created_at from clock_timestamp(), sign_from = created_at + 60 s, sign_until = created_at + requested_sign_seconds, publish_until = sign_until + 720 s, inserted_by = session_user and client_addr = inet_client_addr() (the one nullable column: NULL over a Unix socket). Values a caller supplies for those columns are overwritten; the issuer’s column-level grant refuses naming them at all. The same trigger increments the guard row, then refuses a 65th unrevoked row whose publish_until is still ahead of clock_timestamp() with SQLSTATE 54000. CHECKs, which hold with every trigger bypassed: kid, x and y are canonical unpadded base64url of 32 bytes (^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$); kid is the RFC 7638 thumbprint of (x, y); requested_sign_seconds is 600..=86400; the three windows follow from created_at as above. The canonical-encoding CHECKs are named canonical_* so they run before kid_thumbprint (PostgreSQL tests CHECKs in name order).

identity_key_revocations

INSERT-only revocations: kid (PK, FK → identity_signing_keys), revoked_at, reason and actor (both non-empty), revoked_by = session_user. Written only through identity_revoke_key(kid, reason, actor) (SECURITY DEFINER), on which nobody holds EXECUTE: the revocation runbook runs it as the migration identity. A revoked key frees its cap slot at once, and the JWKS (#2500) excludes it.

identity_signing_key_cap_guard

One row, id = 1, and a generation counter every insert increments. Its row lock serializes the cap: under READ COMMITTED a concurrent inserter waits and then counts the winner’s row, under REPEATABLE READ it fails with 40001. No grants. A missing row refuses every insert.

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

identity_client_assertions

The single-use record of every accepted private_key_jwt client assertion: client (non-empty), jti (1 to 128 characters) and expires_at (the assertion’s exp + 60 s), primary key (client, jti). The issuer inserts all three columns. A replay is the zero row count of INSERT … ON CONFLICT DO NOTHING with no conflict target, which needs INSERT alone: naming the target, by its columns or by the constraint, needs SELECT on its columns, which the issuer never holds. The primary key is therefore the table’s only unique index, since another would widen the bare form’s arbiter. Rows leave only through identity_purge_client_assertions.

identity_issuance_log

One INSERT-only row per mint, per handled refusal and per web-session state change (Amendment 6). The issuer inserts record_id (UUID v7, PK, from the writer), grant_type (client_credentials, token_exchange, revocation, the revocation endpoint, delegation, a token exchange whose requested_token_type names the access-token type, or one of the native grants: device_authorization, device_verification (canopy-web’s code entry), device_code and refresh_token; NULL only on a token request refused before its grant type was established), outcome (issued, refused, revoked, ignored, or code entry’s described and denied), error (the RFC 6749, RFC 8707, RFC 8628 §3.5 or RFC 9449 §5 code, present exactly on a refusal), reason (^[a-z_]{1,64}$, why a refusal happened: the token endpoint’s vocabulary, Cause::reason in identity/token_endpoint.rs, each value distinct and held to the CHECK by a unit test, #2554), client, purpose, audience and scope (NULL when not yet known, as on an unauthenticated refusal; the client and purpose are compiled values, and the request’s audience and scope reach the writer as LogText, which cannot hold the NUL these columns refuse, so one caller’s text never fails the batch its row commits in, #2574: a value holding one is logged as NULL), token_jti (UUID), kid and expires_at, subject_id and session_id (UUIDs: the canopy subject and the session’s public id, never an upstream sub, username, token or credential), session_event (opened, renewed, grace, replayed, superseded or revoked), peer_addr (INET, the request’s source: the TCP peer the server accepted, or, when that peer is listed in CANOPY_TRUSTED_PROXIES, the leftmost X-Forwarded-For hop it names, by the shared client-IP rule; NULL with no peer; ADR-049 Amendment 22), subject_token_jti (UUID: an onward delegation’s subject token, so each hop’s row points at its parent’s), roles and programs (TEXT[]: what an issued delegation, redemption or refresh token grants), device_id (UUID: the device authorization a native row concerns, and the device an approval opened its session for), refresh_version (BIGINT: the refresh credential version a native mint issued or a refused refresh presented) and schema_version (4; the version 1, 2 and 3 rows 20261210000000, 20261213000000 and 20261215000000 wrote stay as history, and a NOT VALID CHECK, identity_issuance_log_v4_new_rows, refuses any new row of another version). The version 4 table below says which columns each row carries. The BEFORE INSERT trigger identity_issuance_log_stamp (SECURITY DEFINER) sets occurred_at from clock_timestamp() and then row_digest, overwriting whatever the caller supplied; the issuer’s column grant refuses naming either. identity_registry_immutable() refuses UPDATE, DELETE and TRUNCATE with 23514, as on the registry.

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

client_credentials

issued

none

token_jti, kid, expires_at (the token’s exp)

client_credentials

refused

none

error

token_exchange

issued

opened, renewed, grace, replayed or superseded

session_id, subject_id, expires_at = the answer’s fresh_until; no token_jti or kid, since a session is opaque and unsigned; device_id beside opened alone, when a device approval opened a native session

token_exchange

refused

none, or revoked

error; subject_id when known, and session_id only with it; revoked needs both

revocation

revoked

revoked

session_id, subject_id

revocation

refused

none

error, one of invalid_request, invalid_client, unauthorized_client and temporarily_unavailable; subject_id and session_id together, when known

revocation

ignored

none

nothing else (an unknown, ended or revoked credential, answered 200)

delegation

issued

none

token_jti, kid, expires_at (the token’s exp), session_id, subject_id, and roles and programs, each a one-dimensional array of at least one value with no NULL; subject_token_jti onward (version 3 only)

delegation

refused

none

error; subject_id and session_id together, when known; subject_token_jti once an onward subject token verified (version 3 only)

device_authorization

issued

none

device_id, expires_at = the device code’s expiry

device_authorization

refused

none

error

device_verification

described or denied

none

device_id, and the worker’s web session_id and subject_id

device_verification

refused

none

error; subject_id and session_id together, when known; device_id when known

device_code

issued

none

as an issued delegation row without subject_token_jti, plus device_id and refresh_version = 1

refresh_token

issued

none

as an issued device_code row, with refresh_version 2 or more and no device_id

device_code

refused

none, or revoked

error; subject_id and session_id together, when known, and revoked exactly when the refusal revoked the session; device_id when known

refresh_token

refused

none, or revoked

as a refused device_code row, with the presented refresh_version (1 or more) when known instead of device_id

none

refused

none

error (a token request refused before its grant type was established)

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

identity_subjects

One canopy subject: subject_id (PK, the UUID v7 candidate the open mints) and created_at. Minted only by identity_link_or_mint_subject, on the first successful open of an unseen upstream pair.

identity_subject_links

The exact upstream pair a subject was minted for: upstream_iss (the issuer exactly as the profile writes it; visible ASCII), upstream_sub (OidcSubject's shape: 1 to 255 bytes of ASCII with no control character), subject_id (FK → identity_subjects) and linked_at. The primary key (upstream_iss, upstream_sub) gives a pair one subject; UNIQUE (subject_id, upstream_iss) gives a subject at most one pair per issuer. A changed issuer mints a new subject until a security admin re-links the pair (Security administration (ADR-049 §12; Amendment 8)): a pair’s effective link is its latest identity_subject_relinks row, else this row, which never changes.

identity_subject_suspensions

INSERT-only suspension events: event_id (UUID v7, PK), subject_id (FK), version (≥ 1, UNIQUE (subject_id, version)), suspended (true suspends, false lifts), recorded_at, actor and reason (1 to 200 bytes each). The latest event, the highest version, wins; recorded_at is audit only. Written only by identity_suspend_subject and identity_lift_subject_suspension, which allocate the version under the subject’s row lock and on which nobody holds EXECUTE: the security-admin functions call them as the owner (Security administration (ADR-049 §12; Amendment 8)), and an operator runs them as the migration identity (Security Operations).

identity_sessions

One session: session_id (UUID v7, PK), credential_hash (32 bytes, unique: the lookup key; a native session’s is its revalidation credential’s, Native sessions and the device flow (ADR-049 §7; Amendment 9)), kind and client (web and canopy-web, or since 20261219000000 native and canopy-cli; no other pair), subject_id (FK), the upstream it opened under (upstream_iss, upstream_client with UpstreamClientId's shape, upstream_sub with OidcSubject's), auth_time, nonce_digest (32 bytes, or NULL when the opening id_token carried no nonce), opened_at and ends_at. opened_at < ends_at, and ends_at - auth_time is at most 86400 s, the largest identity_web_session_max_seconds.

identity_session_validations

A session’s validations: validation_id (UUID v7, PK), session_id (FK), version, recorded_at, kind (open, renewal or grace), validated_at (the upstream validation’s instant), id_token_iat and id_token_digest (32 bytes; both present or both absent, and absent on a grace row), fresh_until (at most 4500 s, one freshness window and the largest grace, after validated_at), roles and programs (non-empty one-dimensional TEXT[] without NULLs, each name 1 to 64 characters of [a-z_], so none holds a comma) and username (1 to 256 bytes with no control character). UNIQUE (session_id, version), version ≥ 1, and (kind = 'open') = (version = 1). The latest validation is the highest version, never the latest recorded_at, since a wall clock can step back.

identity_session_revocations

At most one per session: session_id (PK, FK), revoked_at, reason (logout, upstream_refused, projection_refused, upstream_changed, suspended, admin and relinked from Security administration (ADR-049 §12; Amendment 8), or refresh_reused, device_code_reused and unredeemed from Native sessions and the device flow (ADR-049 §7; Amendment 9)) and client (the client that revoked it: the session’s opener; for admin and relinked the client the security administrator came through; for unredeemed canopy-web, whose renewal found it; for a native session’s logout canopy-cli or canopy-web, whichever revoked it).

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 (since 20261217000000, its latest relink’s, else its link’s), else p_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 with 23505, 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 1 open validation, answering opened. Refuses an unknown subject or an upstream pair not effectively linked to the subject (23503, under the pair’s shared lock since 20261217000000), 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 order suspended; revoked; ended (p_now at or past ends_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 presented iat is not after that row’s, or the session recorded none); superseded (the latest version is not p_expected_version); else inserts the next version as a renewal and answers recorded. 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 order suspended, revoked, ended, superseded, or exhausted when least(validated_at + 900 s + p_grace_seconds, ends_at) of the latest successful validation (the highest version that is not a grace) is not after p_now; else inserts the next version as a grace that copies that validation’s validated_at, roles, programs and username with that freshness, and answers recorded. A second grace before the next success ends where the first did. p_grace_seconds outside 0 to 3600 is refused with 22023.

  • identity_revoke_session(p_session, p_reason, p_client) RETURNS boolean: true when this call revoked the session, false when a revocation exists. Since 20261216000000 it refuses any reason but the issuer’s five with 23514, so an admin or relinked revocation 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 to p_batch sessions that ended, or were revoked, more than 30 days (720 hours) before clock_timestamp(), with their validations and revocation, each session locked FOR UPDATE SKIP LOCKED, and returns how many sessions it deleted; a batch outside 1 to 1000 is refused with 22023. Since 20261219000000 it 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) and identity_lift_subject_suspension(p_subject, p_actor, p_reason), each RETURNS uuid (the event’s id): an event at the subject’s next version, under the subject’s row lock; an unknown subject is refused with P0002. 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

identity_admin_actions

INSERT-only, one row per admin change: action_id (UUID v7, PK), recorded_at, action (suspend, lift, revoke_session, disable_client, enable_client, revoke_key, link or create_subject), exactly the target its action names (target_subject for suspend, lift and create_subject, target_session, target_client or target_kid, or for link the subject with target_upstream_iss and target_upstream_sub, in the link table’s shapes), the actor the bearer token named (actor_subject, actor_session, actor_token_jti, actor_token_kid, a thumbprint, and actor_client), reason (1 to 200 bytes with no control character) and changed (false for a change that left the state as it was). actor_token_kid lets the compromise response find every action made under a revoked key.

identity_client_disablements

INSERT-only runtime disablement events: event_id (UUID v7, PK), client, version (≥ 1, UNIQUE (client, version)), disabled, recorded_at and action_id (FK → identity_admin_actions). The latest event, the highest version, wins; a client with none is enabled.

identity_subject_relinks

INSERT-only re-links of an upstream pair: relink_id (UUID v7, PK), upstream_iss and upstream_sub (the link table’s shapes), version (≥ 1, UNIQUE (upstream_iss, upstream_sub, version)), subject_id (FK → identity_subjects), recorded_at and action_id (FK → identity_admin_actions). A pair’s effective link is its latest relink, the highest version, else its identity_subject_links row.

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_suspend and identity_admin_lift(p_subject, …): under the subject’s row lock (FOR UPDATE), the subject’s latest suspension event; when the state changes, identity_suspend_subject or identity_lift_subject_suspension with the actor’s subject as actor. An unknown subject is P0002.

  • identity_admin_revoke_session(p_session, …): a revocation with reason admin and the actor’s client, ON CONFLICT (session_id) DO NOTHING. An unknown session is P0002.

  • identity_admin_disable_client and identity_admin_enable_client(p_client, …): under pg_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_key with the actor’s subject as actor (revoked_by is the admin login). An unknown kid is P0002.

  • identity_admin_create_subject(p_subject, …) (20261220000000, Amendment 11): refuses the nil UUID (22023), then inserts the subject ON CONFLICT (subject_id) DO NOTHING and records the action create_subject (its only target the subject) either way, changed true only when it inserted. Two creates of one UUID serialize on the primary key and the second records changed false. 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 subject FOR UPDATE in ascending subject_id order, it reads the pair’s effective subject and the target’s effective links under p_iss. A pair already effectively linked to the target changes nothing. A target already effectively linked under p_iss to another upstream subject is 23505, an unknown target P0002. An unlinked pair gets its base link, or relink version 1 when the target’s own base link under p_iss (since re-linked away) holds that issuer’s slot. A pair linked elsewhere gets its next relink, and its live sessions are revoked relinked, 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

identity_device_authorizations

One started device flow: device_id (UUID v7, PK), device_code_hash and user_code_hash (32 bytes each, each unique: the redemption’s and code entry’s lookup keys; a user code any stored row holds, expired or not, is refused), client (canopy-cli), created_at and expires_at (created_at < expires_at, at most 600 s later).

identity_device_decisions

At most one decision per device: device_id (PK, FK), decision (approved or denied), decided_at, subject_id (FK: the subject who decided, an approval’s being its native session’s) and session_id (FK, unique: the native session an approval opened; present exactly on an approval).

identity_native_refresh_credentials

A native session’s refresh credentials: credential_id (UUID v7, PK), credential_hash (32 bytes, unique: the refresh’s lookup key), session_id (FK), version (≥ 1, UNIQUE (session_id, version): 1 at redemption, the latest plus 1 at each rotation, allocated under the session’s row lock), jkt (the RFC 7638 thumbprint of the device key the session is bound to, copied from the latest version at each rotation) and issued_at.

identity_dpop_proofs

The single-use record of every accepted DPoP proof, the shape of identity_client_assertions: jkt (a thumbprint), jti (1 to 128 characters with no control character) and expires_at (the proof’s iat + 120 s), primary key (jkt, jti). A replay is the zero row count of a targetless INSERT … ON CONFLICT DO NOTHING, which needs INSERT alone. The issuer deletes no row; identity_purge_dpop_proofs removes expired ones.

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 and started. A colliding device code or id is 23505.

  • identity_approve_device(p_user_code_hash, p_session, p_now) RETURNS text: unknown, expired (p_now at or past expires_at), decided, else the approval naming p_session and its subject and approved. Two decisions on one device serialize on the decision’s primary key, the second answering decided. A session opened for another client than the device’s is 23514, an unknown one P0002. The caller must roll the approval’s whole transaction back on any answer but approved, 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 is P0002; else unknown, expired, decided, or the denial by p_subject and denied.

  • 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, expired once p_now reaches expires_at, else pending; denied; then for an approval, under its locks, revoked, ended (p_now at or past ends_at), suspended, reused (a refresh credential exists: the session is revoked device_code_reused with its client, and did_revoke is whether that insert revoked it), expired (unredeemed past expires_at), else version 1 bound to p_jkt and redeemed.

  • 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 revoked refresh_reused with its client, did_revoke as above), else the next version bound to the latest’s jkt, never one the caller names, and rotated. The caller finds the presented credential by its hash and holds the proof’s thumbprint to its jkt first. An unknown session, or one holding no refresh credential, is P0002. Since revoked precedes reused, a replay after any revocation revokes nothing and reports did_revoke false.

  • identity_revoke_unredeemed_native_session(p_session, p_now) RETURNS boolean: under the session’s locks, true, revoking it unredeemed with canopy-web as the revoking client, exactly when it is native and unrevoked, holds no refresh credential, and its device’s expires_at is at or before p_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 is P0002.

  • identity_purge_devices(p_batch) RETURNS integer: deletes up to p_batch devices no approval names whose code expired more than 30 days (720 hours) ago, their denials first, each device locked FOR UPDATE SKIP LOCKED; a batch outside 1 to 1000 is 22023. An approved device leaves with its session through identity_purge_sessions. The session sweeper calls it after identity_purge_sessions (#2744).

  • identity_purge_dpop_proofs(batch) RETURNS integer: as identity_purge_client_assertions, up to batch expired proofs, oldest first, FOR UPDATE SKIP LOCKED, 1 to 10000 a call. The jti sweeper calls it after identity_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.

Diagram

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 and verify_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 — the programs && $scope arm); 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 on true 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_key and identity_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 and identity_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 on breach_alerts.status and detection_rules.severity; idx_unique_nist_control

  • 20260402000001_add_hash_chain.sql — previous_hash + event_hash on audit_events (ADR-014); idx_audit_events_event_hash

  • 20260409000000_align_archive_hash_columns.sql — the same hash columns on audit_events_archive (the LIKE predated the chain)

  • 20260425000001_create_fti_chain_verifications.sql — the per-FTI-service verification ledger

  • 20260601000010_add_household_id_to_audit_events.sql — household_id on 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 SMALLINT on 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): drops hash_version from 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, not CONCURRENTLY — the sqlx migrator lock deadlocks with CONCURRENTLY; 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_staging and 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 _app views, 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 at event_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_key on audit_events_v2 and its archive twin, audit_events_v2_dedup_key_uq, chain_append_rows_audit replaced 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 on after_hours_count with the accessed / ssn predicate

  • 20261208000010_create_worker_directory.sql — #597 (ADR-046): worker_directory + worker_directory_last_seen_idx

  • 20261209000000_identity_signing_keys.sql — #2498 (ADR-049 §9): the canopy_identity_owner / canopy_identity_issuer roles 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_log with 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 from canopy_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_id and session_event, the widened outcome, 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: the delegation grant, subject_token_jti, roles and programs, 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): the canopy_identity_admin role and its guards, identity_admin_actions and identity_client_disablements, the session-revocation reason admin, identity_revoke_session refusing 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 reason relinked, the action link and its target CHECKs, identity_admin_link, identity_link_or_mint_subject and identity_open_session replaced 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_id and refresh_version, the four native grant types and the outcomes described and denied, version 3’s CHECKs restated as identity_issuance_log_v4_* for versions 2 to 4 with _v4_device and _v4_refresh added, 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 in identity_sessions, the three native revocation reasons, identity_device_authorizations, identity_device_decisions, identity_native_refresh_credentials and identity_dpop_proofs, their eight owner functions and immutability triggers, identity_purge_sessions replaced 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 action create_subject and 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 role canopy_security_runtime, the main pool’s login, with the main pool’s grant matrix and canopy_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 on identity_admin_actions for the action-log route, and the closing audit with the admin matrix extended

All migrations are forward-only per ADR-016.

Edit this page · default