Skip to content

Guide library

Guide · Cloud AI platforms

GitHub Actions OIDC Trust Policy: Pin the sub Claim

Which sub claim each GitHub Actions job gets, which trust-policy patterns over-allow or break after GitHub's July 2026 switch to owner and repo IDs, and a seven-step move for AWS, Google Cloud and Azure.

Owen Prestwick · Dec 5, 2026 · 9 min read

GitHub Docs Actions social card
GitHub, GitHub Docs Actions social card (Open Graph image of the OpenID Connect reference), accessed 5 Dec 2026. Source: https://docs.github.com/en/actions/reference/security/oidc

A GitHub Actions OIDC trust policy is only as tight as the sub string it matches, and two things catch teams out. The repo:org/repo:* wildcard from GitHub's own AWS example also accepts every pull request run, every branch push and every environment in that repo. And since 15 July 2026, any repository that is created, renamed or transferred gets a new subject format with numeric owner and repo IDs in it, which name-only patterns such as repo:org/* no longer match.

This guide maps which sub each kind of job receives, which common patterns over-allow or quietly break, and the order to move AWS, Google Cloud and Azure trust to the ID-based format without a failed deploy.

Formats and limits below come from GitHub, AWS, Google Cloud and Microsoft documentation, all checked on 5 Dec 2026. Metarix did not call a cloud account; the pattern matches in the diagram reproduce the documented formats with a glob matcher.

Who needs this, and who can skip it

You need it if a workflow on github.com assumes a cloud role through OIDC: aws-actions/configure-aws-credentials, Google's auth action, azure/login, or a HashiCorp Vault JWT role. Moving from long-lived keys to OIDC is still the right call, and it is the cloud half of the advice in How to Stop AI Coding Agents Leaking Secrets. OIDC just moves the risk into one condition string.

You can skip the migration part on GitHub Enterprise Server. GitHub says the immutable format applies to github.com only. Old repositories on github.com also keep the name-only format until someone opts in, renames or transfers them, so nothing changed overnight on 15 July. The change lands the next time a repo is renamed.

Who acts: a repository admin can opt one repo in; an organization admin can opt in the whole org or set an org-wide sub template; and whoever owns the cloud roles has to edit trust policies first. Line those three up before you touch any setting.

What GitHub puts in sub for each kind of job

GitHub builds the default subject from a prefix and a context. The context follows a fixed order in the OpenID Connect reference: an environment wins over everything, then the pull_request event, then the branch or tag.

Scroll the table horizontally on smaller screens.

Default GitHub Actions OIDC sub claim by job type, github.com, checked 5 Dec 2026
JobName-only format (older repos)Immutable format (new, renamed, transferred or opted-in repos)
Job with environment: prod (any trigger, including a pull request)repo:octo-org/octo-repo:environment:prodrepo:octo-org@123456/octo-repo@456789:environment:prod
pull_request event, no environmentrepo:octo-org/octo-repo:pull_requestrepo:octo-org@123456/octo-repo@456789:pull_request
Push, schedule or manual run on main, no environmentrepo:octo-org/octo-repo:ref:refs/heads/mainrepo:octo-org@123456/octo-repo@456789:ref:refs/heads/main
Tag v2.1.0, no environmentrepo:octo-org/octo-repo:ref:refs/tags/v2.1.0repo:octo-org@123456/octo-repo@456789:ref:refs/tags/v2.1.0
Source: GitHub Docs, OpenID Connect reference (example subject claims and immutable subject claims), checked 5 Dec 2026. 123456 and 456789 are GitHub's documentation placeholders for the owner ID and repository ID. The prefix pattern for the immutable rows follows GitHub's documented syntax.

Three details from that table matter for policy writing. A pull_request subject carries no branch name, so a policy that accepts it accepts every PR in the repo. A colon inside a value, such as an environment called production:eastus, is encoded as %3A. And GitHub picked @ as the separator because it cannot appear in GitHub user or repository names, so @123456 is a safe anchor in a pattern.

