mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(router): enforce team scope for credential lookup
This commit is contained in:
parent
b473339ac0
commit
4dc7ca6ec3
2 changed files with 33 additions and 0 deletions
|
|
@ -9577,6 +9577,8 @@ class Router:
|
|||
"""
|
||||
# Try to get deployment by model_id first
|
||||
deployment = self.get_deployment(model_id=model_id)
|
||||
if deployment is not None and team_id is not None and not self._deployment_usable_by_team(deployment, team_id):
|
||||
deployment = None
|
||||
|
||||
# If not found, try by model_group_name
|
||||
if deployment is None:
|
||||
|
|
|
|||
|
|
@ -4739,6 +4739,37 @@ def test_get_deployment_credentials_with_provider_no_fallback_to_other_team_only
|
|||
)
|
||||
|
||||
|
||||
def test_get_deployment_credentials_with_provider_rejects_other_team_exact_id():
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "team-b-model",
|
||||
"litellm_params": {
|
||||
"model": "openai/gpt-5.2",
|
||||
"api_key": "team-b-key",
|
||||
},
|
||||
"model_info": {
|
||||
"id": "team-b-deployment",
|
||||
"team_id": "team-b",
|
||||
},
|
||||
},
|
||||
],
|
||||
)
|
||||
|
||||
owner_credentials = router.get_deployment_credentials_with_provider(
|
||||
model_id="team-b-deployment", team_id="team-b"
|
||||
)
|
||||
assert owner_credentials is not None
|
||||
assert owner_credentials["api_key"] == "team-b-key"
|
||||
|
||||
assert (
|
||||
router.get_deployment_credentials_with_provider(
|
||||
model_id="team-b-deployment", team_id="team-a"
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
def test_deployment_usable_by_team_helpers():
|
||||
"""
|
||||
Direct coverage of the team-ownership filter: a team-scoped deployment is
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue