Sub topic 11
Protecting the trail and its logs
A trail is only useful if you can trust what it records. An attacker who gets into an account will often try to stop logging, delete the logs, or change what is recorded. This chapter covers the controls that make those moves hard to carry out and easy to notice.
This chapter assumes you can read IAM and S3 bucket policies, have created a trail (see the earlier chapter on trails), and can use the AWS CLI.
Threats to defend against
Three things can go wrong:
- Silencing: someone calls
StopLogging,DeleteTrail,UpdateTrail, orPutEventSelectorsso that later activity is not captured. - Tampering: someone edits or deletes log files already in S3.
- Unintended reading: log files contain user names, IP addresses, and resource names, so broad read access is itself a leak.
Lock down the bucket
CloudTrail writes to your bucket as a service principal, so the bucket policy must allow only that. Scope it to your trail with aws:SourceArn, so another account's trail cannot write into your bucket.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck",
"Effect": "Allow",
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::my-cloudtrail-logs-bucket",
"Condition": {
"StringEquals": {
"aws:SourceArn": "arn:aws:cloudtrail:us-east-1:123456789012:trail/org-audit-trail"
}
}
},
{
"Sid": "AWSCloudTrailWrite",
"Effect": "Allow",
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-cloudtrail-logs-bucket/AWSLogs/123456789012/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control",
"aws:SourceArn": "arn:aws:cloudtrail:us-east-1:123456789012:trail/org-audit-trail"
}
}
}
]
}Then add these bucket settings:
aws s3api put-public-access-block \
--bucket my-cloudtrail-logs-bucket \
--public-access-block-configuration \
BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true
aws s3api put-bucket-versioning \
--bucket my-cloudtrail-logs-bucket \
--versioning-configuration Status=EnabledVersioning keeps earlier copies when an object is overwritten or deleted. For stronger guarantees, consider S3 Object Lock, which blocks deletion for a retention period, and replicating logs to a bucket in a separate security account. Keep reader access narrow: grant s3:GetObject on the log prefix only to auditors and security tooling.
Encrypt with KMS
By default, CloudTrail encrypts log files with S3-managed keys (SSE-S3). With a KMS key, reading a log file also requires kms:Decrypt on that key, which gives you a second, separate permission check.
aws cloudtrail update-trail \
--name org-audit-trail \
--kms-key-id arn:aws:kms:us-east-1:123456789012:key/<key-id>The key policy must let cloudtrail.amazonaws.com call kms:GenerateDataKey*, and must let your auditors call kms:Decrypt. If the key policy is missing the CloudTrail statement, the update fails or log delivery stops, so test delivery after the change.
Restrict who can change the trail
Treat the four actions that silence a trail as privileged. In an organization, a service control policy (SCP) can deny them to everyone except a break-glass role.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ProtectCloudTrail",
"Effect": "Deny",
"Action": [
"cloudtrail:StopLogging",
"cloudtrail:DeleteTrail",
"cloudtrail:UpdateTrail",
"cloudtrail:PutEventSelectors"
],
"Resource": "*",
"Condition": {
"ArnNotLike": {
"aws:PrincipalArn": "arn:aws:iam::*:role/SecurityAdmin"
}
}
}
]
}SCPs do not apply to the organization's management account, so keep workloads out of it. An organization trail also cannot be modified from member accounts, which helps here.
Detect tampering anyway
Prevention can fail, so combine it with detection:
- Keep log file validation on, and run
aws cloudtrail validate-logsregularly. - Alert on
StopLogging,DeleteTrail, and bucket policy changes using the alerting approach from the previous chapter.
Common errors
- No logs arrive after a policy edit. The bucket policy
Resourcepath must include the correct account ID underAWSLogs/. - Auditors get
AccessDeniedon a readable object. They lackkms:Decrypton the trail's key. - The trail owner can still delete everything. Bucket versioning alone does not stop a privileged user, so add Object Lock or cross-account replication.
Exercise
A teammate with broad admin rights in a member account runs aws cloudtrail stop-logging on the organization's trail. Which two controls from this chapter would have stopped or exposed this, and which one does each job?
Show answer
An SCP denying cloudtrail:StopLogging (and related actions) to everyone except a break-glass role prevents the call. An alert on the StopLogging event, raised from the trail's own records, exposes it if the call gets through. Log file validation does not help here, because it detects changes to delivered files rather than a stopped trail.