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(scim): accept entitlements and roles entries without a value on SCIM user PUT
ryanb6410d563bd3
diff --git a/litellm/proxy/_lazy_openapi_snapshot.json b/litellm/proxy/_lazy_openapi_snapshot.jsonindex b244678e201..e889daf6c67 100644--- a/litellm/proxy/_lazy_openapi_snapshot.json+++ b/litellm/proxy/_lazy_openapi_snapshot.json@@ -38245,6 +38245,7 @@"type": "object"},"SCIMMultiValuedAttribute": {+ "additionalProperties": true,"properties": {"display": {"anyOf": [@@ -38280,13 +38281,17 @@"title": "Type"},"value": {- "title": "Value",- "type": "string"+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ],+ "title": "Value"}},- "required": [- "value"- ],"title": "SCIMMultiValuedAttribute","type": "object"},diff --git a/litellm/proxy/management_endpoints/scim/scim_v2.py b/litellm/proxy/management_endpoints/scim/scim_v2.pyindex 34c1ad42435..2b74dc1e838 100644--- a/litellm/proxy/management_endpoints/scim/scim_v2.py+++ b/litellm/proxy/management_endpoints/scim/scim_v2.py@@ -2107,7 +2107,7 @@ def _handle_multi_valued_attribute_update(path: str, op_type: str, value: objectexcept ValidationError:raise HTTPException(status_code=400,- detail={"error": f"Invalid value for {base}: expected a list of objects with a 'value' sub-attribute"},+ detail={"error": f"Invalid value for {base}: expected a list of objects or strings"},)dumped: Final = [attr.model_dump(exclude_none=True) for attr in attrs]diff --git a/litellm/types/proxy/management_endpoints/scim_v2.py b/litellm/types/proxy/management_endpoints/scim_v2.pyindex 61fd5c36b16..6f2c48ab283 100644--- a/litellm/types/proxy/management_endpoints/scim_v2.py+++ b/litellm/types/proxy/management_endpoints/scim_v2.py@@ -61,7 +61,9 @@ class SCIMUserGroup(BaseModel):class SCIMMultiValuedAttribute(BaseModel):- value: str+ model_config = ConfigDict(extra="allow")++ value: str | None = Nonedisplay: str | None = Nonetype: str | None = Noneprimary: bool | None = Nonediff --git a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_patch_user.py b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_patch_user.pyindex c3af4208d37..edcce16ab41 100644--- a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_patch_user.py+++ b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_patch_user.py@@ -422,7 +422,7 @@ def test_apply_patch_ops_invalid_entitlements_value_raises_400():patch_ops = SCIMPatchOp(Operations=[SCIMPatchOperation(- op="replace", path="entitlements", value=[{"display": "no value"}]+ op="replace", path="entitlements", value=[42])])@@ -433,6 +433,22 @@ def test_apply_patch_ops_invalid_entitlements_value_raises_400():assert exc_info.value.status_code == 400+def test_apply_patch_ops_replace_entitlements_without_value_member_is_stored_as_sent():+ patch_ops = SCIMPatchOp(+ Operations=[+ SCIMPatchOperation(+ op="replace", path="entitlements", value=[{"groups": ["S0506MKA55L"]}]+ )+ ]+ )++ update_data, _ = _apply_patch_ops(+ existing_user=_user_with_metadata({}), patch_ops=patch_ops+ )++ assert update_data["metadata"]["scim_entitlements"] == [{"groups": ["S0506MKA55L"]}]++def test_apply_patch_ops_add_without_value_raises_400_naming_value_member():patch_ops = SCIMPatchOp(Operations=[SCIMPatchOperation(op="add", path="entitlements")]diff --git a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.pyindex 364ec4aad61..6d85691d8ac 100644--- a/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py@@ -1,3 +1,4 @@+import jsonimport loggingimport timefrom collections.abc import Callable, Mapping, Sequence@@ -1303,6 +1304,77 @@ async def test_update_user_success(mocker):assert call_args[1]["data"]["teams"] == ["new-team"]+async def test_update_user_put_with_valueless_entitlements_deactivates_user(scim_test_client, mocker):+ """A suspend PUT whose entitlements entries carry no `value` member (an IdP-specific shape)+ must not be rejected by body validation: the user is deactivated and the entries are stored as sent"""+ existing_user = mocker.MagicMock()+ existing_user.teams = []+ existing_user.metadata = {"scim_active": True}++ updated_user = {+ "user_id": "suspend-me",+ "user_email": "[email protected]",+ "user_alias": None,+ "teams": [],+ "metadata": "{}",+ }+ response_scim_user = SCIMUser(+ schemas=["urn:ietf:params:scim:schemas:core:2.0:User"],+ id="suspend-me",+ userName="suspend-me",+ active=False,+ )++ mock_prisma_client = mocker.MagicMock()+ mock_prisma_client.db = mocker.MagicMock()+ mock_prisma_client.db.litellm_usertable = mocker.MagicMock()+ mock_prisma_client.db.litellm_usertable.update = AsyncMock(return_value=updated_user)++ mocker.patch( # test-quality-ok: endpoint collaborators are module-level, not injectable+ "litellm.proxy.management_endpoints.scim.scim_v2._get_prisma_client_or_raise_exception",+ AsyncMock(return_value=mock_prisma_client),+ )+ mocker.patch( # test-quality-ok: endpoint collaborators are module-level, not injectable+ "litellm.proxy.management_endpoints.scim.scim_v2._check_user_exists",+ AsyncMock(return_value=existing_user),+ )+ mocker.patch( # test-quality-ok: endpoint collaborators are module-level, not injectable+ "litellm.proxy.management_endpoints.scim.scim_v2._handle_team_membership_changes",+ AsyncMock(),+ )+ set_keys_blocked_mock = mocker.patch( # test-quality-ok: endpoint collaborators are module-level, not injectable+ "litellm.proxy.management_endpoints.scim.scim_v2._set_user_keys_blocked",+ AsyncMock(return_value=1),+ )+ mocker.patch( # test-quality-ok: endpoint collaborators are module-level, not injectable+ "litellm.proxy.management_endpoints.scim.scim_v2.ScimTransformations.transform_litellm_user_to_scim_user",+ AsyncMock(return_value=response_scim_user),+ )++ async with scim_test_client as client:+ response = await client.put(+ "/scim/v2/Users/suspend-me",+ json={+ "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],+ "userName": "suspend-me",+ "emails": [{"value": "[email protected]", "primary": True}],+ "entitlements": [{"groups": ["S0506MKA55L", "S0506MKA56M"]}],+ "roles": [{"display": "Viewer"}],+ "active": False,+ },+ )++ assert response.status_code == 200, response.text+ assert response.json()["active"] is False++ written_metadata = json.loads(mock_prisma_client.db.litellm_usertable.update.call_args.kwargs["data"]["metadata"])+ assert written_metadata["scim_active"] is False+ assert written_metadata["scim_entitlements"] == [{"groups": ["S0506MKA55L", "S0506MKA56M"]}]+ assert written_metadata["scim_roles"] == [{"display": "Viewer"}]+ set_keys_blocked_mock.assert_awaited_once_with(user_id="suspend-me", blocked=True)++@pytest.mark.asyncio@pytest.mark.parametrize("groups", [None, []], ids=["groups-omitted", "groups-empty"])async def test_update_user_without_groups_preserves_memberships_and_role(mocker, monkeypatch, groups):diff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.tsindex fd882937e79..4883611c3b1 100644--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts@@ -36612,7 +36612,9 @@ export interface components {/** Type */type?: string | null;/** Value */- value: string;+ value?: string | null;+ } & {+ [key: string]: unknown;};/** SCIMPatchOp */SCIMPatchOp: {