Description
Registering an MFA device for an IAM user does not enforce MFA on every API call. Check the caller’s permissions and the target role’s trust policy for sensitive role assumptions.
Potential impact
If a user can assume the role without MFA, exposed credentials can give someone access to the role’s permissions.
Remediation
Use MFA-backed temporary credentials or supply MFA when assuming the role. Requests signed with long-term access keys lack aws:MultiFactorAuthPresent. In an Allow, BoolIfExists also passes when the key is missing. Test with and without MFA and check other grants.
Examples
Supply the IAM user and the role referenced by var.target_role_arn. For federated users, check the IdP’s MFA settings. Give automation a separate least-privilege workload role.
Before
resource "aws_iam_user_policy" "example" {
name = "terraform-user"
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
resource "aws_iam_user_policy" "example" {
name = "terraform-user"
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 second example’s Bool condition applies this sts:AssumeRole grant only when MFA is true. Console sign-in and other API actions need their own controls.