[Fix] UI - Allow Proxy Admin Viewer to access /api-keys page - #26690
[Fix] UI - Allow Proxy Admin Viewer to access /api-keys page#26690kimsehwan96 wants to merge 3 commits into
Conversation
The /api-keys page was hard-blocking proxy_admin_viewer at the user_dashboard entry point with an "Access Denied" screen, contradicting the role's own description ("view all keys, view all spend") in litellm/proxy/_types.py and the backend route_checks/admin_viewer_routes/key handler that already allow /key/list and /key/info for this role. Component-level guards (rolesWithWriteAccess in ui/litellm-dashboard/src/utils/roles.ts) already hide the Create / Edit / Delete affordances for this role, so removing the entry-level gate makes the UI consistent with the backend and with sibling viewer-open features (Audit Logs BerriAI#23419, Spend Logs BerriAI#26583).
Greptile SummaryThis PR removes a redundant frontend gate in Confidence Score: 5/5Safe to merge — change is a targeted UI gate removal backed by existing backend role checks and new test coverage. Only two small deletions and additive tests. Backend authorization for No files require special attention.
|
| Filename | Overview |
|---|---|
| ui/litellm-dashboard/src/components/user_dashboard.tsx | Removes the early-return "Access Denied" block for Admin Viewer role; the component now falls through to render the keys view for all authenticated roles. |
| ui/litellm-dashboard/src/app/page.tsx | Removes the Admin Viewer → "usage" page redirect from the JWT-decode useEffect; consistent with the gate removal so viewers land on whatever page they navigated to. |
| ui/litellm-dashboard/src/components/user_dashboard.test.tsx | Adds screen import and two role-based rendering tests verifying Admin Viewer and Admin both reach the keys table without an Access Denied screen; all networking mocked, no real calls. |
| ui/litellm-dashboard/e2e_tests/tests/proxy-admin-viewer/api-keys-access.spec.ts | New Playwright e2e spec verifying read-only access for proxy_admin_viewer: keys table visible, Create/Regenerate/Delete/Edit buttons hidden. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["User navigates to /ui?page=api-keys"] --> B["page.tsx: JWT decode useEffect"]
B -->|"Before PR: userRole == 'Admin Viewer'"| C["setPage('usage') — redirect away REMOVED"]
B -->|"After PR: all roles"| D["userRole set from token, page unchanged"]
D --> E["UserDashboard renders"]
E -->|"Before PR: userRole == 'Admin Viewer'"| F["Return Access Denied REMOVED"]
E -->|"After PR: all roles"| G["Render keys view"]
G --> H{"rolesWithWriteAccess check"}
H -->|"Admin Viewer"| I["VirtualKeysTable (read-only) - No Create / Edit / Delete / Regenerate buttons"]
H -->|"Admin / proxy_admin"| J["VirtualKeysTable + write affordances"]
Reviews (3): Last reviewed commit: "[Test] UI - Cover proxy_admin_viewer acc..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Removes the JWT-decode useEffect that overrode `?page=api-keys` to "usage" for Admin Viewer. Backend already allows /key/list and /key/info for this role.
vitest: assert UserDashboard renders the keys table for both Admin Viewer and proxy_admin (no Access Denied). e2e: viewer sees seeded keys (admin scope), Create button is hidden, key detail view loads without Regenerate / Delete / Edit.
72b4d2a to
e232c9e
Compare
|
Related changes are already merged with #26846. So I close this PR |
Relevant issues
Fixes #26689
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
AS-IS
TO-BE
Type
🐛 Bug Fix
Changes
Remove the entry-level "Access Denied" gate in ui/litellm-dashboard/src/components/user_dashboard.tsx that was hard-blocking proxy_admin_viewer from /ui/?page=api-keys.
The backend (admin_viewer_routes, route_checks, key handler) already allows /key/list and /key/info for this role, and component-level guards (rolesWithWriteAccess in ui/litellm-dashboard/src/utils/roles.ts) already hide Create / Edit / Delete affordances — so the gate was redundant and inconsistent with the role's documented intent.
There's a useEffect that was forcing page to "usage" for Admin Viewer right after JWT decode, so even if you went to /ui?page=api-keys it would silently rewrite the URL.
That was probably a workaround for the Access Denied screen (push viewers somewhere they can actually see something).
Now that the gate is gone, viewers can stay on the keys page in read-only mode, so the redirect isn't needed anymore. also the e2e below would fail without removing it.
Tests