Skip to content

πŸ› fix(proxy): task MCP and public knowledge MCP reach the hive through the gateway - #16905

Merged
hivecommons-hive[bot] merged 3 commits into
hivecommons:v6from
Danathar:fix/proxy-task-mcp-public-path
Nov 6, 2026
Merged

hivecommons-hive[bot] merged 3 commits into
hivecommons:v6from
Danathar:fix/proxy-task-mcp-public-path

Conversation

@Danathar

@Danathar Danathar commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Summary

On standalone deployments (Docker Compose, Podman Quadlet, LXC) every request goes through the bundled auth proxy before it reaches the hive. The proxy refused the hive's two MCP endpoints, although the hive checks their callers itself. Hub-launched agents and remote contributors got 401 from the task MCP whenever its URL went through the gateway (dashboard.public_url or a hub-assigned dashboard URL). The public knowledge MCP could not be reached at all, even with the owner's switch on. The proxy now forwards exactly these two paths and adds no credential of its own.

What went wrong

The proxy answers a write request with 401 unless it carries the dashboard token or a session cookie, or its path is on a short public list. Neither MCP path was on that list. /mcp/knowledge also had no route to the hive, so it failed even with the dashboard token.

Before this change, with a dashboard token configured:

POST /api/contribute/mcp?token=<launch token>    401 {"error":"Unauthorized"}  from the proxy
POST /api/contribute/mcp  Bearer <lease token>   401 {"error":"Unauthorized"}  from the proxy
POST /mcp/knowledge                              401 {"error":"Unauthorized"}  from the proxy
POST /mcp/knowledge       Bearer <dashboard>     404, the proxy has no route
GET  /mcp/knowledge                              200, the dashboard page

What changes

  • POST /api/contribute/mcp passes the proxy and reaches the hive. The hive verifies the launch token or the lease as before and refuses everyone else.
  • POST /mcp/knowledge passes the proxy and reaches the hive. The hive serves it only while the owner's "Public read-only MCP" switch is on.
  • Any other method on /mcp/knowledge gets 405 with Allow: POST instead of the dashboard page.
  • Both paths are matched exactly. Only the query string is ignored. /api/contribute/mcpx, /mcp/knowledge/extra and /mcp/other still get 401.

Why this is safe:

  • The proxy adds X-Hive-Internal only when the request carried the dashboard token in its Authorization header. A token in the query string never counts, so a launch token cannot be taken for the dashboard token.
  • On /mcp/knowledge the proxy never adds X-Hive-Internal. It also removes X-Hive-Internal, X-Hive-User and X-Hive-Role if the client sent them.
  • The hive's own checks do not change. Both endpoints were already reachable without the proxy on Kubernetes, where the Service goes straight to the hive.
  • PUT, PATCH and DELETE on the two exact paths also pass the gate, as they already do for the device-flow sign-in paths. On /mcp/knowledge the proxy answers them with 405. On /api/contribute/mcp the hive has no handler for them.

This follows the device-flow sign-in change in #15882: same list, same exact match.

Not in this change: the endpoint URL shown under Settings β†’ Knowledge is built from the request's Host header, so behind the proxy it shows the internal address.

Files

  • src/proxy/server.js: two paths added to PUBLIC_EXACT_POST_PATHS; new knowledgeMcpProxy with a POST route and a 405 route for /mcp/knowledge.
  • src/proxy/api_internal_header.test.js: the new checks; the mock hive echoes Authorization and the req helper returns response headers.
  • changelog.d/fixed-proxy-mcp-endpoints.md: release note.

Tests

New checks in src/proxy/api_internal_header.test.js, which CI runs through npm test:

  • Task MCP with a ?token= launch token is forwarded without X-Hive-Internal, query string intact.
  • Task MCP with a lease bearer is forwarded without X-Hive-Internal, Authorization intact.
  • The dashboard token in a task MCP ?token= never earns X-Hive-Internal.
  • Anonymous POST /mcp/knowledge is forwarded with no trust headers.
  • Client-sent X-Hive-Internal, X-Hive-User and X-Hive-Role on /mcp/knowledge never reach the hive.
  • POST /mcp/knowledge with the dashboard token still gets no X-Hive-Internal.
  • GET, PUT and DELETE on /mcp/knowledge get 405 with Allow: POST.
  • Seven sibling paths still get 401: /api/contribute/mcpx, /api/contribute/mcp/, /api/contribute/mcp/extra, /mcp/knowledgex, /mcp/knowledge/, /mcp/knowledge/extra, /mcp/other.

Without the change, every check above except the sibling ones fails (nine checks: they get 401 or 404 instead). The seven sibling checks pass before and after. They pin the boundary.

express and http-proxy-middleware were not installed where this was prepared. The real test file was run against the real server.js with small local stand-ins for the two packages: 30 of 30 checks pass with the change, 21 of 30 without it. CI is the first run against the real packages.

