On this page
An AWS access key stored as a repository secret is a credential that never expires, works from anywhere, and is available to every workflow on every branch of the repository. If it leaks through a log, a compromised action or a malicious pull request, it keeps working until someone notices.
GitHub Actions can instead request a short-lived OpenID Connect (OIDC) token for each job and exchange it with the cloud provider for temporary credentials. Nothing long-lived is stored in GitHub. The security of the setup then rests on one thing: the trust conditions on the cloud side. This guide shows the configuration for AWS, Azure and Google Cloud, and the conditions that keep it safe.
How the exchange works
- The job declares
permissions: id-token: write. - A step requests a JSON Web Token from GitHub's OIDC provider,
https://token.actions.githubusercontent.com. The token is signed by GitHub and contains claims about the run: repository, ref, environment, workflow, actor, event name. - The cloud provider validates the signature, checks the audience and your trust conditions against the claims, and returns temporary credentials.
The claim that matters most is sub (subject). By default it looks like:
| Trigger | Default sub |
|---|---|
| Job with an environment | repo:ACME/app:environment:production |
| Push to a branch | repo:ACME/app:ref:refs/heads/main |
| Tag | repo:ACME/app:ref:refs/tags/v1.2.0 |
| Pull request | repo:ACME/app:pull_request |
Other useful claims include repository_owner, repository_id, job_workflow_ref (the reusable workflow that ran the job) and environment.
The rule: never trust the whole organization
The most common OIDC mistake is a trust condition that only checks the organization, or uses a wildcard like repo:ACME/*. Then any repository in the organization, including one a member creates for a test, and any branch, including an unreviewed feature branch, can assume a production role. Worse, a condition that does not check the repository owner at all lets any GitHub repository in the world assume the role.
Bind each production role to:
- One repository (ideally by immutable ID as well as name), and
- One environment that is protected by required reviewers and branch restrictions, or one protected branch.
Using the environment is the strongest option, because the environment's protection rules (reviewers, allowed branches) must pass before the job, and therefore before the token exists.
AWS
Create the identity provider once per account:
aws iam create-open-id-connect-provider \
--url https://token.actions.githubusercontent.com \
--client-id-list sts.amazonaws.com
AWS now validates GitHub's certificate chain through its own trusted root store, so the thumbprint you pass is not used for this provider; the CLI may still require a value on older versions.
Trust policy for the deployment role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111122223333: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:ACME/app:environment:production"
}
}
}
]
}
Use StringEquals on sub, not StringLike with wildcards, for production roles. Workflow:
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
- uses: aws-actions/configure-aws-credentials@e1253824e5c10ff9df46874f81ed3ec929e19cfd # v6.3.0
with:
role-to-assume: arn:aws:iam::111122223333:role/app-deploy-production
aws-region: eu-west-3
role-duration-seconds: 900
- run: aws sts get-caller-identity
Keep role-duration-seconds short and the role's permission policy limited to what the deployment touches. CloudTrail records each AssumeRoleWithWebIdentity call with the subject, which gives you a clean audit trail from GitHub run to AWS API call.
Azure
In Microsoft Entra ID, create an app registration or a user-assigned managed identity, then add a federated credential:
az identity federated-credential create \
--name github-app-production \
--identity-name app-deploy \
--resource-group rg-ci \
--issuer https://token.actions.githubusercontent.com \
--subject repo:ACME/app:environment:production \
--audiences api://AzureADTokenExchange
Assign the identity the narrowest Azure RBAC role on the narrowest scope (a resource group, not the subscription). Workflow:
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
id-token: write
steps:
- uses: azure/login@a641126d1b8aa4d1fa005f4f92df94a3a4c4c906 # v3.1.0
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: az group show --name rg-app-prod
The client, tenant and subscription IDs are identifiers, not secrets; storing them as variables makes that explicit. Entra federated credentials match the subject exactly; flexible federated identity credentials add pattern matching, which you should use sparingly for the same reason as wildcards on AWS.
Google Cloud
Create a Workload Identity pool and an OIDC provider with an attribute condition. Google requires a condition for GitHub providers, and it is where you restrict who can authenticate:
gcloud iam workload-identity-pools create github \
--location=global --display-name="GitHub Actions"
gcloud iam workload-identity-pools providers create-oidc acme \
--location=global \
--workload-identity-pool=github \
--issuer-uri="https://token.actions.githubusercontent.com" \
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner,attribute.environment=assertion.environment" \
--attribute-condition="assertion.repository_owner == 'ACME'"
Then grant access only to the specific repository and environment, either directly to the principal or by allowing it to impersonate a service account:
gcloud iam service-accounts add-iam-policy-binding \
app-deploy@acme-prod.iam.gserviceaccount.com \
--role=roles/iam.workloadIdentityUser \
--member="principal://iam.googleapis.com/projects/123456789/locations/global/workloadIdentityPools/github/subject/repo:ACME/app:environment:production"
Workflow:
- uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github/providers/acme
service_account: app-deploy@acme-prod.iam.gserviceaccount.com
Customize the subject claim
The default sub does not include everything you might want to check. GitHub lets you change the subject template for an organization or repository, for example to include the repository ID (immune to renames and to a deleted repository being recreated under the same name) and the reusable workflow that ran the job:
gh api -X PUT "/repos/ACME/app/actions/oidc/customization/sub" \
--input - <<'JSON'
{ "use_default": false,
"include_claim_keys": ["repository_owner_id", "repository_id", "environment", "job_workflow_ref"] }
JSON
The subject then looks like repository_owner_id:123:repository_id:456:environment:production:job_workflow_ref:ACME/workflows/.github/workflows/deploy.yml@refs/heads/main. Update the cloud trust conditions at the same time, or deployments will fail. Binding to job_workflow_ref is a powerful pattern: only your central, reviewed deployment workflow can obtain production credentials, regardless of which repository calls it.
Common pitfalls
A few mistakes show up again and again in OIDC reviews:
- Pull request subjects on privileged roles. A trust condition that accepts
repo:ACME/app:pull_requestlets any pull request from a branch in the repository assume the role before review. Pull request jobs should get read-only roles at most, and fork pull requests do not receive an OIDC token withid-token: writeunless you grant it through a privileged trigger, which is exactly what the pull_request_target guide warns against. - Missing audience checks. Always pin
aud(for AWS,sts.amazonaws.com; for Azure,api://AzureADTokenExchange). Without it, a token minted for another audience could be replayed. id-token: writeat the top of the workflow. Grant it only in the job that needs it, so that a build or test job compromised through a dependency cannot mint a token for the deployment role.- One role for everything. Separate roles per environment (staging, production) and per purpose (deploy, read-only plan). A Terraform plan on pull requests can use a read-only role, while apply on
mainthrough a protected environment uses the write role. - Repository renames and recreation. Name-based subjects follow the name. If a repository is deleted and someone creates a new one with the same name, it matches the old trust policy. Including
repository_idin a custom subject, as shown above, prevents that.
Migrate and clean up
- Inventory long-lived cloud credentials stored as Actions secrets (
gh secret listper repository and organization). - Create OIDC roles per repository and environment, deploy once with both in place, then switch.
- Delete the old secret and deactivate the old key in the cloud provider. Deleting it from GitHub alone leaves a working key wherever else it was copied.
- Add a detection: any use of the old key ID in CloudTrail or the Azure and Google audit logs after the cut-over date is an incident.
Secrets that cannot use OIDC (third-party SaaS API keys) belong in protected environments, and leaks of those are what secret scanning is for.
References
- About security hardening with OpenID Connect (GitHub Docs)
- Configuring OpenID Connect in Amazon Web Services (GitHub Docs)
- aws-actions/configure-aws-credentials (GitHub repository)
- Create an OpenID Connect identity provider in IAM (AWS Documentation)
- Workload identity federation (Microsoft Learn)
- Workload Identity Federation with deployment pipelines (Google Cloud)
- google-github-actions/auth (GitHub repository)
- OpenID Connect Core 1.0 specification
- RFC 7519: JSON Web Token (JWT)
Written by
Florian Amette, Security Engineer & EditorSecurity engineer writing practical hardening guides for GitHub organizations, repositories and CI/CD pipelines, with a focus on software supply-chain security.