Deploy to a client's cloud with no access keys left in your CI
OIDC removes long-lived keys, but one loosely written sub condition is enough to let a repository you do not control assume the client's role.
In brief
- With OIDC, the cloud issues each job a short-lived token that expires on its own, and CI stores no keys.
- The sub condition in the trust policy decides who gets in: write it loosely and repositories outside your control can assume the role.
- Repositories created after July 15, 2026 use a new sub format that includes IDs, so the trust policy must match that format exactly.
On December 22, 2022, an attacker who had broken into CircleCI made off with customer data of a very particular kind: environment variables, keys and tokens. After the incident, CircleCI advised customers to use OIDC wherever possible so that no long-lived credentials sat in CI.
Those secrets were there because of a familiar shortcut. A pipeline that deploys into a client’s cloud needs an identity, and the quickest route is always to ask for an access key and paste it into the CI secrets.
For a forward deployed engineer, the credentials question arrives early in a project. You are deploying into someone else’s account, so if a key leaks, the client suffers the incident and your company is the name that gets mentioned.
Walk into the meeting with the client’s security team carrying a design that has no key to leak, and you skip a round of argument and give them one more reason to trust you.
A token that lives for one job, instead of a key that lives for years
The idea is simple. Each time a job runs, GitHub signs a JWT describing that job: which repository, which branch or environment. The client’s cloud checks the signature and the claims, then returns a short-lived access token that works only for that job and expires on its own.
On AWS, the exchange is the STS call AssumeRoleWithWebIdentity. Making it requires no AWS credentials, because the caller’s identity is established by the identity provider’s token. The session lasts one hour by default, and you can set it anywhere from 15 minutes up to the maximum the role allows.
All of the security therefore collapses into one place: the role’s trust policy. There is no key to lose, but if the trust policy is too permissive, anyone who can issue a valid token gets in.
Example: deploying to the client’s prod account
Say you deploy a service from the repository octo-org/octo-repo into the client’s prod account, and only jobs tied to the prod environment may do so. The workflow needs two things: the id-token: write permission, without which the job cannot request an OIDC JWT, and the environment declaration.
permissions:
id-token: write # required to request the OIDC JWT
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: prod # sub will contain this environment name
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::<CUSTOMER_ACCOUNT_ID>:role/deploy-prod
aws-region: <REGION>
role-duration-seconds: 900 # 15 minutes, enough for one deploy
On the client’s side, the trust policy of the deploy-prod role must match the sub claim. When a job references an environment, sub contains the environment name, so the condition has to be written against the environment rather than the branch.
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::<CUSTOMER_ACCOUNT_ID>: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:octo-org/octo-repo:environment:prod"
}
}
}
Read the real sub before writing the condition
The sub value above uses the old format. Repositories created after July 15, 2026 use an immutable format by default, which includes the owner and repository IDs: repo:OWNER@OWNER-ID/REPO@REPO-ID:.... Repositories renamed or transferred after that date also move to the new format; older repositories keep the old one unless they opt in, and GitHub Enterprise Server is not part of this change.
GitHub changed the format because of a real weakness: a repository or organization name is abandoned, someone else claims it, and the new owner can issue tokens carrying exactly the old subject. With the IDs attached, a matching name is no longer enough.
For the same job as above, the sub condition takes one of two forms, depending on which group the repository falls into:
# Old format: repo created before July 15, 2026 that has not opted in to the new format
repo:octo-org/octo-repo:environment:prod
# Immutable format: repo created, renamed or transferred after July 15, 2026
repo:octo-org@<OWNER-ID>/octo-repo@<REPO-ID>:environment:prod
Do not guess which group the client’s repository is in. The surest method is a test job, also with id-token: write and environment: prod, that requests a token and prints only the sub claim, never the whole token, to the log:
- uses: actions/github-script@v7
with:
script: |
const t = await core.getIDToken('sts.amazonaws.com');
const claims = JSON.parse(Buffer.from(t.split('.')[1], 'base64url').toString());
core.info(claims.sub); // copy this exact string into the trust policy
The printed string is what the cloud will match against, so copy that into the trust policy rather than a template found online.
Why one sub line decides everything
AWS says it plainly in its documentation: if the trust policy does not restrict sub to a specific organization or repository, GitHub Actions from organizations and repositories outside your control can also assume the role. IAM now refuses to create or update a GitHub trust policy that lacks sub or whose sub is only a wildcard.
People are already hunting for this mistake. Datadog Security Labs collected more than 500 unique role ARNs from more than 275 AWS accounts to probe for misconfigured roles that trust GitHub Actions. The 500 figure is the number of ARNs gathered, not the number of vulnerable roles, but the team still managed to assume a role in an AWS account belonging to GDS, a UK government agency.
The UNC6426 case, as described in a Cloud Security Alliance note, shows the full attack chain. A stolen GitHub token was enough to trigger a workflow and obtain a valid OIDC JWT. The victim’s AWS role lacked a sufficiently narrow sub condition, and its CloudFormation permissions were used to create a new role with AdministratorAccess.
The second lesson from that case is easier to miss. A deploy role that can create IAM resources through CloudFormation is, in practice, an admin. Separate the infrastructure deploy role from the application deploy role, and give the client a permissions table down to individual actions.
Google Cloud and Azure put the lock elsewhere
The idea is the same, but each cloud places the condition somewhere different. If your client does not use AWS, this is where to look first:
| Cloud | Where the lock sits | Common trap |
|---|---|---|
| AWS | The sub and aud conditions in the role’s trust policy |
sub uses a wildcard, or names a branch while the job uses an environment |
| Google Cloud | The attribute condition in Workload Identity Federation | GitHub, GitLab SaaS and HCP Terraform share one issuer across all organizations, so filtering by your organization is mandatory |
| Microsoft Entra | The federated identity credential | Issuer, subject and audience must match the token exactly, including case |
What they share is that no cloud knows which repositories belong to you. You have to tell it, as narrowly as possible.
When your own system enters the client’s account
In some cases it is your company’s product, not CI, that assumes a cross-account role in the client’s account. AWS then requires an external ID, and that ID must be generated by your side rather than chosen by the client, so that each one is unique. AWS also states that the external ID is not to be treated as a secret.
AWS recommends a further check worth running every time you receive a new ARN. Try to assume the role ARN the client gave you both with and without the correct external ID. If it works without the ID, do not store that ARN until the client fixes the trust policy.
The mistakes that sink the first deploy
One easy mistake is forgetting id-token: write: without that permission the job cannot request an OIDC JWT, so hunting for the cause on the cloud side turns up nothing.
Another is adding environment: prod to the job while the trust policy still names a branch, or writing an old-format sub for a repository that has moved to the new format, so nothing matches and the request is refused.
On Entra, a single wrong capital letter in the repository name is enough to break it.
The more dangerous mistake is the one that does not make the deploy fail: an overly broad sub works smoothly from day one and only surfaces when someone else uses it. The most important test, then, is to try deploying from a place that ought to be blocked.
This week’s exercise: write a one-page deploy design as if you were about to send it to the client’s security team, with the trust policy containing the real sub string you printed from your own repository, the session duration and the deploy role’s permissions table.
That page also earns you a CV line that carries more weight than any “proficient in AWS”: deployed into client accounts with OIDC, no long-lived access keys, roles locked to repository and environment.
Was this article useful?
Thanks for the feedback!
12 sources
- OpenID Connect (GitHub Docs)
- OpenID Connect reference (GitHub Docs)
- AssumeRoleWithWebIdentity (AWS STS API Reference)
- Create a role for OpenID Connect federation (AWS IAM User Guide)
- Configuring OpenID Connect in Amazon Web Services (GitHub Docs)
- Immutable subject claims for GitHub Actions OIDC tokens (GitHub Changelog) · 2026-04-23
- Configure Workload Identity Federation with deployment pipelines (Google Cloud)
- Workload Identity Federation - Microsoft Entra Workload ID · 2025-04-09
- Access to AWS accounts owned by third parties (AWS IAM User Guide)
- CircleCI incident report for January 4, 2023 security incident
- Exploring GitHub-to-AWS keyless authentication flaws (Datadog Security Labs) · 2023-07-27
- UNC6426: nx Supply Chain to AWS Admin via OIDC (Cloud Security Alliance)