mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

[BUG][AUTH]: UI/API Users with no admin privileges can no longer login

Open IuliaGaitan opened this issue 10 months ago • 3 comments

🐞 Bug Summary

Users with no admin privileges can no longer login


🧩 Affected Component

Select the area of the project impacted:

  • [x] mcpgateway - API
  • [x] mcpgateway - UI (admin panel)
  • [ ] mcpgateway.wrapper - stdio wrapper
  • [ ] Federation or Transports
  • [ ] CLI, Makefiles, or shell scripts
  • [ ] Container setup (Docker/Podman/Compose)
  • [ ] Other (explain below)

🔁 Steps to Reproduce

  1. Go to http://localhost:8000/admin/login
  2. Add an user email and password
  3. Click Sign In

🤔 Results

Users with no admin privileges can no longer login


Image Image Image

🤔 Expected Behavior

User should have the option to login and the user menu should be loaded successfully.


📓 Logs / Error Output

Paste any relevant stack traces or logs here. ⚠️ Do not paste secrets, credentials, or tokens.


🧠 Environment Info

You can retrieve most of this from the /version endpoint.

Key Value
Version or commit v0.128.0
Runtime Python 3.12.3
Platform / OS Linux 6.6.87.2-microsoft-standard-WSL2 (x86_64)
Container none

🧩 Additional Context (optional)

Related to #2390

IuliaGaitan avatar Jan 30 '26 15:01 IuliaGaitan

Root Cause Identified

The AdminAuthMiddleware added in commit a44ca2b5b (PR #2548 - "feat(auth): add token revocation and proxy auth to middleware") intentionally blocks ALL non-admin users from accessing any /admin/* routes.

Technical Details

Location: mcpgateway/main.py:1565-1567

if not user.is_admin:
    logger.warning(f"Admin access denied for non-admin user: {username}")
    return self._error_response(request, root_path, 403, "Admin privileges required", "admin_required")

The middleware only exempts:

  • /admin/login
  • /admin/logout
  • /admin/static

All other /admin/* routes return 403 Forbidden for non-admin users.

Breaking Change

Previous behavior: Non-admin users could access the admin dashboard with limited functionality. Template sections were hidden via {% if is_admin %} conditionals in admin.html.

Current behavior: Non-admin users are completely blocked from accessing the admin UI after login.

Possible Solutions

  1. Add dashboard to exempt paths: Add /admin/ (main dashboard) to EXEMPT_PATHS in AdminAuthMiddleware and continue relying on template-level access control for feature visibility

  2. Tiered permission system: Modify the middleware to allow authenticated users to access read-only views while restricting admin-specific actions

  3. Document as intended: If blocking non-admin users is the intended behavior, update documentation to clarify that all admin UI users must have is_admin=True

Related

This is related to issue #2390 (authentication testing) as mentioned in the bug report.

crivetimihai avatar Jan 31 '26 20:01 crivetimihai

This appears to be the same root cause as #2694 - newly created users don't have any roles assigned in the user_roles table, so they fail the admin.dashboard permission check when trying to access the Admin UI.

The login itself succeeds, but the redirect to /admin fails with 403 Forbidden because users without RBAC roles have no permissions.

Duplicate of #2694 - will be fixed when default role assignment is implemented.

crivetimihai avatar Feb 06 '26 14:02 crivetimihai

Canonical tracking issue is #2741 (same root cause as #2694). EmailAuthService.create_user() sets is_admin flag but never creates a user_roles entry, and the entire Admin UI uses allow_admin_bypass=False — so without an RBAC role assignment, all users (admin or not) get 403 on /admin/.

crivetimihai avatar Feb 07 '26 10:02 crivetimihai