Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 170Security · AWS

How to see who did what in AWS with CloudTrail

"Who deleted the bucket?", "Who opened port 22 in the security group?", "Did someone log in as root?" — CloudTrail records every AWS API call: who (user/role), what (action), when, from which IP, and the result. The last 90 days of management events are always there; for longer history and S3 object events you need a trail. This how-to searches the event history, reads an event, creates an organization trail, and alerts on dangerous actions.

  • 5 Lessen
  • 2 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

170.1

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 20

This searches the Event history (last 90 days, management events, per region).

Commando's in deze les

170.2

Step by step

  1. Search by what you know:
AttributeExample
EventNameDeleteBucket, StopInstances, ConsoleLogin, CreateAccessKey
UsernameThe IAM user or the role session name
ResourceNameA bucket name, an instance or security group ID
EventSources3.amazonaws.com, ec2.amazonaws.com

Add --start-time / --end-time and the right --region (global services like IAM log in us-east-1).

  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.

  1. 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-trail

The 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).

  1. Query long history — Athena on the trail bucket, or CloudTrail Lake (SQL), or your SIEM.
  2. Alert on dangerous actions — EventBridge rules to SNS/Slack, for example: root login, ConsoleLogin without MFA, StopLogging/DeleteTrail, CreateAccessKey, security group opened to 0.0.0.0/0.
eventbridge-pattern.json
{
  "detail-type": ["AWS Console Sign In via CloudTrail"],
  "detail": { "userIdentity": { "type": ["Root"] } }
}

Commando's in deze les

170.3

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.

Commando's in deze les

170.4

Common problems

ProblemCauseFix
Event not foundWrong 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 personShared role or long session names.SSO with personal sessions; set RoleSessionName to the user in tools.
lookup-events is slow / throttled2 calls per second limit.Narrow by attribute and time; use Athena/Lake for big searches.
Someone stopped the trailNot protected.SCP denying StopLogging/DeleteTrail; alert on these events.
Log bucket readable by manyLogs show your whole infrastructure.Separate log account, tight bucket policy, Object Lock.
Cost jumped after enabling data eventsData events for all buckets.Only for sensitive buckets, or advanced selectors.

170.5

Go further

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.

Commando's in deze les

Alle commando's in dit hoofdstuk