Supply chain
GitHub Actions OIDC → AWS: removing static CI keys without breaking deployments
Trust policy, per-environment roles and the July 2026 immutable sub format: move GitHub CI to AWS with no static keys, plus the commands that prove the migration to an auditor.
In almost every repository I audit, an AWS_ACCESS_KEY_ID secret sits in the GitHub settings. It was created two years ago, belongs to an IAM user with overly broad rights, and nobody knows which workflows (or forks, or third-party actions) read it. One compromised action or one injection in a workflow is enough to exfiltrate it, and it stays valid until someone revokes it.
OIDC federation replaces that secret with a token signed by GitHub, exchanged for short-lived AWS credentials. There is nothing left to steal at rest. But the security of the mechanism rests on a single line: the sub condition of the trust policy. This article gives the configuration, the migration plan, and a change that has been breaking deployments since July 2026.
The threat: a long-lived secret in a system that runs third-party code
A GitHub Actions workflow runs code you did not always write: third-party actions, build scripts, dependencies. Any secret exposed to a job is readable by that code. With a static key:
- a compromised action or a
${{ }}injection (see GitHub Actions misconfigurations) exfiltrates the key, which then works from anywhere with no expiry; - the key is rarely rotated and often shared across repos and environments;
- nothing links the AWS call to the workflow that made it: during an incident, CloudTrail shows “user ci-deploy” and nothing more.
With OIDC, credentials last at most the role session (1 hour by default), are issued only if the token matches the trust policy, and the session is tied to the token of the workflow that requested it. The GitHub documentation describes the flow; the risk is in the configuration.
The control: a strict trust policy, one role per environment
The identity provider and roles (Terraform)
One OIDC provider per account, then one role per environment, each restricted to the matching GitHub environment. GitHub environments let you add required reviewers and branch restrictions before the environment:production token is issued.
variable "github_org" { type = string } # e.g. "acme"
variable "github_org_id" { type = string } # gh api /orgs/acme --jq .id
variable "github_repo" { type = string } # e.g. "api"
variable "github_repo_id" { type = string } # gh api /repos/acme/api --jq .id
resource "aws_iam_openid_connect_provider" "github" {
url = "https://token.actions.githubusercontent.com"
client_id_list = ["sts.amazonaws.com"]
}
locals {
env_subjects = {
for env in ["staging", "production"] : env => [
"repo:${var.github_org}/${var.github_repo}:environment:${env}",
"repo:${var.github_org}@${var.github_org_id}/${var.github_repo}@${var.github_repo_id}:environment:${env}",
]
}
}
data "aws_iam_policy_document" "trust" {
for_each = local.env_subjects
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [aws_iam_openid_connect_provider.github.arn]
}
condition {
test = "StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
condition {
test = "StringEquals"
variable = "token.actions.githubusercontent.com:sub"
values = each.value
}
}
}
resource "aws_iam_role" "deploy" {
for_each = local.env_subjects
name = "gha-${var.github_repo}-${each.key}"
assume_role_policy = data.aws_iam_policy_document.trust[each.key].json
max_session_duration = 3600
}
Things to note:
StringEquals, notStringLike, whenever possible: a wildcard insubopens the role to everything it covers. Withrepo:org/*, any repository in the organisation, including a test repo created yesterday by an intern, can assume your production role.- Always check
aud: it is thests.amazonaws.comvalue used by the official action. - A separate permissions policy per role (not shown):
stagingmust not be able to touch production.
The workflow
name: deploy
on:
push:
branches: [main]
permissions: {}
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
id-token: write # request the OIDC token, nothing else
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: aws-actions/configure-aws-credentials@45666896f5d8e0f10ae255413f3a4cdd03bdc8f5 # v6.3.1
with:
role-to-assume: arn:aws:iam::111122223333:role/gha-api-production
role-session-name: gha-${{ github.run_id }}
aws-region: eu-west-3
- run: aws sts get-caller-identity
id-token: write grants no write access to the repository: it only lets the job request a token. Set it at job level, not workflow level, so other jobs do not get it. Actions are pinned by SHA (versions current as of 30 November 2026).
The July 2026 trap: the immutable sub format
GitHub introduced a sub that carries the immutable numeric IDs of the organisation and repository, to prevent reuse of a deleted or renamed repository name. According to the GitHub documentation, this format applies to repositories created after 15 July 2026 or those that opted in (not available on GitHub Enterprise Server):
classic: repo:acme/api:environment:production
immutable: repo:acme@12345678/api@987654321:environment:production
As a result, a trust policy written with names fails with Not authorized to perform sts:AssumeRoleWithWebIdentity on any new repository, as this field report details. The Terraform above therefore lists both forms with pinned IDs: you keep rename protection without breaking existing repos. To see which format a repository emits:
gh api /repos/acme/api/actions/oidc/customization/sub
# {"use_default": true, "use_immutable_subject": false, ...}
gh api /orgs/acme --jq .id ; gh api /repos/acme/api --jq .id
Do not “fix” it by switching to repo:acme/*: you would lose exactly the control you just put in place. If you need a wildcard, use StringLike and pin at least the organisation ID (repo:acme@12345678/*).
Migrating in a week without breaking production
- Inventory (day 1). List the keys and their real usage:The
aws iam generate-credential-report >/dev/null; sleep 5 aws iam get-credential-report --query Content --output text | base64 -d \ | awk -F, 'NR==1 || $9=="true" || $14=="true" {print $1,$9,$11,$14,$16}' gh secret list --org acme | grep -i awsaccess_key_*_last_used_datecolumns show which keys are still used. - Roles and provider (day 2). Deploy the Terraform above for a pilot service; start from the old user’s permissions, then shrink them based on CloudTrail.
- Pilot cutover (day 3). Replace the secrets with
role-to-assume. Keep the old key deactivated but not deleted for 48 hours. - Rollout (days 4-5). One repo at a time. On
productionenvironments, add required reviewers and a restriction tomainin the GitHub environment settings. - Removal. Deactivate, wait a week with no calls, delete the access key then the IAM user, and remove the GitHub secrets.
The proof: what you show an auditor
Three reproducible items.
1. No GitHub trust policy without a restrictive sub condition:
aws iam list-roles --query 'Roles[].[RoleName,AssumeRolePolicyDocument]' --output json \
| jq -r '.[] | select(.[1] | tostring | test("token.actions.githubusercontent.com"))
| select(.[1] | tostring | test("githubusercontent.com:sub") | not) | .[0]'
Any output is a role assumable by any GitHub repository: fix it immediately. Complement it by searching for wildcards: look for "repo:*" and ":*" as sub values. IAM Access Analyzer also flags roles reachable from outside the account.
2. No active access key left on CI users: the same get-credential-report command with no access_key_1_active=true row for deployment users.
3. Per-workflow traceability: CloudTrail records AssumeRoleWithWebIdentity with the token subject and the gha-<run_id> session name:
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRoleWithWebIdentity \
--max-results 20 --query 'Events[].CloudTrailEvent' --output json \
| jq -r '.[] | fromjson | [.userIdentity.userName, .requestParameters.roleSessionName] | @tsv'
You can now answer “which workflow changed this resource, and when?” with a run ID, which a static key never allowed.
What OIDC does not solve
- A compromised workflow still gets the role. OIDC removes the secret, not code execution: a
subrestricted to a protected environment and minimal role permissions limit the blast radius. - Non-AWS secrets (registry, SaaS, databases) remain to be handled: Azure and GCP offer the same federation, and any remaining secret must be rotated.
- Custom
subclaims (addingjob_workflow_ref, for example to allow only a central reusable workflow) are possible but add a layer to document; start with the environment.
Scoping this migration across all your repositories (inventory, roles, protected environments, evidence pack) is part of the Supply Chain & CI/CD Security offer.
Found this useful? Share it.
Go further
A topic, a project, a question?
Distribuée supports demanding SMBs on cloud security, CI/CD supply chain and AI security.
Book 15 min