Plan: Authz verification integrity — a verified helper registry and a runtime witness (#2666, #2667)

Archive record

4 MRs across 2026-11-03 → 2026-11-04: !2112 (U1, #2666: the verified helper registry and its pins), !2113 (U2a, #2897: the in-process witness refusing an unwired 2xx), !2114 (U2b, #2667: the witness in the devstack images with the per-row filter hook) and !2115 (marked Done). The ci-integration audit-wait flake found on the way is #2900.

Status

Done (2026-11-04) — the verified helper registry and pins (U1, #2666), the in-process witness (U2a, #2897) and the witness in the devstack images with the per-row filter hook (U2b, #2667) are merged. The ci-integration audit-wait flake found on the way is #2900.

Epic: &111 (gate integrity and tooling audit)
Issues: #2666 (U1), #2897 (U2a), #2667 (U2b); label Plan::AUTHZ-INTEGRITY
Branches: fix/authz-helper-registry, feat/authz-witness, feat/authz-witness-devstack

A Design + Scope plan: GitLab owns tracking; the plan freezes when U1 starts. The first program of the 2026-11-03 ruled order (#1654, lane 3).

Erratum (2026-11-03): a registry row’s kind also scopes its definitions — a fn row verifies the free fns of its name in defined_in, a method row the impl and trait-default methods — because the cases ledger core’s free retract shares ledgers/mod.rs with the non-authorizing RetractAct::retract constructor (decision 2).

Erratum (2026-11-03): craig-intake builds its own router, not the ApiServer stack, deliberately depends on no craig-api (the stateless edge, ADR-017) and has no engine-checked route — every handler is a declared exemption. The witness is not mounted there; the eight services that mount ApiServer carry it (decisions 5 and 6). A follow-up issue tracks mounting it if craig-intake ever gains an engine-checked route.

Erratum (2026-11-03): decision 6’s dev-dependency activation is dropped. The services' in-process harnesses build the bare api::routes(..) router, so the witness would test nothing there; a suite that builds the full ApiServer stack would mount the witness without the craig-bootstrap engine wrap, and every wired route would answer 500. The witness modules compile under cfg(any(test, feature)) and are unit-tested in craig-authz and craig-api; only the mount in build_protected_routes is feature-gated. U2b’s devstack run is the end-to-end proof.

Erratum (2026-11-03): a per-row filter (an unreadable row is omitted, never refused) over no rows reaches no engine entry point, so the witness read its empty 2xx as unwired — the U2b battery’s two findings, cases POST /v1/cases/batch-lookup and placement GET /v1/placement/children/{child_id}/episodes. Ruled: AuthzEngine::filtered_empty(candidates), a provided no-op that RecordingEngine counts as one decision only when candidates is 0; a filter calls it with the rows it would check. It takes a count, not a slice, so the trait stays dyn-compatible.

Erratum (2026-11-03): release_artifact_gate.rs needs no change for decision 7. It already reads any ${VAR:+--features "$VAR"} expansion on the build line and refuses a CI promote build that sets the variable.

Erratum (2026-11-03): U2b’s proof is a devstack test in craig-cases that asserts the authz-decisions count: 0 on an exempt route, the exact count on wired ones. It is not a handler copy run under the witness, because erratum 3 leaves no test build that mounts the witness, and dev-dependency activation would unify into every workspace test run. The refusal of an unwired 2xx stays pinned by craig-api’s unit tests (ruled 2026-11-03).

Context

cargo xtask validate-authz-coverage (xtask/src/cmd/validate_authz_coverage.rs, validate step [37]) walks every #[utoipa::path] handler under services/*/src and accepts it when its body calls .check( / .auto_scope_list( on an engine receiver (is_engine_receiver, line 847) or carries // authz: skip — <reason> above its attribute (classify, line 760). On main: 483 handlers, 270 engine-wired, 202 allowlisted.

Of the 202 skip comments, about 139 say the handler is wired through a helper: 66 name the generic ledger core (api::ledgers::{record,correct,retract,close,events,read,history}, services/craig-cases/src/api/ledgers/mod.rs:320–470), 32 name a placement *Path::authorize, 13 the craig-rules bootstrap helpers (rules_authz_or_admin_fallback, list_authz_gate_with_bootstrap, services/craig-rules/src/api.rs:88,118), and 27 other helpers (authorize_case_read, check_update_dual_state, check_lifecycle_authz, authz_list_or_forbid, resolve_batch_cases, authorize_item, ive_act::admit_act, readable_episodes, craig_api::jobs::get_job, craig_ledger::act::retract_with). The gate reads none of them. The chains run up to three deep through generics and trait dispatch — handler → record::<L> → L::Path::authorize (eight impls across cases and placement) → ctx.authz.check — so if record lost its path.authorize(…) call, 66 handlers would still pass. Two helpers reach the engine through check_typed / auto_scope_list_typed, which the gate does not list; three live outside services/ (crates/craig-api, crates/craig-ledger, crates/craig-authz). The remaining ~46 comments are true exemptions: service-only bearer gates (19), partner-key / JWS edges (9), public or unauthenticated endpoints (8), human-admin operator acts gated on claims alone (7), and three one-offs.

The gate’s pins live only in tests: xtask/authz-engine-wired.txt is read by a #[cfg(test)] census (line 1472) and the eight nil-id exceptions are a test const (RECORDED_NIL_ID_EXCEPTIONS, line 2912); the remediation text names a test function (line 385).

Static analysis has a floor: UFCS and turbofish calls, glob imports and generic cores stay invisible to syn (module doc, lines 24–26). Every handler reaches the engine through objects one function installs — craig_bootstrap::attach_standard_extensions (crates/craig-bootstrap/src/lib.rs:203) layers Extension(ctx.authz) and Extension(AuthzContext) (which holds its own clone) — and every service mounts the shared ApiServer stack (crates/craig-api/src/lib.rs:791, build_protected_routes), which already reads MatchedPath per request (http_observability.rs:109). So a wrapper installed once can count decisions per request. The runtime-coverage-matrix recorder (plan done 2026-10-26, !2004) is the per-request record the #2667 criteria mean: craig_test_lib::recording::HttpRecord (crates/craig-test-lib/src/recording.rs:88) already reads the Idempotent-Replayed response header into a field.

Scope

In scope:

  • A committed registry of authorizing helpers, each verified to reach the engine; the gate accepts a registered helper call as wiring; the ~139 helper-wiring skip comments are deleted (#2666).

  • The engine-wired pin and the nil-id exceptions enforced by the gate itself (validate and --bail-on-bypass), not only by nextest.

  • A test-only cargo feature authz-witness: a decision-counting engine wrapper, an ApiServer middleware that refuses a 2xx made with no decision on a non-exempt route, an authz-decisions response header, and the recorder field that reads it (#2667).

  • The exemption table the witness consults, generated from the handlers' skip comments and pinned by validate.

  • The devstack and e2e images built with the feature; every finding wired or exempted.

Out of scope:

  • The route_layer exemption marker #2667 names: see Design, decision 4.

  • Reporting authz_decisions in cargo xtask coverage-matrix output: a follow-up issue filed at U2a.

  • Scanning once instead of four times (#2298) and the gate’s other classes (#1898, #1902), which are unchanged.

  • Non-handler authorization (the BFFs craig-web and craig-portal, which hold no AuthzEngine).

Design

  1. One declaration per exemption, two consumers. The // authz: skip — <reason> comment on a handler stays the only exemption declaration. The static gate reads it as today; the runtime witness reads a table the gate generates from it. A router-level marker would be a second declaration in another file, and syn cannot attribute a route_layer to one route of a Router chain, so the static gate would have kept the comments anyway. Drift between the comments and the table fails validate.

  2. The registry is by name, verified at every definition. xtask/authz-helpers.toml rows: name (the fn or method ident as called), defined_in (one or more workspace-relative files), kind (fn | method), reason. A handler body that calls <name>( or <name>::<…>( (free fn, any path prefix, turbofish included: the ledger wrappers call super::record::<T>(…)) or .<name>( (method, any receiver) is wired via that helper; the matcher is a sibling of lint_tokens::calls_method_on (xtask/src/cmd/lint_tokens.rs:131) that reads path calls. For every row the gate finds every fn or impl-method definition named name in defined_in and requires each to reach: its body calls one of check, check_typed, auto_scope_list, auto_scope_list_typed on an engine receiver, or calls another registered helper; reach is the transitive closure with cycle detection (a cycle with no engine call does not reach). A row with no definition, a definition that does not reach, or a method row whose name is also defined in defined_in by a non-reaching impl fails the gate, naming the helper and every handler that wires through it. Name matching is coarse on purpose: for authorize, all eight impls must reach, so an unrelated non-reaching fn authorize in a listed file is a gate failure, not a hole.

  3. The four engine entry points are the terminals. ENGINE_CHECK / ENGINE_LIST become the set {check, check_typed, auto_scope_list, auto_scope_list_typed} (crates/craig-authz/src/engine.rs:68–122); the #1898 list-handler precondition keeps reading auto_scope_list and gains auto_scope_list_typed. The receiver rule (is_engine_receiver) is unchanged.

  4. The exemption table. crates/craig-api/authz-exempt-routes.txt: one line per allowlisted handler, <service> <METHOD> <path> — <reason>, service from the file path, method and path from the handler’s #[utoipa::path(<method>, path = "…")] (the OpenAPI registration gate, #2247, already requires that opening). The gate writes the table under --write-exempt-routes and otherwise compares and fails on drift. The witness parses it once (OnceLock) and keys on (service_name, method, MatchedPath); MatchedPath is the mounted pattern, which the registration gate holds equal to the annotated path. One route is declared elsewhere: POST /v1/admin/events/replay, mounted by ApiServer itself for every service (crates/craig-api/src/lib.rs:555, admin_replay::routes), whose handler is gated on claims alone (require_admin, admin_replay.rs:367) and lives outside the gate’s universe. Its exemption is a const beside the witness in craig-api (SHARED_EXEMPT_ROUTES), the one declaration for that route; #2577 (annotating it) may later move it onto the handler like the others.

  5. The witness. In crates/craig-authz, feature witness: tokio::task_local! { static DECISIONS: Cell<u32> } and pub struct RecordingEngine<E: AuthzEngine>(E) whose four entry points DECISIONS.try_with(|c| c.set(c.get() + 1)) then delegate (try_with, so a call outside a request scope — a warm-up task — counts nowhere). attach_standard_extensions wraps ctx.authz before building AuthzContext, so both extensions hold the wrapper. In crates/craig-api, feature authz-witness (enables craig-authz/witness, craig-bootstrap/authz-witness): a middleware added in build_protected_routes after the auth layer, mounted with from_fn_with_state(service_name, …) as http_metrics_middleware is (build_protected_routes gains the service_name: &'static str parameter from opts.service_name, lib.rs:394), which runs next inside DECISIONS.scope(Cell::new(0), …), stamps authz-decisions: <n> on every response, and, when the status is 2xx, n == 0 and (service, method, MatchedPath) is not in the table, replaces the response with the typed 500 authz-unwired (a new problem_types constant) and increments craig_authz_unwired_total{service,route}. Non-2xx responses pass through. A handler whose only engine call runs on a spawned task is invisible to the task-local and answers 500: fail-closed, and the remedy is the request task or an exemption.

  6. Feature classification. authz-witness is listed under [package.metadata.craig] test-only-features on craig-api, craig-bootstrap and each of the nine engine services (which define authz-witness = ["craig-api/authz-witness"] so the multi--p image build can name it); craig-authz lists witness. The existing release-artifact gate then forbids it in every release graph. In-process harnesses activate it the way they activate test-util: craig-api = { workspace = true, features = ["authz-witness"] } in each service’s [dev-dependencies].

  7. The devstack build. A Dockerfile build-arg CRAIG_DEVSTACK_FEATURES (empty default = the release graph), passed as --features on the cook and build lines like CRAIG_WEB_FEATURES; docker-compose.yml sets it to authz-witness for the devstack and e2e images; `xtask/src/docker.rs’s recipe key and `release_artifact_gate.rs’s build-line model learn the arg.

  8. The recorder. HttpRecord gains authz_decisions: Option<u32> read from the header (absent → None); RECORD_VERSION becomes 2.

Units — U1 → U2a → U2b

Weights: 1 trivial · 2 small · 3 medium · 5 large. One unit = one MR = one issue; every unit adds its CHANGELOG.adoc == Unreleased entry and updates quality-gates.adoc § authz coverage.

U1 (w5) — The verified helper registry; the pins move into the gate (closes #2666)

Files: xtask/authz-helpers.toml (new), xtask/authz-nil-id-exceptions.txt (new), xtask/authz-engine-wired.txt, xtask/src/cmd/validate_authz_coverage.rs, xtask/src/cmd/validate.rs, xtask/src/cmd/lint_tokens.rs, the ~139 handler files under services/*/src that lose a comment, docs/modules/ROOT/pages/quality-gates.adoc.

  1. Registry. Write authz-helpers.toml from the census above (about 20 rows). defined_in paths may point under crates/; the scan reads those files for definitions only (handlers stay a services/ universe; AUTHZ_FILES_FLOOR is unchanged).

  2. Gate. In classify: after the direct-call test, calls_registered_helper(tokens) marks the handler engine_wired with via: Option<String>; the report and --verbose output print the helper. A new verify_helpers(registry, files) → Result<HelperGraph> runs before classification; its failure lists helper, defined_in:line, and the handlers wired through it. ENGINE_METHODS replaces the two consts (decision 3).

  3. Pins into the gate. check_authz_coverage_gate (validate.rs:1197) and run --bail-on-bypass compare the wired set to authz-engine-wired.txt and the nil-id exceptions to authz-nil-id-exceptions.txt (lint_scan::recorded::{lines, drift}), failing on drift and naming each line; --write-pins rewrites both. The test census becomes a call to the same function. Every remediation text names a file, never a test.

  4. Comments. Delete each skip comment whose reason names a registered helper; keep the ~46 exemptions, each reason re-read and corrected where it no longer matches the code (a changed reason is a finding on the MR, not scope growth). Re-bless the wired pin (~270 → ~409).

  5. Tests (xtask, all unit tests over fixture trees unless named otherwise): a_registered_helper_that_stops_reaching_the_engine_fails_naming_its_callers (regression: a fixture where record loses path.authorize); a_turbofish_call_to_a_registered_helper_wires; a_cycle_of_helpers_with_no_engine_call_does_not_reach; a_method_row_requires_every_impl_to_reach; a_typed_engine_call_wires (check_typed); the_committed_registry_resolves_every_row_on_the_real_tree (contract, real tree); the_pins_are_enforced_by_the_gate_not_only_here (contract: the census calls the gate function); remediation_texts_name_a_pin_file_and_no_test (unit, over the bail strings). Red-proof on the MR: remove authz.check from CaseChildPath::authorize → the gate names authorize and its 66 callers.

U2a (w3) — The witness, in process

Files: crates/craig-authz/src/witness.rs (new), crates/craig-authz/Cargo.toml, crates/craig-bootstrap/src/lib.rs, crates/craig-bootstrap/Cargo.toml, crates/craig-api/src/authz_witness.rs (new), crates/craig-api/src/lib.rs, crates/craig-api/Cargo.toml, crates/craig-api/authz-exempt-routes.txt (new), crates/craig-common/src/error.rs (the problem type), crates/craig-common/src/metrics.rs, crates/craig-test-lib/src/recording.rs, services/*/Cargo.toml (nine), xtask/src/cmd/validate_authz_coverage.rs, xtask/src/cmd/validate.rs.

  1. Wrapper and task-local per decision 5; RecordingEngine forwards every other trait method untouched. attach_standard_extensions wraps under #[cfg(feature = "authz-witness")].

  2. Middleware per decision 5, mounted in build_protected_routes so health, metrics and the OpenAPI routes never meet it (pinned by a test below). The header is emitted on every response in witness builds, refusals included.

  3. Table. The gate gains the generator and drift check of decision 4; validate step [37] runs it. The witness’s parser refuses a malformed line at first use (a panic in a test build, never a silent empty table).

  4. Recorder per decision 8. Pre-1.0, no dual-version reading: RecordFile accepts version 2 only and refuses a v: 1 file naming the remedy (re-run the battery).

  5. Features per decision 6; dev-dependency activation in the nine services; release-artifact-gate passes unchanged because the new features are classified.

  6. Tests: craig-api, integration over ApiServer::router_inner with a stub engine: a_two_xx_with_no_decision_on_a_non_exempt_route_is_refused_as_authz_unwired, an_exempt_route_passes_with_zero_decisions, the_shared_admin_replay_route_is_exempt, a_non_two_xx_passes_through_uncounted, a_decision_made_through_the_authz_context_extension_counts, the_header_counts_every_decision_of_the_request (two checks → 2), health_and_openapi_routes_answer_without_the_header; concurrency: two_concurrent_requests_keep_separate_counts (one request that decides and one that does not, in flight together, each answered by its own count); unit: a_malformed_exempt_table_line_refuses_at_first_use. craig-authz, unit: a_call_outside_a_request_scope_counts_nowhere. craig-test-lib, unit: a_record_reads_authz_decisions_from_the_header, a_version_one_record_file_is_refused_naming_the_remedy; contract: the committed table parses. In-process service suites (the KeyedHarness rigs) run green with the feature on.

U2b (w3) — The witness in the devstack; findings closed (closes #2667)

Files: Dockerfile, docker-compose.yml, xtask/src/docker.rs, xtask/src/cmd/release_artifact_gate.rs, the handler files each finding touches, docs/modules/ROOT/pages/quality-gates.adoc, docs/modules/ROOT/pages/testing-reference.adoc, docs/modules/ROOT/pages/security.adoc.

  1. Build-arg per decision 7; cargo xtask dev start rebuilds with the feature; release-artifact-gate proves the release stage’s graph still excludes it.

  2. Run the battery and e2e with the witness on. Each authz-unwired refusal is a finding: the handler is wired (a real check), or exempted with a skip comment whose reason survives review (which regenerates the table). A routed handler with no #[utoipa::path] (the #2577 class) that answers 2xx with no decision must gain the annotation to be exemptable, or a check. A finding that needs a product ruling stops for the maintainer, as the doctrine says.

  3. Proof: a devstack test in craig-cases (regression) that mounts a copy of one ledger handler with its authorize leg removed under the witness and asserts the 500 authz-unwired; the battery and e2e green with the witness on; the craig_authz_unwired_total metric at zero across the run.

  4. Docs: quality-gates.adoc § authz coverage describes the registry, the table and the witness; testing-reference.adoc names the feature and the build-arg; security.adoc gains one paragraph on the two-stage verification.

Files Touched

File Change

xtask/authz-helpers.toml, xtask/authz-nil-id-exceptions.txt, xtask/authz-engine-wired.txt

The registry (new), the nil-id pin (new, from the test const), the wired pin re-blessed (U1)

xtask/src/cmd/validate_authz_coverage.rs, xtask/src/cmd/validate.rs, xtask/src/cmd/lint_tokens.rs

Helper verification, via, the four engine methods, pins and the exemption table enforced by the gate (U1, U2a)

services//src/* (about 139 handler attributes)

Helper-wiring skip comments deleted (U1); findings wired or exempted (U2b)

crates/craig-authz/src/witness.rs, Cargo.toml

RecordingEngine, the task-local, feature witness (U2a)

crates/craig-bootstrap/src/lib.rs, Cargo.toml

Wrap in attach_standard_extensions; feature authz-witness (U2a)

crates/craig-api/src/authz_witness.rs, src/lib.rs, authz-exempt-routes.txt, Cargo.toml

The middleware, the table and its parser, SHARED_EXEMPT_ROUTES, build_protected_routes(service_name), feature authz-witness test-only (U2a)

crates/craig-common/src/error.rs, src/metrics.rs

AUTHZ_UNWIRED problem type; craig_authz_unwired_total (U2a)

crates/craig-test-lib/src/recording.rs

HttpRecord.authz_decisions; RECORD_VERSION = 2 (U2a)

services/{cases,placement,exchange,financial,reporting,security,intake,composition,rules}/Cargo.toml

Feature authz-witness (test-only) and the dev-dependency activation (U2a)

Dockerfile, docker-compose.yml, xtask/src/docker.rs, xtask/src/cmd/release_artifact_gate.rs

CRAIG_DEVSTACK_FEATURES (U2b)

docs/modules/ROOT/pages/quality-gates.adoc, testing-reference.adoc, security.adoc, CHANGELOG.adoc

The gate’s page (every unit); the feature and build-arg; one security paragraph; release notes

Risks

  • A helper the registry names by a common ident (U1). authorize, record, close, events are ordinary names. A non-authorizing fn of that name in a defined_in file fails the gate: fail-closed. A call to an unrelated .close( in a handler would count as wiring: fail-open. Mitigation: defined_in bounds the definitions; the wired pin turns a handler newly "wired" by a stray call into drift that review sees; the MR records the stray-call count per registered name on the real tree (expected zero for the ledger verbs, which are called as super::record::<T>).

  • The witness finds live routes with no decision (U2b). Fail-closed by design: the battery stays red until each is wired or exempted, nothing is admitted silently. Mitigation: a finding needing a product ruling stalls U2b only; U1 and U2a stand alone.

  • MatchedPath and the utoipa path disagree (U2a/b). Fail-closed: a spelling difference reads as an unexempted route and answers 500, never as a silent exemption. Mitigation: the registration gate already requires the annotated path; U2b’s run proves equality for every exercised route.

  • Task-local scope and spawned work (U2a). Fail-closed: a check on a spawned task is uncounted and the route answers 500. Mitigation: the census found no handler that authorizes off the request task; U2b’s run is the proof, and the concurrency test pins that two in-flight requests never share a count.

  • Feature leakage into release (U2a/b). The failure would be silent: a release binary carrying the witness. Mitigation, twice: the test-only classification the existing release-artifact gate enforces on every release graph, and the empty default of the build-arg, which U2b proves against the release stage.

  • The shared admin-replay exemption (U2a). Declared in craig-api code, not on its handler: a second place to look, but one declaration for that route. Fail-closed if forgotten: the route would answer 500 in every devstack.

Verification

  1. Every unit passes the pre-push battery.

  2. U1: cargo xtask validate-authz-coverage --bail-on-bypass passes on main; with ctx.authz.check removed from CaseChildPath::authorize it fails naming authorize and its callers; with a pin line removed it fails naming the line; git grep -c 'authz: skip' services is about 46.

  3. U2a: cargo nextest run -p craig-api -p craig-authz -p craig-test-lib with the feature; cargo xtask release-artifact-gate passes and lists authz-witness among the declared test-only features; the table drift check fails when a skip comment is added without regenerating.

  4. U2b: docker image inspect of a devstack service shows the feature build-arg; cargo xtask validate and cargo xtask e2e green with the witness on; the proof test answers 500 authz-unwired; a release-stage build (docker build --target craig-cases .) has no authz-witness in its cargo build line.

Documentation Updates

  • quality-gates.adoc § authz coverage gate (U1, U2a, U2b)

  • testing-reference.adoc (U2b); security.adoc (U2b)

  • CHANGELOG.adoc == Unreleased, every unit

Review log

Round Vendor Resolved model Verdict

1 (cold read)

Anthropic

vertex-anthropic/claude-fable-5-1

FLAGS (2): P1 risk bullets lacked a fail-open / fail-closed / silent class, and no concurrency test for the task-local; P2 cited files unsupplied, build_protected_routes has no service name, the shared admin-replay route had no exemption path. All fixed before approval.

2 (second vendor)

Google

vertex-gemini/gemini-4-argon

FLAGS (2): P1 risk classes and test categories; P2 the ledger read / history verbs, turbofish helper calls, the service name, and three unpinned "never" claims. All fixed before approval. Approved by the maintainer 2026-11-03.

Edit this page · latest