Add Microsoft Authenticator MFA to AWS Accounts

The aim of this post is to configure policies in AWS to allow accounts that have been provisioned for users with specific permissions to register for MFA themselves.  The authenticator we will be using is the Microsoft IOS app but it could also be Google or any other authenticator.

First, we need to create a policy that can be assigned to the user that will not only force them to login with MFA but also allow them the permissions they need in order to carry out the registration process.

Go to IAM and click Policies then click create policy.  Click the JSON tab and copy the below JSON code into the policy.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowViewAccountInfo",
            "Effect": "Allow",
            "Action": [
                "iam:GetAccountPasswordPolicy",
                "iam:GetAccountSummary",       
                "iam:ListVirtualMFADevices"
            ],
            "Resource": "*"
        },       
        {
            "Sid": "AllowManageOwnPasswords",
            "Effect": "Allow",
            "Action": [
                "iam:ChangePassword",
                "iam:GetUser"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnAccessKeys",
            "Effect": "Allow",
            "Action": [
                "iam:CreateAccessKey",
                "iam:DeleteAccessKey",
                "iam:ListAccessKeys",
                "iam:UpdateAccessKey"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnSigningCertificates",
            "Effect": "Allow",
            "Action": [
                "iam:DeleteSigningCertificate",
                "iam:ListSigningCertificates",
                "iam:UpdateSigningCertificate",
                "iam:UploadSigningCertificate"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnSSHPublicKeys",
            "Effect": "Allow",
            "Action": [
                "iam:DeleteSSHPublicKey",
                "iam:GetSSHPublicKey",
                "iam:ListSSHPublicKeys",
                "iam:UpdateSSHPublicKey",
                "iam:UploadSSHPublicKey"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnGitCredentials",
            "Effect": "Allow",
            "Action": [
                "iam:CreateServiceSpecificCredential",
                "iam:DeleteServiceSpecificCredential",
                "iam:ListServiceSpecificCredentials",
                "iam:ResetServiceSpecificCredential",
                "iam:UpdateServiceSpecificCredential"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnVirtualMFADevice",
            "Effect": "Allow",
            "Action": [
                "iam:CreateVirtualMFADevice",
                "iam:DeleteVirtualMFADevice"
            ],
            "Resource": "arn:aws:iam::*:mfa/${aws:username}"
        },
        {
            "Sid": "AllowManageOwnUserMFA",
            "Effect": "Allow",
            "Action": [
                "iam:DeactivateMFADevice",
                "iam:EnableMFADevice",
                "iam:ListMFADevices",
                "iam:ResyncMFADevice"
            ],
            "Resource": "arn:aws:iam::*:user/${aws:username}"
        },
        {
            "Sid": "DenyAllExceptListedIfNoMFA",
            "Effect": "Deny",
            "NotAction": [
                "iam:CreateVirtualMFADevice",
                "iam:EnableMFADevice",
                "iam:GetUser",
                "iam:ListMFADevices",
                "iam:ListVirtualMFADevices",
                "iam:ResyncMFADevice",
                "sts:GetSessionToken"
            ],
            "Resource": "*",
            "Condition": {
                "BoolIfExists": {
                    "aws:MultiFactorAuthPresent": "false"
                }
            }
        }
    ]
}

 

Click Review Policy

Add Microsoft Authenticator MFA to AWS Accounts-1

Name the policy Force_MFA

Add Microsoft Authenticator MFA to AWS Accounts-2

While still in IAM click groups and create a new group called EC2MFA.

Add Microsoft Authenticator MFA to AWS Accounts-3

Attach the Force_MFA policy we just created to the group

Add Microsoft Authenticator MFA to AWS Accounts-4

Add Microsoft Authenticator MFA to AWS Accounts-5

Next select the user that we want to force to register for MFA and add them to the group

Add Microsoft Authenticator MFA to AWS Accounts-6

Now using a different browser or a completely new session login as the user you just applied the MFA policy too. (This is just for demo purposes – the user will do this part themselves)

Add Microsoft Authenticator MFA to AWS Accounts-7

Check the user’s permissions and they should not be able to do anything at this point as MFA is required.

Add Microsoft Authenticator MFA to AWS Accounts-8

Click the username and select My Security Credentials

Add Microsoft Authenticator MFA to AWS Accounts-9

Click Assign MFA device

Add Microsoft Authenticator MFA to AWS Accounts-10

There seems to be a bug whereby sometimes it appears as though the user has already registered for MFA as the below error suggests:

Add Microsoft Authenticator MFA to AWS Accounts-11

To overcome this we can use the AWS PowerShell module.  Login with an appropriate account and run the below command to see which accounts have an MFA device attached:

Get-IAMVirtualMFADevice

 

Add Microsoft Authenticator MFA to AWS Accounts-12

Copy the user’s details and put into a remove command as below:

Remove-IAMVirtualMFADevice -SerialNumber arn:aws:iam::194574524582:mfa/route53accessdev 

 

Add Microsoft Authenticator MFA to AWS Accounts-13

Now the user can try again to register and MFA device as before:

Add Microsoft Authenticator MFA to AWS Accounts-14

You then need to ensure that the user has downloaded the Microsoft Authenticator app to their mobile device.  Then click Show QR code.

Add Microsoft Authenticator MFA to AWS Accounts-15

On the mobile device tap the +

Add Microsoft Authenticator MFA to AWS Accounts-16

Select Work or school account

Add Microsoft Authenticator MFA to AWS Accounts-17

Hold your camera over the QR code on screen

Add Microsoft Authenticator MFA to AWS Accounts-18

AWS is automatically associated

Add Microsoft Authenticator MFA to AWS Accounts-19

We then just have to put in the next two codes that appear on the app and click Assign MFA

Add Microsoft Authenticator MFA to AWS Accounts-20

The Setup should be successful

 

 

 

Add Microsoft Authenticator MFA to AWS Accounts-21

The user can then login again as normal:

Add Microsoft Authenticator MFA to AWS Accounts-22

But will then be prompted for their MFA code from the authenticator app

Add Microsoft Authenticator MFA to AWS Accounts-23

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *