The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(auth): preserve scope-admin email policy during status lookup
Joshua Valluru124196cbaa68
diff --git a/litellm/proxy/auth/handle_jwt.py b/litellm/proxy/auth/handle_jwt.pyindex d621bc634e6..996911cdfaa 100644--- a/litellm/proxy/auth/handle_jwt.py+++ b/litellm/proxy/auth/handle_jwt.py@@ -2463,12 +2463,27 @@ class JWTAuthManager:proxy_logging_obj=proxy_logging_obj,team_id_upsert=team_id_upsert,)- if provisioning is None or prisma_client is not None:+ if provisioning is None:identity: Final = await JWTAuthManager._resolve_claim_identity(jwt_valid_token, handler, prisma_client, user_api_key_cache, parent_otel_span, proxy_logging_obj)return {**admin_result, "user_object": identity.user_object}- return admin_result+ if prisma_client is None:+ return admin_result+ try:+ admin_user: Final = await get_user_object(+ user_id=user_id,+ user_email=user_email,+ sso_user_id=user_id,+ prisma_client=prisma_client,+ user_api_key_cache=user_api_key_cache,+ user_id_upsert=False,+ parent_otel_span=parent_otel_span,+ proxy_logging_obj=proxy_logging_obj,+ )+ except UserNotFoundError:+ return admin_result+ return {**admin_result, "user_object": admin_user}# Get team with model access## Check if team_id is specified via x-litellm-team-id headerdiff --git a/tests/test_litellm/proxy/auth/test_handle_jwt.py b/tests/test_litellm/proxy/auth/test_handle_jwt.pyindex 232884d89fa..e768139f04a 100644--- a/tests/test_litellm/proxy/auth/test_handle_jwt.py+++ b/tests/test_litellm/proxy/auth/test_handle_jwt.py@@ -7149,16 +7149,17 @@ async def test_admin_jwt_team_header_only_provisions_during_admission(monkeypatc@pytest.mark.asyncio@pytest.mark.parametrize("existing_user", [False, True])@pytest.mark.parametrize("warm_cache", [False, True])async def test_scope_admin_admission_resolves_existing_user_without_provisioning(- monkeypatch: pytest.MonkeyPatch, existing_user: bool, warm_cache: bool+ monkeypatch: pytest.MonkeyPatch, existing_user: bool, warm_cache: bool, email: str | None) -> None:from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCacheprivate_key, jwk = _get_rsa_key_and_jwk("admin-status")cache: Final = UserApiKeyCache()cache.set_cache("litellm_jwt_auth_keys_https://admin.example/jwks", [jwk])- user_id: Final = f"admin-status-{existing_user}-{warm_cache}"- user: Final = LiteLLM_UserTable(user_id=user_id, metadata={"scim_active": False}, organization_memberships=[])+ user_id: Final = f"admin-status-{existing_user}-{warm_cache}-{email}"+ user: Final = LiteLLM_UserTable(user_id=user_id, user_email="[email protected]", metadata={"scim_active": False}, organization_memberships=[])if existing_user and warm_cache:cache.set_cache(user_id, user)database: Final = MagicMock()@@ -7170,14 +7171,17 @@ async def test_scope_admin_admission_resolves_existing_user_without_provisioninghandler.update_environment(prisma_client=database,user_api_key_cache=cache,- litellm_jwtauth=LiteLLM_JWTAuth(user_id_jwt_field="sub", user_id_upsert=True),+ litellm_jwtauth=LiteLLM_JWTAuth(+ user_id_jwt_field="sub", user_id_upsert=True, user_email_jwt_field="email",+ user_allowed_email_domain="allowed.example",+ ),)monkeypatch.setenv("JWT_PUBLIC_KEY_URL", "https://admin.example/jwks")monkeypatch.setenv("JWT_ISSUER", "https://admin.example")monkeypatch.setenv("JWT_AUDIENCE", "gateway")token: Final = _encode_rsa_jwt(private_key, "https://admin.example", "gateway", "admin-status",- {"sub": user_id, "scope": "litellm_proxy_admin"},+ {"sub": user_id, "scope": "litellm_proxy_admin", **({"email": email} if email else {})},)result: Final = await JWTAuthManager.auth_builder(api_key=token, jwt_handler=handler, prisma_client=database, user_api_key_cache=cache,@@ -7187,3 +7191,5 @@ async def test_scope_admin_admission_resolves_existing_user_without_provisioningassert result["user_id"] == user_idassert result["user_object"] == (user if existing_user else None)users.create.assert_not_awaited()+ if existing_user:+ assert users.find_unique.await_count == (0 if warm_cache else 1)