Skip to content

fix(mcp): require a per-daemon token for STOP and REPORT_HYPERD_ERROR - #387

Open
StefanSteiner wants to merge 1 commit into
tableau:mainfrom
StefanSteiner:fix/daemon-control-token
Open

StefanSteiner wants to merge 1 commit into
tableau:mainfrom
StefanSteiner:fix/daemon-control-token

Conversation

@StefanSteiner

Copy link
Copy Markdown
Contributor

Summary

Phase S, task S.1 of the hyperdb-daemon extraction design (#385): the daemon's state-changing health commands now require a per-daemon control token, and the daemon record carries a protocol version.

  • Control token. Each daemon start generates 32 random bytes (OS RNG) and publishes them hex-encoded as control_token in the owner-only daemon.json. Clients send STOP <token> and REPORT_HYPERD_ERROR <token>; a missing or wrong token gets ERR unauthorized and changes nothing, so a rejected report cannot trip the restart limiter. PING, HEARTBEAT and STATUS are unchanged.
  • Token handling. ControlToken is a newtype with a redacted Debug and a constant-time matches. It never appears in STATUS, doctor output or logs. A client uses the token only if the record's endpoint matches the daemon it is talking to.
  • Protocol version. daemon.json and STATUS gain protocol_version (1; absent means 0). PING is unchanged in this phase.
  • Takeover. If a running daemon refuses STOP, version takeover fails at once with PermissionDenied instead of waiting out the stop timeout, and never spawns a second daemon. hyperdb-mcp daemon stop distinguishes "no token found" from "token rejected".

Compatibility

Upgrade every hyperdb-mcp client together. A newer client talking to an older daemon (no token in the record) sends the bare command as before. An older client talking to a newer daemon gets ERR unauthorized on STOP and REPORT_HYPERD_ERROR: it cannot stop or take over the daemon, and loses the fast restart path (the daemon's 5 s liveness poll still applies). Details in hyperdb-mcp/CHANGELOG.md.

Test plan

  • cargo fmt --check; cargo clippy --workspace --all-targets --all-features -- -D warnings
  • Windows-target clippy (x86_64-pc-windows-msvc, -p hyperdb-mcp --all-targets --all-features -D warnings): exit 0
  • cargo test -p hyperdb-mcp (absolute HYPERD_PATH, pinned hyperd 0.0.26479): 37 suites, 805 passed, 0 failed, 20 ignored
  • Full workspace cargo test before the review fix round: 2045 passed, 0 failed
  • New tests: token round trip and redaction, unauthorized STOP / REPORT_HYPERD_ERROR leave state unchanged, endpoint-mismatch token ignored, takeover fails fast on a refused STOP

Each daemon start generates a random control token and publishes it in
the owner-only daemon.json. STOP and REPORT_HYPERD_ERROR must carry it;
otherwise the daemon answers ERR unauthorized and changes nothing. PING,
HEARTBEAT and STATUS stay open, and the token never appears in STATUS,
doctor output or logs. daemon.json and STATUS gain protocol_version (1).
A takeover refused by a token-checking daemon fails at once with
PermissionDenied. Phase S.1 of the hyperdb-daemon extraction design.
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