Triage and Remediation
How to Prevent
Using Console
Using Console
To prevent inactive user account access keys in IAM using the AWS Management Console, follow these steps:
-
Enable Access Key Rotation Policy:
- Navigate to the IAM Dashboard in the AWS Management Console.
- Go to “Policies” and create a new policy or modify an existing one.
- Define a policy that enforces access key rotation, ensuring that keys older than a specified period (e.g., 90 days) are rotated or deactivated.
-
Set Up CloudWatch Alarms:
- Go to the CloudWatch Dashboard.
- Create a new alarm that monitors IAM access key usage.
- Set the alarm to trigger if an access key has not been used within a specified period (e.g., 30 days).
- Configure notifications to alert administrators when the alarm is triggered.
-
Enable IAM Credential Reports:
- In the IAM Dashboard, go to “Credential Report.”
- Generate a credential report to review the status of all IAM users’ access keys.
- Schedule regular reviews of this report to identify and take action on inactive access keys.
-
Implement IAM Access Analyzer:
- Navigate to the IAM Dashboard and select “Access Analyzer.”
- Enable Access Analyzer to continuously monitor and analyze permissions granted using access keys.
- Review findings and take action to remove or deactivate any unnecessary or inactive access keys.
Using CLI
Using CLI
To prevent inactive user account access keys in AWS IAM using the AWS CLI, you can follow these steps:
-
List All IAM Users:
First, list all IAM users to identify which users have access keys.
-
List Access Keys for Each User:
For each user, list their access keys to check their status and last used date.
-
Monitor Access Key Usage:
Regularly monitor the usage of access keys to identify inactive keys. You can use the following command to get the last used date of each access key.
-
Automate Inactive Key Deactivation:
Create a script to automate the deactivation of access keys that have not been used for a specified period. Here is a basic example in Python:
Using Python
Using Python
To prevent inactive user account access keys in IAM using Python scripts, you can follow these steps:
-
Set Up AWS SDK (Boto3) and Authentication:
- Install the Boto3 library if you haven’t already.
- Configure your AWS credentials.
-
Define the Inactivity Period:
- Set the period of inactivity after which access keys should be considered inactive.
-
List All Users and Their Access Keys:
- Retrieve all IAM users and their associated access keys.
-
Check Last Used Date and Deactivate Inactive Keys:
- Check the last used date of each access key and deactivate keys that have been inactive for the defined period.