Repository navigation
feat(auth): controller-scoped MCP key — creator-tier, attributable, refused on grant surfaces - #3762
trinity-ability wants to merge 1 commit into
Conversation
…efused on grant surfaces Adds a fourth machine scope, `controller`, for a remote controller that provisions and operates an instance from outside it (Abilityai/trinity-enterprise#693). - Reach: passes require_role("creator"), the owner/access tier and the agent capability gates (Operator tier). Kept out of ADMIN_GATE_SCOPES; an admin route admits it only via allow_scopes={"controller"} (named code controller_route_not_admitted otherwise; role == admin still enforced). - Refused at the auth entry point on grant surfaces with controller_grant_refused + surface: key_minting, permissions, credential_values, system_teardown, destructive_delete (agent delete). - Backstop guard walks the live route table and fails any grant-shaped route with neither a refusing gate nor a fence entry. - Attribution: audit rows actor_type=controller / actor_id=key id; execution rows source_mcp_scope (new nullable column, SQLite + Alembic 0099); skill-assignment history assigned_by=controller:<key id>:<key name>. - Minting: admin + signed-in session only, like ops. Agent activity attribution and MCP tool exposure are deferred. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
|
Resolve by running |
|
Resolve by merging |
Summary
Adds a fourth machine scope,
controller, for a remote controller (fleet-facing automation that provisions and operates an instance from outside it). Today such a controller has two wrong options. Anagentkey is refused at admin gates and bound to one container. Auserkey is the person: it passes every admin gate on an admin owner, and every write is recorded as that human.Related: abilityai/trinity-enterprise#693 (companion: abilityai/trinity-enterprise#692)
Scope semantics
Minting —
POST /api/mcp/keyswith{"scope": "controller"}. Admin only, and only from a signed-in session (require_interactive+assert_admin), the same asops. A key can never mint one. The key is minted against the caller's account, so mint it under a dedicated service account. It never carries anagent_name.Reach (creator-tier, not admin-blanket)
require_role("creator")(create agent, deploy/restart system) and the owner/access tier on whatever its owner may reach. The service account's role decides which fleet it sees.skills.manage,schedules.manage,agents.manage, …), per the Operator ruling.ADMIN_GATE_SCOPES. Every admin gate refuses it with the named codecontroller_route_not_admittedunless the route opts in viaallow_scopes={"controller"}/require_admin_allowing("controller"). That is the existing feat: machine identities for admin/ops APIs — service credentials that survive enforced 2FA #2323 mechanism, androle == "admin"still runs afterwards. No route opts in yet; that comes with Config Validation: 5 critical config issues found (TRINITY_PASSWORD P0, 4x undocumented vars) #692.require_person,require_interactive, ask endings,/ws/events.Refused on grant surfaces —
_enforce_controller_key_fenceinget_current_userruns before any route gate and answers 403{"code": "controller_grant_refused", "surface": …}:key_minting/api/mcp/keys/**,/api/agents/{n}/mcp-key/**permissionscredential_valuesPOST /api/subscriptions, Nevermined config POST/DELETE, webhook signing-secret mint/revokesystem_teardownDELETE /api/enterprise/system-teardown/{name}destructive_deleteDELETE /api/agents/{name}, a soft delete whose workspace/shared/public volumes are purged after retention. Anchored on the agent itself, so sub-resources stay reachableA controller may name a credential (status, requirements reads pass) but may never read or set one.
Why a denylist, and the human-only backstop
The Operator ruling ships the controller ungated inside the instance, so its reach is deliberately broad, and an allowlist of what it may reach would be the whole API. The fence therefore names the grant surfaces. Three layers keep a denylist from failing open:
require_person/require_interactiveand theADMIN_GATE_SCOPESallowlist never containcontroller, so any route gated by them (including every new grant route classified under the bug(auth): agent-scoped keys can toggle their own agent's autonomy — PUT /api/agents/{name}/autonomy lacks reject_agent_principal #2996 census) refuses it with no edit here.test_every_grant_shaped_route_refuses_a_controllerimports the real app (the bug(auth): agent-scoped keys can toggle their own agent's autonomy — PUT /api/agents/{name}/autonomy lacks reject_agent_principal #2996 census subprocess; it fails, never skips). Every route whose shape is key / permission / credential-value must either carry a gate the controller is refused by, or have a fence entry. Its first run found five ownership-only routes the fence was missing (webhook secret POST/DELETE, email-whitelist POST, canvas share POST, Nevermined config DELETE); all five are now fenced.Attribution (AC 2: partial)
actor_type="controller",actor_id=<key id>,mcp_scope="controller", key name, and the owner asactor_email. Neveruser, so the owner's activity view doesn't show the controller's acts as theirs.schedule_executions.source_mcp_scope, read from the key row inside the INSERT so it survives key deletion. Execution detail shows Controller: .agent_skills.assigned_by/agent_skill_sets.assigned_byrecordcontroller:<key id>:<key name>(dependencies.assignment_author) on every assignment write: single assign, bulk replace, set assign/replace/unassign. Every other principal keeps its username, so existing rows and readers are unchanged and no schema change is needed.Migrations
One additive nullable column,
schedule_executions.source_mcp_scope, with no backfill. Both tracks: SQLiteexecution_source_mcp_scopeindb/migrations.py, and Alembic0099_execution_source_mcp_scope(renumber before merge, see the top).schema.pyandtables.pyare updated. Alembic heads: one head.Deferred
OPERATOR_SCOPES/access.ts). The key gets no MCP tools until then (fail-closed); it's a REST credential for now. Kept out of this PR to avoid colliding with ent#662./ws/eventsadmission (refused today)..mcp.json(reports it as a personal user key).POST …/webhook) stays reachable as schedule management; only the signing secret is fenced.Test evidence
tests/unit/test_ent693_controller_scope_key.py: 93 passed. Driven through the real gates: the realget_current_userwith a key minted into the real schema and presented as a bearer, the real assign route via TestClient, the real audit and execution writers, and the live route table.destructive_delete, new fence entries, the guard).assignment_author; the single-assign wiring; the set-assign wiring; thedestructive_deleteentry; the webhook-secret entry.test_1310_auth_consolidation::test_admin_sites_admit_admin[avatar.generate_default_avatars], which fails identically ondev: it writes to/data, which is read-only on macOS.tsc(no local node_modules in the worktree; the change is one added value in a type union) and the frontend unit suite (raw-color class counts are unchanged in both touched files).🤖 Generated with Claude Code