Skip to content
Merged
82 changes: 67 additions & 15 deletions litellm/proxy/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,21 +724,73 @@ class LiteLLMRoutes(enum.Enum):
"/organization/member_delete",
]

# Routes accessible by Admin Viewer (read-only admin access)
admin_viewer_routes = [
"/user/list",
"/user/available_users",
"/user/available_roles",
"/user/daily/activity",
"/team/daily/activity",
"/tag/daily/activity",
"/tag/list",
"/audit",
"/audit/{id}",
"/global/activity",
"/global/activity/model",
"/global/activity/cache_hits",
] + info_routes
# Routes accessible by Admin Viewer (read-only admin access).
#
# Admin Viewer follows a read-parity-with-Proxy-Admin rule: anything Proxy
# Admin can read/list/get, Admin Viewer can too (no writes, no cost-incurring
# actions).
#
# NOTE: This list is no longer the primary mechanism for granting access —
# `_check_proxy_admin_viewer_access()` in route_checks.py default-allows
# any safe HTTP method (GET/HEAD/OPTIONS) on non-inference routes. This
# list now matters only for non-GET routes that are semantically reads
# (e.g. POST /spend/calculate). Adding a new GET endpoint does not require
# updating this list — the default-allow behavior covers it automatically.
admin_viewer_routes = (
[
"/user/list",
"/user/available_users",
"/user/available_roles",
"/user/daily/activity",
"/team/daily/activity",
"/tag/daily/activity",
"/tag/list",
"/audit",
"/audit/{id}",
"/global/activity",
"/global/activity/model",
"/global/activity/cache_hits",
# Customer / end-user listing (handlers already gate on
# PROXY_ADMIN_VIEW_ONLY — the route gate must match).
"/customer/list",
"/customer/info",
# UI Logs page detail drawer (single + session). The list endpoint
# `/spend/logs/ui` is covered via spend_tracking_routes below.
"/spend/logs/ui/{logId}",
"/spend/logs/session/ui",
# Settings / observability read endpoints exposed in admin-only
# sidebar groups (Logging & Alerts, Admin Settings, Budgets,
# Invitations).
"/callbacks/list",
"/callbacks/configs",
"/get/config/callbacks",

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.

High: Secrets exposure to read-only admin role

The /get/config/callbacks handler (proxy_server.py ~line 13282) has no handler-level role check and returns decrypted values of LANGFUSE_SECRET_KEY, AWS_SECRET_ACCESS_KEY, SMTP_PASSWORD, SLACK_WEBHOOK_URL, and other integration secrets. By adding this route to admin_viewer_routes, any PROXY_ADMIN_VIEW_ONLY user can now retrieve these secrets.

The other two callback routes (/callbacks/list, /callbacks/configs) are safe — they return only callback names and static schema. Consider removing /get/config/callbacks from this list, or adding a _user_has_admin_view guard inside the handler that redacts secret values for the view-only role.

"/alerting/settings",
"/config/list",
"/config/field/info",
"/budget/list",
"/budget/settings",
# Invitation viewing (admin viewer cannot create/delete; can read).
"/invitation/info",
# Guardrails / Policies pages (read-only views).
"/guardrails/list",
"/v2/guardrails/list",
"/guardrails/submissions",
"/guardrails/submissions/{guardrail_id}",
"/guardrails/usage/overview",
"/policies/attachments/list",
# MCP semantic filter settings (read).
"/get/mcp_semantic_filter_settings",
# Model cost map maintenance views (read-only status / source).
"/schedule/model_cost_map_reload/status",
"/model/cost_map/source",
]
# Spend tracking reads (/spend/logs, /spend/logs/ui, /spend/keys,
# /spend/users, /spend/tags, /spend/calculate, /cost/estimate). Admin
# Viewer can already read /global/spend/* via global_spend_tracking_routes;
# the per-tenant /spend/* views were the missing peer.
+ spend_tracking_routes
+ info_routes
)

