Skip to content

MCP 2b-2: write classification + per-agent repo allowlists#30

Merged
chaodu-agent merged 4 commits into
mainfrom
mcp-repo-policy
Jul 13, 2026
Merged

MCP 2b-2: write classification + per-agent repo allowlists#30
chaodu-agent merged 4 commits into
mainfrom
mcp-repo-policy

Conversation

@chaodu-agent

Copy link
Copy Markdown
Contributor

Replaces #29 (auto-closed when its stacked base branch was deleted during #28's merge). #28's content is included via merge from main; the diff against main is this slice only.

Summary

Second slice of #17's [2b] gate items: the policy engine for writes — per-tool read/write classification and repository-level authorization — while the upstream stays read-only. Closes gate items [2b] Resource-level authorization and [2b] Per-tool write classification.

Design

  • src/policy.rs (new): a tool is Read iff it matches the /readonly surface's naming rules (get_*, list_*, search_*, *_read — verified against MCP proxy Phase 0: compliance & compatibility spike (hosted endpoint contract, App tokens) #22 probe data); everything else, including never-seen tools, is Write. Conservative direction: misclassifying a read is an inconvenience; misclassifying a write would be a security bug.
  • Write blocking now: a write-classified tool gets 403 even if allowlisted — today the readonly upstream is the barrier, but after 2b-5 that flips on config, so the operator-adds-create_issue-too-early gap is closed at the proxy from this slice onward.
  • Repo allowlist: repos = ["owner/repo", "owner/*"] per agent. Every tools/call must resolve its target from arguments.owner+repo; no resolvable target → denied (deny-if-unresolvable, RFC Rev 2) — so repo-restricted agents cannot use repo-less tools like search_code by design. repos = [] = unrestricted (additional constraint; existing 2a configs keep working unchanged).
  • Audit: tools/call lines include the resolved repo.
  • Phase 1 no-agent mode untouched.

Enforcement order (authenticated agents)

tool allowlist → write classification → repo allowlist. Each denial has a distinct 403 message + audit warn.

Tested

59 tests (14 new). Policy unit tests: classification incl. unknown→Write, repo resolution shapes, exact/wildcard/case-insensitive/malformed-fails-closed matching. Integration: allowlisted write blocked (upstream never called), repo allow/deny/wildcard, deny-unresolvable with distinct error, empty-repos backward compat, Phase 1 mode unaffected. Clippy -D warnings clean.

First slice of #17's [2b] items:

- SessionPin { identity_id, agent_id } replaces the plain identity string
  in the session cache. A session ID presented by a different agent (or by
  a different mode: agent vs network-trust) is rejected with 403 — session
  IDs are not portable between agents.
- Dual keys: [[mcp.agents]] accepts keys = [...] alongside key = ... (both
  merged at load) so two keys can be simultaneously valid for zero-downtime
  rotation. Config load fails loudly when an agent has no key at all.
- Pin log line now includes the owning agent.

Closes the '[2b] Session-to-agent binding' gate item (the session-cannot-
outlive-credential half lands with the App backend slice) and the dual-key
rotation open question from 2a.

45 tests (3 new: cross-agent session rejection, mode-mismatch rejection,
rotation accepting both keys with identical policy).
Second slice of #17's [2b] items (stacked on 2b-1):

- src/policy.rs: rule-based tool classification — Read iff get_*/list_*/
  search_*/*_read (matches the observed /readonly surface), everything
  else including unknown names is Write (conservative: misclassifying a
  read is an inconvenience, misclassifying a write would be a security
  bug). Repo resolution from tool arguments (owner+repo) and allowlist
  matching (owner/repo exact, owner/* wildcard, case-insensitive,
  malformed entries fail closed).
- Enforcement for authenticated agents on tools/call, in order:
  tool allowlist -> write classification (ALL writes 403 until 2b-5's
  enable switch, even if allowlisted — closes the operator-typo gap) ->
  repo allowlist with deny-if-unresolvable.
- repos = [] means unrestricted (additional constraint, keeps 2a configs
  working). Phase 1 no-agent mode is untouched (readonly upstream is its
  write barrier).
- Audit lines now include the resolved repo: MCP tools/call issue_read
  repo=openabdev/ghpool [agent=... via ...]

59 tests (14 new: 7 policy unit, 7 integration incl. allowlisted-write
blocked, wildcard match, deny-unresolvable, 2a backward compat).
@chaodu-agent chaodu-agent merged commit 6d64e56 into main Jul 13, 2026
1 check failed
@chaodu-agent chaodu-agent deleted the mcp-repo-policy branch July 13, 2026 04:18
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