Passwordless deploys to Azure with GitHub Actions and OIDC
Set up a workflow that signs in to Azure with a short-lived token and no client secret, step by step in the portal or the CLI.
A workflow on main that signs in to Azure with no stored secret, and turns away runs from other branches. How it works under the hood is in What OIDC federation is.
Copy: marks a value you'll need later.
What you need
- Entra ID: at least Application Developer to register the app; its owner, an Application Administrator or a Cloud Application Administrator to add the credential.
- The Azure resource: Role Based Access Control Administrator or User Access Administrator.
- Admin rights on the GitHub repository.
1. Register the deploy identity
CLIENT_ID=$(az ad app create --display-name github-deploy-<app> --query appId -o tsv)
az ad sp create --id "$CLIENT_ID" # the CLI creates the service principal as a second step
echo "client: $CLIENT_ID" # copy these three for GitHub
az account show --query "{tenant: tenantId, subscription: id}" -o tsvIn the Entra admin center: Entra ID → App registrations → New registration.
- Name: for example
github-deploy-<app>. - Supported account types: Single tenant only.
Register. Copy: Application (client) ID and Directory (tenant) ID from Overview, and the Subscription ID (portal → Subscriptions). The service principal is created for you.
Leave Client secrets empty. The federated credential in step 3 takes its place.
2. Find the subject your repository sends
repo:<owner>@<owner-id>Owner, name and ID/<repo>@<repo-id>Repository, name and ID:ref:refs/heads/mainWhat runs: the main branch
The ending, by what the job runs for
- A branch
:ref:refs/heads/<branch>- A tag
:ref:refs/tags/<tag>- An environment
:environment:<name>- A pull request
:pull_request
The start, by repository
- Created after 15 July 2026, or renamed or transferred since
repo:<owner>@<owner-id>/<repo>@<repo-id>- Older, until they opt in
repo:<owner>/<repo>
Entra ID compares the token's subject with your credential, exactly, letter case included. GitHub sends one of two formats:
| Format | Sent by | Subject for main |
|---|---|---|
| Immutable | Repositories created after 15 July 2026, and ones renamed or transferred since | repo:<owner>@<owner-id>/<repo>@<repo-id>:ref:refs/heads/main |
| Name-based | Older repositories, until they opt in | repo:<owner>/<repo>:ref:refs/heads/main |
The ending depends on the job:
| The job runs for | Subject ends with |
|---|---|
| A branch | :ref:refs/heads/<branch> |
| A tag | :ref:refs/tags/<tag> |
An environment (environment: in the job) | :environment:<name> |
| A pull request | :pull_request |
A job that names an environment sends the environment form, not the branch. The IDs are numbers GitHub never reuses:
Works for private repositories too.
gh api repos/<owner>/<repo> --jq '"owner-id: \(.owner.id) repo-id: \(.id)"'Public repository: open https://api.github.com/repos/<owner>/<repo>. Copy: id (repository) and owner → id (owner).
Not sure which format? Every run's Azure login step prints Federated token details, even when sign-in fails. Its subject claim is the exact string to trust.
3. Add the federated credential
Save as credential.json, with your subject from step 2:
{
"name": "github-main",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:<owner>@<owner-id>/<repo>@<repo-id>:ref:refs/heads/main",
"audiences": ["api://AzureADTokenExchange"]
}az ad app federated-credential create --id "$CLIENT_ID" --parameters credential.jsonApp registration → Certificates & secrets → Federated credentials → Add credential:
| Field | Value |
|---|---|
| Federated credential scenario | GitHub Actions deploying Azure resources |
| Organization | <owner> |
| Repository | <repo> |
| Owner and repository ID (optional) | Only if your repository sends the immutable subject |
| Entity type | Branch (or Environment, Tag, Pull request) |
| GitHub branch name | main |
| Name | github-main: 3 to 120 letters, digits, - or _; can't be renamed |
Issuer, Audience (api://AzureADTokenExchange) and Subject identifier fill in. Check the subject against step 2 → Add.
A wrong subject saves without warning and fails only at sign-in. No wildcards: each branch, tag or environment needs its own credential (20 per app at most).
4. Give it one role on one resource
Pick the smallest built-in role that covers the deploy, on that one resource. Still too broad? A custom role lists only the actions you need. What it only reads gets Reader.
SP_ID=$(az ad sp show --id "$CLIENT_ID" --query id -o tsv)
TARGET=$(az resource show -g <resource-group> -n <target-resource> \
--resource-type <resource-type> --query id -o tsv)
az role assignment create --assignee-object-id "$SP_ID" \
--assignee-principal-type ServicePrincipal --role Contributor --scope "$TARGET"The resource → Access control (IAM) → Add → Add role assignment:
- Role: Job function roles for service roles, Privileged administrator roles for Contributor.
- Members: User, group, or service principal → your app registration.
- Review + assign.
Prove nothing broader slipped in (Cloud Shell, >_ in the portal, works too):
az role assignment list --all -o table \
--assignee "$(az ad sp show --id <client-id> --query id -o tsv)"Every Scope should end at a resource, never a resource group or subscription. Roles take up to 10 minutes to apply.
5. Store the three IDs in GitHub
They aren't passwords, but store them as secrets: GitHub masks secrets in logs, variables show as plain text, and the azure/login docs recommend secrets. Variables also work, read with vars..
secrets.NAME reads only secrets, vars.NAME only variables. A missing name comes back empty, and the login step stops.
Repository values reach every workflow; environment values only jobs that name the environment, after any required reviewer approves.
gh secret set AZURE_CLIENT_ID # prompts for the value
gh secret set AZURE_TENANT_ID
gh secret set AZURE_SUBSCRIPTION_ID
# for an environment, add: --env <environment>Settings → Secrets and variables → Actions → Secrets → New repository secret. Add AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_SUBSCRIPTION_ID, each with Add secret.
For an environment: Settings → Environments → the environment → Environment secrets → Add secret.
6. Write the workflow
Save as .github/workflows/deploy.yml:
name: deploy
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read # every job: read the code, nothing more
jobs:
deploy:
if: github.ref == 'refs/heads/main' # other branches never try to sign in
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # only this job may ask GitHub for an OIDC token
steps:
- uses: azure/login@<full-length-commit-sha> # v3
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Check the sign-in
run: az account show --query name -o tsvpermissions: once you set any, the rest becomenone. Only the deploy job addsid-token: write.if:keeps other branches away from the login step.- The SHA can't be moved to other code, unlike a tag. Copy it from the action's own repository, not a fork, and update it on each release: a pinned SHA gets no fixes on its own.
Swap the last step for your deploy, like the one in CI/CD for a .NET API on Azure Container Apps.
7. Test both ways
- Actions → deploy → Run workflow on
main. Azure login passes and the check prints the subscription name. - Run it on another branch.
if:skips the job, and without it Entra ID would refuse the other branch's subject. - Delete any old client secret from the app registration and GitHub.
Something failed? See Fix and maintain GitHub Actions sign-in to Azure.
Sources
- OIDC reference: subject formats (GitHub Docs)
- Immutable GitHub subjects (Microsoft Learn)
- Trust GitHub from an app registration (Microsoft Learn)
- Federated credential limits (Microsoft Learn)
- Assign Azure roles in the portal (Microsoft Learn)
- Use secrets in GitHub Actions (GitHub Docs)
- Secure use: pin actions to a SHA (GitHub Docs)
- azure/login: inputs and troubleshooting (GitHub)