Repository navigation
✨ hub: route hive-mx mail to hives with the relay key (Betty C2 part 3) - #18429
Conversation
GET /api/mail/hosts lists every hosted hive's subdomain, vanity and reported dashboard host (a host two hives claim is left out). POST /api/mail/inbound reads only id, kind and recipient of a hive-mx delivery, maps the recipient host to its SaaSHive, signs the unchanged body with that hive's relay key (signWebhookRelayHeaders, delivery id in X-Hive-Relay-Delivery) and forwards it to /api/meetings/invites, /api/inbox/email or /api/meetings/calendar-emails/proof behind the webhook relay's private-address guard and a no-redirect client. It stores nothing and logs the delivery id only; status codes tell hive-mx whether the sender should retry. Both endpoints need HIVE_HUB_MAIL_TOKEN and 404 without it. The three spoke paths pass the hosted auth-check (isSaaSPublicPath). The spoke's relay verification accepts X-Hive-Relay-Delivery for non-GitHub relays with the same skew and replay rules, replay ids namespaced per kind, and verifyRelayedRequest for the mail endpoints. Part of #18391, #18395. Signed-off-by: Andy Anderson <andy@clubanderson.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether a spoke-reported dashboard URL host may be used to route inbound mail to that hive.
This adds a new public-facing hub ingest path (POST /api/mail/inbound, bearer HIVE_HUB_MAIL_TOKEN) that signs bodies with a hive's relay key, and widens isSaaSPublicPath. That is a credentials and external-input surface, so it goes to a person. I found no concrete bug.
What I read: the token check is constant-time and fails to 404 when unset (mail_relay.go, mailAuthorized); redirects are disabled; the spoke-side change only namespaces replay keys (github:/relay:) and requires X-Hive-Relay-Delivery in verifyRelayedRequest, with the same MAC, skew and replay checks.
Open question, not verified as a defect: mailHostMap also maps hostOf(dashboards[h.ID]), and that URL is reported by the spoke through the registry. A host claimed by two hives is dropped from the map. So a spoke that reports another hive's host would remove that hive's mail routing, or one reporting an unclaimed host would receive mail for it. Please confirm that registry DashboardURL is validated against the hive's own domain before it is trusted here (the same concern as #14813).
— hive: agent=reviewer-2 backend=claude model=claude-sonnet-5-5 claude=2.1.325
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. @clubanderson this PR is held at Why:
Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path. Evidence bundle `#184291aed879` sha256:cbcc384378413245c31c3ab9a9a78862a6bfd3c43964b21fe2d688a3984565d1 — download from the dashboard or `hivectl review evidence #18429`. |
Mutation testing✅ Resolved: no surviving or uncovered mutants in changed files on the current head. Verdict: |
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether a spoke-reported dashboard URL host may count toward hive-mx host routing, given a self-service (byo-) hive can then claim a host and make the hub drop mail for any host it shares?
Routing to a human: this adds a token-gated endpoint, signs with per-hive relay keys, and widens publicExactPaths — all trust-surface changes. I read mail_relay.go, the webhook_relay.go change and the saas_auth.go hunk at head 1aed879.
What looks correct to me:
mailAuthorizedcompares in constant time and fails to 404 whenHIVE_HUB_MAIL_TOKENis unset (mail_relay.go,gateMail).- The forward goes through
spokeWebhookRelayGuardand a no-redirect client; the signature binds the delivery id, and replay ids are namespaced (relay:/github:) inverifyWebhookRelay, with tests for both.
One question I could not settle from the diff (open question, not a confirmed defect): mailHostMap includes e.DashboardURL from s.registry.Hives, which the PR body says is "the dashboard URL its spoke reports". On a host claimed by two hives, add deletes it and blacklists it for everyone. If a spoke (including a self-service byo- hive, #18060) can report another hive's host as its dashboard URL, it can silently stop mail routing for that hive. I did not find where the heartbeat validates that URL. Worth a maintainer confirming it is constrained (or restricting the host map to hub-assigned subdomain/vanity hosts).
Minor, suggestion only: the three spoke paths added to publicExactPaths (saas_auth.go hunk) are only safe if the spoke handlers in the next PR call verifyRelayedRequest; nothing in this PR enforces that, so that PR deserves a close read.
— hive: agent=reviewer-2 backend=claude model=claude-sonnet-5-5 claude=2.1.325
|
merged by Hive trusted-author auto-merge: author @clubanderson holds role owner and GitHub permission admin on repo; CI green at 1aed879. |
Part 3 of #18395 (Betty C2, email in; plan #18391 "Email invites"). Uses the
pkg/mailin/wirecontract from #18423.Hub (
src/pkg/hub/mail_relay.go)GET /api/mail/hosts: every hosted hive's subdomain host, vanity URL host and the dashboard URL host its spoke reports, sorted; a host two hives claim is left out (mail for it cannot be routed safely).POST /api/mail/inbound: reads onlyid,kindandrecipientof a hive-mx delivery (8 MiB cap), maps the recipient host to its SaaSHive, signs the unchanged body with that hive's relay key (signWebhookRelayHeaders, delivery id inX-Hive-Relay-Delivery) and forwards it to/api/meetings/invites,/api/inbox/emailor/api/meetings/calendar-emails/proofby kind, behind the webhook relay's private-address guard (spokeWebhookRelayGuard) and a client that never follows redirects. Stores nothing; logs the delivery id, hive id and status only.202delivered,400/404/413/422permanent,502/503temporary (no relay key yet, spoke unreachable, spoke 401/404/405/408/429/5xx).HIVE_HUB_MAIL_TOKEN(constant-time compare) and answer404while it is unset, so a hub without hive-mx exposes nothing.isSaaSPublicPath: the spoke handlers fail closed without a valid relay signature.Spoke (
src/pkg/dashboard/webhook_relay.go)The relay verification accepts
X-Hive-Relay-Deliveryfor non-GitHub relays: when present it is the id the signature is bound to and the one remembered for replay, with the same 5-minute skew and replay window; replay ids are namespaced (github:/relay:) so the two kinds never collide.verifyRelayedRequestrequires the header (used by the spoke endpoints in the next PR).Docs:
api-reference/hub-server.md(citations fixed withcheck-docs-citations.py --fix),env-vars.md.🤖 Generated with Claude Code