Deploying from Actions with OIDC
Deploy to a cloud account without a long-lived key in GitHub: let each workflow run prove its identity with OpenID Connect and get a short-lived credential.
Workflows, triggers, jobs and stepsSecrets, variables and contextsGitHub accounts, SSH keys and authentication
Deploying from Actions with OIDC
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A long-lived cloud key stored as a secret works until it leaks, and then it works for the attacker too, so the safer design stores no cloud credential in GitHub at all.
- With OIDC, each workflow run gets a signed identity token from GitHub, and the cloud provider exchanges it for a credential that expires with the job.
- The job must have permissions: id-token: write to request the token, and contents: read if it also checks out code.
- The cloud side decides who may deploy by matching claims in the token, especially sub, which names the repository and the branch, tag or environment.
- A trust rule that is too broad, such as any branch in the repository, lets code from a pull request branch deploy, so scope it to a branch or an environment.
The problem with a deploy key
To deploy the notes site to a cloud account, the workflow needs permission. The obvious way is to create an access key for a cloud user and store it as a secret named AWS_ACCESS_KEY_ID, plus its partner. It works. It also means a powerful credential that never expires sits in a settings page. It can be read by any workflow that has access to it, and it is valid from anywhere on the internet. If it leaks, it is useful to the attacker until someone notices and rotates it.
The idea behind OIDC (OpenID Connect) is to stop storing a credential, and to prove who is asking instead.
How it works
Think of a visitor badge at a building. You do not give every contractor a permanent key. You give them a badge at the door, after the front desk checks who they are and who they are visiting. The badge opens only certain doors and expires at the end of the day.
In OIDC, GitHub is the front desk and the cloud provider is the building. The flow, from GitHub’s docs on OIDC:
- You set up a trust relationship in the cloud provider that says “accept identities from GitHub’s OIDC provider, for this repository and this branch”.
- When a job runs, GitHub generates a signed token for that job, a JSON web token with claims about it.
- A step presents the token to the cloud provider.
- The cloud provider checks the signature and the claims against your trust rules. If they match, it returns a short-lived access credential.
The docs list the claims in a token. The ones that matter are:
| Claim | Example |
|---|---|
iss (issuer) |
https://token.actions.githubusercontent.com |
aud (audience) |
sts.amazonaws.com when you use AWS’s action |
sub (subject) |
repo:octo-org/octo-repo:ref:refs/heads/main |
repository |
octo-org/octo-repo |
ref |
refs/heads/main |
environment |
prod |
The subject claim is the core of your policy. It says where the run came from: a branch, a tag, a pull request or an environment. The docs show the shapes repo:OWNER/REPO:ref:refs/heads/BRANCH and repo:OWNER/REPO:environment:NAME.
Newer format. The OIDC reference I read on 2026-11-23 says that repositories created after July 15, 2026 use an immutable default subject format that includes the numeric owner and repository IDs, like repo:octo-org@123456/octo-repo@456789:ref:refs/heads/main. The docs do not say why. My reading is that it ties trust to the repository itself, not to a name that could be reused. Older repositories keep the previous format unless they opt in. Check which format your repository’s token actually uses before writing a trust rule, because a rule written for one will not match the other.
The workflow side
A deployment job for the notes site on AWS:
name: Deploy
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm test
- run: npm run build
- uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::123456789012:role/notes-site-deploy
aws-region: eu-west-1
- run: aws s3 sync dist s3://notes-site-example-bucket --delete
I parsed the YAML. I could not run it. It needs a real AWS account, an IAM role and a GitHub repository, and I have none of them here, so the account number, role and bucket are made up. Here is what each part does.
permissions: id-token: write. Without it the docs say the token “cannot be requested”. It does not give the job write access to your repository, which is whycontents: readis listed separately, for the checkout.environment: production. The job runs in theproductionenvironment, which can require reviewer approval before it starts. It also putsenvironment:productioninto thesubclaim, which a trust policy can require.aws-actions/configure-aws-credentials@v6. The action requests the token, exchanges it, and sets credentials for the later steps.v6.3.0was the latest release when I checked, and I read theaction.ymlatv6. It requiresaws-region, acceptsrole-to-assume, and itsaudiencedefaults tosts.amazonaws.com.- No secrets. Nothing in this file is sensitive. The role ARN identifies a role, but cannot be used on its own.
The cloud side
On AWS you create an identity provider for https://token.actions.githubusercontent.com with audience sts.amazonaws.com, then a role whose trust policy names it. From the AWS example in GitHub’s docs, the policy restricts who may assume the role:
{
"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:ada/notes-cli:environment:production"
}
}
}
]
}
I parsed the JSON, so it is well formed. Whether AWS accepts it, I have not tested. The structure, the sts:AssumeRoleWithWebIdentity action and the aud and sub condition keys follow the docs. The permissions the role carries, here the right to write to one bucket, are a separate policy attached to the role. Give it the minimum.
The mistake to avoid
The docs show a wildcard example, "StringLike" with repo:octo-org/octo-repo:*, matching any branch, pull request or environment in the repository, and recommend evaluating the sub key. That is convenient and dangerous. A workflow running from a pull request branch would match too. Think about what a contributor could do with an unreviewed workflow file that assumes your deploy role. The usual tightening: require an environment, so sub ends in :environment:production, and put required reviewers and a branch rule on that environment. The hardening lesson goes further.
Beyond AWS
Everything above is the same idea on other clouds. Azure and Google Cloud have their own federation setup, with their own claim checks, and the same two pieces: id-token: write on the job, and a trust configuration on the cloud side that matches claims. I did not research those, so use each provider’s guide. Any custom tool can also request a token directly. The docs show the runner exposes ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN for that.
What the video covers
GitHub’s “Securely deploy to AWS with GitHub Actions and OIDC” is about 17 minutes and was published around 2024. Its description says managing deployment credentials need not be complex, and that with a little configuration you can enable access for workflows. I could not read a transcript or chapters, so I cannot say whether it uses the newer immutable subject format, which post-dates it. It is an official video and fits this lesson closely. It is AWS-specific. English is judged from the title, description and channel. The AWS-focused docs page is linked under deeper for the current trust policy examples.
Where this fits
You have removed the biggest credential from your pipeline. The last lesson collects the rest of the habits that keep a workflow from becoming a way in: hardening your workflows.
Check yourself
What problem does OIDC solve compared with storing AWS access keys as a secret?
There is no long-lived credential to leak or rotate. Each run receives a short-lived credential that expires when the job ends.
Which permission lets a job request an OIDC token, and does it grant write access to your code?
permissions: id-token: write. It only lets the job request the identity token and does not grant write access to the repository or other resources.
What is the sub claim, and why is it the key part of the trust policy?
It identifies where the run came from, such as repo:octo-org/octo-repo:ref:refs/heads/main or an environment. The cloud trust policy matches it, so it decides which runs may assume the deploy role.
Your trust policy allows repo:octo-org/octo-repo:*. What can go wrong?
Any branch, pull request or environment in the repository matches, so a workflow on an unreviewed branch can assume the deploy role. Narrow it to the main branch or a protected environment.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.