【问题标题】:AWS IAM Policies: require user to provision MFA themselvesAWS IAM 策略:要求用户自己预置 MFA
【发布时间】:2016-11-08 12:48:42
【问题描述】:

我想向我们的新用户发送他们的 IAM 用户名和临时凭证,然后要求他们更改密码并要求他们配置自己的虚拟 MFA,然后他们才能访问控制台。

1) 创建用户时,我显然可以生成一个临时密码,并要求他们在首次登录时更改它。 Security Credentials-->Manage Password-->'Require user to create a new password at next sign-in'.

2) 以下政策将permit IAM users to change their own passwords:

{
  "Version": "2012-10-17",
  "Statement": {
    "Effect": "Allow",
    "Action": [
      "iam:ChangePassword",
      "iam:GetAccountPasswordPolicy"
    ],
    "Resource": "*"
  }
}

3) 以下政策allows users to manage only their own virtual mfa devices

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowUsersToCreateEnableResyncDeleteTheirOwnVirtualMFADevice",
      "Effect": "Allow",
      "Action": [
        "iam:CreateVirtualMFADevice",
        "iam:EnableMFADevice",
        "iam:ResyncMFADevice",
        "iam:DeleteVirtualMFADevice"
      ],
      "Resource": [
        "arn:aws:iam::account-id-without-hyphens:mfa/${aws:username}",
        "arn:aws:iam::account-id-without-hyphens:user/${aws:username}"
      ]
    },
    {
      "Sid": "AllowUsersToDeactivateTheirOwnVirtualMFADevice",
      "Effect": "Allow",
      "Action": [
        "iam:DeactivateMFADevice"
      ],
      "Resource": [
        "arn:aws:iam::account-id-without-hyphens:mfa/${aws:username}",
        "arn:aws:iam::account-id-without-hyphens:user/${aws:username}"
      ],
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": true
        }
      }
    },
    {
      "Sid": "AllowUsersToListMFADevicesandUsersForConsole",
      "Effect": "Allow",
      "Action": [
        "iam:ListMFADevices",
        "iam:ListVirtualMFADevices",
        "iam:ListUsers"
      ],
      "Resource": "*"
    }
  ]
}

使用上述三种方法我可以要求他们更改密码并允许他们配置自己的虚拟MFA设备,我只是不知道是否有方法要求他们配置MFA强>。

【问题讨论】:

  • 要求他们配置 MFA 的方式是指,您是否希望每个用户都必须配置 MFA?
  • 显然你不能。但是如果您的用户都在组中,您可以在组策略中添加一个条件来强制执行 mfa 设置。但是,如果您的用户一开始没有 MFA,我不确定它是否可以工作,我想他们可能会被阻止......无论如何,这是“serverfault.com/questions/483183/…”的副本
  • 谢谢@Olivier -- 我最初认为这不是重复的,因为我希望他们能够自己配置它,并认为策略中的条件会完全限制他们登录,但如果我将它附加到只读策略中,它确实有效,但您需要我上面的两个选项才能使其工作,因此另一个答案不是完整的解决方案。
  • AWS 已发布有关如何执行此操作的文档:docs.aws.amazon.com/IAM/latest/UserGuide/…

标签: amazon-web-services amazon-iam multi-factor-authentication


【解决方案1】:

AWS 对此有书面答复:https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html

这是一个包含多个声明的单一政策:

  1. 允许列出所有用户和所有 MFA 设备。
  2. 只允许列出您自己的用户和他们自己的 MFA 设备。
  3. 允许管理您自己的 MFA 设备。
  4. 如果您已使用 MFA 登录,则允许停用 MFA。
  5. 禁止访问其他所有内容,除非使用 MFA 登录。

【讨论】:

    【解决方案2】:

    我发布了完整的解决方案,因为它不是 Can you require MFA for AWS IAM accounts? 的副本,这非常有用,但也不是允许新 IAM 用户登录控制台、更改密码的完整解决方案并自行添加自己的虚拟 MFA

    1) 创建托管策略以允许用户change their own passwords

    {
      "Version": "2012-10-17",
      "Statement": {
        "Effect": "Allow",
        "Action": [
          "iam:ChangePassword",
          "iam:GetAccountPasswordPolicy"
        ],
        "Resource": "*"
      }
    }
    

    2) 创建托管策略以允许用户manage their own virtual mfa devices

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "AllowUsersToCreateEnableResyncDeleteTheirOwnVirtualMFADevice",
          "Effect": "Allow",
          "Action": [
            "iam:CreateVirtualMFADevice",
            "iam:EnableMFADevice",
            "iam:ResyncMFADevice",
            "iam:DeleteVirtualMFADevice"
          ],
          "Resource": [
            "arn:aws:iam::account-id-without-hyphens:mfa/${aws:username}",
            "arn:aws:iam::account-id-without-hyphens:user/${aws:username}"
          ]
        },
        {
          "Sid": "AllowUsersToDeactivateTheirOwnVirtualMFADevice",
          "Effect": "Allow",
          "Action": [
            "iam:DeactivateMFADevice"
          ],
          "Resource": [
            "arn:aws:iam::account-id-without-hyphens:mfa/${aws:username}",
            "arn:aws:iam::account-id-without-hyphens:user/${aws:username}"
          ],
          "Condition": {
            "Bool": {
              "aws:MultiFactorAuthPresent": true
            }
          }
        },
        {
          "Sid": "AllowUsersToListMFADevicesandUsersForConsole",
          "Effect": "Allow",
          "Action": [
            "iam:ListMFADevices",
            "iam:ListVirtualMFADevices",
            "iam:ListUsers"
          ],
          "Resource": "*"
        }
      ]
    }
    

    3) 将以下条件添加到您想要要求 MFA 的所有策略中:

    {
        "Version": "2012-10-17",
        "Statement": [{
            "Sid": "ReadOnlyEC2RequireMFA",
            "Action": [
                "ec2:Describe*"
            ],
            "Effect": "Allow",
            "Resource": "*",
            "Condition": {
                "Null": {
                    "aws:MultiFactorAuthAge": "false"
                }
            }
        }]
    }
    

    4) 当您创建新的 IAM 用户并为其分配密码时,请选中“要求用户在下次登录时创建新密码”框并应用上述三个托管策略(或将托管策略分配给组并将用户添加到组中)。

    现在将用户名和临时密码分发给新的 IAM 用户。当他们登录时,它会提示他们更改密码,然后他们将只能进入 IAM,选择他们自己的用户帐户和add their own MFA device。他们将需要使用 MFA 注销并重新登录以获得ec2:Describe* 权限。

    【讨论】:

      猜你喜欢
      • 2015-01-31
      • 1970-01-01
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 2020-12-16
      相关资源
      最近更新 更多