Skip to content

bug: Nevermined config returns 403 for shared (non-owner) users #72

Closed as not planned

Description

@vybe

Summary

The Nevermined payment configuration endpoints use can_user_share_agent (owner-only permission) for ALL operations, including viewing config. Users who have an agent shared with them get 403 on every request — the GET on page load, the POST to save, and all other operations. From the user's perspective, the Save button appears to do nothing (the error notification is easy to miss).

Component

Backend / Nevermined Router + Frontend / NeverminedPanel

Priority

P2 - Feature impaired for shared users, owner/admin can still configure.

Error

HTTP 403 {"detail":"Owner access required"}

All requests to /api/nevermined/agents/{name}/config return 403 for shared (non-owner) users.

Location

  • File: src/backend/routers/nevermined.py
  • Lines: 26-31
  • Function: _require_agent_access()

Root Cause

The _require_agent_access helper uses db.can_user_share_agent() which only allows owners and admins — it does NOT check if the agent is shared with the user. This is more restrictive than other agent endpoints.

For comparison:

  • Agent detail, logs, chat, terminal — use can_user_access_agent() (includes shared users) ✅
  • Agent sharing, rename — use can_user_share_agent() (owner-only) — appropriate for destructive ops ✅
  • Nevermined config (all ops) — uses can_user_share_agent() (owner-only) ❌ — too restrictive for viewing config

Additionally, the frontend NeverminedPanel.vue doesn't clearly communicate the 403 failure:

  • On page load, GET returns 403 → shows a brief "Failed to load Nevermined config" notification but still renders the empty form
  • On save, POST returns 403 → shows "Owner access required" notification, but user may miss it since the form stays unchanged

Reproduction Steps

  1. Create an agent as admin
  2. Share that agent with another user (email auth)
  3. Log in as the shared user
  4. Navigate to the agent's Payments tab
  5. Fill in all Nevermined fields (API Key, Agent ID, Plan ID)
  6. Click "Save Configuration"
  7. Nothing visibly happens — the request returns 403, a subtle notification appears briefly

Suggested Fix

Backend — Use appropriate permission levels in _require_agent_access:

# Option A: Allow shared users to view, only owners can modify
def _require_agent_access(agent_name: str, current_user: User, write: bool = False):
    """Verify the user has appropriate access to the agent."""
    if current_user.role == "admin":
        return
    if write:
        if not db.can_user_share_agent(current_user.username, agent_name):
            raise HTTPException(status_code=403, detail="Owner access required")
    else:
        if not db.can_user_access_agent(current_user.username, agent_name):
            raise HTTPException(status_code=403, detail="Access denied")

# Then use write=True for POST/PUT/DELETE, write=False for GET
# Option B: Simply allow all shared users (simpler)
def _require_agent_access(agent_name: str, current_user: User):
    if current_user.role == "admin":
        return
    if not db.can_user_access_agent(current_user.username, agent_name):
        raise HTTPException(status_code=403, detail="Access denied")

Frontend — Make 403 errors more visible in NeverminedPanel.vue:

// In loadConfig() catch block, show a persistent/clear message for 403
catch (err) {
    if (err.response?.status === 403) {
        permissionError.value = 'You need owner access to configure payments for this agent.'
    } else if (err.response?.status !== 404) {
        showNotification('Failed to load Nevermined config', 'error')
    }
    config.value = null
}

Environment

  • Trinity version: f50ee3e

Related

  • src/backend/routers/nevermined.py — all endpoints use _require_agent_access with owner-only check
  • src/backend/db/agents.py:278 — can_user_share_agent (owner-only)
  • src/backend/db/agents.py:114 — can_user_access_agent (includes shared users)
  • src/frontend/src/components/NeverminedPanel.vue — error handling in loadConfig() and saveConfig()

Activity

  1. AndriiPasternak31 commented on Mar 27, 2026

    @AndriiPasternak31
    Contributor

    This bug was already fixed in commit f1dfd7d (2026-03-05). The fix split Nevermined endpoint permissions into read/write access levels:

    • Backend: _require_read_access (GET endpoints) uses can_user_access_agent — allows shared users to view config and payment history. _require_write_access (POST/PUT/DELETE) uses can_user_share_agent — owner-only for modifications.
    • Frontend: NeverminedPanel.vue accepts canEdit prop, shows read-only notice banner for shared users, disables form inputs, and hides action buttons.
    • Tests: tests/test_nevermined_permissions.py covers owner CRUD, unauthenticated rejection, and nonexistent agent checks.
  2. AndriiPasternak31 commented on Mar 27, 2026

    @AndriiPasternak31
    Contributor

    This bug was already fixed in commit f1dfd7d (2026-03-05). The fix split Nevermined endpoint permissions into read/write access levels:

    • Backend: _require_read_access (GET endpoints) uses can_user_access_agent — allows shared users to view config and payment history. _require_write_access (POST/PUT/DELETE) uses can_user_share_agent — owner-only for modifications.
    • Frontend: NeverminedPanel.vue accepts canEdit prop, shows read-only notice banner for shared users, disables form inputs, and hides action buttons.
    • Tests: tests/test_nevermined_permissions.py covers owner CRUD, unauthenticated rejection, and nonexistent agent checks.

    This issue can be closed.

  3. added
    complexity-low
    theme-monetization
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-lowpriority-p2theme-monetizationtype-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions