Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=AuthorizeSecurityGroupIngress --max-results 10 --query 'Events[].[EventTime,Username,EventName]' --output table
aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceName,AttributeValue=sg-0123456789abcdef0 --max-results 20This searches the Event history (last 90 days, management events, per region).
Step by step
- Search by what you know:
| Attribute | Example |
|---|---|
EventName | DeleteBucket, StopInstances, ConsoleLogin, CreateAccessKey |
Username | The IAM user or the role session name |
ResourceName | A bucket name, an instance or security group ID |
EventSource | s3.amazonaws.com, ec2.amazonaws.com |
Add --start-time / --end-time and the right --region (global services like IAM log in us-east-1).
- Read one event — the important fields:
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=DeleteBucket --max-results 1 --query 'Events[0].CloudTrailEvent' --output text | jq '{time: .eventTime, who: .userIdentity.arn, ip: .sourceIPAddress, what: .eventName, params: .requestParameters, error: .errorCode}'userIdentity.arn for an SSO user looks like …assumed-role/AWSReservedSSO_Admin_…/alice — the last part is the person.
- Create an organization trail for long-term, tamper-resistant history (once, in the management account):
aws cloudtrail create-trail --name org-trail --s3-bucket-name acme-cloudtrail-logs --is-organization-trail --is-multi-region-trail --enable-log-file-validation
aws cloudtrail start-logging --name org-trailThe log bucket lives in a separate log archive account, versioned, with Object Lock if possible. Add S3 data events only for buckets that need them (they cost more).
- Query long history — Athena on the trail bucket, or CloudTrail Lake (SQL), or your SIEM.
- Alert on dangerous actions — EventBridge rules to SNS/Slack, for example: root login,
ConsoleLoginwithout MFA,StopLogging/DeleteTrail,CreateAccessKey, security group opened to0.0.0.0/0.
{
"detail-type": ["AWS Console Sign In via CloudTrail"],
"detail": { "userIdentity": { "type": ["Root"] } }
}Check that it worked
lookup-events finds the action you look for with user, time and IP; aws cloudtrail get-trail-status --name org-trail shows IsLogging: true; and a test console login with the root user (in a sandbox) triggers your alert.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Event not found | Wrong region, older than 90 days, or a data event. | Check the region (us-east-1 for IAM/console); use the trail/Athena; data events need to be enabled. |
| Only a role name, no person | Shared role or long session names. | SSO with personal sessions; set RoleSessionName to the user in tools. |
lookup-events is slow / throttled | 2 calls per second limit. | Narrow by attribute and time; use Athena/Lake for big searches. |
| Someone stopped the trail | Not protected. | SCP denying StopLogging/DeleteTrail; alert on these events. |
| Log bucket readable by many | Logs show your whole infrastructure. | Separate log account, tight bucket policy, Object Lock. |
| Cost jumped after enabling data events | Data events for all buckets. | Only for sensitive buckets, or advanced selectors. |
Go further
- Command pages: aws, jq.
- Next how-tos: Find public S3 buckets, Find drift between Terraform and the cloud, Log in to AWS with SSO.
- Full guide: AWS CLI. At work: Host security tools.
- Practise: Lab: multi-account guardrails — Organizations, SCPs and a central log trail.
1How long does the CloudTrail event history keep management events without a trail?
90 days.
2Why put the trail's log bucket in a separate account?
So an attacker or admin in the workload account can not delete or change the evidence.