Force-MFA for IAM Users

Step 1: Create a Policy to Enforce MFA Sign-In

You begin by creating an IAM customer managed policy that denies all permissions except those required for IAM users to manage their own credentials and MFA devices.

  1. Sign in to the AWS Management Console as a user with administrator credentials. To adhere to IAM best practices, don’t sign in with your AWS account root user credentials. For more information, see Create individual IAM users.

  2. Open the IAM console at https://console.aws.amazon.com/iam/.

  3. In the navigation pane, choose Policies, and then choose Create policy.

  4. Choose the JSON tab and copy the text from the following JSON policy document. Paste this text into the JSON text box.

Step 2: Attach Policies to Your Test Group

Next you attach two policies to the test IAM group, which will be used to grant the MFA-protected permissions.

  1. In the navigation pane, choose Groups.

  2. In the search box, type EC2MFA, and then choose the group name (not the check box) in the list.

  3. On the Permissions tab, and click Attach Policy.

  4. On the Attach Policy page, in the search box, type EC2Full and then select the check box next to AmazonEC2FullAccess in the list. Don't save your changes yet.

  5. In the search box, type Force, and then select the check box next to Force_MFA in the list.

  6. Choose Attach Policy.

Step 3: Test Your User's Access

In this part of the tutorial, you sign in as the test user and verify that the policy works as intended.

  1. Sign in to your AWS account as MFAUser with the password you assigned in the previous section. Use the URL: https://<alias or account ID number>.signin.aws.amazon.com/console

  2. Choose EC2 to open the Amazon EC2 console and verify that the user has no permissions to do anything.

  3. On the navigation bar, choose Services, and then choose IAM to open the IAM console.

  4. In the navigation pane, choose Users, and then choose the user (not the check box) MFAUser. If the Groups tab appears by default, note that it says that you don't have permissions to see your group memberships.

  5. Now add an MFA device. Choose the Security credentials tab. Next to Assigned MFA device, choose Manage.

  6. For this tutorial, we use a virtual (software-based) MFA device, such as the Google Authenticator app on a mobile phone. Choose Virtual MFA device, and then click Continue.

    IAM generates and displays configuration information for the virtual MFA device, including a QR code graphic. The graphic is a representation of the secret configuration key that is available for manual entry on devices that do not support QR codes.

  7. Open your virtual MFA app. (For a list of apps that you can use for hosting virtual MFA devices, see Virtual MFA Applications.) If the virtual MFA app supports multiple accounts (multiple virtual MFA devices), choose the option to create a new account (a new virtual MFA device).

  8. Determine whether the MFA app supports QR codes, and then do one of the following:

    • From the wizard, choose Show QR code. Then use the app to scan the QR code. For example, you might choose the camera icon or choose an option similar to Scan code, and then use the device's camera to scan the code.

    • In the Manage MFA Device wizard, choose Show secret key, and then type the secret key into your MFA app.

    When you are finished, the virtual MFA device starts generating one-time passwords.

  9. In the Manage MFA Device wizard, in the MFA Code 1 box, type the one-time password that currently appears in the virtual MFA device. Wait up to 30 seconds for the device to generate a new one-time password. Then type the second one-time password into the MFA Code 2 box. Choose Assign MFA.

    Important

    Submit your request immediately after generating the codes. If you generate the codes and then wait too long to submit the request, the MFA device is successfully associated with the user. However, the MFA device is out of sync. This happens because time-based one-time passwords (TOTP) expire after a short period of time. If this happens, you can resync the device.

    The virtual MFA device is now ready to use with AWS.

  10. Sign out of the console and then sign in as MFAUser again. This time AWS prompts you for an MFA code from your phone. When you get it, type the code in the box and then choose Submit.

  11. Choose EC2 to open the Amazon EC2 console again. Note that this time you can see all the information and perform any actions you want. If you go to any other console as this user, you see access denied messages because the policies in this tutorial grant access only to Amazon EC2.

Last updated