Created
June 16, 2017 18:41
-
-
Save timoguin/e255aff237abfc22592ebbfef1bc7f0d to your computer and use it in GitHub Desktop.
AWS Require MFA IAM Policy attached to all users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IAM policy for all users that requires MFA | |
data "aws_iam_policy_document" "require_mfa_policy" { | |
statement { | |
sid = "AllowAllUsersToListAccounts" | |
effect = "Allow" | |
actions = [ | |
"iam:ListAccountAliases", | |
"iam:ListUsers", | |
] | |
resources = [ | |
"arn:aws:iam::${var.account_id}:user/*", | |
] | |
} | |
statement { | |
sid = "AllowIndividualUserToSeeTheirAccountInformation" | |
effect = "Allow" | |
actions = [ | |
"iam:ChangePassword", | |
"iam:CreateLoginProfile", | |
"iam:DeleteLoginProfile", | |
"iam:GetAccountPasswordPolicy", | |
"iam:GetAccountSummary", | |
"iam:GetLoginProfile", | |
"iam:UpdateLoginProfile", | |
] | |
resources = [ | |
"arn:aws:iam::${var.account_id}:user/&{aws:username}", | |
] | |
} | |
statement { | |
sid = "AllowIndividualUserToListTheirMFA" | |
effect = "Allow" | |
actions = [ | |
"iam:ListVirtualMFADevices", | |
"iam:ListMFADevices", | |
] | |
resources = [ | |
"arn:aws:iam::${var.account_id}:mfa/*", | |
"arn:aws:iam::${var.account_id}:user/&{aws:username}", | |
] | |
} | |
statement { | |
sid = "AllowIndividualUserToManageTheirMFA" | |
effect = "Allow" | |
actions = [ | |
"iam:CreateVirtualMFADevice", | |
"iam:DeactivateMFADevice", | |
"iam:DeleteVirtualMFADevice", | |
"iam:EnableMFADevice", | |
"iam:ResyncMFADevice", | |
] | |
resources = [ | |
"arn:aws:iam::${var.account_id}:mfa/&{aws:username}", | |
"arn:aws:iam::${var.account_id}:user/&{aws:username}", | |
] | |
} | |
statement { | |
sid = "AllowGettingAnSTSToken" | |
effect = "Allow" | |
actions = ["sts:GetSessionToken"] | |
resources = ["*"] | |
condition { | |
test = "Bool" | |
variable = "aws:MultiFactorAuthPresent" | |
values = ["true"] | |
} | |
} | |
statement { | |
sid = "AllowUserToManageTheirOwnAccessKeys" | |
effect = "Allow" | |
actions = [ | |
"iam:CreateAccessKey", | |
"iam:DeleteAccessKey", | |
"iam:GetAccessKeyLastUsed", | |
"iam:ListAccessKeys", | |
"iam:UpdateAccessKey", | |
] | |
resources = ["arn:aws:iam::${var.account_id}:user/&{aws:username}"] | |
condition { | |
test = "Bool" | |
variable = "aws:MultiFactorAuthPresent" | |
values = ["true"] | |
} | |
} | |
statement { | |
sid = "DoNotAllowAnythingOtherThanAboveUnlessMFAd" | |
effect = "Deny" | |
not_actions = [ | |
"iam:ListAccountAliases", | |
"iam:ListUsers", | |
"iam:ChangePassword", | |
"iam:CreateLoginProfile", | |
"iam:DeleteLoginProfile", | |
"iam:GetAccountPasswordPolicy", | |
"iam:GetAccountSummary", | |
"iam:GetLoginProfile", | |
"iam:UpdateLoginProfile", | |
"iam:ListVirtualMFADevices", | |
"iam:ListMFADevices", | |
"iam:CreateVirtualMFADevice", | |
"iam:DeactivateMFADevice", | |
"iam:DeleteVirtualMFADevice", | |
"iam:EnableMFADevice", | |
"iam:ResyncMFADevice", | |
] | |
resources = ["*"] | |
condition { | |
test = "Null" | |
variable = "aws:MultiFactorAuthAge" | |
values = ["true"] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment