Sub topic 17
Auditing deployments with CloudTrail
This chapter assumes you have a working OIDC deployment: a GitHub identity provider in IAM, a role with a trust policy, and a workflow that uses aws-actions/configure-aws-credentials. You should also know the AWS CLI and be comfortable reading JSON. The goal is to answer "who deployed what, from which repository and branch, and when" using AWS CloudTrail.
What CloudTrail records for an OIDC deployment
CloudTrail is the AWS service that logs API calls. An OIDC deployment produces two kinds of events that matter for auditing.
- The role assumption. The action calls
sts:AssumeRoleWithWebIdentity. CloudTrail records who asked, which role they got, and whether it succeeded. - Every call made with the temporary credentials.
s3:PutObject,cloudformation:UpdateStackand so on all appear as actions by an assumed-role session.
The two are linked by the role session name. That name appears in the assumption event and again in the ARN of every later call.
Anatomy of the assumption event
The AssumeRoleWithWebIdentity call is not signed with AWS credentials, because the caller has none yet. CloudTrail therefore records the identity as type WebIdentityUser. A trimmed event looks like this:
{
"eventTime": "2026-12-04T15:41:07Z",
"eventSource": "sts.amazonaws.com",
"eventName": "AssumeRoleWithWebIdentity",
"userIdentity": {
"type": "WebIdentityUser",
"userName": "repo:my-org/my-repo:ref:refs/heads/main",
"identityProvider": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"requestParameters": {
"roleArn": "arn:aws:iam::123456789012:role/github-deploy",
"roleSessionName": "deploy-8123456789-1",
"durationSeconds": 3600
},
"sourceIPAddress": "20.0.0.1"
}The fields you will use most:
| Field | What it tells you |
|---|---|
| `userIdentity.userName` | The `sub` claim from the token: the repository and the branch or environment. |
| `userIdentity.identityProvider` | Which IAM OIDC provider vouched for the token. |
| `requestParameters.roleArn` | The role that was requested. |
| `requestParameters.roleSessionName` | The label you can use to find the later calls. |
| `errorCode`, `errorMessage` | Present only when the call failed. |
The sub claim is the strongest piece of evidence here. It is the same value your trust policy conditions match, so the log shows exactly which identity the policy accepted.
Make sessions traceable with a session name
By default the action names the session GitHubActions. Every run then looks identical in the logs. Set a name that includes the run ID so you can trace a session back to a specific workflow run:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-deploy
role-session-name: deploy-${{ github.run_id }}-${{ github.run_attempt }}
aws-region: us-east-1Session names are limited to 64 characters and may contain letters, digits and the characters _+=,.@-. Do not put github.repository in the name, because its / is not allowed.
With this setting, the S3 call from the diagram is recorded with this identity:
userIdentity.type:AssumedRoleuserIdentity.arn:arn:aws:sts::123456789012:assumed-role/github-deploy/deploy-8123456789-1
Search for that run ID and you find every API call from that run. You can also open the run in GitHub, since the same ID appears in the run URL.
Querying recent events from the CLI
CloudTrail's event history keeps 90 days of management events and needs no setup. Management events cover STS and most deployment calls. Use lookup-events to find recent role assumptions:
aws cloudtrail lookup-events \
--region us-east-1 \
--lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRoleWithWebIdentity \
--max-results 20 \
--output json \
| jq -r '.Events[].CloudTrailEvent | fromjson
| [.eventTime, .userIdentity.userName, .requestParameters.roleSessionName, (.errorCode // "OK")]
| @tsv'Each output row gives the time, the sub claim, the session name, and either OK or the error code. A sub you do not recognize, such as another repository or a pull request ref, is worth investigating even if the call failed.
lookup-events has two limits. It accepts a single lookup attribute per call, so you filter further with jq. It also returns events only from the Region you query. STS events are logged in the Region of the endpoint that handled the call, so query the Region your workflow's aws-region and STS endpoint use.
Keeping logs longer with a trail
A trail is a CloudTrail configuration that delivers events to an S3 bucket. Create a multi-Region trail in the account that owns the deployment role. Then query the bucket with Amazon Athena, or send events to CloudWatch Logs. Three practical points:
- Enable log file validation on the trail so you can show the logs were not altered.
- Send the bucket to a separate logging account if you can. A compromised deployment role should not be able to delete its own audit trail.
- Management events cover STS and control-plane calls. Data events, such as individual S3 object reads and writes, are off by default and cost extra. Turn them on only for buckets where you need object-level history.
Alerting on failed or unexpected assumptions
CloudTrail events also flow to Amazon EventBridge, so you can react to failures. This event pattern matches every failed web identity assumption:
{
"source": ["aws.sts"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["sts.amazonaws.com"],
"eventName": ["AssumeRoleWithWebIdentity"],
"errorCode": [{ "exists": true }]
}
}Point the rule at an SNS topic. A failure is usually a misconfigured workflow, such as a wrong branch or a typo in the sub condition. A burst of failures from an unfamiliar repository is a signal that someone is probing your role.
Reading failures
Failed assumptions are logged with an errorCode, and the errorMessage often names the cause. This is useful when the GitHub log only shows a generic "Not authorized to perform sts:AssumeRoleWithWebIdentity".
AccessDeniedwith a matchingsubyou did not expect means the trust policy conditions rejected the token. CompareuserNamewith yourStringLikepattern character by character.InvalidIdentityTokenpoints at the token or provider: a wrong audience, or no provider registered for that issuer.- No event at all means the request never reached STS. Check that the workflow has
id-token: write, or that you are looking in the correct Region and account.
Exercise
A deployment to production changed an S3 bucket at an unexpected time. You find the S3 PutObject event in CloudTrail with the identity arn:aws:sts::123456789012:assumed-role/github-deploy/deploy-8123456789-2. How do you find which repository and branch made the change, and what do the trailing numbers tell you?
Show answer
Search for the AssumeRoleWithWebIdentity event whose requestParameters.roleSessionName is deploy-8123456789-2. Its userIdentity.userName holds the sub claim, which names the repository and the branch or environment. The session name was set as deploy-<run_id>-<run_attempt>, so the run ID is 8123456789 and this was the second attempt (a re-run) of that run. The same ID locates the run in GitHub.