Lesson 2 of 3 AWS CloudTrail

Protecting CloudTrail Logs with Organization Trails and Integrity Validation

This lesson explains how to design CloudTrail for an organisation so that attackers cannot stop, delete or alter the logs, focusing on central collection and tamper resistance.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how an organisation trail logs every account.
  • Explain layers of log protection, such as SSE-KMS, S3 Object Lock and SCPs.
  • Explain how log file integrity validation detects tampering.
  • Write bucket and key policies that only CloudTrail can use for one trail.

Organisation trails

Created in the management account or by a delegated administrator, an organisation trail logs every account. Members can see it but cannot stop, modify or delete it. Deliver it to a bucket in a dedicated log archive account.

True or false

Organisation trails

Exam skills 1.2.2

Check how organisation trails work.

Log in to try this activity Interactive activities are free with an account.

Layers of protection

An attacker who gains access often tries to hide by deleting or stopping logs, so CloudTrail logs need several layers of protection. SSE-KMS with a customer managed key encrypts the logs. The key policy allows CloudTrail to encrypt, with a condition on the trail's ARN, and allows only audit roles to decrypt, so even users who can read the bucket cannot read the logs. A missing key policy permission is a common reason log delivery fails. The bucket policy lets only the CloudTrail service principal write, with an aws:SourceArn condition naming the trail.

Object Lock and versioning prevent logs from being deleted or overwritten. Lifecycle rules enforce retention, and Block Public Access prevents exposure. Service control policies (SCPs) deny cloudtrail:StopLogging, DeleteTrail and UpdateTrail to everyone except a break-glass role, and alerts on attempts show that someone tried. The following table summarises the controls.

ControlPurpose
SSE-KMS with a customer managed keyKey policy lets CloudTrail encrypt (condition on the trail ARN) and only audit roles decrypt. A missing key policy permission is a common cause of failed delivery
Bucket policyOnly the CloudTrail service principal writes, with aws:SourceArn
Object Lock and versioningPrevent deletion or overwriting
Lifecycle rules, Block Public AccessRetention and exposure
SCPsDeny cloudtrail:StopLogging, DeleteTrail, UpdateTrail except to a break-glass role; alert on attempts

The following diagram shows the controls on the bucket and the KMS key that protect an organisation trail's logs.

Protecting the organisation trail's logs. In the log archive account, the bucket policy lets only CloudTrail, for this trail, put objects, and denies deletes except to a break-glass role; Object Lock in compliance mode blocks even that during retention. The key policy lets CloudTrail encrypt only for this trail and the audit role decrypt.
The scenario is illustrative.
Match the pairs

Protecting CloudTrail logs

Exam skills 1.2.2 · 2.2.1

Match each control with what it protects against.

Log in to try this activity Interactive activities are free with an account.

Log file integrity validation

Log files stored in S3 could be modified or deleted by an attacker who gains access to the bucket, which would destroy the evidence of their activity. Log file integrity validation lets investigators prove whether this has happened. When it is enabled, CloudTrail writes an hourly digest file containing SHA-256 hashes of the log files delivered in that hour, and signs each digest file with a private key. Each digest also references the previous one, forming a chain. The aws cloudtrail validate-logs command checks the signatures and hashes and reports any log file that was modified or deleted. Validation detects tampering but does not prevent it, so it is combined with restrictive bucket policies, a separate log archive account and S3 Object Lock.

True or false

Integrity validation

Exam skills 2.2.1 · 5.2.2

Check how CloudTrail log file integrity validation works.

Log in to try this activity Interactive activities are free with an account.
Worked example

A log archive bucket and key that only CloudTrail can write to

The organisation trail delivers to a bucket in the log archive account, encrypted with a customer managed key. The key policy lets CloudTrail encrypt only for this trail, and lets the security team's audit role decrypt:

{
  "Sid": "AllowCloudTrailEncrypt",
  "Effect": "Allow",
  "Principal": { "Service": "cloudtrail.amazonaws.com" },
  "Action": "kms:GenerateDataKey*",
  "Resource": "*",
  "Condition": {
    "StringEquals": { "aws:SourceArn": "arn:aws:cloudtrail:eu-west-1:111111111111:trail/org-trail" },
    "StringLike": { "kms:EncryptionContext:aws:cloudtrail:arn": "arn:aws:cloudtrail:*:111111111111:trail/*" }
  }
},
{
  "Sid": "AllowAuditDecrypt",
  "Effect": "Allow",
  "Principal": { "AWS": "arn:aws:iam::555555555555:role/SecurityAudit" },
  "Action": "kms:Decrypt",
  "Resource": "*"
}

The bucket policy allows s3:PutObject only to cloudtrail.amazonaws.com with the same aws:SourceArn, requires bucket-owner-full-control, and denies deletes to everyone except a break-glass role; Object Lock in compliance mode makes even that impossible during retention. If delivery stops after encryption is enabled, the first thing to check is this key policy statement.

Check yourself

How can you prove that CloudTrail log files have not been tampered with?

Show answer

With log file integrity validation, which produces signed digest files with hashes of the logs.

Exam Tips

Remember for the exam

  • To stop member accounts disabling logging, use an organisation trail with an SCP.
  • To prove that logs have not been tampered with, use log file integrity validation.
  • To encrypt logs with your own key, use SSE-KMS with a key policy that grants CloudTrail access.
  • To make logs undeletable, use S3 Object Lock in a log archive account.
  • If a trail stops delivering after KMS is enabled, fix the key policy.