Skip to main content

Triage and Remediation

How to Prevent

Using Console

To prevent Role Service Inactivity in IAM using the AWS Management Console, follow these steps:
  1. Enable Access Advisor:
    • Navigate to the IAM dashboard in the AWS Management Console.
    • Select the “Roles” tab.
    • Choose the specific role you want to monitor.
    • Go to the “Access Advisor” tab to review the services that the role has accessed and the last accessed time.
    • Regularly review this information to identify and take action on inactive roles.
  2. Set Up CloudWatch Alarms:
    • Go to the CloudWatch dashboard.
    • Create a new alarm based on IAM metrics.
    • Set the alarm to trigger if a role has not been used for a specified period.
    • Configure notifications to alert administrators when the alarm is triggered.
  3. Enable AWS Config Rules:
    • Navigate to the AWS Config dashboard.
    • Ensure that AWS Config is enabled in your account.
    • Add a managed rule such as iam-role-last-used to monitor the last time an IAM role was used.
    • Set up notifications for compliance changes to be alerted when a role becomes inactive.
  4. Implement IAM Role Policies:
    • Go to the IAM dashboard and select the “Roles” tab.
    • Choose the role you want to configure.
    • Attach a policy that includes conditions to limit the role’s permissions based on time or usage.
    • Use the aws:RequestTag or aws:PrincipalTag conditions to enforce policies that disable or restrict roles after a period of inactivity.
By following these steps, you can proactively monitor and manage IAM role activity to prevent role service inactivity in AWS.
To prevent Role Service Inactivity in IAM using AWS CLI, you can follow these steps:
  1. Create a Role with Specific Permissions: Ensure that the role you create has the necessary permissions and is not overly permissive. Use the create-role command to create a role with a specific policy.
  2. Attach a Policy to the Role: Attach a policy to the role that grants only the necessary permissions. Use the attach-role-policy command to attach a managed policy or put-role-policy to attach an inline policy.
  3. Enable CloudTrail to Monitor Role Activity: Enable AWS CloudTrail to monitor and log all activities associated with the role. This helps in identifying any inactivity or misuse.
  4. Set Up CloudWatch Alarms for Inactivity: Create CloudWatch Alarms to monitor the role’s activity and trigger alerts if the role is inactive for a specified period.
By following these steps, you can ensure that roles are properly configured, monitored, and any inactivity is promptly addressed.
To prevent Role Service Inactivity in IAM using Python scripts, you can follow these steps:

1. Set Up AWS SDK (Boto3)

First, ensure you have the AWS SDK for Python (Boto3) installed. You can install it using pip if you haven’t already:

2. Create a Python Script to List Roles

Create a Python script to list all IAM roles and their last used timestamps. This will help you identify inactive roles.

3. Automate Role Deactivation or Notification

You can extend the script to either deactivate the inactive roles or send notifications to the administrators.

Deactivate Inactive Roles

Send Notifications

4. Schedule the Script

Use a task scheduler like cron (Linux) or Task Scheduler (Windows) to run the script periodically to ensure continuous monitoring and prevention of role service inactivity.

Example (Linux Cron Job)

By following these steps, you can effectively prevent role service inactivity in IAM using Python scripts.