从100.11.0 开始,数据库工具支持 Atlas Workload Identity Federation。使用 Workload Identity Federation 对Microsoft Azure和Google Cloud Platform上的MongoDB连接进行身份验证。
示例
本节中的示例使用 Workload Identity Federation。
在连接字符串中,将authMechanism MONGODB-OIDCauthMechanismProperties设立为 并为您的环境设立 :
对于Microsoft Azure,将
authMechanismProperties设立为ENVIRONMENT:azure,TOKEN_RESOURCE:<audience>。使用Microsoft Azure Kubernetes Service (AKS) 时省略TOKEN_RESOURCE。对于Google Cloud Platform,设立
authMechanismProperties设置为ENVIRONMENT:gcp,TOKEN_RESOURCE:<audience>。
将 <audience> 替换为访问权限令牌适用的应用程序或服务。有关更多详细信息,请参阅身份提供者字段。
使用Microsoft Azure实例元数据服务连接到MongoDB
以下 mongodump示例使用Microsoft Azure实例元数据服务 (IMDS) 连接到MongoDB :
mongodump --uri "mongodb://mongodb.example.com:20017/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure,TOKEN_RESOURCE:https://www.example.com" \ --username admin
使用Microsoft Azure Kubernetes服务连接到MongoDB
要使用Microsoft Azure Kubernetes服务连接到MongoDB ,请定义以下环境变量:
环境变量 | 说明 |
|---|---|
| Azure tenant identifier. |
| Azure应用程序客户端标识符。 |
| 要进行身份验证的托管标识的Azure客户端标识符。 |
| Azure联合令牌文件路径。 |
有关Azure和变量的详细信息,请参阅Microsoft Azure文档。
以下 mongodump示例定义了环境变量并连接到MongoDB:
AZURE_TENANT_ID=08206ab8-16a0-406d-85e4-2f15f5620fac \ AZURE_APP_CLIENT_ID=b6c835da-e536-425b-9405-64bc471e245b \ AZURE_CLIENT_ID=f176d4eb-7dcd-4f66-bccf-aaa316ee61fd \ AZURE_FEDERATED_TOKEN_FILE=/var/run/secrets/azure/tokens/azure-identity-token \ mongodump --uri "mongodb://mongodb.example.com:20017/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:azure" \ --username "admin"
TOKEN_RESOURCE 不是本示例中必需的。
连接到Google Cloud Platform上的MongoDB
以下 mongodump示例将连接到Google Cloud Platform上的MongoDB :
mongodump --uri "mongodb://mongodb.example.com:20017/?authMechanism=MONGODB-OIDC&authMechanismProperties=ENVIRONMENT:gcp,TOKEN_RESOURCE:https://www.example.com" \ --username "admin"
Google Cloud Platform不需要环境变量。