fix(keys): use user-account budget as delegation ceiling for UI session personal keys - #33243
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR fixes a bug where a non-admin user creating a personal virtual key via the UI was incorrectly blocked because the delegation-authority ceiling was read from the UI session token's per-session chat spend cap (
Confidence Score: 4/5Safe to merge; the new code path is narrowly scoped to UI session tokens and fails closed on every error path. The No files require special attention beyond a quick sanity-check of
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/key_management_endpoints.py | Adds _resolve_delegation_ceiling to look up the caller's user-account budget when the token is a UI session token, rather than relying on the per-session chat cap; fails closed to the session cap if the user cannot be resolved. |
| tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py | Renames and updates the personal-key ceiling security test to reflect the new user-account ceiling; adds two new tests covering the within-budget success path and the fail-closed behavior when the user cannot be resolved. |
Reviews (1): Last reviewed commit: "fix(keys): use user-account budget as de..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Relevant issues
Fixes #33212
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
Repro against a live proxy (no LLM calls needed; this is a key-creation budget gate). Log in to the UI as a non-admin internal user whose account
max_budgetis $100, then create a personal key (no team) withmax_budget=4.Before this change the request is rejected with
max_budget (4.0) cannot exceed the caller's own max_budget (0.25), because the delegation ceiling was read from the UI session token's per-session chat cap (max_ui_session_budget, default $0.25) instead of the user account.After this change the same request succeeds, and a request above the user's account budget (e.g.
max_budget=500for a $100 account) is still rejected with a message naming the $100 ceiling.Type
🐛 Bug Fix
Changes
A non-admin user creating a personal virtual key through the UI was blocked by the delegated-authority ceiling (GHSA-q775-qw9r-2r4g). The UI authenticates with a session token whose
team_idislitellm-dashboardand whosemax_budgetismax_ui_session_budget(default $0.25); that value is a per-session chat spend cap, not the caller's real authority, but_common_key_generation_helperread it directly as the ceiling:The team-key path was already exempted in #29612, but personal keys kept using the $0.25 cap, so any personal-key
max_budgetabove $0.25 failed.This adds
_resolve_delegation_ceiling, which detects a UI session token (team_id == UI_SESSION_TOKEN_TEAM_ID) and resolves the ceiling from the caller's user-account budget viaget_user_objectrather than the session cap. If the user cannot be resolved it fails closed to the session cap, so a leaked session token still cannot mint an above-authority personal key. Every other caller keeps delegating from its ownmax_budget, falling back to the team budget for a CLI session token creating a team key, exactly as before.Net effect: a UI user with a $100 account can create a personal key up to $100 (the reported case with
max_budget=4now works), while requests above the account budget stay rejected.Final Attestation
Link to Devin session: https://app.devin.ai/sessions/451806c786fb4d76bdbb46e2c60d6c16