注意
The MongoDB Atlas Shared Responsibility Model defines the complementary duties of MongoDB and its customers in maintaining a secure and resilient data environment. Under this framework, MongoDB manages the security and operational integrity of the underlying platform, while customers are responsible for the configuration, management, and data policies of their specific deployments. For a detailed breakdown of ownership across security and operational excellence, see Shared Responsibility Model.
Overview
You can use AWS IAM Users or Roles to authenticate database users to your Atlas clusters without managing passwords. Using AWS IAM reduces the number of authentication mechanisms and number of secrets to manage. Atlas does not receive your authentication secret key over the wire and the driver does not persist it.
为您的使用案例选择适当的身份验证方法:
IAM 角色:AWS 服务(EC2、 Lambda、ECS)或联合用户担任的角色。对于在 AWS 计算资源上运行的工作负载,我们建议您使用 IAM 角色进行应用程序和工作负载访问权限。
IAM Users: Individual AWS users that need direct database access. This option might suit applications running with specific user credentials. For human users such as developers and administrators, we recommend that you use Workforce Identity Federation with OIDC for a direct SSO experience with your identity provider.
重要
在客户端使用 AWS IAM数据库身份验证进行连接之前,您必须创建为 IAM身份验证配置的数据库用户。要学习了解如何创建使用 IAM Users 或 IAM Roles 进行身份验证的数据库用户,请参阅管理数据库用户。
使用Amazon Web Services IAM 角色设置身份验证
您可以设立Amazon Web Services IAM 角色,对Amazon Web Services Atlas集群的 计算类型进行身份验证。
注意
启用 LDAP 授权后,您无法为 Amazon Web Services IAM 主体设立身份验证。
如果您需要对Amazon Web Services IAM 主体进行身份验证,请考虑将要访问权限Amazon Web Services IAM身份验证访问的集群移动到另一个禁用LDAP授权的项目中。
对于 AWS Lambda和HTTP (ECS 和 EC2),驱动程序会自动从环境变量中读取。对于 AWS EKS,您必须手动分配 IAM角色。
本页介绍了 AWS Lambda、AWS ECS 和 AWS EKS 如何使用 AWS IAM 角色进行连接。
注意
您必须在 AWS 控制台中将 IAM角色分配给Lambda、 EC2 、 ECS 或 EKS 。
AWS Lambda passes information to functions through the following environment variables if you assign an execution role to the lambda function.
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SESSION_TOKEN
注意
在函数中使用执行角色时,无需手动创建这些环境变量。
要了解有关这些环境变量的详情,请参阅使用 AWS Lambda 环境变量。
AWS ECS 从以下 URI 获取凭证:
http://169.254.170.2${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI 是一个环境变量。要学习;了解更多信息,请参阅Amazon Web Services文档中的任务的 IAM 角色。
要学习;了解如何配置Amazon Web Services IAM角色以使用Amazon Web Services ECS Fargate 进行身份验证,请参阅Amazon Web Services文档中的Amazon ECS任务执行 IAM角色。
对于 AWS EKS,您必须首先为 pod 分配 IAM 角色,才能在该 pod 中设置以下环境变量:
AWS_WEB_IDENTITY_TOKEN_FILE- 包含网络身份令牌文件的 路径。AWS_ROLE_ARN— 包含用于连接集群的IAM角色。
要学习;了解有关Amazon Web Services EKS 的更多信息,请参阅什么是Amazon EKS?在Amazon Web Services文档中。
向Amazon Web Services IAM 角色授予数据库访问权限
要向 AWS IAM 角色授予数据库访问权限,请完成 AWS IAM 的“配置数据库用户” 部分中描述的步骤。有关使用 Atlas CLI、Atlas 管理 API 或 Atlas 用户界面授予数据库访问权限的更多信息,请参阅 配置数据库用户。
使用Atlas Amazon Web ServicesIAM 连接到 集群
To connect to Atlas with your AWS IAM credentials using mongosh, provide a connection string that specifies the MONGODB-AWS authentication mechanism. This connection string format applies to all AWS IAM authentication mechanisms.
重要
必须使用使用 AWS IAM 角色设置身份验证中描述的方法之一配置身份验证,然后才能使用此连接字符串格式。
使用带有 的 AWS IAM身份验证连接到Atlas需要Shell版本mongosh v..0 90或更高版本。
请考虑以下内容:
使用 AWS IAM 凭证,将访问密钥 ID 作为用户名,将密钥作为密码。
authSource查询参数是$external,URL编码为%24external。authMechanism查询参数是MONGODB-AWS。例子
mongosh "mongodb+srv://<atlas-host-name>/test?authSource=%24external&authMechanism=MONGODB-AWS" --username <access-key-id> --password <secret-key>