[测试版] OpenID Connect (OIDC)
LiteLLM 支持使用 OpenID Connect (OIDC) 进行上游服务的身份验证。这使您可以避免在配置文件中存储敏感凭证。
此功能处于测试版
OIDC 身份提供者 (IdP)
LiteLLM 支持以下 OIDC 身份提供者:
| 提供者 | 配置名称 | 自定义受众 |
|---|---|---|
| Google Cloud Run | google | 是 |
| CircleCI v1 | circleci | 否 |
| CircleCI v2 | circleci_v2 | 否 |
| GitHub Actions | github | 是 |
| Azure Kubernetes Service | azure | 否 |
| 文件 | file | 否 |
| 环境变量 | env | 否 |
| 环境路径 | env_path | 否 |
如果您想使用不同的 OIDC 提供者,请在 GitHub 上提出问题。
除非您知道自己在做什么,并且确定其他提供者都无法适用于您的用例,否则请不要使用 file、env 或 env_path 提供者。提示:它们可能适用于您的用例。
OIDC 依赖方 (RP)
LiteLLM 支持以下 OIDC 依赖方/客户端:
- Amazon Bedrock
- Azure OpenAI
- (即将推出) Google Cloud Vertex AI
配置 OIDC
在可以使用密钥的任何地方,都可以使用 OIDC 代替。通用格式为:
oidc/config_name_here/audience_here
对于不使用 audience 参数的提供者,您可以(并且应该)省略它:
oidc/config_name_here/
非官方提供者 (不推荐)
对于非官方的 file 提供者,您可以使用以下格式:
oidc/file/home/user/dave/this_is_a_file_with_a_token.txt
对于非官方的 env,使用以下格式,其中 SECRET_TOKEN 是包含令牌的环境变量的名称:
oidc/env/SECRET_TOKEN
对于非官方的 env_path,使用以下格式,其中 SECRET_TOKEN 是包含令牌文件路径的环境变量的名称:
oidc/env_path/SECRET_TOKEN
如果您想使用 oidc/env_path/AZURE_FEDERATED_TOKEN_FILE,请不要这样做。相反,请使用 oidc/azure/,因为这可以确保在 Azure 更改其 OIDC 配置和/或添加新功能时继续得到 LiteLLM 的支持。
示例
Google Cloud Run -> Amazon Bedrock
model_list:
- model_name: claude-3-haiku-20240307
litellm_params:
model: bedrock/anthropic.claude-3-haiku-20240307-v1:0
aws_region_name: us-west-2
aws_session_name: "litellm"
aws_role_name: "arn:aws:iam::YOUR_THING_HERE:role/litellm-google-demo"
aws_web_identity_token: "oidc/google/https://example.com"
CircleCI v2 -> Amazon Bedrock
model_list:
- model_name: command-r
litellm_params:
model: bedrock/cohere.command-r-v1:0
aws_region_name: us-west-2
aws_session_name: "my-test-session"
aws_role_name: "arn:aws:iam::335785316107:role/litellm-github-unit-tests-circleci"
aws_web_identity_token: "oidc/circleci_v2/"
Amazon IAM 角色配置 CircleCI v2 -> Bedrock
下面的配置仅为示例。您应调整权限和信任关系以匹配您的具体用例。
权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:*::foundation-model/anthropic.claude-3-haiku-20240307-v1:0",
"arn:aws:bedrock:*::foundation-model/cohere.command-r-v1:0"
]
}
]
}
更多示例请参见 https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html。
信任关系:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::335785316107:oidc-provider/oidc.circleci.com/org/c5a99188-154f-4f69-8da2-b442b1bf78dd"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.circleci.com/org/c5a99188-154f-4f69-8da2-b442b1bf78dd:aud": "c5a99188-154f-4f69-8da2-b442b1bf78dd"
},
"ForAnyValue:StringLike": {
"oidc.circleci.com/org/c5a99188-154f-4f69-8da2-b442b1bf78dd:sub": [
"org/c5a99188-154f-4f69-8da2-b442b1bf78dd/project/*/user/*/vcs-origin/github.com/BerriAI/litellm/vcs-ref/refs/heads/main",
"org/c5a99188-154f-4f69-8da2-b442b1bf78dd/project/*/user/*/vcs-origin/github.com/BerriAI/litellm/vcs-ref/refs/heads/litellm_*"
]
}
}
}
]
}
此信任关系限制CircleCI仅在主分支和以litellm_开头的分支上假设角色。
对于CircleCI(v1和v2),您还需要在AWS IAM设置中添加您组织的OIDC提供程序。更多信息请参见https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-idp_oidc.html。
您永远不需要创建IAM用户。如果创建了,说明您没有正确使用OIDC。您应该只创建一个具有权限和信任关系的角色,以信任您的OIDC提供程序。
Google Cloud Run -> Azure OpenAI
model_list:
- model_name: gpt-4o-2024-05-13
litellm_params:
model: azure/gpt-4o-2024-05-13
azure_ad_token: "oidc/google/https://example.com"
api_version: "2024-06-01"
api_base: "https://demo-here.openai.azure.com"
model_info:
base_model: azure/gpt-4o-2024-05-13
对于Azure OpenAI,您需要在环境中定义AZURE_CLIENT_ID、AZURE_TENANT_ID,并可选地定义AZURE_AUTHORITY_HOST。
export AZURE_CLIENT_ID="91a43c21-cf21-4f34-9085-331015ea4f91" # Azure AD应用程序(客户端)ID
export AZURE_TENANT_ID="f3b1cf79-eba8-40c3-8120-cb26aca169c2" # 在所有Azure AD应用程序中保持一致
export AZURE_AUTHORITY_HOST="https://login.microsoftonline.com" # 👈 可选,默认为"https://login.microsoftonline.com"
您可以通过访问https://login.microsoftonline.com/YOUR_DOMAIN_HERE/v2.0/.well-known/openid-configuration并查找issuer字段中的UUID来找到AZURE_CLIENT_ID。
除非需要覆盖默认值,否则不要在环境中设置AZURE_AUTHORITY_HOST。这样,如果未来默认值发生变化,您无需更新环境。
默认情况下,Azure AD应用程序使用受众api://AzureADTokenExchange。我们建议将受众设置为与您的应用程序更具体的内容。
Azure AD应用程序配置
遗憾的是,与AWS等其他OIDC依赖方相比,Azure的设置要复杂一些。基本上,您需要:
- 创建一个Azure应用程序。
- 为您使用的OIDC IdP(例如Google Cloud Run)添加联合身份凭证。
- 将Azure应用程序添加到包含Azure OpenAI资源的资源组中。
- 为Azure应用程序分配访问Azure OpenAI资源所需的必要角色。
以下自定义角色是推荐的最小权限,以便Azure应用程序访问Azure OpenAI资源。您应根据具体用例调整权限。
{
"id": "/subscriptions/24ebb700-ec2f-417f-afad-78fe15dcc91f/providers/Microsoft.Authorization/roleDefinitions/baf42808-99ff-466d-b9da-f95bb0422c5f",
"properties": {
"roleName": "invoke-only",
"description": "",
"assignableScopes": [
"/subscriptions/24ebb700-ec2f-417f-afad-78fe15dcc91f/resourceGroups/your-openai-group-name"
],
"permissions": [
{
"actions": [],
"notActions": [],
"dataActions": [
"Microsoft.CognitiveServices/accounts/OpenAI/deployments/audio/action",
"Microsoft.CognitiveServices/accounts/OpenAI/deployments/search/action",
"Microsoft.CognitiveServices/accounts/OpenAI/deployments/completions/action",
"Microsoft.CognitiveServices/accounts/OpenAI/deployments/chat/completions/action",
"Microsoft.CognitiveServices/accounts/OpenAI/deployments/extensions/chat/completions/action",
"Microsoft.CognitiveServices/accounts/OpenAI/deployments/embeddings/action",
"Microsoft.CognitiveServices/accounts/OpenAI/images/generations/action"
],
"notDataActions": []
}
]
}
}
注意:您的UUID将有所不同。
如果您需要帮助设置Azure AD应用程序,请联系我们获取付费企业支持。