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, anApiServermiddleware that refuses a 2xx made with no decision on a non-exempt route, anauthz-decisionsresponse 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_layerexemption marker #2667 names: see Design, decision 4. -
Reporting
authz_decisionsincargo xtask coverage-matrixoutput: 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
-
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 aroute_layerto one route of aRouterchain, so the static gate would have kept the comments anyway. Drift between the comments and the table fails validate. -
The registry is by name, verified at every definition.
xtask/authz-helpers.tomlrows: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 callsuper::record::<T>(…)) or.<name>((method, any receiver) is wired via that helper; the matcher is a sibling oflint_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 namednameindefined_inand requires each to reach: its body calls one ofcheck,check_typed,auto_scope_list,auto_scope_list_typedon 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 amethodrow whose name is also defined indefined_inby a non-reaching impl fails the gate, naming the helper and every handler that wires through it. Name matching is coarse on purpose: forauthorize, all eight impls must reach, so an unrelated non-reachingfn authorizein a listed file is a gate failure, not a hole. -
The four engine entry points are the terminals.
ENGINE_CHECK/ENGINE_LISTbecome 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 readingauto_scope_listand gainsauto_scope_list_typed. The receiver rule (is_engine_receiver) is unchanged. -
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-routesand otherwise compares and fails on drift. The witness parses it once (OnceLock) and keys on(service_name, method, MatchedPath);MatchedPathis the mounted pattern, which the registration gate holds equal to the annotated path. One route is declared elsewhere:POST /v1/admin/events/replay, mounted byApiServeritself 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. -
The witness. In
crates/craig-authz, featurewitness:tokio::task_local! { static DECISIONS: Cell<u32> }andpub struct RecordingEngine<E: AuthzEngine>(E)whose four entry pointsDECISIONS.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_extensionswrapsctx.authzbefore buildingAuthzContext, so both extensions hold the wrapper. Incrates/craig-api, featureauthz-witness(enablescraig-authz/witness,craig-bootstrap/authz-witness): a middleware added inbuild_protected_routesafter the auth layer, mounted withfrom_fn_with_state(service_name, …)ashttp_metrics_middlewareis (build_protected_routesgains theservice_name: &'static strparameter fromopts.service_name,lib.rs:394), which runsnextinsideDECISIONS.scope(Cell::new(0), …), stampsauthz-decisions: <n>on every response, and, when the status is 2xx,n == 0and(service, method, MatchedPath)is not in the table, replaces the response with the typed 500authz-unwired(a newproblem_typesconstant) and incrementscraig_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. -
Feature classification.
authz-witnessis listed under[package.metadata.craig] test-only-featureson craig-api, craig-bootstrap and each of the nine engine services (which defineauthz-witness = ["craig-api/authz-witness"]so the multi--pimage build can name it); craig-authz listswitness. The existing release-artifact gate then forbids it in every release graph. In-process harnesses activate it the way they activatetest-util:craig-api = { workspace = true, features = ["authz-witness"] }in each service’s[dev-dependencies]. -
The devstack build. A Dockerfile build-arg
CRAIG_DEVSTACK_FEATURES(empty default = the release graph), passed as--featureson the cook and build lines likeCRAIG_WEB_FEATURES;docker-compose.ymlsets it toauthz-witnessfor the devstack and e2e images; `xtask/src/docker.rs’s recipe key and `release_artifact_gate.rs’s build-line model learn the arg. -
The recorder.
HttpRecordgainsauthz_decisions: Option<u32>read from the header (absent →None);RECORD_VERSIONbecomes 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.
-
Registry. Write
authz-helpers.tomlfrom the census above (about 20 rows).defined_inpaths may point undercrates/; the scan reads those files for definitions only (handlers stay aservices/universe;AUTHZ_FILES_FLOORis unchanged). -
Gate. In
classify: after the direct-call test,calls_registered_helper(tokens)marks the handlerengine_wiredwithvia: Option<String>; the report and--verboseoutput print the helper. A newverify_helpers(registry, files) → Result<HelperGraph>runs before classification; its failure listshelper,defined_in:line, and the handlers wired through it.ENGINE_METHODSreplaces the two consts (decision 3). -
Pins into the gate.
check_authz_coverage_gate(validate.rs:1197) andrun --bail-on-bypasscompare the wired set toauthz-engine-wired.txtand the nil-id exceptions toauthz-nil-id-exceptions.txt(lint_scan::recorded::{lines, drift}), failing on drift and naming each line;--write-pinsrewrites both. The test census becomes a call to the same function. Every remediation text names a file, never a test. -
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).
-
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 whererecordlosespath.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: removeauthz.checkfromCaseChildPath::authorize→ the gate namesauthorizeand 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.
-
Wrapper and task-local per decision 5;
RecordingEngineforwards every other trait method untouched.attach_standard_extensionswraps under#[cfg(feature = "authz-witness")]. -
Middleware per decision 5, mounted in
build_protected_routesso 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. -
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).
-
Recorder per decision 8. Pre-1.0, no dual-version reading:
RecordFileaccepts version 2 only and refuses av: 1file naming the remedy (re-run the battery). -
Features per decision 6; dev-dependency activation in the nine services;
release-artifact-gatepasses unchanged because the new features are classified. -
Tests: craig-api, integration over
ApiServer::router_innerwith 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 (theKeyedHarnessrigs) 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.
-
Build-arg per decision 7;
cargo xtask dev startrebuilds with the feature;release-artifact-gateproves the release stage’s graph still excludes it. -
Run the battery and e2e with the witness on. Each
authz-unwiredrefusal 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. -
Proof: a devstack test in craig-cases (regression) that mounts a copy of one ledger handler with its
authorizeleg removed under the witness and asserts the 500authz-unwired; the battery and e2e green with the witness on; thecraig_authz_unwired_totalmetric at zero across the run. -
Docs:
quality-gates.adoc§ authz coverage describes the registry, the table and the witness;testing-reference.adocnames the feature and the build-arg;security.adocgains one paragraph on the two-stage verification.
Files Touched
| File | Change |
|---|---|
|
The registry (new), the nil-id pin (new, from the test const), the wired pin re-blessed (U1) |
|
Helper verification, |
|
Helper-wiring skip comments deleted (U1); findings wired or exempted (U2b) |
|
|
|
Wrap in |
|
The middleware, the table and its parser, |
|
|
|
|
|
Feature |
|
|
|
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,eventsare ordinary names. A non-authorizing fn of that name in adefined_infile fails the gate: fail-closed. A call to an unrelated.close(in a handler would count as wiring: fail-open. Mitigation:defined_inbounds 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 assuper::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.
-
MatchedPathand 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
-
Every unit passes the pre-push battery.
-
U1:
cargo xtask validate-authz-coverage --bail-on-bypasspasses onmain; withctx.authz.checkremoved fromCaseChildPath::authorizeit fails namingauthorizeand its callers; with a pin line removed it fails naming the line;git grep -c 'authz: skip' servicesis about 46. -
U2a:
cargo nextest run -p craig-api -p craig-authz -p craig-test-libwith the feature;cargo xtask release-artifact-gatepasses and listsauthz-witnessamong the declared test-only features; the table drift check fails when a skip comment is added without regenerating. -
U2b:
docker image inspectof a devstack service shows the feature build-arg;cargo xtask validateandcargo xtask e2egreen with the witness on; the proof test answers 500authz-unwired; a release-stage build (docker build --target craig-cases .) has noauthz-witnessin itscargo buildline.
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, |
2 (second vendor) |
vertex-gemini/gemini-4-argon |
FLAGS (2): P1 risk classes and test categories; P2 the ledger |