Repository navigation
Open
Labels
complexity-mediumComplexity: medium (board points 5-8)priority-p2Importantstatus-incubatingIdea under consideration — pre-Todo, not yet greenlit for developmenttheme-monetizationTheme: Monetizationtype-featureNew functionality
Description
Summary
Subscription credentials have an owner_id column but ownership is not enforced at any boundary. Users can assign any subscription to their agents, auto-assignment picks globally, and only admins can register/list subscriptions. This prevents the target UX where users connect via CLI, register their own auth token, and have it scoped exclusively to their agents.
Problem
- No ownership check on assignment —
PUT /api/subscriptions/agents/{name}checks agent ownership but not subscription ownership. User A can assign User B's subscription to their own agents. - Admin-only registration — Only admins can call
POST /api/subscriptions. Users can't self-register their Claude subscription tokens. - Admin-only listing —
GET /api/subscriptionsrequires admin. Users can't see their own subscriptions. - Global auto-assignment — On agent creation,
get_least_used_subscription()picks globally, not scoped to agent owner. User A's new agent could get User B's subscription. - Global rate-limit auto-switch —
subscription_auto_switch.pyselects alternatives globally, not scoped to agent owner.
Target UX
# User connects to Trinity MCP via CLI
claude mcp add trinity http://your-domain:8080/mcp
# User registers their Claude subscription token
> register_subscription name="my-max" token="sk-ant-oat01-..."
# All agents this user creates auto-get their subscription
# Other users' agents never touch this subscription
Changes Required
Backend — routers/subscriptions.py
- Register: Remove
require_admin(), allow any authenticated user.owner_id = current_user.id - Assign: Add check that subscription
owner_id == current_user.id(admin bypasses) - List: Non-admins see only own subscriptions; admins see all
- Delete: Owner can delete their own subscriptions (not just admin)
Backend — services/agent_service/crud.py
- Auto-assign on creation:
get_least_used_subscription()must filter by agent owner's subscriptions only
Backend — services/subscription_auto_switch.py
- Rate-limit fallback: Alternative subscription selection must filter by agent owner
DB Layer — db/subscriptions.py
- Add
get_subscriptions_by_owner(owner_id)query - Add
get_least_used_subscription_for_owner(owner_id)query - Add ownership verification helper
MCP Server — src/mcp-server/src/tools/subscriptions.ts
-
list_subscriptionsreturns only user's own (unless admin scope) -
assign_subscriptionpasses through to backend which enforces ownership
What Doesn't Change
- Encryption (AES-256-GCM) — already solid
- Usage tracking (
subscription_idsnapshots) — already per-subscription - Container injection flow — works, just needs scoped selection
- DB schema —
owner_idcolumn already exists, just underutilized
Acceptance Criteria
- Non-admin users can register their own subscriptions via API/MCP
- Users can only assign their own subscriptions to their own agents
- Auto-assignment on agent creation scopes to owner's subscriptions
- Rate-limit auto-switch scopes to owner's subscriptions
- Admin retains full access across all subscriptions
- Existing subscriptions continue working (backward compatible)
Labels
enhancement, security, subscriptions
Metadata
Metadata
Assignees
Labels
complexity-mediumComplexity: medium (board points 5-8)priority-p2Importantstatus-incubatingIdea under consideration — pre-Todo, not yet greenlit for developmenttheme-monetizationTheme: Monetizationtype-featureNew functionality
Activity