Sub topic 8
Validating log file integrity
Logs are only useful as evidence if you can show nobody changed them. This chapter explains how CloudTrail log file integrity validation detects modified, deleted, or forged log files. It also shows how to run the check and how to read the results. You will also learn what the check cannot tell you.
It assumes you have already created a trail that delivers to an S3 bucket, and that you can read JSON and run AWS CLI commands. The earlier chapter on S3 delivery covers the file layout used here.
Why integrity needs its own mechanism
A trail writes gzip-compressed JSON files to S3. Anyone with write or delete access to that bucket can edit a file to hide an action, or delete it. S3 permissions reduce that risk, but they do not prove anything after the fact. Integrity validation adds a cryptographic check that you can run later, without trusting the bucket's current contents.
Validation answers one question: are the log files in the bucket the same ones CloudTrail delivered? It does not tell you whether the events are complete or whether the actions were legitimate.
How validation works
When you enable log file validation, CloudTrail does the following:
- It computes a SHA-256 hash of each log file it delivers.
- Once an hour, it writes a digest file listing the log files delivered in that hour, with the hash of each one.
- It signs each digest file with an RSA private key, using SHA256withRSA. The private key stays inside AWS. The signature is stored in the digest object's S3 metadata.
- Each digest file also records the hash and signature of the previous digest file. This links the digests into a chain.
The chain matters. If an attacker deletes one digest file, the next digest still names it and carries its hash, so the gap is visible. If an attacker edits a digest file, its signature no longer verifies.
Where the files live
Digest files are stored in the same bucket as the logs, under a separate folder:
s3://BUCKET/PREFIX/AWSLogs/ACCOUNT_ID/CloudTrail-Digest/REGION/YYYY/MM/DD/Log files stay under CloudTrail/ in the same AWSLogs/ACCOUNT_ID/ folder. The digest file name includes the account ID, Region, trail name, and a timestamp.
What a digest file contains
A digest file is gzip-compressed JSON. These are the fields you will use most:
| Field | Meaning |
|---|---|
| `digestStartTime`, `digestEndTime` | The period the digest covers |
| `digestS3Bucket`, `digestS3Object` | Where this digest is stored |
| `digestPublicKeyFingerprint` | Identifies the public key that verifies the signature |
| `digestSignatureAlgorithm` | `SHA256withRSA` |
| `previousDigestS3Object`, `previousDigestHashValue`, `previousDigestSignature` | Link to the previous digest in the chain |
| `logFiles` | One entry per log file: `s3Object`, `hashValue`, `hashAlgorithm`, `newestEventTime`, `oldestEventTime` |
A digest for an hour with no activity still exists. It has an empty logFiles list.
The hash in each logFiles entry is computed over the uncompressed content of the log file. Keep this in mind if you verify a hash by hand.
Enabling validation
For a new trail, pass --enable-log-file-validation to create-trail, as in the earlier chapter on creating trails. For an existing trail, update it:
aws cloudtrail update-trail \
--name org-audit-trail \
--enable-log-file-validationConfirm the setting:
aws cloudtrail get-trail \
--name org-audit-trail \
--query 'Trail.LogFileValidationEnabled'The command should print true.
Running validate-logs
The validate-logs command downloads the digest files for a time range, verifies each signature, follows the chain, and then checks every log file listed in the digests against its hash.
aws cloudtrail validate-logs \
--trail-arn arn:aws:cloudtrail:us-east-1:123456789012:trail/org-audit-trail \
--start-time 2026-11-01T00:00:00Z \
--end-time 2026-11-20T00:00:00ZOutput for a healthy trail looks similar to this:
Validating log files for trail arn:aws:cloudtrail:us-east-1:123456789012:trail/org-audit-trail between 2026-11-01T00:00:00Z and 2026-11-20T00:00:00Z
Results requested for 2026-11-01T00:00:00Z to 2026-11-20T00:00:00Z
Results found for 2026-11-01T00:00:00Z to 2026-11-19T23:59:59Z:
456/456 digest files valid
1203/1203 log files validThe command takes these options:
--trail-arnidentifies the trail. The command reads the trail's bucket and prefix from it.--start-timeand--end-timeset the range. Use UTC timestamps.--end-timedefaults to now.--s3-bucketand--s3-prefixpoint to where the files are. Use them when you validate a copy of the logs, or logs that were moved to another bucket.--account-idselects an account when validating an organization trail's logs for a member account.--verboseprints a line for every file, including the valid ones.
The principal that runs the command needs cloudtrail:GetTrail and cloudtrail:ListPublicKeys. It also needs s3:ListBucket and s3:GetObject on the bucket. ListPublicKeys returns the public keys used to verify the signatures. The command uses the key that matches each digest's fingerprint.
Validating where the logs are, not where they started
Run validation from a separate account, or from a machine that has a read-only copy of the bucket. If you validate from the same account an attacker controls, the attacker may also have changed the permissions that validate-logs depends on. A clean copy of the logs in another account gives you a result you can trust more.
Reading the results
When something is wrong, validate-logs reports it per file. The common outcomes are:
| Result | Likely meaning |
|---|---|
| `INVALID: hash value doesn't match` | A log file was modified after delivery |
| `INVALID: not found` for a log file | A log file named in a digest was deleted or moved |
| `INVALID: not found` for a digest | A digest file is missing, which breaks the chain at that point |
| `INVALID: signature verification failed` | A digest file was altered, or the wrong public key was used |
| No digest for part of the range | Logging was stopped, validation was not enabled, or the range is too recent |
Two situations produce a gap without any tampering:
- The last hour is incomplete. Digests are delivered about an hour after the period they cover. If
--end-timeis close to now, the final period has no digest yet. End the range at least an hour or two in the past. - Logging was stopped. A
StopLoggingcall, or deleting the trail, means no digests exist for that time. This is a finding in itself, so look for theStopLoggingevent in the surrounding period.
Verifying one file by hand
You rarely need to do this, but it clarifies what the tool checks. The script below downloads one digest file, then recomputes the SHA-256 hash of each log file it lists and compares the two values. It does not verify the RSA signature, so it is a hash check only. Use validate-logs for the full check.
import gzip
import hashlib
import json
import sys
import boto3
s3 = boto3.client("s3")
def read_gz(bucket, key):
body = s3.get_object(Bucket=bucket, Key=key)["Body"].read()
return gzip.decompress(body)
def main(bucket, digest_key):
digest = json.loads(read_gz(bucket, digest_key))
print(f"Digest covers {digest['digestStartTime']} to {digest['digestEndTime']}")
for entry in digest.get("logFiles", []):
# The recorded hash is over the uncompressed log file content.
content = read_gz(entry["s3Bucket"], entry["s3Object"])
actual = hashlib.sha256(content).hexdigest()
status = "OK" if actual == entry["hashValue"].lower() else "MISMATCH"
print(f"{status} {entry['s3Object']}")
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])Run it with the bucket name and the full key of a digest file:
python check_digest.py my-cloudtrail-logs-bucket \
AWSLogs/123456789012/CloudTrail-Digest/us-east-1/2026/11/19/123456789012_CloudTrail-Digest_us-east-1_org-audit-trail_us-east-1_20261119T100000Z.json.gzA MISMATCH line means the log file's content differs from what CloudTrail hashed when it delivered the file.
What validation does not do
Know these limits before you rely on the result in an investigation:
- It detects tampering but does not prevent it. Someone with the right S3 permissions can still change or delete files. Validation tells you afterward.
- It cannot recover deleted data. If a log file and its digest are both deleted, you know there is a hole but not what was in it. Digests older than the deleted one still verify, and the next digest still names the missing file.
- It does not prove completeness. It checks files that CloudTrail delivered. It cannot show that an event type was in scope, since event selectors decide that.
- It does not check events that never reached S3. Delivery can lag, so an attacker's recent actions might not appear yet.
- It trusts AWS-held signing keys. The check relies on the public keys that CloudTrail publishes. That is the intended trust boundary.
For stronger protection, combine validation with the controls in the chapter on protecting the trail. Examples are S3 Object Lock, a bucket in a separate account, and restricted s3:DeleteObject permissions. Validation then confirms what the access controls were meant to guarantee.
Common errors
- No digest files found. Validation was not enabled for the period, or the range starts before it was enabled. Check
LogFileValidationEnabledand compare against the trail's history. - Access denied. The caller lacks
s3:GetObjectors3:ListBucketon the bucket, orcloudtrail:ListPublicKeys. If the bucket uses a KMS key, the caller also needskms:Decrypton it. - Wrong time format. Use UTC with a trailing
Z, such as2026-11-01T00:00:00Z. - Validating a trail from another Region. Pass the trail's own ARN. A multi-Region trail has digests per Region, and the command handles the Regions for that trail.
- Everything invalid after moving logs. If you copy logs to another bucket, keep the key structure the same. Then pass
--s3-bucketand--s3-prefix. Renaming objects breaks the paths that digests record.
Exercise
You run validate-logs for 2026-11-10 through now and it reports every file valid, but it says results were found only up to two hours before the current time. Is this a sign of tampering? What do you do?
Show answer
No. Digest files are delivered about an hour after the period they cover, so the most recent period has no digest yet. Re-run the command with an --end-time at least a couple of hours in the past, or wait and run it again later. A gap that stays in older periods would need investigation.
Exercise
validate-logs reports one log file as "hash value doesn't match", and another as "not found". Which of these suggests modification and which suggests deletion, and where does the tool get the expected hashes from?
Show answer
The hash mismatch suggests the file was modified after delivery. The "not found" result suggests the file was deleted or moved. The expected hashes come from the signed digest files in the CloudTrail-Digest folder, which list every delivered log file with its SHA-256 hash.
Exercise
A teammate enabled log file validation on an existing trail today and asks you to validate last month's logs. What will happen, and what should the team do differently?
Show answer
There are no digests for last month, so those logs cannot be validated. Validation covers only files delivered after it was enabled. Enable --enable-log-file-validation when the trail is created, and add S3 protections such as Object Lock so older logs are protected in other ways.