Skip to content

feat(connect): per-client credentials, bindings service and connect guard (Spec 108-c2) - #1430

Merged
github-actions[bot] merged 18 commits into
mainfrom
108-c2-client-credential-binding
Sep 30, 2026
Merged

github-actions[bot] merged 18 commits into
mainfrom
108-c2-client-credential-binding

Conversation

@Dumbris

@Dumbris Dumbris commented Sep 30, 2026

Copy link
Copy Markdown
Member

Summary

Second half of PR 108-c of Spec 108 (specs/108-profiles-v3): connect stops writing the instance admin API key, every client gets its own mcp_cli_ credential bound to a profile, and that binding can be reassigned server-side without touching the client's config.

This fixes UX-audit finding P4 (backend): before this change every connected client held either no credential or the admin key that opens the whole REST API, so Cursor's calls could not be told from Codex's and a client could not be bound to a profile.

Security-sensitive: everything here fails closed. A named binding that could be escaped by omitting the credential while require_mcp_auth is off is refused on every path that could create it.

User-visible changes per surface

Core and REST

  • POST /api/v1/connect/{client} mints a per-client credential (mcp_cli_...) instead of embedding the admin key, in both auth modes. The body accepts profile, mode and keyless; the result reports the masked credential, token name, binding and, for a reconnect over an active credential, rotation: finalized. A reconnect over an active credential is a staged rotation, so the old secret keeps working until the new config has been written. A request without profile means All servers for a fresh credential and keeps the existing binding on a reconnect, so a plain reconnect never silently widens a locked client.
  • GET /api/v1/connect/{client}/preview masks the credential as mcp_cli_•••• and echoes the requested intent; contains_api_key is now always false. The precondition token binds the intent and the auth toggle through a fixed placeholder, so the real secret never enters the digest.
  • GET /api/v1/connect/{client} classifies what a client's entry carries (client, admin_key, none, revoked, expired); the stat-only listing reports unknown because it never reads a config. Both stay administrator-only.
  • POST /api/v1/connect/{client}/undo is now "as if the connect never happened": the credential the connect minted is revoked unless the restored config still holds it (credential_revoked).
  • New PUT /api/v1/clients/{client}/binding (personal edition only) reassigns profile and/or mode for a client with an active credential. It clears the stored set_profile selection of every live session of that credential, sends notifications/tools/list_changed to each on the server instance that serves it, publishes the administrator-only client.binding_changed event and writes one profile_change activity record. A client without an active credential is refused with 409 no_client_credential; nothing is ever minted implicitly.
  • FR-008a guard: PATCH /config, POST /config/apply and PATCH /config/docker-isolation (all funnelled through Server.ApplyConfig), connect and the binding route now answer 409 binding_bypassable_without_auth with the bindings and fixes when the candidate state would leave a named binding bypassable, and write nothing. The check and the write run under one mutex, so two individually safe concurrent writes cannot combine into a bypassable state. Hand edits are still covered by the existing runtime anonymous guard.
  • 409 with conflicting_token when client-<id> is held by a regular agent token; 400 {error, field} for an unknown profile, bad mode or keyless misuse.
  • Sessions now record the authenticating token, client id, serving server instance and latest effective profile and source.
  • New profile_change activity type (contract enums, TypeScript labels and macOS filter list updated) with actor kind, actor name and surface (X-MCPProxy-Surface, or derived from X-MCPProxy-Client).
  • Staged-rotation reconciler: on startup and on every on-demand classification it finalizes, rolls back or keeps both secrets according to what the client's config actually holds; custom clients finalize after a 24 hour overlap.

MCP

  • No built-in tool schema changed. Client credentials authenticate on MCP endpoints only and keep the fail-closed invariant check on every request.

CLI

  • mcpproxy connect gains --profile <name|all>, --lock, --switchable and --keyless, applies to --all too, and prints Credential: mcp_cli_•••• (token client-cursor, profile ro, locked) between the result line and the existing Config: and Next: lines. With a daemon it goes through the daemon; without one it runs the same service locally with the strictest guard. A guard refusal prints the refusal text and a Fixes: list and exits 1.

Web UI and macOS

  • No component changes in this PR (moved to T042w and T042m in the spec). Both keep working: they call connect without a profile and receive an All servers credential. The connect preview's "includes your API key" notice no longer appears because contains_api_key is now false; the profile picker and updated credential copy land with 108-i and 108-k. TypeScript types gain the additive fields, and the macOS activity-type filter list gains profile_change.

Audit findings fixed

P4 (backend): connect no longer writes the admin key on any surface.

Spec

specs/108-profiles-v3: decisions D1 to D26 recorded in spec.md, data-model.md, contracts and quickstart; tasks T027a, T028a, T029, T030a, T030b, T031, T032, T033, T033a, T035, T036, T038, T039, T040, T040a, T041 and T043 marked done; T042 removed from this phase and split into T042w (Web, 108-i) and T042m (macOS, 108-k). 108-d merged before this PR, so the FR-009a gate is open and the guard offers both fixes.

Tests added

  • Contract enum spellings; storage binding update; clients service (every operation, records, refusals, id rules, rotation reconciler with crash injection, warnings).
  • Guard evaluator delta table, extra reachability rows, config-route refusals through Server.ApplyConfig, runtime guard end to end, concurrent config and binding writes under -race.
  • Connect: every client carrier, no admin key in any mode, keyless rules, refusals write nothing, credential classification, preview intent, undo revocation; REST routes for connect and binding, admin-only reads, SSE scoping, surface attribution.
  • Session identity stamping and per-token tools/list_changed fan-out; resolver cycle and reassignment rows; anonymous confinement gaps.
  • Malformed credential records (13 rows) on /mcp and REST, and the rollback test against frozen pre-108 middleware branches.
  • CLI flags, offline and daemon paths, refusal output and exit codes.

Notes for reviewers

  • Runtime.LockBindingWrites is held across guard check and write; it is never held across a client config write (connect mints, releases, writes the file, then commits or aborts).
  • After a failed config write a fresh mint is revoked and a staged rotation is rolled back. A failure after the write itself is ambiguous and is left to the reconciler.
  • The offline CLI cannot evaluate the tool-dependent reachability condition, so it refuses any named binding while require_mcp_auth is off; it is only ever stricter than the daemon.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

luna:3.1 (medium, confirmed): a reconnect of an EXPIRED kind=client
credential with no explicit profile/mode fell into the fresh-mint branch and
silently re-minted a locked client as All servers/switchable. issueLocked now
keeps the recorded binding for expired credentials as well as active ones.
A revoked credential was cut off deliberately, so it still restarts at the
defaults; documented in rest-api.md. Test added first (failed before the fix).
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: 108-c2-client-credential-binding

Available Artifacts

  • archive-darwin-amd64 (30 MB)
  • archive-darwin-arm64 (27 MB)
  • archive-linux-amd64 (18 MB)
  • archive-linux-arm64 (16 MB)
  • archive-windows-amd64 (30 MB)
  • archive-windows-arm64 (27 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (25 MB)
  • installer-dmg-darwin-arm64 (22 MB)
  • smart-mcp-proxymcpproxy-goCO6JL5.dockerbuild (0 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 36714905059 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

codecov-commenter commented Sep 30, 2026 •

Copy link
Copy Markdown

@github-actions github-actions 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.

Approved (Model B): Paperclip review verdicts = ACCEPT and qa-gate green at this head SHA. Arming auto-merge; GitHub merges when all required checks pass.

@github-actions
github-actions Bot merged commit 748e6ed into main Sep 30, 2026
61 checks passed
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.

2 participants