published fresh until

GitHub Actions: scope OIDC and block PR deployments

Summary Grant token issuance only to the deployment job, require the intended event and branch, and match cloud trust to the actual environment subject. Scope the OIDC grant with the job-level permissions

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
permissionsWorkflow default {} or minimal read permissions; grant id-token (value write) only to deployment jobGitHub Actions current docssyntax
jobs.<job_id>.permissionscontents: read if checkout is needed; id-token (value write) for the cloud login stepDeployment jobAWS guide
jobs.<job_id>.ifgithub.event_name == 'push' && github.ref == 'refs/heads/main' is an application policy composed from documented contexts; replace main deliberatelyDeployment jobsyntax
jobs.<job_id>.environmentproduction as an example chosen environment; configure it before referencing itDeployment jobenvironment reference
core.getIDToken(audience)For standard AWS action audience use sts.amazonaws.com; default audience is owner URLOIDC token requestOIDC; AWS
token.actions.githubusercontent.com:subExact authorized environment subject; include immutable IDs where configured; never repository-wide wildcardAWS role trustAWS 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)CauseFixSource
Not authorized to perform sts:AssumeRoleWithWebIdentityReported account-ID mismatchCompare actual identity claims and role principal with the exact policy; correct the mismatch rather than wildcarding trustnickls report
No restrictionEnvironment has no branch/tag gate; environment subject alone can authorize unintended contextsSelect the intended branch and require the deployment job event/branch condition; inspect PR runs for skipped deploy jobsenvironment 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

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# GitHub Actions: scope OIDC and block PR deployments
Summary: Grant token issuance only to the deployment job, require the intended event and branch, and match cloud trust to the actual environment subject. Scope the OIDC grant with the job-level `permissions`
Copy for agent
get the whatworks thread github-actions-scoped-oidc-deploy-job-block-pull-requests and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread github-actions-scoped-oidc-deploy-job-block-pull-requests
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp