fix: Add PROXY_ADMIN role to system user for key rotation#21896
fix: Add PROXY_ADMIN role to system user for key rotation#21896milan-berri wants to merge 1 commit intoBerriAI:mainfrom
Conversation
The key rotation worker was failing with 'You are not authorized to regenerate this key' when rotating team keys. This was because the system user created by get_litellm_internal_jobs_user_api_key_auth() was missing the user_role field. Without user_role=PROXY_ADMIN, the system user couldn't bypass team permission checks in can_team_member_execute_key_management_endpoint(), causing authorization failures for team key rotation. This fix adds user_role=LitellmUserRoles.PROXY_ADMIN to the system user, allowing it to bypass team permission checks and successfully rotate keys for all teams.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes an authorization bug where the automated key rotation worker failed to rotate team keys because the system user ( The fix is a single-line addition that correctly assigns
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/_types.py | Adds user_role=LitellmUserRoles.PROXY_ADMIN to the internal jobs system user so the key rotation worker can bypass team permission checks. The fix is correct and minimal — no missing test is the only concern. |
Sequence Diagram
sequenceDiagram
participant KRM as KeyRotationManager
participant Types as UserAPIKeyAuth
participant RKF as regenerate_key_fn
participant TMPC as TeamMemberPermissionChecks
participant CMVT as can_modify_verification_token
KRM->>Types: get_litellm_internal_jobs_user_api_key_auth()
Types-->>KRM: system_user (user_role=PROXY_ADMIN)
KRM->>RKF: regenerate_key_fn(data, system_user)
RKF->>TMPC: can_team_member_execute_key_management_endpoint(system_user)
Note over TMPC: Check user_role == PROXY_ADMIN ✅<br/>(Previously failed: user_role was None)
TMPC-->>RKF: Authorized (bypass)
RKF->>CMVT: can_modify_verification_token(system_user)
Note over CMVT: Check user_role == PROXY_ADMIN ✅<br/>(Also checks api_key fallback)
CMVT-->>RKF: Authorized
RKF-->>KRM: GenerateKeyResponse (new key)
Last reviewed commit: 0212275
| key_alias=LITELLM_INTERNAL_JOBS_SERVICE_ACCOUNT_NAME, | ||
| team_alias="system", | ||
| user_id="system", | ||
| user_role=LitellmUserRoles.PROXY_ADMIN, |
There was a problem hiding this comment.
Missing unit test for this change
The PR checklist states "Adding at least 1 test is a hard requirement," but no tests were added. A simple test in tests/test_litellm/proxy/ that asserts the system user returned by get_litellm_internal_jobs_user_api_key_auth() has user_role == LitellmUserRoles.PROXY_ADMIN would serve as a regression test and satisfy this requirement. For example:
from litellm.proxy._types import UserAPIKeyAuth, LitellmUserRoles
def test_internal_jobs_user_has_proxy_admin_role():
system_user = UserAPIKeyAuth.get_litellm_internal_jobs_user_api_key_auth()
assert system_user.user_role == LitellmUserRoles.PROXY_ADMINContext Used: Rule from dashboard - What: Ensure that any PR claiming to fix an issue includes evidence that the issue is resolved, such... (source)
Fixes key rotation authorization issue for team keys
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/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 reviewCI (LiteLLM team)
Type
🐛 Bug Fix
Changes
Problem
The key rotation worker fails with authorization error when attempting to rotate team keys:
Root Cause
The system user created by
UserAPIKeyAuth.get_litellm_internal_jobs_user_api_key_auth()was missing theuser_rolefield. Withoutuser_role=PROXY_ADMIN, the system user couldn't bypass team permission checks incan_team_member_execute_key_management_endpoint(), causing authorization failures.Solution
Added
user_role=LitellmUserRoles.PROXY_ADMINto the system user inlitellm/proxy/_types.py. This allows the internal key rotation worker to bypass team permission checks and successfully rotate keys for all teams.Reproduction Steps
Enable key rotation:
Create a team key with auto-rotation:
Wait for rotation worker to run → observe authorization error
Files Modified
litellm/proxy/_types.py: Addeduser_role=LitellmUserRoles.PROXY_ADMINto system user (1 line change)Impact