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): address CI regressions from centralization
usere0a9c193f892
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.pyindex 8ef3d59043c..85e539fdd06 100644--- a/litellm/proxy/auth/user_api_key_auth.py+++ b/litellm/proxy/auth/user_api_key_auth.py@@ -1554,9 +1554,9 @@ async def _safe_fetch(label: str, awaitable):def _team_obj_from_token(valid_token: UserAPIKeyAuth) -> LiteLLM_TeamTableCachedObj:"""Reconstruct a cached team object from the fields already on the- UserAPIKeyAuth. Used as a last resort when the team DB row can't be- fetched (e.g. outage) — enforcement still runs against the token's- own team_* fields."""+ UserAPIKeyAuth. Only called when valid_token.team_id is known to be+ non-None (the caller gates on it)."""+ assert valid_token.team_id is not Nonereturn LiteLLM_TeamTableCachedObj(team_id=valid_token.team_id,max_budget=valid_token.team_max_budget,@@ -1603,12 +1603,17 @@ async def _run_centralized_common_checks(user_custom_auth,)- # master_key unset = no-auth dev mode. The builder returns an- # INTERNAL_USER token for any api_key and the proxy is- # unauthenticated by configuration; running common_checks would- # block every admin route on these deployments where that was- # previously not the contract.- if master_key is None:+ # No-auth dev mode: master_key unset AND no JWT/OAuth2 auth+ # configured. The builder returns an INTERNAL_USER token for any+ # api_key; the proxy is unauthenticated by configuration.+ # Running common_checks would block every admin route on these+ # deployments where that was previously not the contract. If any+ # authn is enabled (JWT, OAuth2, OAuth2-proxy), authz must run.+ if master_key is None and not (+ general_settings.get("enable_jwt_auth", False)+ or general_settings.get("enable_oauth2_auth", False)+ or general_settings.get("enable_oauth2_proxy_auth", False)+ ):returnif user_custom_auth is not None and not general_settings.get(diff --git a/litellm/proxy/db/exception_handler.py b/litellm/proxy/db/exception_handler.pyindex 9e3f43c9b5f..cfa90a48eee 100644--- a/litellm/proxy/db/exception_handler.py+++ b/litellm/proxy/db/exception_handler.py@@ -31,12 +31,35 @@ class PrismaDBExceptionHandler:@staticmethoddef is_database_connection_error(e: Exception) -> bool:- """Connectivity failures + the ``no_db_connection`` marker only.- Data-layer errors (``UniqueViolationError``, etc.) must NOT match- — matching them would route non-outage exceptions into the HA- fallback and the authentication bypass it grants.+ """True iff the exception is (or could be) a DB-connectivity+ failure, i.e. something that justifies the+ ``allow_requests_on_db_unavailable`` HA fallback.++ Known data-layer PrismaError subclasses (``UniqueViolationError``,+ ``RecordNotFoundError``, etc.) are explicitly excluded — the DB IS+ reachable, so a fallback that grants an anonymous token would be+ an auth bypass. Unknown / bare ``PrismaError`` instances default+ to True so genuine outages that don't match a specific subclass+ still trigger the fallback."""- if PrismaDBExceptionHandler.is_database_transport_error(e):+ import prisma++ # Explicit data-layer exclusion: DB IS reachable, fallback must+ # NOT fire.+ data_layer_errors = (+ prisma.errors.DataError,+ prisma.errors.UniqueViolationError,+ prisma.errors.ForeignKeyViolationError,+ prisma.errors.MissingRequiredValueError,+ prisma.errors.RawQueryError,+ prisma.errors.TableNotFoundError,+ prisma.errors.RecordNotFoundError,+ )+ if isinstance(e, data_layer_errors):+ return False+ if isinstance(e, DB_CONNECTION_ERROR_TYPES):+ return True+ if isinstance(e, prisma.errors.PrismaError):return Trueif isinstance(e, ProxyException) and e.type == ProxyErrorTypes.no_db_connection:return Truediff --git a/tests/test_litellm/proxy/auth/test_auth_exception_handler.py b/tests/test_litellm/proxy/auth/test_auth_exception_handler.pyindex 54b8c4b53d2..2d1586f0b17 100644--- a/tests/test_litellm/proxy/auth/test_auth_exception_handler.py+++ b/tests/test_litellm/proxy/auth/test_auth_exception_handler.py@@ -33,12 +33,17 @@ from litellm.proxy.auth.auth_exception_handler import UserAPIKeyAuthExceptionHan@pytest.mark.parametrize("prisma_error",[+ # Specific connectivity subclasses.HTTPClientClosedError(),ClientNotConnectedError(),+ # Bare / generic PrismaError defaults to connectivity — we can't+ # tell what it is, so err on the safe side for genuine outages.+ PrismaError(),],)async def test_handle_authentication_error_db_unavailable_connectivity(prisma_error):- """Transport-level / connectivity failures trigger the HA fallback."""+ """Transport-level / connectivity failures (and generic PrismaError)+ trigger the HA fallback."""handler = UserAPIKeyAuthExceptionHandler()mock_request = MagicMock()@@ -62,7 +67,6 @@ async def test_handle_authentication_error_db_unavailable_connectivity(prisma_er@pytest.mark.parametrize("prisma_error",[- PrismaError(),DataError(data={"user_facing_error": {"meta": {"table": "test_table"}}}),UniqueViolationError(data={"user_facing_error": {"meta": {"table": "test_table"}}}@@ -85,10 +89,11 @@ async def test_handle_authentication_error_db_unavailable_connectivity(prisma_erasync def test_handle_authentication_error_data_layer_errors_do_not_fall_back(prisma_error,):- """Data-layer PrismaError subclasses (UniqueViolation, RecordNotFound,- etc.) mean the DB IS reachable — they must propagate instead of- triggering the HA fallback, which would grant the restricted- INTERNAL_USER token to a request that should have returned 401."""+ """Known data-layer PrismaError subclasses (UniqueViolation,+ RecordNotFound, etc.) mean the DB IS reachable — they must propagate+ instead of triggering the HA fallback, which would grant the+ restricted INTERNAL_USER token to a request that should have+ returned 401."""handler = UserAPIKeyAuthExceptionHandler()mock_request = MagicMock()