Sub topic 3
Pinning the audience
This chapter assumes you know what a JSON Web Token (JWT) is, can read GitHub Actions workflow YAML, and have written a basic AWS IAM trust policy. Here you will learn what the aud claim does and why a trust policy should check it.
What the audience claim means
The aud (audience) claim names the party the token is meant for. A token issued for one service should not be accepted by another. If a service does not check aud, it may accept a token that was minted for a different purpose.
GitHub signs every OIDC token with the same issuer, https://token.actions.githubusercontent.com. The audience is what changes from one use to the next. When the aws-actions/configure-aws-credentials action requests a token, it asks for the audience sts.amazonaws.com. A workflow that wants to talk to a different service can request a different audience.
The decoded claims of a token for AWS look like this:
{
"iss": "https://token.actions.githubusercontent.com",
"aud": "sts.amazonaws.com",
"sub": "repo:example-org/example-repo:ref:refs/heads/main",
"repository": "example-org/example-repo",
"ref": "refs/heads/main"
}Why the check matters
Every GitHub-hosted workflow in every organization gets tokens from the same issuer. The signature only proves that GitHub issued the token. It does not prove that the token was meant for your AWS account.
Without an audience check, any token whose sub matches your condition could be accepted, even one created for another service. A token requested for a third-party service could be replayed against your role if that service was careless or hostile. Pinning aud closes that gap.
Where the check goes
In AWS, the condition key is the provider hostname followed by :aud. Use StringEquals, because the audience is a fixed value and needs no wildcard.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
}
}
}
]
}This policy checks only the audience. It is not safe to use alone, because it would let any repository that GitHub serves assume the role. Later chapters add the sub condition. Treat the aud check as one required layer, not a substitute for the others.
How the audience is set
The audience in the token must match the value in the trust policy. There are two places it can come from:
- The default for
configure-aws-credentialsissts.amazonaws.com. You normally do not set it. - The
audienceinput of the action overrides the default. If you set it, update the trust policy to the same value.
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/example-deploy-role
aws-region: us-east-1
audience: sts.amazonaws.comAWS also keeps a list of allowed audiences on the OIDC provider resource. The trust policy condition is still the check that applies to each role, so keep it in the policy.
Common errors
| Symptom | Likely cause |
|---|---|
| `Not authorized to perform sts:AssumeRoleWithWebIdentity` | The `aud` in the token differs from the policy value. |
| Role works only in some workflows | Some workflows set a custom `audience` and others do not. |
| Policy has `aud` under `StringLike` with `*` | The check accepts any audience and protects nothing. |
Exercise
A trust policy checks token.actions.githubusercontent.com:sub with an exact repository and branch, but has no aud condition. Why should you still add aud, and which operator should you use?
Show answer
The signature only shows that GitHub issued the token, not who it was meant for. Without an aud check, a token minted for a different audience could be accepted if its sub matches. Add "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" under StringEquals, because the audience is a fixed value and needs no wildcard.