← Back to Pull requests

feat: production mode with one APP_ENV switch #212

Closed
unknown closed this pull request without merging on Nov 11, 2026 09:24 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 10:50 UTC
Author

What and why

Closes #42 (P18): production mode. Previously nothing defined a production
build, and dev-only paths (in-memory vault, HS256, unattested or simulated
execution, demo tenant, fixture sources, local-vault frontend) shipped in
release binaries, selected by env vars or a stray .env. ADR 0009 records
the mechanism.

  • Switch: APP_ENV. Only development selects development; unset,

  • blank or unknown means production. It is read from the process env
    before .env, which is loaded only in development
    (PlatformConfig::load, with the env and loader injected for tests).
  • Gate: PlatformConfig::check_production(service), wrapped by

  • enforce_production, which emits one service.start "denied" audit
    event so both services refuse identically. It runs first in
    platform_api::wiring::build_state and the new
    platform_connectors::startup::build. It is not in from_source, so
    tests can build any config. Production refuses to start when:
    - JWT_HS256_SECRET is set
    - STORAGE_BUCKET is unset
    - TEE_ATTESTATION_REQUIRED=false
    - SIM_ATTESTATION_URL or KEY_RELEASE_URL is set
    - connector-worker only: the demo tenant is set, or jobs are fixtures
    (always, for now)

    All reasons are listed at once, by key name only.

  • Build: devtoken requires the dev feature.

  • PlatformConfig::from_env_dev_tool (used by devstack and devtoken)
    sits behind a new platform-config/dev feature, so release builds can't
    reach it. check.sh also clippies the release binaries without dev.
  • Frontend: npm run build:release fails unless VITE_VAULT_MODE=http,

  • and fails if VITE_DEV_JWT or VITE_ADMIN_JWT is set. release.yml
    runs it before packaging frontend/dist.
  • CI: the build-layer steps of release build has no dev binaries run

  • with APP_ENV=development, so they still test what a non-dev build
    refuses on its own. A new step checks the production-mode refusal.
  • Docs: ADR 0009; a "Production mode" section in ARCHITECTURE.md;

  • PROJECT_SCOPE.md definition-of-done item 3; threat model A2 row and a
    new residual risk; README run commands; CHANGELOG.md; .env.example
    and docker-compose.simulated-tee.yml opt into development.

    Production mode cannot boot yet (expected by the issue) until P28, P51,
    P62, P63 and P67 land. Local runs, CI and the simulated TEE use
    APP_ENV=development:

    export APP_ENV=development
    cargo run -p platform-api
    cargo run -p platform-api --features dev --bin devtoken

    Residual risk: APP_ENV is operator-set, and the in-memory vault,
    HS256 verifier and demo seed are still compiled into release binaries, so
    APP_ENV=development on a production host re-enables them. The simulator
    and key-release stand-in stay dev-only. This is recorded in the threat
    model and in ADR 0009's Consequences.

    Maintainer decisions (ADR marked Proposed until confirmed):

  • Runtime switch vs. Cargo feature: I chose the runtime switch and kept the

  • existing dev feature as the compile-time layer.
  • FEATURE_ZK_ENABLED=false is not refused in production.
  • How it was tested

  • platform-config unit tests: each refusal through from_source; unknown

  • APP_ENV is production; development accepts dev paths; all reasons are
    reported together; refusal text never contains values.
  • .env loading, through PlatformConfig::load with a stand-in loader:

  • - dotenv_is_not_loaded_in_production: unset, production and
    staging never load .env, even when it says APP_ENV=development.
    I checked that it fails if the load is made unconditional.
    - dotenv_is_loaded_in_development_and_read_after
  • platform-api/tests/startup.rs (via wiring::build_state): each refusal;

  • an unknown APP_ENV refuses; development boots with dev paths.
  • platform-connectors/tests/startup.rs: fixture sources, demo tenant and

  • dev settings refused, with an audit event; development builds the
    fixture jobs.
  • platform-api/tests/audit_coverage.rs: a refusal emits service.start

  • "denied", no "ok", and never the secret value.
  • platform-api/tests/research_wiring.rs (from P43) now sets

  • APP_ENV=development, because its HS256 secret and in-memory vault are
    development paths.
  • CI release build has no dev binaries:

  • - New step: both release binaries, with no APP_ENV, exit with the
    production-mode error and a service.start "denied" event.
    - The attestation and KEY_RELEASE_URL steps still check the build-level
    refusals.
  • frontend/src/config/release.test.ts: unset, local or unknown vault

  • mode refused; dev tokens refused without echoing values. Manually checked
    that vite build --mode release aborts on each case.

    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
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: abendrothj Review duration: 1353m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #212"
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 20.5% · Safe to merge
    20.5%