Diagram: which sub claim a GitHub Actions job receives, and a matrix of AWS trust patterns that match or miss name-only and immutable subjects
Which sub a job receives, and which trust patterns match it before and after the switch to immutable IDs. Metarix original diagram, 5 Dec 2026, based on GitHub's OpenID Connect reference.

Patterns that over-allow or break

Scroll the table horizontally on smaller screens.

Common sub patterns in AWS trust policies and what they do, checked 5 Dec 2026
Pattern (StringLike unless noted)What it acceptsRisk
repo:octo-org/octo-repo:*Every branch, every pull request run and every environment in the repo (name-only format)Over-allows: a PR job can assume the deploy role. Stops matching once the repo moves to the immutable format
repo:octo-org/*Every repo in the org, any context (name-only format)Over-allows across repos. Stops matching for any repo created or renamed after 15 Jul 2026
repo:octo-org*Also octo-org-test, octo-organic and any other owner starting with that stringOver-allows across owners. It keeps working after the format switch for the wrong reason
repo:octo-org/octo-repo:ref:refs/heads/main (StringEquals)Push, schedule or manual runs on main onlyFails for jobs that use an environment, and after a rename
repo:octo-org@123456/octo-repo@456789:environment:prod (StringEquals)Only jobs using the prod environment in that exact repoTight. Pair it with deployment branch rules on the environment
Source: Metarix analysis of GitHub's documented subject formats (GitHub Docs OpenID Connect reference) and AWS IAM condition behaviour (AWS IAM User Guide), checked 5 Dec 2026. Matches reproduced with a glob matcher; no AWS account was called.

AWS blocks the worst case. IAM refuses to save a trust policy for GitHub's provider if token.actions.githubusercontent.com:sub is missing or is only * or ?. It does not stop repo:octo-org*, and the AWS guide warns that without an org or repo in sub, workflows outside your control can assume the role.

Google Cloud has a similar rule: its deployment pipelines guide says a GitHub provider must use an attribute condition that limits tokens to your organization. Its sample condition checks assertion.repository_owner, a name. The same page warns that name fields invite cybersquatting after a repo or org is deleted, and tells you to use the numeric _id fields instead. Follow the warning, not the sample.

Move a role to the ID-based subject in seven steps

  1. Print the claims you actually get. Run GitHub's actions-oidc-debugger once in the job that deploys, with id-token: write set on that job. It prints the decoded claims, including sub, repository_id and repository_owner_id. Do not echo the raw token in a log.
  2. Look up the two IDs. gh api repos/octo-org/octo-repo --jq '.owner.id, .id' returns the owner ID and the repo ID. Write them into the role's documentation; they never change, even if the names do.
  3. Decide what the role should accept. One role per environment is the cleanest. Use environment:prod for deploys and protect that environment with required reviewers or deployment branch rules. Use a ref:refs/heads/main subject only for jobs without an environment.
  4. Add the new subject next to the old one. In AWS, a condition key with a list of values matches any of them, so a role can accept both formats during the move (example below). In Azure, add a second federated credential with the immutable subject.
  5. Opt the repo in. A repo admin uses the toggle in the repository's OIDC settings, or PUT /repos/{owner}/{repo}/actions/oidc/customization/sub with use_immutable_subject set to true (REST reference). Read the current template with a GET on the same endpoint first, so you do not reset a custom include_claim_keys template by accident. Org admins have the same switch at org level.
  6. Run the deploy job and confirm. The debugger output should show the @ form. In AWS, CloudTrail records each AssumeRoleWithWebIdentity call, so you can see which subject was accepted.
  7. Remove the name-only value. Leaving it in keeps the cybersquatting gap open: if the org name is ever freed and claimed, the old string matches again.

AWS trust policy during the move

"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": [
"repo:octo-org/octo-repo:environment:prod",
"repo:octo-org@123456/octo-repo@456789:environment:prod"
]
}
}

The audience sts.amazonaws.com is what the official AWS action sends. Account IDs and repo IDs here are placeholders. After step 7, the list shrinks to the second line.

Google Cloud condition with IDs

Map the claims first: google.subject=assertion.sub, plus attribute.repository_id=assertion.repository_id and attribute.repository_owner_id=assertion.repository_owner_id. Google requires a mapping for every field a condition uses. Then set a provider condition such as:

assertion.repository_owner_id=='123456' && assertion.repository_id=='456789' && assertion.ref=='refs/heads/main'

The provider condition does not depend on the sub format, so the opt-in in step 5 does not break it. IAM bindings can: a binding to principal://.../subject/SUBJECT names the full sub string and stops matching after the switch. Bind with principalSet://.../attribute.repository_id/456789 instead. One limit to check: google.subject cannot exceed 127 characters. GitHub's documented example of a custom template with job_workflow_ref comes to 139 characters once immutable IDs are added, so map google.subject to a shorter value if you use templates like that.

Azure federated credentials

Microsoft's federated credential docs say the subject must match exactly, wildcards are not supported, and a failed match is rejected without a helpful error. An app or user-assigned managed identity can hold at most 20 federated credentials. Moving to the new format means one more credential per subject for a while, so count before you add. Microsoft also documents a flexible federated credential with claim-matching expressions, still marked preview as of 5 Dec 2026.

Mistakes to check before you ship

  • Pinning a branch on a job that uses an environment. The subject becomes environment:NAME, so a ref:refs/heads/main condition never matches and the deploy fails with an access-denied error from the cloud.
  • Accepting `pull_request` on a deploy role. Any PR run in the repo gets that subject. If you are also reworking pull_request_target workflows, see pull_request_target Blocked? Fix Each Workflow Safely.
  • Renaming a repo on a Friday. After 15 July 2026, a rename or transfer switches the subject to the immutable format. Add the new value to every trust policy before the rename.
  • Reusable workflows from another org. GitHub's reference says the caller must set id-token: write explicitly in that case. For central deploy workflows, a sub template that includes job_workflow_ref lets the cloud check which reusable workflow asked.
  • Dependabot jobs. Their tokens carry event_name set to dynamic. If your provider can check event_name, allow only the events you expect.
  • Repo groups by property. Since April 2026 GitHub can put repository custom properties in the token as repo_property_* claims (changelog). That beats a wildcard over repo names for a group of repos.

Our take

Do two things this week. Search your cloud accounts for trust policies that use repo: with a * or contain :pull_request, and rewrite each deploy role to one environment in one repo, written in the immutable format. Then opt that repo in on purpose, with both values in place, instead of waiting for a rename to do it for you.

GitHub's switch to owner and repo IDs is the right fix for recycled names, but it only protects roles whose conditions use those IDs. Google Cloud users can mostly avoid the sub string with ID conditions and attribute-based bindings; AWS and Azure users need the two-value move above. If your CI also still uses personal access tokens for GitHub itself, GitHub Apps can now replace enterprise PATs, which is the same idea on the GitHub side. Background on the platform: GitHub Actions and GitHub.

Sources

Tools covered in this guide

Frequently asked questions

Do existing GitHub repositories switch to the immutable sub format automatically?
No. Repositories created before 15 July 2026 keep the name-only format until a repo or org admin opts in, or until the repository is renamed or transferred. New repositories created after that date use the immutable format from the start. The change applies to github.com, not GitHub Enterprise Server.
Can I remove the owner and repo IDs from the sub claim with a custom template?
No. GitHub's reference says that for repositories using immutable subject claims, the owner ID and repo ID are always included in the repo segment, even when you customize the claim with include_claim_keys.
Does id-token: write give a workflow write access to my repository?
No. GitHub documents it as the permission to request the OIDC token only; it does not grant write access to other resources. Set it on the deploy job rather than the whole workflow so other jobs cannot mint a token.
Why does my AWS role fail with an access-denied error after a repository rename?
After 15 July 2026 a rename or transfer moves the repository to the immutable sub format, so a trust policy written for repo:owner/name no longer matches. Add the repo:owner@OWNER-ID/name@REPO-ID value to the condition, confirm a run, then remove the old one.

More in Cloud AI platforms

Follow Metarix

Digital media intelligence hub

AI SaaS · developer workflows · architecture

Share