Skip to content
Français
CI/CD & Automatisation medium

GitHub Actions OIDC: AWS, Azure, GCP

40 min de lecture

Read this page in French

OIDC is configured in two places: on the cloud provider side, where you create the trust link, and on the workflow side, which requests the token. This guide covers both for AWS, Azure and GCP.

What you will learn

  • Create the OIDC identity provider on AWS, Azure and GCP
  • Configure the role or federated identity that trusts GitHub
  • Restrict the trust policy to the right repository and the right branch
  • Write the workflow that requests and uses the token
  • Choose between console, CLI and Terraform for each step

If how OIDC works is not familiar yet, start with OIDC: authentication without secrets.

AWS

On AWS, OIDC rests on an IAM OIDC provider and an IAM role whose trust policy trusts GitHub tokens. Setting it up takes four steps.

Step 1: create the identity provider

The identity provider declares GitHub as a trusted issuer to IAM.

  1. Go to IAM > Identity providers > Add provider
  2. Select OpenID Connect
  3. Provider URL: https://token.actions.githubusercontent.com
  4. Audience: sts.amazonaws.com
  5. Click Add provider

Step 2: create the IAM role

The IAM role carries the permissions granted to the workflow and accepts being assumed through Web Identity.

  1. Go to IAM > Roles > Create role
  2. Select Web identity
  3. Identity provider: token.actions.githubusercontent.com
  4. Audience: sts.amazonaws.com
  5. Add the permissions you need
  6. Name the role (for example github-actions-deploy)

Step 3: configure the trust policy

The trust policy restricts who may assume the role. The sub condition is the most important one: it bounds the repository, the branch or the environment.

{
"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"
},
"StringLike": {
"token.actions.githubusercontent.com:sub": "repo:owner/repo:ref:refs/heads/main"
}
}
}
]
}

Restriction patterns:

PatternAllows
repo:owner/repo:*Every branch and pull request
repo:owner/repo:ref:refs/heads/mainThe main branch only
repo:owner/repo:environment:productionThe production environment
repo:owner/*:*Every repository of the organisation

Step 4: the GitHub workflow

On the GitHub side, the workflow requests the token with id-token: write and presents it to AWS through the official action.

name: Deploy to AWS
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- name: Check out the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Configure the AWS credentials through OIDC
uses: aws-actions/configure-aws-credentials@e6de054238d6b7531b4efff3b6587d9aade6a06c # v6.2.3
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-deploy
aws-region: eu-west-1
- name: Sync to S3
run: aws s3 sync ./dist s3://my-bucket

Azure

On Azure, OIDC goes through an App Registration and federated credentials that tie a precise GitHub subject to the application.

Step 1: create the App Registration

The App Registration is the application identity the workflow will assume.

  1. Go to Azure Active Directory > App registrations > New registration
  2. Name: github-actions
  3. Click Register
  4. Note the Application (client) ID and the Directory (tenant) ID

Step 2: add the federated credentials

The federated credentials declare which GitHub subject (repository, branch, environment) may authenticate as that application.

  1. In the App Registration, go to Certificates & secrets
  2. Federated credentials tab, then Add credential
  3. Scenario: GitHub Actions deploying Azure resources
  4. Organization: your GitHub organisation
  5. Repository: your repository
  6. Entity type: Branch, Environment, or Tag
  7. Based on selection: main (or the environment name)

Step 3: assign the permissions

The application needs a service principal and an Azure role at the narrowest possible scope.

Fenêtre de terminal
# Create a service principal
az ad sp create --id <APP_ID>
# Assign a role (example: Contributor on a resource group)
az role assignment create \
--assignee <APP_ID> \
--role Contributor \
--scope /subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>

Step 4: the GitHub workflow

The workflow authenticates with azure/login, passing the application identifiers: no secret, only vars.

name: Deploy to Azure
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- name: Check out the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Log in to Azure through OIDC
uses: azure/login@532459ea530d8321f2fb9bb10d1e0bcf23869a43 # v3.0.0
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Deploy the web app
run: az webapp deploy --resource-group my-rg --name my-app --src-path ./dist

GCP

On GCP, OIDC relies on Workload Identity Federation: a pool, an OIDC provider, and a service account the workflow impersonates.

Step 1: create the Workload Identity Pool

The pool gathers the external identities allowed to reach the GCP project.

  1. Go to IAM & Admin > Workload Identity Federation
  2. Click Create Pool
  3. Name: github-pool
  4. Click Continue

Step 2: add the provider

The OIDC provider links the pool to the GitHub issuer and maps the claims of the JWT onto GCP attributes.

  1. In the pool, click Add Provider
  2. Select OpenID Connect (OIDC)
  3. Provider name: github-provider
  4. Issuer URL: https://token.actions.githubusercontent.com
  5. Audiences: Default audience
  6. Attribute mapping:
    • google.subject = assertion.sub
    • attribute.repository = assertion.repository
    • attribute.actor = assertion.actor

Step 3: authorise the service account

The service account carries the GCP permissions; the pool is authorised to impersonate it only for the repository you target.

Fenêtre de terminal
# Create a service account
gcloud iam service-accounts create github-actions \
--display-name="GitHub Actions"
# Allow the workload identity to impersonate the service account
gcloud iam service-accounts add-iam-policy-binding \
github-actions@PROJECT_ID.iam.gserviceaccount.com \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/github-pool/attribute.repository/owner/repo"
# Grant the service account the permissions it needs
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="serviceAccount:github-actions@PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/storage.admin"

Step 4: the GitHub workflow

The workflow obtains a token, authenticates to GCP, then installs the gcloud CLI for the deployment commands.

name: Deploy to GCP
on:
push:
branches: [main]
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- name: Check out the code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Authenticate to GCP through OIDC
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
with:
workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github-pool/providers/github-provider
service_account: github-actions@project-id.iam.gserviceaccount.com
- name: Install the gcloud CLI
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3.0.1
- name: Sync to Cloud Storage
run: gsutil rsync -r ./dist gs://my-bucket

Summary of the configurations

The three clouds follow the same logic, an identity provider, a trust link, an official action, each with its own terminology.

ProviderIdentity providerAction
AWSIAM OIDC provideraws-actions/configure-aws-credentials
AzureApp Registration plus federated credentialsazure/login
GCPWorkload Identity Federationgoogle-github-actions/auth

Key points

  • OIDC is configured in two places: a trust link on the cloud side, a token request on the workflow side.
  • AWS: an IAM OIDC provider plus an IAM role assumable through sts:AssumeRoleWithWebIdentity.
  • Azure: an App Registration and federated credentials tied to a precise GitHub subject.
  • GCP: a Workload Identity Pool, an OIDC provider and an impersonated service account.
  • In all three cases, the trust policy (the sub condition) restricts which repository, branch or environment is allowed.

Official documentation per provider: AWS, Azure and GCP.

Next steps

Is this site useful to you?

Fewer than 1% of readers support this site.

I maintain more than 700 free guides, with no ads and no tracking. Any support, even a symbolic one, helps cover hosting and keeps these resources free. Thank you for the help.

The form does not show? Open Ko-fi in a new tab.

Subscribe and follow my DevSecOps work on LinkedIn