Sub topic 16
Auditing access with CloudTrail
This chapter assumes you can read IAM policies and CLI output, you know the parameter and secret APIs from the earlier chapters, and you have used jq or can read JSON. You will learn which Parameter Store and Secrets Manager calls CloudTrail records, how to find them, and how to alert on suspicious reads.
What CloudTrail records
AWS CloudTrail logs API calls made in your account. Parameter Store lives under the ssm.amazonaws.com event source. Secrets Manager uses secretsmanager.amazonaws.com. Both services' calls are management events, which CloudTrail records by default. You do not need to enable data event logging.
| Question | Event names to look for |
|---|---|
| Who read a parameter? | `GetParameter`, `GetParameters`, `GetParametersByPath` |
| Who read a secret? | `GetSecretValue`, `BatchGetSecretValue` |
| Who changed a value? | `PutParameter`, `PutSecretValue`, `UpdateSecret` |
| Who deleted something? | `DeleteParameter`, `DeleteSecret` |
| Who changed access? | `PutResourcePolicy`, `DeleteResourcePolicy` |
| What did rotation do? | `RotateSecret`, `UpdateSecretVersionStage` |
| Who used the key? | `Decrypt`, `GenerateDataKey` from `kms.amazonaws.com` |
CloudTrail does not store the secret or parameter value. The service redacts or omits it from the event. A log entry shows that a read happened, who made it and from where, but never what the value was. This makes the logs safe to share with a security team.
Anatomy of a GetSecretValue event
This trimmed event shows the fields you will use most.
{
"eventTime": "2026-11-26T17:41:07Z",
"eventSource": "secretsmanager.amazonaws.com",
"eventName": "GetSecretValue",
"awsRegion": "us-east-1",
"sourceIPAddress": "10.0.12.34",
"userAgent": "Boto3/1.35.0 Python/3.12",
"userIdentity": {
"type": "AssumedRole",
"arn": "arn:aws:sts::111122223333:assumed-role/myapp-prod-role/i-0abc123",
"sessionContext": {
"sessionIssuer": {
"arn": "arn:aws:iam::111122223333:role/myapp-prod-role"
}
}
},
"requestParameters": {
"secretId": "myapp/prod/db"
},
"readOnly": true
}userIdentity.arnnames the caller. For compute services this is an assumed-role session, and the session name often identifies the instance or function.userIdentity.sessionContext.sessionIssuer.arnnames the underlying role. Use it when you want to match every session of one role.requestParameters.secretIdshows the secret the caller asked for. For parameters, the equivalent field isrequestParameters.name.errorCodeappears only on failed calls, such asAccessDeniedException.
Searching recent events
Event history in the CloudTrail console and CLI covers management events from the last 90 days. lookup-events accepts only one lookup attribute per call, so filter on event name and refine with jq.
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=GetSecretValue \
--max-results 50 \
--query 'Events[].CloudTrailEvent' \
--output json \
| jq -r '.[] | fromjson
| select(.requestParameters.secretId == "myapp/prod/db")
| [.eventTime, .userIdentity.arn, .sourceIPAddress] | @tsv'The output is one line per read, with time, caller and source IP. Compare the callers with the roles you expect. A developer's SSO session reading a production secret is the kind of line you are looking for.
To find parameter reads, change the attribute value to GetParametersByPath or GetParameter, and select on .requestParameters.path or .requestParameters.name.
Keeping logs beyond 90 days
Event history is a short window for investigations. Create a trail that delivers events to an S3 bucket, and optionally to CloudWatch Logs. Then you can query the logs with Athena, or a log search tool, over any period you retain.
Turn on log file integrity validation for the trail. CloudTrail then writes signed digest files, and aws cloudtrail validate-logs can show whether a log file was altered or deleted. This matters when you are investigating a secret leak and need to trust the evidence.
For account-wide coverage, an organization trail records every member account into one bucket that member accounts cannot modify.
The KMS side of the story
Reading a secret or a SecureString parameter produces two kinds of events. The service logs GetSecretValue or GetParameter, and KMS logs a Decrypt call against the key. With a customer managed key, the KMS event gives you a second view of the same access.
The KMS event's encryption context ties the decryption to a specific secret or parameter. For Secrets Manager the context includes the secret's ARN. This helps in two cases:
- You can see decryption requests that did not come from your application's normal path, such as someone calling KMS directly.
- You can see which secrets a role really decrypts, which helps when you tighten a KMS key policy.
The AWS managed keys alias/aws/ssm and alias/aws/secretsmanager also log to CloudTrail, but you cannot restrict who uses them beyond IAM on the calling service. A customer managed key gives you a key policy as an extra control and a clean audit target.
Alerting on suspicious reads
Searching logs finds problems after the fact. To be told when it happens, route CloudTrail events to Amazon EventBridge. Management events from the default bus arrive with detail-type set to AWS API Call via CloudTrail.
This pattern matches any GetSecretValue call for the production secret that did not come from the application role.
{
"source": ["aws.secretsmanager"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["secretsmanager.amazonaws.com"],
"eventName": ["GetSecretValue"],
"requestParameters": {
"secretId": ["myapp/prod/db"]
},
"userIdentity": {
"sessionContext": {
"sessionIssuer": {
"arn": [
{ "anything-but": "arn:aws:iam::111122223333:role/myapp-prod-role" }
]
}
}
}
}
}Attach the rule to an SNS topic or a Lambda function that opens a ticket. Two caveats:
- Events with no
sessionIssuerfield, such as calls from an IAM user with long-term keys, do not match ananything-butcondition on a missing field. Add a second rule foruserIdentity.typeequal toIAMUserso those calls do not slip past. - The
secretIdin the request can be the name or the full ARN, depending on what the caller sent. List both forms in the pattern.
Other events worth a rule are DeleteSecret, PutResourcePolicy and AccessDeniedException errors on reads. A burst of denied reads usually means a misconfigured deployment or someone probing for secrets.
How the pieces fit together
Limits and gotchas
- Caching hides reads. The caching patterns from earlier chapters mean one
GetSecretValueevent may stand for thousands of uses. Log entries show when a value was fetched, not each time the application used it. Plan investigations around refresh intervals. - Events arrive with a delay. CloudTrail usually delivers events within several minutes, so treat alerts as near real time, not instant.
- Regional scope. Each Region records its own calls. A trail created with the multi-Region option collects them all. Check this for replicated secrets, because a read of a replica in another Region appears in that Region's events.
- Denied calls are logged too. A call that IAM rejects still appears, with an
errorCode. That makes CloudTrail useful for debugging a missing permission as well as for security. - Cross-account reads. When another account reads your secret through a resource policy, the event appears in both accounts' logs. The caller's account records the call, and the secret owner's account records it as well, so make sure your trail covers the owning account.
- Audit is not prevention. CloudTrail records access after it happens. Least-privilege IAM and key policies remain the control that blocks it.
Exercise
Exercise
A secret myapp/prod/db was read by an unknown IAM user. You have only the CLI and no trail configured, and the read happened 40 days ago. Can you find it, and which command and filter would you use? What changes if the read happened 120 days ago?
Show answer
Yes for 40 days. Event history keeps management events for 90 days, so run aws cloudtrail lookup-events with AttributeKey=EventName,AttributeValue=GetSecretValue, then filter the output with jq on requestParameters.secretId and inspect userIdentity.arn and sourceIPAddress. At 120 days the event has aged out of event history, and without a trail delivering to S3 there is no record. The fix is to create a trail, preferably multi-Region and with log file validation, so future investigations are not limited to 90 days.