Guides

Detecting risky IAM changes with CloudTrail LookupEvents

Use CloudTrail event history and the LookupEvents API to spot new access keys, changed trust policies and stopped logging in AWS, with nothing to deploy.

Updated

Every AWS account already keeps a searchable record of its recent management events: CloudTrail event history. You don't need a trail, an S3 bucket or an EventBridge rule to read it, which makes it a good first place to look for risky IAM changes.

What event history gives you

Event history is a viewable, searchable record of the past 90 days of CloudTrail management events in each Region (AWS: CloudTrail concepts). You can read it with the LookupEvents API (API reference). Its limits shape how you use it:

  • one lookup attribute per call: an event name, an event source, a user name, a resource and so on;
  • up to 50 events per page, newest first, with a token for the next page;
  • two requests per second per account per Region, after which calls are throttled.

Events from global services such as IAM and STS are recorded in US East (N. Virginia), us-east-1 (AWS: global service events), so that's where to look for IAM changes.

Look up IAM changes

Every IAM write in the last day:

aws cloudtrail lookup-events --region us-east-1 \
  --lookup-attributes AttributeKey=EventSource,AttributeValue=iam.amazonaws.com \
  --start-time "$(date -u -v-1d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '1 day ago' +%Y-%m-%dT%H:%M:%SZ)" \
  --query 'Events[?ReadOnly==`false`].[EventTime,EventName,Username]' --output table

One event type, with the request that made it. Each event's full record is a JSON string in CloudTrailEvent:

aws cloudtrail lookup-events --region us-east-1 \
  --lookup-attributes AttributeKey=EventName,AttributeValue=UpdateAssumeRolePolicy \
  --max-results 5 --output json \
| jq -r '.Events[].CloudTrailEvent | fromjson
         | [.eventTime, .userIdentity.arn, .requestParameters.roleName] | @tsv'

Which events matter

These IAM, sign-in and CloudTrail events usually deserve a look:

EventWhy
CreateUser, CreateAccessKey, CreateLoginProfileNew long-lived credentials.
AttachUserPolicy, AttachRolePolicy, PutUserPolicy, PutRolePolicyPermissions added directly.
CreatePolicyVersion, SetDefaultPolicyVersionA managed policy's effective permissions changed.
UpdateAssumeRolePolicySomeone changed who can assume a role.
DeleteRolePermissionsBoundary, DeactivateMFADeviceA guardrail was removed.
CreateSAMLProvider, CreateOpenIDConnectProviderA new way to federate into the account.
ConsoleLoginRoot sign-ins, and IAM-user sign-ins without MFA (additionalEventData.MFAUsed).
StopLogging, DeleteTrailSomeone turned off the audit trail.

The IAM events and what they mean are documented in Logging IAM and AWS STS API calls with AWS CloudTrail.

Polling, and its limits

A small script can poll LookupEvents every few minutes, remember the time of the last event it saw, and alert on the events above. Keep it under the rate limit (one event source per call, a pause between pages), and overlap each window a little, because events take time to appear.

This approach has trade-offs worth being honest about:

  • It only sees events while something is polling, and only from the past 90 days.
  • It's not instant. For near-real-time alerting, the usual answer is a trail with CloudWatch Logs metric filters and alarms, as the CIS benchmark's monitoring controls describe for events such as IAM policy changes (AWS: CIS controls in Security Hub CSPM). That means deploying infrastructure in each account.
  • Event history covers management events only, not data events.

Doing this in AccessLens

AccessLens polls LookupEvents for iam.amazonaws.com, signin.amazonaws.com and cloudtrail.amazonaws.com in every account you add, while the app is open or in the tray. It turns the events above and a few more into alerts with a severity (attaching an admin policy is critical; failed attempts are one level lower), deduplicates them, and shows them as OS notifications and in an alert center. It installs nothing in your accounts: no trail, rule or log group. See Changes, alerts and scheduling.

Check every account at once.

Sign in with IAM Identity Center, create one read-only role, and scan. Your findings stay on your machine.