Skip to content

Production hardening: audit remediation phases 1–3 - #46

Merged
blakebauman merged 3 commits into
mainfrom
hardening/audit-remediation
Aug 12, 2026
Merged

blakebauman merged 3 commits into
mainfrom
hardening/audit-remediation

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Remediates the high- and medium-severity findings from the 2026-08-11 production-hardening audit (three parallel review lanes: security model, runtime robustness, deploy & supply chain), in three commits:

Phase 1 — survive panics, expire idle sessions, bound the listener (65d4981)

  • Panic recovery at every site where one panic ended the process: the middleware dispatch path (routeSafe mints a generic -32603 and still exits through audit — the single-exit-door rule holds), fan-out/health workers (degrade to partial failure), background loops (resume after a recovered tick), reload/telemetry goroutines, SDK-invoked bridge/notification handlers, and the audit delivery worker (via audit.WithPanicHook so its recoveries alert like the rest). Counted in fold_panics_total{site}; FoldPanicRecovered alert ships in both rule files.
  • server.sessionIdleTimeoutMs (default 30 min, construction-wired): abandoned downstream sessions no longer pin gateway state and upstream subscriptions forever, and reapSubscribers actually releases what they held.
  • Listener bounds: IdleTimeout 120s + explicit MaxHeaderBytes; embedding docs note the embedder's responsibility (and warn off WriteTimeout, which would sever SSE).
  • Session observability: fold_downstream_sessions / fold_upstream_bridged_sessions gauges + dashboard panel.

