MCP 2b-2: write classification + per-agent repo allowlists#30
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.create_issue-too-early gap is closed at the proxy from this slice onward.repos = ["owner/repo", "owner/*"]per agent. Everytools/callmust resolve its target fromarguments.owner+repo; no resolvable target → denied (deny-if-unresolvable, RFC Rev 2) — so repo-restricted agents cannot use repo-less tools likesearch_codeby design.repos = []= unrestricted (additional constraint; existing 2a configs keep working unchanged).tools/calllines include the resolved repo.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 warningsclean.