使用 OIDC (Azure AD/Keycloak 等) 控制模型访问
信息
示例 Token
- Azure AD
- Keycloak
{
"sub": "1234567890",
"name": "John Doe",
"email": "john.doe@example.com",
"roles": ["basic_user"] # 👈 ROLE
}
{
"sub": "1234567890",
"name": "John Doe",
"email": "john.doe@example.com",
"resource_access": {
"litellm-test-client-id": {
"roles": ["basic_user"] # 👈 ROLE
}
}
}
代理配置
- Azure AD
- Keycloak
general_settings:
enable_jwt_auth: True
litellm_jwtauth:
user_roles_jwt_field: "roles" # the field in the JWT that contains the roles
user_allowed_roles: ["basic_user"] # roles that map to an 'internal_user' role on LiteLLM
enforce_rbac: true # if true, will check if the user has the correct role to access the model
role_permissions: # control what models are allowed for each role
- role: internal_user
models: ["anthropic-claude"]
model_list:
- model: anthropic-claude
litellm_params:
model: claude-3-5-haiku-20241022
- model: openai-gpt-4o
litellm_params:
model: gpt-4o
general_settings:
enable_jwt_auth: True
litellm_jwtauth:
user_roles_jwt_field: "resource_access.litellm-test-client-id.roles" # the field in the JWT that contains the roles
user_allowed_roles: ["basic_user"] # roles that map to an 'internal_user' role on LiteLLM
enforce_rbac: true # if true, will check if the user has the correct role to access the model
role_permissions: # control what models are allowed for each role
- role: internal_user
models: ["anthropic-claude"]
model_list:
- model: anthropic-claude
litellm_params:
model: claude-3-5-haiku-20241022
- model: openai-gpt-4o
litellm_params:
model: gpt-4o
工作原理
指定 JWT_PUBLIC_KEY_URL - 这是你的 OpenID 提供商的公钥端点。对于 Azure AD,它是
https://login.microsoftonline.com/{tenant_id}/discovery/v2.0/keys
。对于 Keycloak,它是{keycloak_base_url}/realms/{your-realm}/protocol/openid-connect/certs
。将 JWT 角色映射到 LiteLLM 角色 - 通过
user_roles_jwt_field
和user_allowed_roles
完成- 当前只支持
internal_user
用于角色映射。
- 当前只支持
指定模型访问权限
role_permissions
: 控制每个角色允许访问哪些模型。role
: LiteLLM 中用于控制访问的角色。允许的角色 =["internal_user", "proxy_admin", "team"]models
: 角色被允许访问的模型列表。
model_list
: 代理上的父模型列表。了解更多
模型检查:代理将对接收到的 JWT 运行验证检查。代码