What this thread does
Do first: put id-token (value write) only under the deployment job permissions and gate that job on both the push event and the intended branch.
Short answer
As of November 2026, use GitHub Actions current docs, November 2026. OIDC token is exchanged for a cloud access token; token issuance permission does not grant write access to other resources. GitHub’s October 27, 2021 announcement establishes the flow. Cloud trust and the role’s resource permissions must both be scoped.
Choose / don't choose
- Branch trust: choose for an automated deploy from one branch; do not trust every subject in the repository.
- Environment trust: choose for deployment approvals and branch rules; its subject uses the environment context, so enforce the branch separately.
- PR validation: run builds without deployment permissions or credentials; do not execute untrusted PR code inside the credential-bearing job.
Not for: runner disconnects and OIDC incident triage; see github-actions-oidc-credentials-runner-communication-errors.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
permissions | Workflow default {} or minimal read permissions; grant id-token (value write) only to deployment job | GitHub Actions current docs | syntax |
jobs.<job_id>.permissions | contents: read if checkout is needed; id-token (value write) for the cloud login step | Deployment job | AWS guide |
jobs.<job_id>.if | github.event_name == 'push' && github.ref == 'refs/heads/main' is an application policy composed from documented contexts; replace main deliberately | Deployment job | syntax |
jobs.<job_id>.environment | production as an example chosen environment; configure it before referencing it | Deployment job | environment reference |
core.getIDToken(audience) | For standard AWS action audience use sts.amazonaws.com; default audience is owner URL | OIDC token request | OIDC; AWS |
token.actions.githubusercontent.com:sub | Exact authorized environment subject; include immutable IDs where configured; never repository-wide wildcard | AWS role trust | AWS guide; OIDC |
Order of operations
1. Configure cloud issuer, audience and exact subject trust before changing login. Restrict the resulting role to required deployment resources (AWS setup). 2. Create the production environment, select only the intended deployment branch, and configure required review when available. Avoid the No restriction option; Protected branches only allows all branches if none has protection. Rules must pass before the environment job proceeds (environment rules). 3. Add the job-level event/branch condition and permissions. Environment authorization does not by itself distinguish all PR trigger contexts; require push explicitly. An environment subject includes the environment name. The current OIDC reference also documents immutable owner/repository IDs; inspect the actual subject rather than copying an older example (claims). 4. After the gate passes, request the OIDC token and exchange it with the provider. Compare only the needed issuer/audience/subject claims locally with provider rejection logs; do not print the JWT or confuse the request bearer token with the returned identity token. nickls’s February 27, 2023 report records a Not authorized to perform sts:AssumeRoleWithWebIdentity failure with an account-ID mismatch. 5. In an isolated deployment target, require an intended push to authenticate while a PR run and a non-target branch skip the deployment job. Review cloud audit identity and denied assume-role attempts. Once the new path succeeds, revoke the old long-lived credential and remove its secret.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Not authorized to perform sts:AssumeRoleWithWebIdentity | Reported account-ID mismatch | Compare actual identity claims and role principal with the exact policy; correct the mismatch rather than wildcarding trust | nickls report |
No restriction | Environment has no branch/tag gate; environment subject alone can authorize unintended contexts | Select the intended branch and require the deployment job event/branch condition; inspect PR runs for skipped deploy jobs | environment rules |
Missing
- Cloud provider and repository policy are unspecified; the AWS audience/trust keys apply only to that provider. Required-reviewer availability depends on repository visibility and plan. An event condition cannot protect a workflow that an attacker can rewrite on the trusted branch.
Checked
2026-11-12; GitHub; Actions current docs, November 2026; workflow syntax, contexts, OIDC/AWS/environment references, launch changelog and nickls report read. No application commands were executed.
Started from a post by @GitHub, packaged by the editor. Original post