diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.py index 11f616a5e18..0e7a379b60c 100644 --- a/litellm/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/proxy/management_endpoints/model_management_endpoints.py @@ -1319,6 +1319,19 @@ async def patch_model( param=None, ) + # Pause/resume (`blocked`) is a proxy-admin-only privilege. Refuse it + # before the member write-authorization check so a team member (or + # team/org admin) patching only the blocked flag gets this documented + # refusal instead of the auto-router membership refusal the member + # write path raises for bodies without auto-router permissions. + if patch_data.blocked is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: + raise ProxyException( + message="Only proxy admins can change a model's blocked flag.", + type=ProxyErrorTypes.auth_error.value, + code=status.HTTP_403_FORBIDDEN, + param="blocked", + ) + write_authorization: Final = await ModelManagementAuthChecks.can_user_make_model_call( model_params=db_model, user_api_key_dict=user_api_key_dict, @@ -1355,17 +1368,6 @@ async def patch_model( else patch_data ) - # Pause/resume (`blocked`) is a proxy-admin-only privilege. Team admins - # passed the auth check above for team-scoped models, but they must not - # be able to unblock (or block) a model their proxy admin has paused. - if patch_data.blocked is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: - raise ProxyException( - message="Only proxy admins can change a model's blocked flag.", - type=ProxyErrorTypes.auth_error.value, - code=status.HTTP_403_FORBIDDEN, - param="blocked", - ) - ModelManagementAuthChecks.can_user_attach_credential( litellm_params=patch_data.litellm_params, user_api_key_dict=user_api_key_dict, diff --git a/tests/integration/authorization/test_team_admin_gate.py b/tests/integration/authorization/test_team_admin_gate.py index a7513277609..567cae0b9e0 100644 --- a/tests/integration/authorization/test_team_admin_gate.py +++ b/tests/integration/authorization/test_team_admin_gate.py @@ -851,10 +851,6 @@ def test_only_proxy_admin_reads_or_changes_credentials( def test_non_team_admin_patching_the_blocked_flag_gets_the_blocked_flag_refusal( request: pytest.FixtureRequest, fixture: str, caller: Caller ) -> None: - pytest.skip( - 'BUG: PATCH /model/{id}/update {"blocked": ...} by a non-team-admin returns the auto-router refusal ' - "instead of the blocked-flag refusal (https://github.com/BerriAI/litellm/issues/44792)" - ) with gateway_from_environment() as gateway, gateway.scenario() as scenario: s: Final = _admin_only_team(request, fixture, scenario) model_id, _ = _team_model(s) diff --git a/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py b/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py index 303b8e060ed..a2b0db4d57d 100644 --- a/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py +++ b/tests/unit/proxy/management_endpoints/test_model_management_endpoints.py @@ -5205,6 +5205,9 @@ class TestPatchModelBlockedAuthGate: mock_prisma.db.litellm_proxymodeltable.find_unique = AsyncMock( return_value=existing_row ) + write_authorization = AsyncMock( + side_effect=AssertionError("blocked changes must be refused before member write authorization") + ) with ( patch("litellm.proxy.proxy_server.prisma_client", mock_prisma), @@ -5213,7 +5216,7 @@ class TestPatchModelBlockedAuthGate: patch("litellm.proxy.proxy_server.premium_user", True), patch( "litellm.proxy.management_endpoints.model_management_endpoints.ModelManagementAuthChecks.can_user_make_model_call", - new=AsyncMock(return_value=None), + new=write_authorization, ), ): with pytest.raises(Exception, match="Only proxy admins can change a model's blocked flag\\.") as exc_info: @@ -5225,6 +5228,7 @@ class TestPatchModelBlockedAuthGate: err = exc_info.value assert getattr(err, "param", "") == "blocked" assert "proxy admin" in getattr(err, "message", "").lower() + write_authorization.assert_not_awaited() @pytest.mark.asyncio async def test_proxy_admin_can_toggle_blocked(self):