amazon-web-services - 如何使用 boto3 在 AWS 中禁用用户的密码

标签 amazon-web-services boto3 amazon-iam

我正在使用 boto3 在 AWS 中审计用户密码,但我没有找到实现以下 CIS 基准的方法:“确保禁用 90 天或更长时间未使用的凭证(启用密码)被禁用。”

我有提取密码年龄并提取上次使用密码的代码,但我没有找到任何使密码无效的代码。

对于访问 key (但不是密码),我们有以下内容:

client = session.client('iam')

... (get user and keyid) ...

last_used = client.get_access_key_last_used(AccessKeyId=keyid)

... (determine the age of the key) ...

if age >= 90:

    client.update_access_key(AccessKeyId=keyid, Status='Inactive', UserName=user)

有没有人有任何指示?

最佳答案

delete_login_profile如果您想删除指定 IAM 用户的密码,则应使用该密码,这会终止用户通过 AWS 管理控制台访问 AWS 服务的能力。

但是,为了防止所有用户访问(包括 CLI 和 API 访问),您还必须使任何访问 key 处于非事件状态或将其删除。

来自 Boto3文档:

Warning

Deleting a user's password does not prevent a user from accessing AWS through the command line interface or the API. To prevent all user access you must also either make any access keys inactive or delete them. For more information about making keys inactive or deleting them, see UpdateAccessKey and DeleteAccessKey.

关于amazon-web-services - 如何使用 boto3 在 AWS 中禁用用户的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49459238/

相关文章:

python - 调用 assume_role 导致 "InvalidClientTokenId"错误

amazon-web-services - 如何将 IAM 角色附加到 EC2 实例,以便它们可以从 Terraform 中的 ECR 中提取特定图像

MySQL:无法通过 SSH 使用 TCP/IP 进行连接

amazon-web-services - 在 aws 上将 boto3 用于 dynamoDB 时出现 InvalidSignatureException

python-3.x - 使用 boto3 在 Dynamo 中按分区键查询所有项目

python - 编写 Boto3 过滤器以使用自定义标签名称的正确方法是什么?

amazon-web-services - 如何修复 aws CODE BUILD COMMAND_EXECUTION_ERROR 退出状态 255

amazon-web-services - 使用自定义资源访问cloudformation中的API网关端点

amazon-web-services - AWS S3 文件夹删除历史记录

amazon-web-services - 您可以从 CLI 或 API 查询 AWS Amplify 预览版本的部署状态吗?