Skip to content

fix(coordinator): fail closed on capabilities and internal auth, check host ownership - #1850

Merged
nikhilunni merged 7 commits into
mainfrom
audit/p0-coordinator-security
Dec 3, 2026
Merged

nikhilunni merged 7 commits into
mainfrom
audit/p0-coordinator-security

Conversation

@nikhilunni

@nikhilunni nikhilunni commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hardens engram-coordinator authentication, credential minting, host-session ownership, and eviction error propagation:

  • Fail-closed capability lookup: Propagates metadata-store errors from get_session_capabilities in api/forge.rs and session_boot.rs instead of falling back to unscoped provider defaults.
  • Host ownership on host_http::refresh_inject: Verifies the session exists and is bound to the requesting host_id (403), then that it is non-terminal (409), before minting credentials. The ownership check comes first, so a host cannot learn the state of a session it does not run.
  • Internal HTTP auth & deduplication: Filters empty tokens in AuthState::new, fails closed when ENGRAM_AUTH_TOKENS is empty unless ENGRAM_ALLOW_INSECURE_INTERNAL_AUTH=1 (local dev; the Tiltfile sets it), and consolidates constant-time comparison and Bearer extraction into crates/engram-coordinator/src/auth.rs. The parser follows RFC 6750 section 2.1 and RFC 9110 section 11.1: the scheme is case-insensitive, one or more spaces are allowed, and the token is exact with no whitespace. The router logs an error at startup when no token is set (or a warning when the insecure bypass is on).
  • Eviction-cancel error propagation: Propagates Postgres errors from op_cancel_queued in api/snapshot.rs instead of swallowing them with .unwrap_or(false). All callers map the error to an op Retry.
  • Simulator: engram-dst configures its coordinator replica with SIM_HTTP_TOKEN, so the bearer middleware runs and accepts the simulator's requests.

Upgrade note

A deployment that runs the coordinator with no ENGRAM_AUTH_TOKENS (Helm auth.existingSecret: "") now refuses every host request. The changelog carries the upgrade note. The shipped Terraform quickstarts and the e2e stack (Tilt) already set the token or the dev bypass.

Merge order

#1857 also changes api/mod.rs (the AuthState::new line and its comment) and adds a grpc_app test that calls the internal HTTP router without a bearer. Whichever PR lands second must resolve the api/mod.rs conflict and give that test a token (or allow_insecure_internal_auth: true).

Validation

  • cargo fmt --check
  • cargo clippy -p engram-coordinator -p engram-dst --all-targets -- -D warnings
  • cargo nextest run -p engram-coordinator (non-live-PG): 545 passed
  • cargo nextest run -p engram-dst: 58 passed
  • site: leak lint

🤖 Generated with Claude Code

nikhilunni and others added 7 commits December 2, 2026 13:57
The simulator sends SIM_HTTP_TOKEN on every internal HTTP request, but the
replica used CoordinatorConfig::default(), which has no tokens. With the
internal routes now fail closed, every harness-event and admin call got 401,
and the simulation and dst tests failed. Configure the replica with the
token so the bearer middleware runs and accepts it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… refresh

A host that does not run the session now gets 403 before any 409, so it
cannot learn whether another host's session is terminal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RFC 9110 section 11.1 makes the auth scheme case-insensitive, and RFC 6750
section 2.1 allows one or more spaces before the token. The shared parser
now accepts "bearer" and "BEARER" and extra spaces. The token itself stays
exact: no whitespace in it, compared byte for byte.

The constant-time compare now passes the accumulator through
std::hint::black_box, so the optimizer cannot turn the loop into an early
exit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With no ENGRAM_AUTH_TOKENS, the router logs an error (every internal
request is refused) or, with ENGRAM_ALLOW_INSECURE_INTERNAL_AUTH=1, a
warning (internal routes are open). An operator whose hosts get 401 after
the upgrade sees the cause in the coordinator log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omment

The comment pointed at token-list filtering in main.rs that this branch
moved into the auth constructors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add an upgrade note to the changelog and state the empty-value behavior
in the deploy guide and the configuration reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nikhilunni
nikhilunni force-pushed the audit/p0-coordinator-security branch from c50f3d9 to 9895169 Compare December 2, 2026 21:57
@nikhilunni
nikhilunni marked this pull request as ready for review December 3, 2026 17:06
@nikhilunni
nikhilunni merged commit 79c3e0e into main Dec 3, 2026
29 checks passed
@nikhilunni
nikhilunni deleted the audit/p0-coordinator-security branch December 3, 2026 17:07
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