Skip to content

Instantly share code, notes, and snippets.

@drAlberT
Created September 7, 2018 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drAlberT/b134f21d335f8a8e70d834ef81030dc1 to your computer and use it in GitHub Desktop.
Save drAlberT/b134f21d335f8a8e70d834ef81030dc1 to your computer and use it in GitHub Desktop.
AWS IAM :: Enforce MFA both on Console and CLI
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAllUsersToListAccountAliases",
"Effect": "Allow",
"Action": [
"iam:ListAccountAliases"
],
"Resource": [
"*"
]
},
{
"Sid": "AllowAllUsersToListTheAvailbleMFADevices",
"Effect": "Allow",
"Action": [
"iam:ListVirtualMFADevices"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:mfa/*"
]
},
{
"Sid": "AllowAllUsersToListAccounts",
"Effect": "Allow",
"Action": [
"iam:GetAccountPasswordPolicy",
"iam:ListUsers"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:user/*"
]
},
{
"Sid": "AllowAllUsersToGetRole",
"Effect": "Allow",
"Action": [
"iam:GetRole"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:role/*"
]
},
{
"Sid": "AllowIndividualUserToSeeTheirAccountInformationAndCreateAccessKey",
"Effect": "Allow",
"Action": [
"iam:ChangePassword",
"iam:CreateLoginProfile",
"iam:DeleteLoginProfile",
"iam:GetAccountPasswordPolicy",
"iam:GetAccountSummary",
"iam:GetLoginProfile",
"iam:UpdateLoginProfile"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:user/${aws:username}"
]
},
{
"Sid": "AllowIndividualUserToListTheirMFA",
"Effect": "Allow",
"Action": [
"iam:ListMFADevices"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:mfa/${aws:username}",
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:user/${aws:username}"
]
},
{
"Sid": "AllowIndividualUserToManageTheirMFA",
"Effect": "Allow",
"Action": [
"iam:CreateVirtualMFADevice",
"iam:DeleteVirtualMFADevice",
"iam:EnableMFADevice",
"iam:ResyncMFADevice"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:mfa/${aws:username}",
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:user/${aws:username}"
]
},
{
"Sid": "DenyEverythingExceptForBelowUnlessMFAd",
"Effect": "Deny",
"NotAction": [
"iam:ChangePassword",
"iam:CreateAccessKey",
"iam:CreateLoginProfile",
"iam:CreateVirtualMFADevice",
"iam:DeleteLoginProfile",
"iam:DeleteVirtualMFADevice",
"iam:EnableMFADevice",
"iam:GetAccountPasswordPolicy",
"iam:GetAccountSummary",
"iam:GetLoginProfile",
"iam:GetRole",
"iam:ListAccessKeys",
"iam:ListAccountAliases",
"iam:ListMFADevices",
"iam:ListUsers",
"iam:ListVirtualMFADevices",
"iam:ResyncMFADevice",
"iam:UpdateLoginProfile"
],
"Resource": "*",
"Condition": {
"BoolIfExists": {
"aws:MultiFactorAuthPresent": "false"
}
}
},
{
"Sid": "AllowBelowWhenMFAd",
"Effect": "Allow",
"Action": [
"iam:GetUser",
"iam:DeactivateMFADevice"
],
"Resource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:mfa/${aws:username}",
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:user/${aws:username}"
],
"Condition": {
"BoolIfExists": {
"aws:MultiFactorAuthPresent": "true"
}
}
},
{
"Sid": "DenyIamAccessToOtherAccountsUnlessMFAd",
"Effect": "Deny",
"Action": [
"iam:ChangePassword",
"iam:CreateAccessKey",
"iam:CreateLoginProfile",
"iam:CreateVirtualMFADevice",
"iam:DeactivateMFADevice",
"iam:DeleteLoginProfile",
"iam:DeleteVirtualMFADevice",
"iam:EnableMFADevice",
"iam:GetAccountPasswordPolicy",
"iam:GetLoginProfile",
"iam:ListAccessKeys",
"iam:ResyncMFADevice",
"iam:UpdateLoginProfile"
],
"NotResource": [
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:mfa/${aws:username}",
"arn:aws:iam::XXX-REPLACE-WITH-ACCOUNT-ID-XXX:user/${aws:username}"
],
"Condition": {
"BoolIfExists": {
"aws:MultiFactorAuthPresent": "false"
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment