Plan: Audit rows name who acted, and every detection rule can fire

Status

Done (2026-11-17) — audit rows name the worker or the calling service where a publisher holds one, and the detection rules count closed action tokens.

Closes: #3116, #3114. Depends on: #2314 (merged through !2405: the audit header is where an actor is stated).
Tree: written against feat/audit-header-parser-removal (main plus !2404 and !2405).
Rulings (maintainer, 2026-11-16/17): one plan for both issues, built right after #2314; an SSN release names the requesting caseworker; the real initiator is named wherever the staging site knows it; the privilege-escalation rule counts denials; the failed-authentication and account-lockout rules are removed until an identity-provider event feed exists.

Erratum (2026-11-17): the removed rule types are refused with the existing 400 invalid-enum-value, which is what an unknown rule_type already answers; the Tests table’s "existing 422" was wrong.

Erratum (2026-11-17): two of step 1’s three devstack "fires on a real publisher’s rows" tests build an envelope with the header that publisher states, because craig-security cannot call another service’s publisher; the denial test uses craig-authz’s real builder.

Erratum (2026-11-17): step 3 lowers no ceiling. Each of its six sites keeps a SYSTEM_OR_RECORDLESS row, reworded: five can still state System on a path that remains, and the placement AFCARS release names no record. The ceiling stays 55.

Erratum (2026-11-17): the engine never evaluates for itself, so rules.evaluated states System only for a caller whose claims name neither a worker nor a service and whose raw sub is empty or the word system.

Erratum (2026-11-17): a manual scan’s alert names the acting principal by D1, which is service:<name> for a service caller the scan’s authorization admits; D2’s row said Sub(worker) only.

Erratum (2026-11-17): five of step 3’s publishers build their envelope in a named function their unit tests call, so their allowlist rows are keyed by that function (afcars_released_envelope, payment_created_envelope, payments_voided_envelope, alert_created_envelope, evaluated_envelope). The sweep’s admin reaches the header through a field of the event struct that is never serialized, not a publisher parameter.

Context

  1. #3116. SYSTEM_OR_RECORDLESS (services/craig-security/src/audit_header_census_tests.rs, 58 rows, ceiling 58) lists every site whose header states System or no record. Most are right (a scheduler, a reconciler, an inbox consumer, a cache signal). Some are not: the act has a worker or a calling service behind it and the row says system only because the payload never carried an actor key the old parser lifted. The clearest is publish_person_pii_released_for_screening (services/craig-cases/src/events.rs): an SSN release that names nobody, though its payload carries requested_by.

  2. #3114. The five pattern rules of services/craig-security/src/detection_sql.rs count audit_log rows by ILIKE on action. With the closed action set (crates/craig-mq/src/audit_meta.rs), %auth%fail%, %privilege%, %escalat%, %unauthorized%, %lockout%, %get%, %list% and %download% match no token (the_detection_substrings_match_the_same_actions_as_before, services/craig-security/src/audit_columns.rs), so three of the rule types can never fire.

Design

D1. The actor rule

A header states, in this order of preference:

  1. Sub(worker) when a worker’s act or a worker-started run causes the event and the staging site holds that worker.

  2. AuditActor::named("service:<name>") when a service principal called and no worker is known. The text is the ADR-085 encoding craig-authz already writes (acting_encoding, crates/craig-authz/src/engine.rs).

  3. System only for a scheduler tick, a reconciler, an inbox consumer acting on another service’s event, or a cache signal.

A worker asserted by a calling service as data (not the authenticated caller) may be stated as Sub only when the endpoint is service-only and allowlisted to that one caller. The authenticated service stays in the payload.

D2. Sites that change

Site (publisher) Today After

publish_person_pii_released_for_screening, publish_person_ssn_release_refused (craig-cases)

System

Sub(audit.requested_by); requestor stays in the payload

publish_person_updated on the SOLQ flip (apply_verification_cas, craig-cases)

System

named("service:craig-exchange") (the caller record_ssa_outcome admits); worker paths unchanged

publish_person_pii_released_for_outbound, publish_person_pii_released_for_afcars (craig-cases); publish_afcars_released (craig-placement)

System

named of the calling service’s encoding, taken from the claims at the handler

publish_report_submitted with no created_by (craig-cases)

System

named of the submitting service’s encoding (the intake edge)

publish_payment_created, publish_payments_voided under generate_for_month (craig-financial)

System

the run’s Initiator: Sub for Manual, System for Scheduled; the inbox-consumer paths stay System

publish_payment_created under persist_backpay_payment (subsidy/generator.rs, the backpay finalize)

System

AuditActor::named(payment.created_by), the worker the payment row already records

publish_alert_created (craig-security)

System

Sub(worker) on the manual scan handler; System on the scheduler tick

publish_screening_run_invalidated from the stale-cohort sweep (screening_rotation.rs, craig-exchange)

System

Sub of the sweeping admin; supersede, expiry and cohort-change paths stay System

stage_evaluated (rules.evaluated, craig-rules)

System

the evaluator the evaluation row already records, by D1; System when the engine evaluates for itself

Each publisher gains the actor as a typed parameter (AuditActor or the existing initiator type); no payload key is added or removed, so consumers are untouched. Sites not in the table keep their header and their allowlist row. publish_subsidy_anchor_replaced, publish_payment_generation_skipped and the auto-link pass stay System: they are inbox consumers, and the causing worker is on the causing event.

A site that can state System on some path keeps its SYSTEM_OR_RECORDLESS row, reworded to name the paths that remain. The two SSN sites and the two person-PII release sites lose System entirely; the ceiling drops by the rows that lose both System and a None id (the refusal, at least), and SYSTEM_OR_RECORDLESS_CEILING is lowered to the new length.

D3. Detection rules count closed tokens

detection_sql.rs stops matching substrings. Each rule’s predicate names action tokens exactly:

Rule type Predicate on audit_log

bulk_access

action IN ('read', 'portal_read')

data_export

action IN (<the five export tokens>, 'reveal'): the five tokens %export% matches today (export, and the AFCARS and NCANDS _export_generated and _export_failed pairs), plus reveal. The two _failed tokens release nothing; they stay counted because the rule counts them today and a burst of failed exports is export activity. The placement AFCARS release states read and is counted by bulk_access.

privilege_escalation

action = 'deny' AND success = false

after_hours_access

unchanged

The token lists are built in Rust from AuditAction variants (as_token()), so a renamed token cannot drift from the SQL. failed_auth and account_lockout are removed: the rule_type CHECK and VALID_RULE_TYPES (services/craig-security/src/api/mod.rs) lose them, count_for_rule (detection.rs) loses their arms, and the CLI help (services/craig-cli/src/cmd/detection.rs) and store/models.rs docs follow. The same step changes every place that creates a rule of a removed type, or it is not green alone: the seeder (tools/craig-seed/src/datagen/security.rs, the failed_auth_burst and account_lockout_pattern rules, replaced by a privilege_escalation rule) and the fixtures in services/craig-security/tests/api/detection.rs, config_act_events.rs, refusal_echo.rs, replay_guards.rs and the unit test in src/detection.rs, which move to bulk_access (a test that needs a removed type to prove the refusal keeps it as the refused input).

One migration in craig-security (ADR-063 contract migration, floor bump): detach alerts from rules of the two removed types (security_alerts.rule_id = NULL; such alerts cannot exist unless hand-inserted, since the rules never fired), delete those rules, tighten the CHECK, drop the five partial indexes of 20260726060000_detection_partial_indexes.sql and create three that mirror the new predicates.

privilege_escalation counts every denial system-wide (ruled 2026-11-17): a rule’s threshold and window_minutes are its tuning. Per-actor counting is not built here.

A headerless degraded row stores the halves of its event type, so one whose type ends in a counted token (placement.portal_read, reporting.afcars_export_generated) still counts. That is the intended direction: it is the same act, filed without its header, and detection should not go blind to it.

bulk_access counts what publishers state today: portal_read (caregiver portal reads) and read (the placement AFCARS release). A worker’s ordinary record read stages no event and is not counted by any rule; that is unchanged and out of scope.

D4. Out of scope

  • An identity-provider event feed (failed logins, lockouts). The two rule types return with it.

  • Per-actor or per-resource thresholds for any rule.

  • Changing any payload, or naming an actor on a consumer-driven event.

Scope and order

