Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions litellm/proxy/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,11 @@ class LiteLLMRoutes(enum.Enum):
"/tag/list",
"/audit",
"/audit/{id}",
"/spend/logs",
"/spend/logs/ui",
"/spend/logs/v2",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 /spend/logs/v2 missing from spend_tracking_routes

/spend/logs/v2 is added to admin_viewer_routes but its three sibling routes (/spend/logs, /spend/logs/ui, /spend/logs/session/ui) are already present in spend_tracking_routes, making them accessible to INTERNAL_USER and INTERNAL_USER_VIEW_ONLY roles as well. The new public-API endpoint /spend/logs/v2 shares the same handler as /spend/logs/ui but will be inaccessible to those roles, creating an inconsistency where the internal UI path works but the public API path does not for the same users. Consider adding /spend/logs/v2 to spend_tracking_routes for parity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 1c8901f

"/spend/logs/session/ui",
"/spend/logs/ui/{request_id}",
"/global/activity",
"/global/activity/model",
"/global/activity/cache_hits",
Expand Down
48 changes: 48 additions & 0 deletions tests/test_litellm/proxy/auth/test_route_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,54 @@ def test_proxy_admin_viewer_can_access_audit_logs(route):
)


@pytest.mark.parametrize(
"route",
[
"/spend/logs",
"/spend/logs/ui",
"/spend/logs/v2",
"/spend/logs/session/ui",
"/spend/logs/ui/some-request-id",
],
)
def test_proxy_admin_viewer_can_access_spend_logs(route):
"""
Test that proxy_admin_viewer can access /spend/logs endpoints.

The role description states "view all spend across the platform", so the
raw spend log endpoints (which back the admin Logs UI page) must be
reachable by proxy_admin_viewer.
"""

user_obj = LiteLLM_UserTable(
user_id="viewer_user",
user_email="viewer@example.com",
user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value,
)

valid_token = UserAPIKeyAuth(
user_id="viewer_user",
user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value,
)

request = MagicMock(spec=Request)
request.query_params = {}

try:
RouteChecks.non_proxy_admin_allowed_routes_check(
user_obj=user_obj,
_user_role=LitellmUserRoles.PROXY_ADMIN_VIEW_ONLY.value,
route=route,
request=request,
valid_token=valid_token,
request_data={},
)
except Exception as e:
pytest.fail(
f"proxy_admin_viewer should be able to access {route} route. Got error: {str(e)}"
)


class TestModelsRouteExemptFromDisableLLMEndpoints:
"""
Test that /models and /v1/models are exempt from DISABLE_LLM_API_ENDPOINTS.
Expand Down
Loading