-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Description
In the IAM assumable role module, the option to create a role with an MFA condition is not working properly when using long-term credentials. The condition to check if MFA is enabled is currently Bool, which fails when the aws:MultiFactorAuthPresent variable is not present (such as when running with long-term credentials using the AWS CLI).
AWS strongly recommends not doing this, as this breaks the above use case of the AWS CLI.
Instead, they recommend that you use the BoolIfExists operator to check this condition.
Therefor I suggest that you change the operator to BoolIfExists. In addition, I suggest changing the operator for the aws:MultiFactorAuthAge condition to NumericLessThanIfExists to make sure this does not fail either when using a long-term credential type.
- ✋ I have searched the open/closed issues and my issue is not listed.
Versions
- Module version: 5.44.0
Reproduction Code
I understand that you ask for "code that works without modifications", but uh no.. I will redact things.
module "describecluster_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = ">= 5.44.0, < 6.0.0"
name = "describecluster"
path = "/"
description = "Policy with the DescribeCluster permission for the cluster"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "eks:DescribeCluster",
"Resource": "<Redacted>"
}
]
}
EOF
}
module "cluster_admin_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
version = ">= 5.44.0, < 6.0.0"
create_role = true
trusted_role_arns = [
"<Redacted>",
]
role_name = "cluster_admin_role"
role_requires_mfa = true
custom_role_policy_arns = [
module.describecluster_policy.arn
]
}Steps to reproduce the behavior:
- It doesn't matter how you set up the describecluster policy, as long as you can assume the role it's fine.
- Set up your user's arn in the
trusted_role_arnsarray. - Deploy the code
- Use long-term credentials to try and assume the role (via the CLI for example)
Expected behavior
I expect that using the role_requires_mfa makes it so that I can actually use the role using my terminal as well.
I also expect that this AWS module follows AWS's recommendations.
Following from that, I expect the operation of assuming the role to succeed.
Actual behavior
Assuming the role doesn't succeed.
I don't have access, because long-term credentials don't have the aws:MultiFactorAuthPresent condition set to anything, so the Bool operator fails.