Skip to content

Commit b9f3409

Browse files
enverbryantbiggs
andauthored
fix: Do not attach force MFA statement for iam-groups-with-policies by default (#333)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent fb9e74c commit b9f3409

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

modules/iam-group-with-policies/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ No modules.
4444
| <a name="input_create_group"></a> [create\_group](#input\_create\_group) | Whether to create IAM group | `bool` | `true` | no |
4545
| <a name="input_custom_group_policies"></a> [custom\_group\_policies](#input\_custom\_group\_policies) | List of maps of inline IAM policies to attach to IAM group. Should have `name` and `policy` keys in each element. | `list(map(string))` | `[]` | no |
4646
| <a name="input_custom_group_policy_arns"></a> [custom\_group\_policy\_arns](#input\_custom\_group\_policy\_arns) | List of IAM policies ARNs to attach to IAM group | `list(string)` | `[]` | no |
47+
| <a name="input_enable_mfa_enforcment"></a> [enable\_mfa\_enforcment](#input\_enable\_mfa\_enforcment) | Determines whether permissions are added to the policy which requires the groups IAM users to use MFA | `bool` | `true` | no |
4748
| <a name="input_group_users"></a> [group\_users](#input\_group\_users) | List of IAM users to have in an IAM group which can assume the role | `list(string)` | `[]` | no |
4849
| <a name="input_iam_self_management_policy_name_prefix"></a> [iam\_self\_management\_policy\_name\_prefix](#input\_iam\_self\_management\_policy\_name\_prefix) | Name prefix for IAM policy to create with IAM self-management permissions | `string` | `"IAMSelfManagement-"` | no |
4950
| <a name="input_name"></a> [name](#input\_name) | Name of IAM group | `string` | `""` | no |

modules/iam-group-with-policies/policies.tf

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,29 @@ data "aws_iam_policy_document" "iam_self_management" {
145145
]
146146
}
147147

148-
statement {
149-
sid = "DenyAllExceptListedIfNoMFA"
150-
151-
effect = "Deny"
152-
153-
not_actions = [
154-
"iam:ChangePassword",
155-
"iam:CreateVirtualMFADevice",
156-
"iam:EnableMFADevice",
157-
"iam:GetUser",
158-
"iam:ListMFADevices",
159-
"iam:ListVirtualMFADevices",
160-
"iam:ResyncMFADevice",
161-
"sts:GetSessionToken"
162-
]
163-
164-
resources = ["*"]
165-
166-
condition {
167-
test = "BoolIfExists"
168-
variable = "aws:MultiFactorAuthPresent"
169-
values = ["false"]
148+
dynamic "statement" {
149+
for_each = var.enable_mfa_enforcment ? [1] : []
150+
151+
content {
152+
sid = "DenyAllExceptListedIfNoMFA"
153+
effect = "Deny"
154+
not_actions = [
155+
"iam:ChangePassword",
156+
"iam:CreateVirtualMFADevice",
157+
"iam:EnableMFADevice",
158+
"iam:GetUser",
159+
"iam:ListMFADevices",
160+
"iam:ListVirtualMFADevices",
161+
"iam:ResyncMFADevice",
162+
"sts:GetSessionToken"
163+
]
164+
resources = ["*"]
165+
166+
condition {
167+
test = "BoolIfExists"
168+
variable = "aws:MultiFactorAuthPresent"
169+
values = ["false"]
170+
}
170171
}
171172
}
172173
}

modules/iam-group-with-policies/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ variable "custom_group_policies" {
2828
default = []
2929
}
3030

31+
variable "enable_mfa_enforcment" {
32+
description = "Determines whether permissions are added to the policy which requires the groups IAM users to use MFA"
33+
type = bool
34+
default = true
35+
}
36+
3137
variable "attach_iam_self_management_policy" {
3238
description = "Whether to attach IAM policy which allows IAM users to manage their credentials and MFA"
3339
type = bool

0 commit comments

Comments
 (0)