Phase 2 — supply chain (c5a70be)

  • The three release images and the Helm chart now carry BuildKit provenance + SBOM in-registry and a sigstore attestation per digest (gh attestation verify oci://… documented in docs/deploy.md). Images were the one deployment artifact without supply-chain evidence.
  • Every workflow uses: SHA-pinned with version comments (Dependabot maintains the pins); golangci-lint pinned; base images digest-pinned with a new Docker Dependabot ecosystem; release-workflow default permissions dropped to contents: read.
  • (Applied outside this PR: branch protection now requires all seven CI checks.)

Phase 3 — audit-trail and config-contract integrity (ba6d62a)

  • /oauth/token joins the audit trail: every terminal response — mint, invalid assertion, rate-limited 429, and detected ID-JAG replay — emits one event under method="oauth/token", with the exchange outcome verbatim in the decision field so replays are alertable structurally.
  • Minted -32041 messages redacted (raw transport errors named internal endpoints and secret env-var names); details stay on gateway log lines.
  • timeouts.streamIdleMs implemented as opt-in — it was schema-validated and documented but read nowhere. Not defaulted on: the SDK client's reconnect budget only replenishes when events arrive, so a default idle cut against a legitimately quiet upstream would eventually kill its session (security-auditor finding on the first cut of this fix). defaults.md corrects the never-true "120 s" claim.
  • Failover walk capped at 3 candidates per connect attempt; negative durations rejected (aligning Validate with the schema's minimum: 0); poll intervals floored at 1s; MemOnce bounded at 100k on internal/bounded.

Verification

  • make check green at each phase (gofmt, tidy, vet, build, go test -race, golangci-lint 0 issues)
  • Added-latency bench gate passes with headroom (added p50 ~171 µs vs 5 ms gate) — the recover wrapper on the hot path is open-coded by the compiler
  • 14 new tests, including: a full-middleware test proving a panicking handler yields exactly one audit event and a generic wire error; real-SDK-client session expiry; EMA exchange/replay audit records; redaction; failover bounding
  • Reviewed by the gateway-reviewer and security-auditor agents; all findings addressed (two review findings materially changed the implementation: the audit-worker panic hook, and streamIdle shipping opt-in)

🤖 Generated with Claude Code

blakebauman and others added 3 commits August 11, 2026 17:57
Phase 1 of the production-hardening audit (2026-08-11):

- Panic recovery at every site where one panic ended the process: the
  middleware dispatch path (routeSafe mints a generic -32603 and still
  exits through audit), fan-out/health workers, background loops (which
  resume after a recovered tick), reload/telemetry goroutines,
  SDK-invoked bridge/notification handlers, and the audit delivery
  worker (via audit.WithPanicHook so its recoveries alert like the
  rest). Counted in fold_panics_total{site}; FoldPanicRecovered alert
  in both rule files.
- server.sessionIdleTimeoutMs (default 30 min): downstream sessions
  expire when idle, so abandoned clients no longer pin gateway state
  and upstream subscriptions forever. Construction-wired.
- Public listener: IdleTimeout 120s + explicit MaxHeaderBytes;
  embedding docs note the embedder's responsibility.
- fold_downstream_sessions / fold_upstream_bridged_sessions gauges and
  a Sessions dashboard panel, so session population is watchable.

Gate: make check green, bench added p50 171µs (< 5ms gate).

Co-Authored-By: Claude Fable 5 <[email protected]>
Phase 2 of the production-hardening audit (2026-08-11):

- Release images (fold, fold-discovery, fold-stdio) now ship BuildKit
  provenance + SBOM in-registry and a sigstore attestation on each
  digest; the Helm chart's OCI artifact is attested the same way. The
  images were the one deployment artifact without supply-chain
  evidence — binaries already had it.
- Every workflow `uses:` is pinned to a full commit SHA (a moved tag
  on a dependency action is code execution inside jobs holding
  release-signing permissions); golangci-lint binary pinned to
  v2.12.2. Dependabot maintains the SHA pins.
- Base images pinned by digest in deploy/docker; a new Dependabot
  docker ecosystem keeps the digests moving.
- Release workflow default permissions dropped to contents: read;
  each job declares exactly what it needs.
- docs/deploy.md: "Verifying what you deploy" — gh attestation verify
  for images, chart, and binaries.

Co-Authored-By: Claude Fable 5 <[email protected]>
…edges

Phase 3 of the production-hardening audit (2026-08-11):

- /oauth/token now obeys the single-exit-door rule: every terminal
  response (mint, invalid assertion, rate-limited 429, and above all a
  detected ID-JAG replay) emits one audit event under
  method="oauth/token", with the exchange outcome verbatim in the
  decision field so a replay is alertable structurally. Wired via
  auth.EMA.OnExchange so auth stays decoupled from audit.
- Fold-minted -32041 messages are generic ("details in gateway logs"):
  raw transport errors name internal endpoints and can name secret
  env vars — the same strings /health already redacts. Details stay on
  the gateway's warn lines.
- timeouts.streamIdleMs is implemented (it was schema-validated and
  documented but read nowhere): opt-in idle bound on the standalone
  upstream SSE stream, cutting a wedged stream so the SDK client
  retries it. Deliberately not defaulted on — the client's reconnect
  budget only replenishes when events arrive, so a default cut against
  a legitimately quiet upstream would eventually kill its session.
  defaults.md corrects the never-true "120 s" claim.
- One connect attempt walks at most 3 endpoint candidates instead of
  every replica (K x connectTimeout per caller while all are down).
- Negative timeout/breaker values are rejected (the schema always said
  minimum 0); static health-probe and discovery poll intervals are
  clamped to the same floors the discovery path already enforced.
- MemOnce (jti single-use records) moved onto internal/bounded (100k
  cap), closing the one identifier-keyed store that was unbounded and
  removing an O(n) scan per exchange.

Reviewed by the security-auditor agent; its streamIdle-default finding
(SDK no-progress retry budget) is why the knob ships opt-in.

Gate: make check green, bench added p50 within gate.

Co-Authored-By: Claude Fable 5 <[email protected]>
@blakebauman
blakebauman merged commit cd87e7e into main Aug 12, 2026
7 checks passed
@blakebauman
blakebauman deleted the hardening/audit-remediation branch August 13, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant