Review MFA requirements in IAM user policies

Verify MFA requirements for human role assumption against actual credentials and the complete policy set.

Description

If MFA is required to assume a sensitive role, review the IAM user’s sts:AssumeRole permission and the target role’s trust policy together.

Potential impact

A condition on one user-policy statement can leave another grant in place. Exposed credentials could still give access to the role.

Remediation

Long-term access keys lack aws:MultiFactorAuthPresent. Use MFA-backed temporary credentials or supply MFA when assuming the role. An Allow with BoolIfExists also passes if the key is missing. Check that assumption succeeds with MFA and fails without it. Use the external IdP’s MFA for federation and workload roles for automation.

Examples

Provide the IAM user and the role specified by var.target_role_arn. The user policy applies to its attached identity. Specify Principal in the role’s trust policy.

Before

hcl
resource "aws_iam_user_policy" "example" {
  name = "test"
  user = aws_iam_user.example.name

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Resource": "${var.target_role_arn}",
      "Action": "sts:AssumeRole"
    }
  ]
}
EOF
}

After

hcl
resource "aws_iam_user_policy" "example" {
  name = "test"
  user = aws_iam_user.example.name

  policy = <<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Resource": "${var.target_role_arn}",
      "Action": "sts:AssumeRole",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent" : "true"
        }
      }
    }
  ]
}
EOF
}

The first grant has no MFA condition. In the second, Bool makes this grant apply only when the MFA value is true.

References