Skip to content

[Vault] MCP HTTP proxy 运行时注入 static_bearer - #212

Draft
qifanlili wants to merge 2 commits into
feat/vault-secret-envelope-encryptionfrom
feat/vault-runtime-injection
Draft

[Vault] MCP HTTP proxy 运行时注入 static_bearer#212
qifanlili wants to merge 2 commits into
feat/vault-secret-envelope-encryptionfrom
feat/vault-runtime-injection

Conversation

@qifanlili

@qifanlili qifanlili commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

总览

本 PR 在 Session MCP HTTP proxy(/v2/ccr-sessions/{id}/mcp)转发前,按真实 mcp_url 匹配 session vault_ids 中的活动凭证,并把命中的 static_bearer token 注入上游 Authorization。Sandbox / mcp_config 只看到 proxy URL 与 session JWT,看不到明文 token。

依赖存库信封加密(#199 / feat/vault-secret-envelope-encryption)。本 PR 只做运行时注入 MVP,不覆盖 mcp_oauth、环境变量出口替换,也不走 CONNECT MITM。

提供的功能与改动

1. Credential URL 匹配与注入决策

  • vault_ids 顺序遍历活动凭证;首个可注入的 static_bearer 命中胜出。
  • host+port 未覆盖 → passthrough;同 host 无 path 命中 → fail-closed。
  • path 按 / 分段前缀匹配(/mcp 命中 /mcp/sse,不命中 /mcp-admin)。

2. MCP HTTP proxy 接线

  • codesessions.WithVaultSecretsinjectMCPProxyHeadersvaults.Injector.RewriteAuthorization
  • 注入拒绝 / Open 失败 → HTTP 502。
  • 每请求查库加载 vault_ids 与凭证;明文 token 不缓存,用完清零。

3. 文档与测试

  • 更新 docs/design/be/vault-runtime.md 与 permission-bridge 设计说明。
  • 补充匹配、Open、proxy 502 等单测。

测试

  • go test ./internal/vaults/ ./internal/db/ ./internal/codesessions/ -count=1

不做

  • mcp_oauth 注入与 refresh
  • environment_variable 出口替换
  • Credential 级 networking.allowed_hosts
  • CONNECT MITM 注入路径

在 Session MCP proxy 转发前按真实 mcp_url 匹配 vault 凭证并注入 Bearer,沙箱不接触明文 token。

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a223e139-35a7-4bc1-9a4d-49c31fac1b4e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
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