Sub topic 13
The id-token permission and OIDC to cloud providers
This chapter assumes you can read workflow YAML, know how the permissions key works at workflow and job level, and have a basic idea of what an IAM role is in a cloud provider. It covers the id-token permission, which is different from the other scopes you have seen. It does not grant access to anything in GitHub. It lets a job ask GitHub for a signed identity token that a cloud provider can verify.
The problem OIDC solves
A workflow that deploys to AWS, Azure, or Google Cloud needs credentials. The old approach is to create a long-lived access key, store it as a repository secret, and read it in the workflow. That key has several weaknesses:
- It does not expire until someone rotates it, so a leaked copy stays useful.
- It works from anywhere, not only from your workflow.
- Rotation is manual, so it often does not happen.
- Every workflow that can read the secret has the same access.
OpenID Connect (OIDC) replaces the stored key with a short-lived token. GitHub acts as an identity provider. For each job that asks, GitHub issues a signed JSON Web Token (JWT) that states where the job is running: which repository, which branch or tag, which workflow, and which environment. The cloud provider checks the signature and the claims, and if they match a trust rule you wrote, it returns temporary cloud credentials. No cloud secret is stored in GitHub.
What id-token: write does
The id-token scope has only two useful values, write and none. There is no read level that does anything. Setting id-token: write allows the job to request an OIDC token from GitHub. When the permission is granted, GitHub exposes two environment variables to the job, ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN. Official cloud login actions use them to fetch the JWT.
The name is misleading. write does not let the job modify anything in your repository. It only allows the job to mint an identity token. What that token can do depends entirely on the trust policy you configure in the cloud account.
Because id-token is a separate scope, contents: read does not include it. If you restrict permissions at the workflow level and forget to add it, the cloud login step fails. The cause is explained in the troubleshooting section below.
A minimal AWS example
The following workflow assumes an AWS IAM role through OIDC. The role must already exist, with GitHub's OIDC provider (token.actions.githubusercontent.com) registered as an identity provider in the account.
name: deploy
on:
push:
branches: [main]
permissions: {}
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
aws-region: us-east-1
- run: aws sts get-caller-identityNote the pattern from earlier chapters. The workflow starts with no permissions, and only the one job that needs the token gets id-token: write, plus contents: read so checkout works. Setting id-token: write at job level also keeps unrelated jobs, and any third-party actions they run, from requesting identity tokens.
Azure uses azure/login and Google Cloud uses google-github-actions/auth. Both read the same two environment variables, so the permission block looks the same for all three providers. Only the cloud-side setup differs.
The trust policy does the real work
The workflow permission is only the first gate. The second gate is the trust policy in the cloud account, and it is where least privilege is actually enforced for OIDC. The JWT carries claims, and the policy decides which claim values are allowed.
| Claim | Meaning | Example value |
|---|---|---|
| `iss` | Token issuer | `https://token.actions.githubusercontent.com` |
| `aud` | Audience the token is meant for | `sts.amazonaws.com` |
| `sub` | Subject, which identifies the workflow context | `repo:my-org/my-repo:ref:refs/heads/main` |
| `repository` | Owner and repository name | `my-org/my-repo` |
| `ref` | Git ref that triggered the run | `refs/heads/main` |
| `environment` | Deployment environment, if the job uses one | `production` |
| `job_workflow_ref` | The workflow file that ran, including a reusable workflow | `my-org/my-repo/.github/workflows/deploy.yml@refs/heads/main` |
Here is an AWS trust policy that accepts tokens only from the main branch of one repository:
{
"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",
"token.actions.githubusercontent.com:sub": "repo:my-org/my-repo:ref:refs/heads/main"
}
}
}
]
}Both conditions matter. The aud condition makes sure the token was minted for AWS. The sub condition pins the role to one repository and branch.
Common trust policy mistakes
- Wildcards that are too wide. A condition such as
repo:my-org/*lets every repository in the organization assume the role, including a new repository someone creates tomorrow. Pin the full repository name. - No
subcondition at all. Without it, any repository on GitHub that can produce a token with the right audience may be able to assume the role. - Trusting pull request subjects. A subject like
repo:my-org/my-repo:pull_requestis issued for pull request runs. Do not attach production permissions to it. - Pinning to a branch when you want an approval gate. Use a deployment environment instead, so the subject becomes
repo:my-org/my-repo:environment:production. Required reviewers on that environment then control who can deploy.
Forks, Dependabot, and the OIDC token
The event rules from the previous chapters apply here too. For a pull_request event from a fork, GitHub forces the token to read-only. In that case id-token: write is not granted, so a fork cannot obtain an OIDC token through that path. This is why you should not rely on pull_request runs to deploy preview environments from forks.
Be careful with pull_request_target. It runs in the context of the base repository and can receive write permissions. If a pull_request_target workflow checks out and runs code from the pull request while holding id-token: write, an attacker's code can request a token and assume your cloud role. Treat that combination as a vulnerability. Keep id-token: write out of any workflow that executes untrusted code.
Reusable workflows
A reusable workflow called with workflow_call can request id-token: write only if the calling workflow grants it. A called workflow can lower permissions but never raise them above what the caller allows. The caller must therefore set the permission on the job that calls the reusable workflow:
name: release
on:
push:
tags: ['v*']
permissions: {}
jobs:
deploy:
permissions:
contents: read
id-token: write
uses: my-org/shared-workflows/.github/workflows/deploy.yml@v2
with:
environment: productionThe job_workflow_ref claim lets the cloud trust policy require a particular reusable workflow. That way, only your reviewed shared deployment workflow can assume the role, and a copy of the logic in another workflow cannot.
Troubleshooting
If the id-token permission is missing, the login action usually fails with a message similar to:
Error: Credentials could not be loaded, please check your action inputs: Could not load credentials from any providersor, in the Google and Azure actions, a message that ACTIONS_ID_TOKEN_REQUEST_TOKEN or ACTIONS_ID_TOKEN_REQUEST_URL is not set. Check these in order:
- Does the job (or workflow) have
id-token: write? Remember that defining anypermissionsblock sets every unlisted scope tonone. - Is the job running on a fork pull request, where the permission is dropped?
- If the token was issued but the cloud rejected it, compare the
subandaudvalues in the trust policy against the real claims. A wrong branch name, a missing environment, or a typo in the repository name is the usual cause.
You can print the claims while debugging by decoding the middle part of the JWT, but never print the token itself in a shared log. Decode it locally and discard the output.
Limits and decision criteria
OIDC removes stored cloud secrets, but it does not remove the need for care. A job with id-token: write can mint tokens for any audience, not only the one your login action uses. Any step in that job, including a compromised third-party action, can do the same. Keep jobs with this permission short, keep their step list small, and pin actions to full commit SHAs where you can. Cloud-side limits help as well: give the role only the permissions the deployment needs, and set a short session duration.
Use OIDC when the target is a cloud provider or a service that supports GitHub's identity provider. For systems that do not support OIDC, fall back to a scoped secret, and put it in an environment with required reviewers.
Exercise
A workflow sets permissions: contents: read at the top level. A deploy job in it uses aws-actions/configure-aws-credentials with role-to-assume and fails because no OIDC token is available. What change fixes it with the least privilege, and what should the IAM role's trust policy check besides aud?
Show answer
Add a job-level permissions block to the deploy job with contents: read and id-token: write. Do not add id-token: write at workflow level, because that would let every job request tokens. The trust policy should also check the sub claim, for example repo:my-org/my-repo:ref:refs/heads/main or an environment subject, so only the intended repository and branch or environment can assume the role.
Exercise
A reusable workflow in a shared repository needs id-token: write, but the call fails to get a token. The reusable workflow file declares the permission correctly. Where is the missing configuration?
Show answer
In the caller. A reusable workflow cannot raise permissions above what the calling job grants, so the job that uses the reusable workflow must declare id-token: write (and any other needed scopes) in its own permissions block.