# All routes accesible by an Org Admin
org_admin_allowed_routes = (
Expand Down
160 changes: 104 additions & 56 deletions litellm/proxy/auth/route_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def non_proxy_admin_allowed_routes_check(
route=route,
_user_role=_user_role,
request_data=request_data,
request=request,
)
elif (
_user_role == LitellmUserRoles.INTERNAL_USER.value
Expand Down Expand Up @@ -596,80 +597,127 @@ def is_generate_content_route(route: str) -> bool:
return True
return False

# HTTP methods that are intrinsically read-only and therefore safe to
# default-allow for PROXY_ADMIN_VIEW_ONLY. Anything else (POST/PUT/PATCH/
# DELETE) is treated as a write attempt and goes through the explicit
# write-allowlist below.
_SAFE_HTTP_METHODS = frozenset({"GET", "HEAD", "OPTIONS"})

# Explicit write routes that PROXY_ADMIN_VIEW_ONLY must NEVER call. The
# role-principle is "no writes, ever" — the management_routes list is the
# authoritative source for which non-llm routes are writes; we just need
# to filter out the read endpoints (info / list) that share the prefix.
# A cleaner approach is to denylist by HTTP verb (POST/PUT/PATCH/DELETE);
# this block stays as a backstop in case a write is implemented as GET.
_ADMIN_VIEWER_BLOCKED_WRITE_ROUTES = frozenset(
[
"/user/new",
"/user/delete",
"/user/bulk_update",
"/team/new",
"/team/update",
"/team/delete",
"/model/new",
"/model/update",
"/model/delete",
"/key/generate",
"/key/delete",
"/key/update",
"/key/regenerate",
"/key/service-account/generate",
"/key/block",
"/key/unblock",
]
)

@staticmethod
def _check_proxy_admin_viewer_access(
route: str,
_user_role: str,
request_data: dict,
request: Optional[Request] = None,
) -> None:
"""
Check access for PROXY_ADMIN_VIEW_ONLY role
Check access for PROXY_ADMIN_VIEW_ONLY role.

Admin Viewer follows a read-parity-with-Proxy-Admin rule: anything Proxy
Admin can read/list/get, Admin Viewer can read/list/get. The only
exclusions are cost-incurring inference routes (Playground, /chat/
completions, etc.) and any state-mutating request.

Implementation:
1. LLM/inference routes → 403 (cost-incurring).
2. Safe HTTP method (GET/HEAD/OPTIONS) → allow by default. This is
the read-parity guarantee — every new GET endpoint added anywhere
in the codebase is automatically readable by Admin Viewer
without needing to remember to add it to an allowlist.
3. Unsafe HTTP method (POST/PUT/PATCH/DELETE):
- Allow `/user/update` only when restricted to user_email/password.
- Block all explicit writes in `_ADMIN_VIEWER_BLOCKED_WRITE_ROUTES`.
- Otherwise allow only if the route is in admin_viewer_routes /
global_spend_tracking_routes (legacy explicit-allow set).
- Else 403.
"""
if RouteChecks.is_llm_api_route(route=route):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=f"user not allowed to access this OpenAI routes, role= {_user_role}",
)

# Check if this is a write operation on management routes
if RouteChecks.check_route_access(
route=route, allowed_routes=LiteLLMRoutes.management_routes.value
):
# For management routes, only allow read operations or specific allowed updates
if route == "/user/update":
# Check the Request params are valid for PROXY_ADMIN_VIEW_ONLY
if request_data is not None and isinstance(request_data, dict):
_params_updated = request_data.keys()
for param in _params_updated:
if param not in ["user_email", "password"]:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=f"user not allowed to access this route, role= {_user_role}. Trying to access: {route} and updating invalid param: {param}. only user_email and password can be updated",
)
elif (
route
in [
"/user/new",
"/user/delete",
"/user/bulk_update",
"/team/new",
"/team/update",
"/team/delete",
"/model/new",
"/model/update",
"/model/delete",
"/key/generate",
"/key/delete",
"/key/update",
"/key/regenerate",
"/key/service-account/generate",
"/key/block",
"/key/unblock",
]
or route.startswith("/key/")
and route.endswith("/regenerate")
):
# Block write operations for PROXY_ADMIN_VIEW_ONLY
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=f"user not allowed to access this route, role= {_user_role}. Trying to access: {route}",
)
# Allow read operations on management routes (like /user/info, /team/info, /model/info)
method = request.method.upper() if request is not None else "GET"
is_safe_method = method in RouteChecks._SAFE_HTTP_METHODS

# ── Safe HTTP method: default-allow ──────────────────────────────
if is_safe_method:
return
elif RouteChecks.check_route_access(
route=route, allowed_routes=LiteLLMRoutes.admin_viewer_routes.value
):
# Allow access to admin viewer routes (read-only admin endpoints)

# ── Unsafe HTTP method: explicit checks ──────────────────────────
# Allow `/user/update` for self-service email / password change.
if route == "/user/update":
if request_data is not None and isinstance(request_data, dict):
for param in request_data.keys():
if param not in ["user_email", "password"]:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=(
f"user not allowed to access this route, role= {_user_role}. "
f"Trying to access: {route} and updating invalid param: {param}. "
"only user_email and password can be updated"
),
)
return
elif RouteChecks.check_route_access(
route=route, allowed_routes=LiteLLMRoutes.global_spend_tracking_routes.value

# Hard-block known write routes regardless of HTTP method (defensive
# — these are POSTs in practice, but pinning them here protects
# against future GET-shaped writes).
if route in RouteChecks._ADMIN_VIEWER_BLOCKED_WRITE_ROUTES or (
route.startswith("/key/") and route.endswith("/regenerate")
):
# Allow access to global spend tracking routes (read-only spend endpoints)
# proxy_admin_viewer role description: "view all keys, view all spend"
return
else:
# For other routes, block access
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=f"user not allowed to access this route, role= {_user_role}. Trying to access: {route}",
)

# Legacy explicit-allow sets (kept for routes that are POST but
# semantically read-only, e.g. /spend/calculate). Both admin_viewer_routes
# and global_spend_tracking_routes are reads/listings.
if RouteChecks.check_route_access(
route=route, allowed_routes=LiteLLMRoutes.admin_viewer_routes.value
):
return
if RouteChecks.check_route_access(
route=route, allowed_routes=LiteLLMRoutes.global_spend_tracking_routes.value
):
return

# NOTE: We intentionally do NOT fall back to allowing all
# `management_routes`. That set is a mix of reads (info/list — handled
# via the safe-method branch above) and writes (`/team/block`,
# `/team/permissions_update`, `/jwt/key/mapping/{new,update,delete}`,
# `/key/bulk_update`, `/key/{id}/reset_spend`). A blanket allow would
# let Admin Viewer POST these write endpoints — violating the
# "no writes, ever" rule. Default-deny instead.
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=f"user not allowed to access this route, role= {_user_role}. Trying to access: {route}",
)
6 changes: 5 additions & 1 deletion litellm/proxy/guardrails/guardrail_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.management_endpoints.common_utils import _user_has_admin_view
from litellm.proxy.guardrails.guardrail_hooks.custom_code.sandbox import (
build_sandbox_globals,
compile_sandboxed,
Expand Down Expand Up @@ -842,7 +843,10 @@ async def list_guardrail_submissions(
if prisma_client is None:
raise HTTPException(status_code=500, detail="Prisma client not initialized")

is_admin = user_api_key_dict.user_role == LitellmUserRoles.PROXY_ADMIN
# Admin Viewer follows the read-parity rule: see all submissions like a
# Proxy Admin would (no writes — registration / approval still gated
# elsewhere by their own per-action checks).
is_admin = _user_has_admin_view(user_api_key_dict)
visible_team_ids: Optional[List[str]] = None
if not is_admin:
visible_team_ids = await _get_user_team_ids(user_api_key_dict)
Expand Down
15 changes: 13 additions & 2 deletions litellm/proxy/management_endpoints/access_group_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def _require_proxy_admin(user_api_key_dict: UserAPIKeyAuth) -> None:
)


def _require_admin_view(user_api_key_dict: UserAPIKeyAuth) -> None:
"""Admin Viewer parity: PROXY_ADMIN or PROXY_ADMIN_VIEW_ONLY may read."""
from litellm.proxy.management_endpoints.common_utils import _user_has_admin_view

if not _user_has_admin_view(user_api_key_dict):
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail={"error": CommonProxyErrors.not_allowed_access.value},
)


def _record_to_response(record) -> AccessGroupResponse:
return AccessGroupResponse(
access_group_id=record.access_group_id,
Expand Down Expand Up @@ -370,7 +381,7 @@ async def create_access_group(
async def list_access_groups(
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
) -> List[AccessGroupResponse]:
_require_proxy_admin(user_api_key_dict)
_require_admin_view(user_api_key_dict)
prisma_client = get_prisma_client_or_throw(
CommonProxyErrors.db_not_connected_error.value
)
Expand All @@ -389,7 +400,7 @@ async def get_access_group(
access_group_id: str,
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
) -> AccessGroupResponse:
_require_proxy_admin(user_api_key_dict)
_require_admin_view(user_api_key_dict)
prisma_client = get_prisma_client_or_throw(
CommonProxyErrors.db_not_connected_error.value
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from litellm.proxy.common_utils.timezone_utils import get_budget_reset_time
from litellm.proxy._types import *
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.management_endpoints.common_utils import _user_has_admin_view
from litellm.proxy.utils import jsonify_object

router = APIRouter()
Expand Down Expand Up @@ -238,7 +239,7 @@ async def budget_settings(
detail={"error": CommonProxyErrors.db_not_connected_error.value},
)

if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:
if not _user_has_admin_view(user_api_key_dict):
raise HTTPException(
status_code=400,
detail={
Expand Down Expand Up @@ -305,7 +306,7 @@ async def list_budget(
detail={"error": CommonProxyErrors.db_not_connected_error.value},
)

if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:
if not _user_has_admin_view(user_api_key_dict):
raise HTTPException(
status_code=400,
detail={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,11 @@ async def get_hashicorp_vault_config(
Get current Hashicorp Vault configuration.
Returns decrypted values from DB, or falls back to current env vars.
"""
from litellm.proxy.management_endpoints.common_utils import _user_has_admin_view
from litellm.proxy.proxy_server import prisma_client, proxy_config

if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN:
# Admin Viewer follows the read-parity rule.
if not _user_has_admin_view(user_api_key_dict):
raise HTTPException(
status_code=403,
detail="Only admin users can view config overrides",
Expand Down
Loading
Loading