Triage and Remediation
How to Prevent
Using Console
Using Console
To prevent user accounts without any usage in AWS IAM using the AWS Management Console, follow these steps:
-
Monitor User Activity:
- Navigate to the IAM Dashboard in the AWS Management Console.
- Go to the “Access Advisor” tab for each user to review their last accessed services and activities.
- Regularly check the “Last Activity” column to identify users who have not accessed any services for a specified period.
-
Set Up CloudWatch Alarms:
- Create CloudWatch Alarms to monitor IAM user activity.
- Set up alarms to trigger notifications when there is no activity for a specified period.
- Use these alarms to identify inactive users promptly.
-
Enable Logging with CloudTrail:
- Ensure AWS CloudTrail is enabled to log all IAM user activities.
- Regularly review CloudTrail logs to identify users with no activity.
- Use CloudTrail insights to detect unusual inactivity patterns.
-
Implement IAM Policies:
- Create and attach IAM policies that enforce regular reviews of user activity.
- Use policies to mandate the removal or deactivation of users who have not logged in or performed any actions within a specified timeframe.
- Ensure compliance with these policies through regular audits and reviews.
Using CLI
Using CLI
To prevent user accounts without any usage in AWS IAM using the AWS CLI, you can follow these steps:
-
List All IAM Users:
Use the following command to list all IAM users in your AWS account. This will help you identify which users exist and need to be monitored for activity.
-
Monitor User Activity:
Regularly check the last activity of each IAM user. You can use the following command to get the last used information for each user. This will help you identify users who have not used their credentials recently.
-
Automate Inactive User Detection:
Create a script to automate the detection of inactive users. You can use AWS CLI commands within a Python script to check the last activity of each user and flag those who have not been active for a specified period.
Example Python script snippet:
-
Implement a Policy for Regular Review:
Establish a policy to regularly review IAM users and their activity. This can be done by scheduling the above script to run periodically (e.g., using AWS Lambda and CloudWatch Events) to ensure continuous monitoring and prompt action on inactive users.
Example of scheduling a Lambda function using AWS CLI:
Using Python
Using Python
To prevent user accounts without any usage in IAM from existing in AWS, Azure, and GCP using Python scripts, you can follow these steps:
AWS (Amazon Web Services)
-
List All IAM Users:
Use the
boto3
library to list all IAM users. -
Check User Activity:
Check the last activity of each user by examining their access keys and login profile.
Azure (Microsoft Azure)
-
List All Users:
Use the
azure-identity
andazure-graphrbac
libraries to list all users. -
Check User Activity:
Check the last sign-in activity of each user.
GCP (Google Cloud Platform)
-
List All Users:
Use the
google-auth
andgoogle-api-python-client
libraries to list all users. -
Check User Activity:
Check the last login time of each user.