Skip to main content

Triage and Remediation

How to Prevent

Using Console

To prevent inactive user account access keys in IAM using the AWS Management Console, follow these steps:
  1. 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.
  2. 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.
  3. 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.
  4. 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.
By following these steps, you can proactively manage and prevent inactive user account access keys in AWS IAM.
To prevent inactive user account access keys in AWS IAM using the AWS CLI, you can follow these steps:
  1. List All IAM Users: First, list all IAM users to identify which users have access keys.
  2. List Access Keys for Each User: For each user, list their access keys to check their status and last used date.
  3. 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.
  4. 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:
By following these steps, you can ensure that inactive access keys are identified and deactivated, thereby enhancing the security of your AWS environment.
To prevent inactive user account access keys in IAM using Python scripts, you can follow these steps:
  1. Set Up AWS SDK (Boto3) and Authentication:
    • Install the Boto3 library if you haven’t already.
    • Configure your AWS credentials.
  2. Define the Inactivity Period:
    • Set the period of inactivity after which access keys should be considered inactive.
  3. List All Users and Their Access Keys:
    • Retrieve all IAM users and their associated access keys.
  4. 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.
This script will help you identify and deactivate inactive access keys for IAM users in AWS. Make sure to run this script periodically to ensure that inactive keys are consistently deactivated.