You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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
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
-
180
159
## Control model access with Teams
181
160
182
161
@@ -330,4 +309,65 @@ general_settings:
330
309
user_email_jwt_field: "email" # 👈 checks 'email' field in jwt payload
331
310
user_allowed_email_domain: "my-co.com" # allows user@my-co.com to call proxy
332
311
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)
0 commit comments