πŸ€– Generated with Claude Code

…h the gateway

On Compose, Quadlet and LXC every request passes the Node auth proxy. Its
gate answers 401 to a write with no dashboard token unless the path is on
its public list, so the two MCP endpoints that authenticate their own
callers never reached the Go API: the task MCP (launch token in ?token=
or a lease bearer) and the public knowledge MCP (anonymous while the
owner's switch is on). /mcp/knowledge had no route to the Go API either.

Both paths join the exact-match public list (query string aside, never by
prefix). /mcp/knowledge gets its own forwarder that drops X-Hive-Internal,
X-Hive-User and X-Hive-Role; other methods on it answer 405, Allow: POST.
X-Hive-Internal is still added only for a request that sent the dashboard
token in its Authorization header.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Danathar <Danathar@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 6, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

No conflicting open PRs or same-file overlaps were found.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision needed: @clubanderson should decide whether the standalone gateway may forward anonymous POSTs on exactly /api/contribute/mcp and /mcp/knowledge to the Go API, relying on the Go-side launch-token/lease check and the owner's public-knowledge switch instead of the proxy's dashboard-token gate.

The code does what the body says, and I could not find a way for it to mint trust it should not. I'm routing it rather than calling it done because it widens the gateway's unauthenticated-write allowlist, which is a proxy-policy call for an approver (src/proxy/** is not in .github/CODEOWNERS; OWNERS approvers are the right people).

What I verified at ce1195e:

  • The gate (src/proxy/server.js:1038-1041) sets hiveTokenVerified solely from bearerTokenMatches(req.headers.authorization) (server.js:704-711), which never reads the query string, and the exact-path check uses req.url.split('?')[0]. So a ?token=<launch> request passes the gate with hiveTokenVerified=false, and apiProxy then strips rather than injects X-Hive-Internal (server.js:1068-1071). A caller who does present the dashboard bearer gets X-Hive-Internal as before β€” unchanged behaviour for already-authenticated callers.
  • Go side: isPublicPath already allows /api/contribute/* (pkg/dashboard/server.go:2640) and /mcp/knowledge only while publicKnowledgeEnabled() (server.go:2603), so neither needed X-Hive-Internal to be reachable; handleContributeMCP authenticates the lease, then the launch token, then falls back to a bearer check against the dashboard token (pkg/dashboard/task_mcp.go:36-41). Nothing on the Go side trusts the proxy for these two routes.
  • knowledgeMcpProxy (server.js:1149-1166) strips X-Hive-Internal, X-Hive-User, X-Hive-Role unconditionally, and the app.all 405 at server.js:1170-1173 sits after app.post, so only POST is forwarded.
  • Exact matching means /api/contribute/mcp/ and /mcp/knowledge/extra still hit requireAuth; the new tests pin seven such siblings.

One thing the body flags itself, worth keeping in mind for the decision: PUT/PATCH/DELETE on /api/contribute/mcp also pass the gate (same as the existing device-flow paths) and rely on the Go mux to reject them. That's consistent with #15882 but it is the one place the allowlist is wider than "POST only".

Nothing here is a defect; the question above is the only thing I can't settle.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

  • the reviewer swarm returned requires_human @ce1195e
  • the review found: the reviewer marked this change high-risk
  • reviewer question: @clubanderson should decide whether the standalone gateway may forward anonymous POSTs on exactly /api/contribute/mcp and /mcp/knowledge to the Go API, relying on the Go-side launch-token/lease check and the owner's public-knowledge switch instead of the proxy's dashboard-token gate.
  • the automerge lane will not merge this unattended

Head: verdict requires_human @ce1195e, 63/63 checks green, DCO yes, soak 0s of 10m0s.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decision needed: @clubanderson should confirm the dashboard auth proxy may forward anonymous POSTs to exactly /api/contribute/mcp and /mcp/knowledge, delegating caller authentication to the Go API for those two paths.

Read the code: the change does what it says, and it is a deliberate widening of the gateway's anonymous-write allowlist β€” flagging for a maintainer's sign-off rather than approving.

What I verified against this head (74bb1ad):

  • src/proxy/server.js:1038-1041 β€” the gate sets req.hiveTokenVerified from bearerTokenMatches(req.headers.authorization) before the allowlist check, and bearerTokenMatches (server.js:704-712) reads only the Authorization header. So a ?token= launch token can never earn X-Hive-Internal; apiProxy (server.js:1068-1072) strips it unless the header matched. The "no credential leaks through" claim holds.
  • src/pkg/dashboard/server.go:2644 β€” /api/contribute/ is already a Go public-path prefix, so the Go side was always reachable anonymously there; task_mcp.go:34-45 then requires a lease bearer, a launch token, or the dashboard bearer and 401s otherwise. The proxy's 401 was purely redundant with a stricter check downstream. This is the real bug fix.
  • src/pkg/dashboard/server.go:2603 β€” /mcp/knowledge is public in Go only while publicKnowledgeEnabled(); otherwise it falls through to normal auth. So the new knowledgeMcpProxy (server.js:1150-1172) opening it at the proxy does not open it at the hive while the owner's switch is off.
  • Exact-match semantics: req.url.split('?')[0] against the list, so /mcp/knowledge/extra, /api/contribute/mcp/ etc. still hit requireAuth. The new sibling tests pin this.
  • Route order: app.post('/mcp/knowledge') is registered after the token gate and before express.static (server.js:1304) and the SPA fallback (:1364), so the 405 handler correctly displaces the dashboard page for GET.

The PR body says the test could not be run against the real express/http-proxy-middleware. I ran node src/proxy/api_internal_header.test.js on this head with the real packages: 30/30 pass.

Body and diff agree; no mismatch found. Nothing else in the tree (docs, callers) needs to change β€” public-knowledge-mcp.md already defers reverse-proxy detail to the operator, and the changelog fragment is present.

The one thing I will not decide alone: this PR moves the authentication boundary for two write paths from the proxy to the Go API. Both Go handlers do fail closed today (cited above), but that now depends on task_mcp.go and publicKnowledgeEnabled() continuing to do so. That is a trust-surface change and belongs to an approver.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive
hivecommons-hive Bot merged commit 259928c into hivecommons:v6 Nov 6, 2026
67 of 68 checks passed
@hivecommons-hive

hivecommons-hive Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

Evidence bundle `#1690574bb1ad` sha256:a7b06204f0234f7f04fadd94af33cf9e4c547d26f204d97bfe0e550c77220ab0 β€” download from the dashboard or `hivectl review evidence #16905`.

Review findings from adjudicator-2 (folded here because this head already carries its hive review):

HUMAN DECISION NEEDED β€” Danathar: confirm that the standalone gateway may forward anonymous POST /api/contribute/mcp and POST /mcp/knowledge to the Go API, relying solely on the Go-side checks.

Security re-review at 74bb1ad. The delta since ce1195e is two Merge branch 'v6' commits (25 already-landed v6 PRs); the PR's own files (src/proxy/server.js, src/proxy/api_internal_header.test.js, changelog.d/fixed-proxy-mcp-endpoints.md) are byte-identical to the previous head, so nothing new to report from the delta.

Previous finding β€” still present (unchanged, it is the change itself): src/proxy/server.js:1024-1027 adds /api/contribute/mcp and /mcp/knowledge to PUBLIC_EXACT_POST_PATHS, so the proxy's token gate no longer stops unauthenticated writes on those two paths. What I verified at head so the decision is informed:

  • src/pkg/dashboard/task_mcp.go:34-48 β€” handleContributeMCP accepts only a lease bearer, a per-launch ?token=, or the dashboard bearer, else 403.
  • src/pkg/dashboard/mcp_knowledge.go:469-479 β€” handlePublicKnowledgeMCP returns 404 while the owner switch is off and 405 for non-POST.
  • src/proxy/server.js:1150-1168 β€” the knowledge route strips X-Hive-Internal/X-Hive-User/X-Hive-Role and never adds them; the test file covers forged headers and sibling paths.

The mechanism is sound; the remaining question is policy (gateway no longer a second gate for these endpoints), which the hive won't decide for a contributor PR.

Review findings from ci-maintainer (folded here because this head already carries its hive review):

docs-currency (delta re-review ce1195eb β†’ 74bb1ada): the delta is two Merge branch 'v6' commits; the PR's own three files are unchanged. Changelog fragment matches the diff; no existing doc describes the proxy allowlist or claims the MCP endpoints fail behind the gateway, so nothing goes stale. No in-scope docs blocker.

Advisory (out of scope, pre-existing, already noted in your "Not in this change"): with /mcp/knowledge now reachable through the gateway, standalone operators will follow src/docs/public-knowledge-mcp.md:32-33 ("a copyable endpoint URL") and copy the internal Host-derived address. Until the URL is built from dashboard.public_url, a one-line hint would save them a round trip:

- **Settings β†’ Knowledge β†’ Knowledge sharing**: the same control, plus tags
  and a copyable endpoint URL. Behind the bundled gateway (Docker Compose,
  Podman Quadlet, LXC) that URL is built from the request's `Host` header;
  hand clients your external origin (port 3001) with the `/mcp/knowledge` path.

Hive filed review findings that do not block this PR as backlog items:

Cap: 10 backlog item(s) per PR per day.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

merged by Hive trusted-author auto-merge: author @Danathar holds role owner and GitHub permission maintain on repo; CI green at 74bb1ad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant