mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 08:23:17 +00:00
[BETA] Support OIDC role based access to proxy (#8260)
* feat(proxy/_types.py): add new jwt field params allows users + services to auth into proxy * feat(handle_jwt.py): allow team role proxy access allows proxy admin to set allowed team roles * fix(proxy/_types.py): add 'routes' to role based permissions allow proxy admin to restrict what routes a team can access easily * feat(handle_jwt.py): support more flexible role based route access v2 on role based 'allowed_routes' * test(test_jwt.py): add unit test for rbac for proxy routes * feat(handle_jwt.py): ensure cost tracking always works for any jwt request with `enforce_rbac=True` * docs(token_auth.md): add documentation on controlling model access via OIDC Roles * test: increase time delay before retrying * test: handle model overloaded for test
This commit is contained in:
@@ -21,7 +21,7 @@ from datetime import datetime, timedelta
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from fastapi import Request
|
||||
from fastapi import Request, HTTPException
|
||||
from fastapi.routing import APIRoute
|
||||
from fastapi.responses import Response
|
||||
import litellm
|
||||
@@ -1164,3 +1164,22 @@ async def test_end_user_jwt_auth(monkeypatch):
|
||||
mock_client.call_args.kwargs[
|
||||
"end_user_id"
|
||||
] == "81b3e52a-67a6-4efb-9645-70527e101479"
|
||||
|
||||
|
||||
def test_can_rbac_role_call_route():
|
||||
from litellm.proxy.auth.handle_jwt import JWTAuthManager
|
||||
from litellm.proxy._types import RoleBasedPermissions
|
||||
from litellm.proxy._types import LitellmUserRoles
|
||||
|
||||
with pytest.raises(HTTPException):
|
||||
JWTAuthManager.can_rbac_role_call_route(
|
||||
rbac_role=LitellmUserRoles.TEAM,
|
||||
general_settings={
|
||||
"role_permissions": [
|
||||
RoleBasedPermissions(
|
||||
role=LitellmUserRoles.TEAM, routes=["/v1/chat/completions"]
|
||||
)
|
||||
]
|
||||
},
|
||||
route="/v1/embeddings",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user