One merge request per step, each green alone.

  1. Detection (Closes #3114): D3, its migration, tests, docs, fragment changelog.d/3114.changed.adoc.

  2. craig-cases actors (Relates to #3116): the SSN release and refusal, the SOLQ flip, the two releases, the intake-edge report. Fragment changelog.d/3116.cases.changed.adoc.

  3. The rest (Closes #3116): craig-placement, craig-financial, craig-security, craig-exchange, craig-rules; the ceiling lowered. Fragment changelog.d/3116.changed.adoc.

Risks

Risk Mode Mitigation

A service asserts a worker who did not act, and the SSN release row names them.

silent

Only the service-only, single-caller release_ssn path states an asserted worker (D1); the authenticated requestor stays in details; an_ssn_release_names_the_requesting_caseworker_and_keeps_the_requestor asserts both.

A worker path of a changed publisher is passed System by mistake, losing attribution it has today.

silent

The allowlist row for each mixed site names its remaining System paths; per-site tests assert the worker on the worker path; existing actor_audit_tests legs stay.

privilege_escalation now fires where it never did, flooding alerts.

fail-closed

One standing alert per rule (uq_security_alerts_standing_rule); threshold and window are rule data; the release note tells operators to review the rule’s threshold.

A deployment has rules of the removed types; the migration deletes them.

fail-closed

They could never fire; the release note says they are deleted and why; the_migration_removes_rules_that_could_not_fire asserts no alert row is lost.

A token is renamed or added and a predicate silently stops matching.

silent

Predicates are built from AuditAction; every_detection_predicate_matches_a_token_some_publisher_states fails on a predicate token no staging site names.

The new partial indexes do not match the predicates and scans go back to the heap.

silent

The existing plan-pin integration test reads the shared constants; it is extended to the three new indexes.

A headerless degraded row is missed by a rule its act belongs to, or an unrelated type is counted by a substring accident.

silent

Exact token equality replaces substring match, and a degraded row whose event type ends in a counted token still counts (D3); a_headerless_row_counts_only_when_its_type_ends_in_a_counted_token pins both directions, with the kept deny case.

Tests

Category Tests

Regression (#3114)

a_headerless_row_counts_only_when_its_type_ends_in_a_counted_token (audit_columns.rs, unit). services/craig-security/src/detection_sql.rs unit: every_detection_predicate_matches_a_token_some_publisher_states; no_rule_type_is_accepted_that_has_no_counter (VALID_RULE_TYPES equals the arms of count_for_rule). Replaces the_detection_substrings_match_the_same_actions_as_before, whose table of dead patterns is the defect.

Regression (#3116)

Per changed site, a non-devstack test of the stated header on each path (worker, service, system); the census every_system_actor_and_recordless_site_is_allowlisted with reworded rows; the_allowlist_holds_no_more_rows_than_its_ceiling at the lower ceiling.

Integration (devstack-gated, run by the car)

Each rule fires on rows a real publisher staged: a denial through craig-authz for privilege_escalation, a caregiver portal read for bulk_access, a person-PII release for data_export. The seeder’s rules insert under the tightened CHECK. an_ssn_release_names_the_requesting_caseworker_and_keeps_the_requestor; a manual scan’s alert names the worker; a worker-started generation run’s payments name the worker.

Migration

the_migration_removes_rules_that_could_not_fire; the N−1 binary refuses to boot past the floor; the plan-pin test over the three new indexes.

Hostile input

The rule-create handler refuses failed_auth and account_lockout with the existing 422.

Every new test gets a red proof. Devstack-gated tests are written and compiled locally and run by the train car.

Delivery

  • Canonical page: docs/modules/ROOT/pages/data-model-security.adoc (§ audit_log: who the actor is, by D1; § detection rules: the predicates and the four rule types).

  • Also updated: every live page that lists the rule types (security-operations.adoc, nist-architecture-mapping.adoc; security.adoc lists none); the CLI help text. Archived plan pages are not edited.

  • CHANGELOG entry: the three fragments named under Scope, each a declared audit-row or behaviour change with its Ops clause (review privilege_escalation thresholds; rules of the removed types are deleted; saved filters on user_id = 'system' for the listed events must change).

  • Close: Closes #3114 on step 1, Closes #3116 on step 3; one line with each merge SHA; then cargo xtask plan-lint --done and the archive move.

Review log

Round Vendor Resolved model Verdict

1

Anthropic

claude-fable-5-2

FLAGS (1): the removed rule types' seeder and fixtures were missing from step 1; folded.

2

Google

gemini-4-carbon

FLAGS (1): the backpay caller, the seeder, the headerless-row risk and the doc pages; folded. Approved by the maintainer in plan mode, 2026-11-17.

Edit this page · latest