Triage and Remediation
How to Prevent
Using Console
Using Console
To prevent the misconfiguration where the root account should have Multi-Factor Authentication (MFA) and an external ID set in AWS Identity and Access Management (IAM) using the AWS Management Console, follow these steps:
-
Enable MFA for the Root Account:
- Sign in to the AWS Management Console using your root account credentials.
- Navigate to the IAM dashboard.
- In the left navigation pane, select Dashboard.
- Under Security Status, find the section labeled Activate MFA on your root account and click on Manage MFA.
- Follow the on-screen instructions to enable MFA for the root account. You can choose between a virtual MFA device, a U2F security key, or other supported MFA devices.
-
Create an External ID for Cross-Account Access:
- Go to the IAM dashboard.
- In the left navigation pane, select Roles.
- Click on Create role.
- Select Another AWS account as the type of trusted entity.
- Enter the Account ID of the external account that will assume this role.
- In the Options section, enter a unique External ID. This ID should be shared with the external account that will assume the role.
- Click Next: Permissions to attach the necessary policies and complete the role creation process.
-
Review and Update IAM Policies:
- In the IAM dashboard, navigate to Policies in the left navigation pane.
- Review existing policies to ensure they do not grant excessive permissions to the root account.
- Update policies as necessary to follow the principle of least privilege.
-
Monitor and Audit IAM Activities:
- Enable AWS CloudTrail to log all API calls made in your AWS account.
- Regularly review CloudTrail logs to monitor activities performed by the root account.
- Set up AWS Config rules to continuously monitor and alert on any changes to the root account’s MFA status or IAM roles.
Using CLI
Using CLI
To prevent the misconfiguration where the root account should have Multi-Factor Authentication (MFA) and an External ID set in AWS Identity and Access Management (IAM) using AWS CLI, follow these steps:
-
Enable MFA on the Root Account:
- First, list the MFA devices associated with the root account to ensure none are already configured:
- If no MFA devices are listed, you can enable MFA by creating a virtual MFA device and associating it with the root account. First, create the virtual MFA device:
- Then, enable the MFA device for the root account. You will need the authentication codes from the virtual MFA device:
- First, list the MFA devices associated with the root account to ensure none are already configured:
-
Set an External ID for IAM Roles:
- Identify the IAM role that requires an external ID. List the roles to find the specific role:
- Update the trust policy of the IAM role to include an external ID. First, get the current trust policy:
- Modify the trust policy JSON to include the
sts:ExternalId
condition. Here is an example of a trust policy with an external ID: - Update the role with the modified trust policy:
- Identify the IAM role that requires an external ID. List the roles to find the specific role:
-
Verify MFA and External ID Configuration:
- Verify that the MFA device is enabled for the root account:
- Verify the trust policy of the IAM role to ensure the external ID is set correctly:
- Verify that the MFA device is enabled for the root account:
-
Automate Checks Using AWS CLI Scripts:
- Create a script to periodically check and ensure that MFA is enabled and the external ID is set. Here is a simple example in Bash:
- Create a script to periodically check and ensure that MFA is enabled and the external ID is set. Here is a simple example in Bash:
Using Python
Using Python
To prevent the misconfiguration where the root account should have Multi-Factor Authentication (MFA) and an External ID set in IAM using Python scripts, you can follow these steps:
1. Install Required Libraries
Ensure you have the necessary libraries installed. You will needboto3
for AWS, azure-identity
and azure-mgmt-resource
for Azure, and google-auth
and google-api-python-client
for GCP.2. AWS: Enforce MFA on Root Account
3. Azure: Enforce MFA on Root Account
Azure does not have a direct equivalent of a “root” account, but you can enforce MFA for all users in the directory.4. GCP: Enforce MFA on Root Account
GCP also does not have a direct equivalent of a “root” account, but you can enforce MFA for all users in the organization.Summary
- Install Required Libraries: Ensure you have the necessary Python libraries installed.
- AWS: Use
boto3
to check and enforce MFA on the root account. - Azure: Use
azure-identity
andazure-mgmt-resource
to ensure Conditional Access policies enforce MFA. - GCP: Use
google-auth
andgoogle-api-python-client
to ensure Identity Platform enforces MFA.