MFA Should Be Enabled On User Accounts
More Info:
MFA must be enabled on user accounts. AWS recommends that you configure multi-factor authentication (MFA) to help protect your AWS resources.
Risk Level
Critical
Address
Security
Compliance Standards
- APRA CPS 234 (Australia)
- AWS Startup Security Baseline
- AWS Well Architected Framework
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS AWS
- CIS Critical Security Controls v8
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- Cloudanix Best Practice
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- GDPR
- HIPAA
- ISO 27001
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIS2 Directive
- NIST
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- PCI
- Reserve Bank of India (RBI) Master Direction – Information Technology Framework
- SOC2
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- Securities and Exchange Board of India (SEBI) - Cloud Security Adoption Framework
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Prevention
- Cause
- Remediation
How to Prevent
Using Console
To prevent the misconfiguration of not having Multi-Factor Authentication (MFA) enabled on user accounts in AWS Identity and Access Management (IAM) using the AWS Management Console, follow these steps:
-
Navigate to IAM Dashboard:
- Sign in to the AWS Management Console.
- In the top navigation bar, select "Services" and then choose "IAM" under the "Security, Identity, & Compliance" section.
-
Select Users:
- In the IAM dashboard, click on "Users" in the left-hand navigation pane.
- This will display a list of all IAM users in your AWS account.
-
Enable MFA for Each User:
- Click on the username of the user for whom you want to enable MFA.
- In the user details page, select the "Security credentials" tab.
- Under the "Multi-factor authentication (MFA)" section, click on the "Manage" button.
- Follow the on-screen instructions to assign and activate an MFA device for the user. This typically involves scanning a QR code with an MFA app (like Google Authenticator) and entering the generated code to verify.
-
Enforce MFA Policy:
- To ensure that all users have MFA enabled, you can create an IAM policy that requires MFA for specific actions.
- Go to the "Policies" section in the IAM dashboard.
- Click on "Create policy" and use the JSON editor to define a policy that requires MFA. For example:
{"Version": "2012-10-17","Statement": [{"Effect": "Deny","Action": "*","Resource": "*","Condition": {"BoolIfExists": {"aws:MultiFactorAuthPresent": "false"}}}]}
- Attach this policy to all IAM users or groups to enforce MFA.
By following these steps, you can ensure that MFA is enabled for all IAM user accounts, thereby enhancing the security of your AWS environment.
Using CLI
To prevent the misconfiguration of not having Multi-Factor Authentication (MFA) enabled on user accounts in AWS IAM using the AWS CLI, follow these steps:
-
Create an MFA Device for the User: First, you need to create an MFA device for the user. This can be a virtual MFA device or a hardware MFA device. Here, we'll use a virtual MFA device.
aws iam create-virtual-mfa-device --virtual-mfa-device-name <VirtualMFADeviceName> --outfile /path/to/qr-code.pngThis command will create a virtual MFA device and output a QR code that can be scanned by an MFA application (like Google Authenticator).
-
Enable MFA for the User: Once the virtual MFA device is created, you need to enable it for the user by associating it with the user account. You will need two consecutive MFA codes from the MFA device.
aws iam enable-mfa-device --user-name <UserName> --serial-number arn:aws:iam::<AccountID>:mfa/<VirtualMFADeviceName> --authentication-code1 <MFA_Code1> --authentication-code2 <MFA_Code2> -
Update User's Login Profile to Require MFA: Ensure that the user's login profile is updated to require MFA. This can be done by setting up an IAM policy that enforces MFA.
aws iam put-user-policy --user-name <UserName> --policy-name MFARequired --policy-document '{"Version": "2012-10-17","Statement": [{"Effect": "Deny","Action": "*","Resource": "*","Condition": {"BoolIfExists": {"aws:MultiFactorAuthPresent": "false"}}}]}' -
Verify MFA Device Association: Finally, verify that the MFA device is correctly associated with the user.
aws iam list-mfa-devices --user-name <UserName>This command will list all MFA devices associated with the specified user, allowing you to confirm that the MFA device is properly set up.
By following these steps, you can ensure that MFA is enabled on user accounts in AWS IAM using the AWS CLI.
Using Python
To prevent the misconfiguration of not having Multi-Factor Authentication (MFA) enabled on user accounts in IAM using Python scripts, you can follow these steps for AWS, Azure, and GCP:
AWS
-
Install Boto3 Library: Ensure you have the Boto3 library installed, which is the AWS SDK for Python.
pip install boto3 -
Create a Python Script to Enable MFA: Use the following script to enforce MFA on IAM user accounts. This script lists all users and attaches an MFA device to each user if not already attached.
import boto3# Initialize a session using Amazon IAMiam_client = boto3.client('iam')# List all IAM usersusers = iam_client.list_users()for user in users['Users']:user_name = user['UserName']mfa_devices = iam_client.list_mfa_devices(UserName=user_name)if not mfa_devices['MFADevices']:# Create a virtual MFA devicemfa_device = iam_client.create_virtual_mfa_device(VirtualMFADeviceName=f'{user_name}_mfa')# Enable MFA for the useriam_client.enable_mfa_device(UserName=user_name,SerialNumber=mfa_device['VirtualMFADevice']['SerialNumber'],AuthenticationCode1='123456', # Replace with actual MFA codeAuthenticationCode2='789012' # Replace with actual MFA code)print(f'MFA enabled for user: {user_name}')else:print(f'MFA already enabled for user: {user_name}')
Azure
-
Install Azure SDK for Python: Ensure you have the Azure Identity and Management libraries installed.
pip install azure-identity azure-mgmt-authorization -
Create a Python Script to Enforce MFA: Use the following script to enforce MFA on Azure user accounts. This script assumes you have the necessary permissions to manage user settings.
from azure.identity import DefaultAzureCredentialfrom azure.mgmt.authorization import AuthorizationManagementClient# Initialize credentials and clientcredential = DefaultAzureCredential()client = AuthorizationManagementClient(credential, '<subscription_id>')# List all users and enforce MFAusers = client.users.list()for user in users:# Check if MFA is enabled (this is a simplified example)if not user.additional_properties.get('mfaEnabled'):# Enforce MFA (this is a placeholder, actual implementation may vary)user.additional_properties['mfaEnabled'] = Trueclient.users.create_or_update(user.object_id, user)print(f'MFA enforced for user: {user.display_name}')else:print(f'MFA already enabled for user: {user.display_name}')
GCP
-
Install Google Cloud SDK: Ensure you have the Google Cloud SDK installed.
pip install google-auth google-api-python-client -
Create a Python Script to Enforce MFA: Use the following script to enforce MFA on GCP user accounts. This script assumes you have the necessary permissions to manage user settings.
from google.oauth2 import service_accountfrom googleapiclient.discovery import build# Initialize credentials and servicecredentials = service_account.Credentials.from_service_account_file('path/to/your/service-account-file.json')service = build('admin', 'directory_v1', credentials=credentials)# List all users and enforce MFAresults = service.users().list(customer='my_customer', maxResults=200).execute()users = results.get('users', [])for user in users:# Check if MFA is enabled (this is a simplified example)if not user.get('isEnrolledIn2Sv'):# Enforce MFA (this is a placeholder, actual implementation may vary)user['isEnrolledIn2Sv'] = Trueservice.users().update(userKey=user['id'], body=user).execute()print(f'MFA enforced for user: {user["primaryEmail"]}')else:print(f'MFA already enabled for user: {user["primaryEmail"]}')
These scripts provide a basic framework to enforce MFA on user accounts in AWS, Azure, and GCP. You may need to adjust the scripts based on your specific requirements and environment.
Check Cause
Using Console
-
Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
-
In the navigation pane, choose "Users". This will display a list of all IAM users associated with the current AWS account.
-
Select a user from the list. This will open the summary page for the selected user.
-
In the "Security credentials" tab, check the "Assigned MFA device" column. If it says "None", then MFA is not enabled for that user. Repeat this process for all users to ensure MFA is enabled on all user accounts.
Using CLI
-
Install and configure AWS CLI: Before you can start using AWS CLI, you need to install it on your local machine and configure it with your AWS account credentials. You can do this by running the following commands:
Installation:
pip install awscliConfiguration:
aws configureYou will be prompted to provide your AWS Access Key ID, Secret Access Key, Default region name, and Default output format.
-
List all IAM users: Once AWS CLI is set up, you can list all IAM users in your AWS account by running the following command:
aws iam list-usersThis command will return a JSON object containing details of all IAM users.
-
Check MFA status: For each user, you need to check if MFA is enabled. You can do this by running the following command for each user:
aws iam list-mfa-devices --user-name <username>Replace
<username>with the name of the user. This command will return a JSON object containing details of all MFA devices associated with the user. -
Analyze the output: If the output from the previous command is an empty list, it means that MFA is not enabled for that user. If the output contains one or more MFA devices, it means that MFA is enabled for that user. Repeat steps 3 and 4 for each user in your AWS account.
Using Python
-
First, you need to install the AWS SDK for Python (Boto3). You can do this by running the command
pip install boto3in your terminal. -
Once Boto3 is installed, you can use it to interact with AWS services. To check if MFA is enabled on IAM user accounts, you can use the
list_mfa_devicesmethod. Here is a sample script:
import boto3
def check_mfa():
client = boto3.client('iam')
users = client.list_users()
for user in users['Users']:
mfa = client.list_mfa_devices(UserName=user['UserName'])
if not mfa['MFADevices']:
print(f"MFA not enabled for {user['UserName']}")
check_mfa()
-
This script first lists all the IAM users in your AWS account. Then, for each user, it checks if any MFA devices are associated with the user. If no MFA devices are found, it prints a message indicating that MFA is not enabled for that user.
-
To run the script, save it to a file (e.g.,
check_mfa.py), then runpython check_mfa.pyin your terminal. You'll need to have your AWS credentials configured (either by setting theAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_SESSION_TOKENenvironment variables, or by configuring them using the AWS CLI or AWS SDKs).
Remediation
Using Console
To remediate the misconfiguration of MFA not being enabled on user accounts in AWS, you can follow the below steps:
Step 1: Log in to the AWS Management Console.
Step 2: Navigate to the IAM service.
Step 3: Click on the "Users" tab on the left-hand side of the page.
Step 4: Select the user account that needs MFA enabled.
Step 5: Click on the "Security credentials" tab.
Step 6: Under the "Multi-factor authentication (MFA)" section, click on "Manage".
Step 7: Choose "Virtual MFA device" or "U2F security key" and click on "Continue".
Step 8: Follow the on-screen instructions to complete the MFA setup process.
Step 9: Once the MFA is set up, click on "Activate MFA" to enable it for the user account.
Step 10: Repeat steps 4-9 for all user accounts that require MFA to be enabled.
By following these steps, you can remediate the misconfiguration of MFA not being enabled on user accounts in AWS.
Using CLI
To remediate the misconfiguration of MFA not being enabled on user accounts in AWS using AWS CLI, you can follow the below steps:
-
Firstly, you need to install and configure AWS CLI on your local machine.
-
Next, you need to list all the IAM users in your account using the following command:
aws iam list-users
- For each user returned in the previous command, you need to check if MFA is enabled or not by running the following command:
aws iam list-mfa-devices --user-name <username>
- If MFA is not enabled for a user, you can enable it by running the following command:
aws iam enable-mfa-device --user-name <username> --serial-number <serial-number> --authentication-code-1 <code1> --authentication-code-2 <code2>
Here, <serial-number> is the unique identifier of the MFA device, and <code1> and <code2> are the two consecutive authentication codes generated by the MFA device.
- Once you have enabled MFA for all the IAM users in your account, you can verify the configuration by running the following command:
aws iam list-mfa-devices
This command will list all the MFA-enabled users in your account along with their MFA device information.
By following these steps, you can remediate the misconfiguration of MFA not being enabled on user accounts in AWS using AWS CLI.
Using Python
To remediate the misconfiguration of MFA not being enabled on user accounts in AWS using Python, you can use the following steps:
- Install the AWS SDK for Python (Boto3) using the following command:
pip install boto3
- Create an AWS IAM client using the following code:
import boto3
iam = boto3.client('iam')
- List all the IAM users using the following code:
response = iam.list_users()
users = response['Users']
- Loop through each user and check if MFA is enabled. If it is not enabled, enable it using the following code:
for user in users:
username = user['UserName']
response = iam.list_mfa_devices(UserName=username)
mfa_devices = response['MFADevices']
if not mfa_devices:
iam.enable_mfa_device(UserName=username, SerialNumber='arn:aws:iam::<account-id>:mfa/'+username, AuthenticationCode1='<code1>', AuthenticationCode2='<code2>')
Replace <account-id> with your AWS account ID and <code1> and <code2> with the MFA codes generated by the user's device.
- Save the Python file and run it using the following command:
python <filename>.py
This will remediate the misconfiguration of MFA not being enabled on user accounts in AWS.
Using Terraform
Terraform cannot enable MFA on an IAM user because AWS requires an interactive flow with one-time codes, and there is no Terraform (or AWS API) resource/argument that performs create-virtual-mfa-device + enable-mfa-device end‑to‑end.
You must do this outside Terraform, either:
- Via AWS Console: IAM → Users → select USER_NAME → Security credentials tab → Assign MFA device → follow the wizard with the user’s authenticator codes.
- Or via CLI, exactly as in the verified remediation:
aws iam create-virtual-mfa-device \--virtual-mfa-device-name USER_NAME-mfa \--outfile QRCode.png \--bootstrap-method QRCodePNGaws iam enable-mfa-device \--user-name USER_NAME \--serial-number MFA_DEVICE_ARN_FROM_STEP_1 \--authentication-code-1 FIRST_MFA_CODE \--authentication-code-2 SECOND_MFA_CODE
There is no Terraform change to plan or apply for this; terraform plan will show no IAM MFA-related changes.