Skip to content

Commit 4e34fc3

Browse files
author
Krish Dholakia
authored
[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
1 parent 7f06b88 commit 4e34fc3

10 files changed

Lines changed: 411 additions & 141 deletions

File tree

docs/my-website/docs/proxy/token_auth.md

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TabItem from '@theme/TabItem';
33

44
# OIDC - JWT-based Auth
55

6-
Use JWT's to auth admins / projects into the proxy.
6+
Use JWT's to auth admins / users / projects into the proxy.
77

88
:::info
99

@@ -156,27 +156,6 @@ scope: ["litellm-proxy-admin",...]
156156
scope: "litellm-proxy-admin ..."
157157
```
158158
159-
## Control Model Access with Roles
160-
161-
Reject a JWT token if it's valid but doesn't have the required scopes / fields.
162-
163-
Only tokens which with valid Admin (`admin_jwt_scope`), User (`user_id_jwt_field`), Team (`team_id_jwt_field`) are allowed.
164-
165-
```yaml
166-
general_settings:
167-
enable_jwt_auth: True
168-
litellm_jwtauth:
169-
user_roles_jwt_field: "resource_access.litellm-test-client-id.roles"
170-
user_allowed_roles: ["basic_user"] # roles that map to an 'internal_user' role on LiteLLM
171-
enforce_rbac: true # if true, will check if the user has the correct role to access the model + endpoint
172-
173-
role_permissions: # control what models + endpointsare allowed for each role
174-
- role: internal_user
175-
models: ["anthropic-claude"]
176-
```
177-
178-
**[Architecture Diagram (Control Model Access)](./jwt_auth_arch)**
179-
180159
## Control model access with Teams
181160
182161
@@ -330,4 +309,65 @@ general_settings:
330309
user_email_jwt_field: "email" # 👈 checks 'email' field in jwt payload
331310
user_allowed_email_domain: "my-co.com" # allows user@my-co.com to call proxy
332311
user_id_upsert: true # 👈 upserts the user to db, if valid email but not in db
333-
```
312+
```
313+
314+
## [BETA] Control Access with OIDC Roles
315+
316+
Allow JWT tokens with supported roles to access the proxy.
317+
318+
Let users and teams access the proxy, without needing to add them to the DB.
319+
320+
321+
Very important, set `enforce_rbac: true` to ensure that the RBAC system is enabled.
322+
323+
**Note:** This is in beta and might change unexpectedly.
324+
325+
```yaml
326+
general_settings:
327+
enable_jwt_auth: True
328+
litellm_jwtauth:
329+
object_id_jwt_field: "oid" # can be either user / team, inferred from the role mapping
330+
roles_jwt_field: "roles"
331+
role_mappings:
332+
- role: litellm.api.consumer
333+
internal_role: "team"
334+
enforce_rbac: true # 👈 VERY IMPORTANT
335+
336+
role_permissions: # default model + endpoint permissions for a role.
337+
- role: team
338+
models: ["anthropic-claude"]
339+
routes: ["/v1/chat/completions"]
340+
341+
environment_variables:
342+
JWT_AUDIENCE: "api://LiteLLM_Proxy" # ensures audience is validated
343+
```
344+
345+
- `object_id_jwt_field`: The field in the JWT token that contains the object id. This id can be either a user id or a team id. Use this instead of `user_id_jwt_field` and `team_id_jwt_field`. If the same field could be both.
346+
347+
- `roles_jwt_field`: The field in the JWT token that contains the roles. This field is a list of roles that the user has. To index into a nested field, use dot notation - eg. `resource_access.litellm-test-client-id.roles`.
348+
349+
- `role_mappings`: A list of role mappings. Map the received role in the JWT token to an internal role on LiteLLM.
350+
351+
- `JWT_AUDIENCE`: The audience of the JWT token. This is used to validate the audience of the JWT token. Set via an environment variable.
352+
353+
### Example Token
354+
355+
```
356+
{
357+
"aud": "api://LiteLLM_Proxy",
358+
"oid": "eec236bd-0135-4b28-9354-8fc4032d543e",
359+
"roles": ["litellm.api.consumer"]
360+
}
361+
```
362+
363+
### Role Mapping Spec
364+
365+
- `role`: The expected role in the JWT token.
366+
- `internal_role`: The internal role on LiteLLM that will be used to control access.
367+
368+
Supported internal roles:
369+
- `team`: Team object will be used for RBAC spend tracking. Use this for tracking spend for a 'use case'.
370+
- `internal_user`: User object will be used for RBAC spend tracking. Use this for tracking spend for an 'individual user'.
371+
- `proxy_admin`: Proxy admin will be used for RBAC spend tracking. Use this for granting admin access to a token.
372+
373+
### [Architecture Diagram (Control Model Access)](./jwt_auth_arch)

litellm/proxy/_experimental/out/404.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

litellm/proxy/_experimental/out/model_hub.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

litellm/proxy/_new_secret_config.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ litellm_settings:
3535
general_settings:
3636
enable_jwt_auth: True
3737
litellm_jwtauth:
38-
user_id_jwt_field: "sub"
39-
user_email_jwt_field: "email"
40-
team_ids_jwt_field: "groups" # 👈 CAN BE ANY FIELD
38+
object_id_jwt_field: "client_id" # can be either user / team, inferred from the role mapping
39+
roles_jwt_field: "resource_access.litellm-test-client-id.roles"
40+
role_mappings:
41+
- role: litellm.api.consumer
42+
internal_role: "team"
43+
enforce_rbac: true
44+
role_permissions: # default model + endpoint permissions for a role.
45+
- role: team
46+
models: ["anthropic-claude"]
47+
routes: ["openai_routes"]
48+
49+

0 commit comments

Comments
 (0)