← Back to Pull requests

feat(research): seal research results to the enrolled key and sign them #289

Closed
unknown closed this pull request without merging on Nov 26, 2026 05:35 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 22:50 UTC
Author

What and why

Part of #177 (P55), following the split agreed with #176 on #177: this PR provides what #176's sealed handler (#275) calls once a query has run. Nothing routes to it yet; #275 wires it in.

  • ConnectorQueryService::verify_recipient accepts a sealed request's recipient_key only if it equals, by suite and bytes, the key enrolled for the researcher (ADR 0010 "Recipient key"): 400 for a malformed key, 403 with no enrolled key or a different one, 502 for an unreadable enrollment record. Each refusal is audited once as auth.decision with the key's fingerprint (SHA-256("recipient-key-v1" ‖ suite ‖ key)), never the key. It calls sealed::verify_recipient(dev_build, vault, …), which runs the release-build gate, reads the enrollment record and compares the key in one call; the gate and the compare are private to sealed, so nothing in the crate can supply the enrolled key or skip the gate, and only this path builds a VerifiedRecipient.

  • ConnectorQueryService::seal_research_result seals the whole result (counts and budget_remaining included) to that key under research_result(tid, research_query_binding(grant_id, request_nonce, sql, schema_version)), in the key's suite. It signs the frame with the key set's result-signing key and returns ADR 0010's SealedQueryResponse, with the signature as SignatureWire. The payload is serialized by to_json_zeroizing into an exactly sized Zeroizing buffer, so no outgrown copy is freed unwiped, and wiped after sealing. #275's to_vec of the stored response can use the same helper.

  • A release build refuses sealed research queries with 503 until create-once enrollment (#175, P33), because the enrolled key a result is sealed to can still be overwritten through the API. The gate runs inside verify_recipient, so #275's handler gets it by calling the recipient check.

  • enrolled_key moves into lib.rs, shared by the upload path's suite check and the recipient check.

  • README and THREAT_MODEL.md describe the seal, the signature and the recipient check as built but not routed. THREAT_MODEL.md records that sealed results depend on create-once enrollment (P33) and TLS inside the VM (P67), and that release builds answer 503 until P33.
  • #275 also changes sealed.rs and query.rs and merges first; this PR then rebases onto it, renames one of the two sealed_research_app test helpers, and keeps one recipient_key 400 check. Wiring these calls into the handler, and the "Retries" item in #177's done-when, land after both.

    How it was tested

  • sealed.rs unit tests:

  • - a sealed result opens only with the intended key;
    - a flipped byte anywhere in the frame is refused;
    - a result signed by any other key set, or with a signature that does not decode, is refused;
    - a result replayed against another request nonce, SQL text, grant or schema version is refused;
    - the result info carries the role label and the researcher;
    - the recipient fingerprint layout is pinned;
    - only the enrolled key is a recipient, and a malformed key is a 400;
    - a release build gets 503 even for the enrolled key, and a dev build accepts the same request;
    - verify_recipient reads the enrolled key itself: another key is a 403, no record a 403, an unparseable record a 502;
    - results serialize into a buffer whose capacity equals its length;
    - Debug prints neither the bound SQL nor the recipient key.
  • tests/sealed_result_api.rs:

  • - a research result run through the query service is sealed to the enrolled key and signed, verifies against the key set from the evidence bundle, carries no result value in the clear, and does not open against a replayed request;
    - a recipient key substituted in the enrollment record is refused.
  • audit_coverage.rs: each recipient refusal, including the release-build 503, is audited exactly once (count_outcome), with fingerprints only.

  • scripts/check.sh passes locally.
  • Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made (n/a: implements ADR 0010)
  • Diff: 563 lines (+422 / -141) across 7 files Reviewer: abendrothj Review duration: 4724m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.55) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 563 lines diff across 7 files
    0.55
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.379
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #289"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 54.7% (MEDIUM) · Higher = larger blast radius
    54.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.6% · Safe to merge
    21.6%