All guides

Set up OIDC between GitHub Actions and Azure

A client secret stored in GitHub works until it leaks or expires. With OpenID Connect, a workflow proves which repository and branch it runs from, and Azure hands it a token that lasts minutes.

Hands typing on a laptop that shows code

How it works

Each job asks GitHub for a signed token. Azure compares the token's issuer, subject and audience with a federated credential you create once, then issues a short-lived access token. Nothing secret is stored on either side.

1. Create the identity

az ad app create --display-name github-deploy
az ad sp create --id <application-id>

The first command prints the application (client) ID; the second creates its service principal. A user-assigned managed identity works the same way if you would rather not create an app registration.

2. Give it a role

az role assignment create --assignee <application-id> --role Contributor \
  --scope /subscriptions/<subscription-id>/resourceGroups/<resource-group>

Scope the role to the resource group the workflow deploys to, not to the whole subscription.

3. Add the federated credential

Save this as credential.json:

{
  "name": "github-main",
  "issuer": "https://token.actions.githubusercontent.com",
  "subject": "repo:my-org/my-repo:ref:refs/heads/main",
  "description": "Deploys from the main branch",
  "audiences": ["api://AzureADTokenExchange"]
}
az ad app federated-credential create --id <application-id> --parameters credential.json

The subject decides which runs may log in. It takes one of four forms:

  • a branch: repo:my-org/my-repo:ref:refs/heads/main
  • a tag: repo:my-org/my-repo:ref:refs/tags/v1.0
  • an environment: repo:my-org/my-repo:environment:production
  • any pull request: repo:my-org/my-repo:pull-request

The subject must match exactly. Wildcards are not supported, and a wrong subject is saved without any error, so the mistake only shows when the workflow runs. One identity holds 20 federated credentials at most.

4. Store three values in GitHub

Add AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_SUBSCRIPTION_ID as repository or environment secrets. None of them is a password, but the login action expects them from secrets.

5. Log in from the workflow

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: azure/login@v3
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
      - run: az account show

id-token: write lets the job request its token. It gives the workflow no write access to anything.

Repositories created after 15 July 2026

For repositories created, renamed or transferred after 15 July 2026, GitHub writes the numeric owner and repository IDs into the subject: repo:octo-org@123456/octo-repo@456789:ref:refs/heads/main. A credential written in the older form will not match. Add a credential with the new subject, keep the old one until a run has logged in, then remove it.

If the login fails

Check three things, in this order: the subject (the branch, tag or environment must be the one the run uses), the id-token: write permission, and the scope of the role assignment.

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides