Skip to content

feat: bind write approvals to the authenticated principal (1.4.0) - #72

Open
bitclicklabs wants to merge 1 commit into
erpipe-org:mainfrom
bitclicklabs:feat/principal-bound-write-approvals-upstream
Open

bitclicklabs wants to merge 1 commit into
erpipe-org:mainfrom
bitclicklabs:feat/principal-bound-write-approvals-upstream

Conversation

@bitclicklabs

Copy link
Copy Markdown

Summary

With the OAuth resource server enabled (ODOO_MCP_AUTH_*), many Streamable HTTP clients share one server process and its in-memory write_approvals store. Approval tokens are a deterministic hash of the payload with no caller identity, so client B could execute a write that client A ran validate_write for, just by sending the same payload.

This PR binds approvals to the authenticated caller:

  • validate_write stores the principal (token client_id, iss, sub, plus the mcp-session-id when the transport has one) in the validation record.
  • execute_approved_write refuses any other caller with approval was validated by a different authenticated principal or MCP session. The refused attempt does not consume or evict the original caller's approval.
  • chatter_post (stateless preview) mixes the principal into its approval token on authenticated calls.
  • IntrospectionTokenVerifier now forwards sub and iss to the SDK AccessToken, so users sharing one OAuth client are distinct principals.
  • ODOO_MCP_AUDIT_LOG lines gain a principal object (client_id, issuer, subject, session_sha256), null when unauthenticated.
  • stdio and unauthenticated HTTP keep the previous per-process behavior.

The principal check sits after the token/payload checks and before confirm / ODOO_MCP_ENABLE_WRITES; no existing write gate or field-ACL choke point changed.

Behavior note: an authenticated client that reconnects (new MCP session) between validate_write and execute_approved_write must re-validate. Stateless HTTP has no session id, so binding there is principal-only.

Version bumped to 1.4.0 with a CHANGELOG entry; README and docs/claude-desktop-connector.md updated.

Coverage

  • Odoo versions tested: none live (unit tests with fake clients; no RPC behavior changed)
  • Transports tested: stdio path and authenticated HTTP path simulated via the SDK auth context var and mcp-session-id request header (tests/test_write_principal_binding.py)

Verification

uv run python -m ruff check .
uv run python -m mypy src
uv run python -m pytest
uv run --with import-linter lint-imports
  • ruff: clean. mypy: no issues (34 files). lint-imports: 2 kept, 0 broken.
  • pytest: 940 passed, 1 failed — test_from_path_rejects_file_swapped_for_symlink_after_root_check, which fails identically on main on Windows (symlink semantics); test_list_tasks_newest_first is intermittently flaky on Windows timer resolution, also pre-existing.
  • Not run: scripts/odoo_compose_smoke.py and a live OAuth end-to-end session.

On Streamable HTTP with the OAuth resource server enabled, many clients
share one server process and its write_approvals store. Approval tokens are
a deterministic hash of the payload, so client B could execute a write that
client A validated by replaying the same payload.

validate_write now stores the caller principal (token client_id, issuer,
subject, and MCP session id) in the approval record, and
execute_approved_write refuses any other caller without consuming the
record. chatter_post mixes the principal into its stateless token. stdio and
unauthenticated HTTP keep the per-process behavior.

The introspection verifier now forwards sub and iss so users sharing one
OAuth client are distinct principals. Audit JSONL lines carry a principal
object, with the session id digested.

This branch has not been deployed

No deployments
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