Symptom
A deployment workflow that signs in to Azure with OpenID Connect (OIDC) fails at the azure/login step, or partway through the job. You usually see one of these errors:
AADSTS70021: No matching federated identity record found for presented assertion.orAADSTS700213: No matching federated identity record found for presented assertion subjectUnable to get ACTIONS_ID_TOKEN_REQUEST_URL env variableNo subscriptions found for <client-id>AADSTS700024: Client assertion is not within its valid time rangeafter the job has been running for a while
With OIDC there is no secret to expire. Entra ID compares the claims in GitHub's token with the federated credentials on the app registration or managed identity, and the comparison is an exact string match. Almost every failure comes down to that match.
Map the error to the cause
| Error | Usual cause | Fix |
|---|---|---|
AADSTS70021 / AADSTS700213 | Token sub doesn't match any federated credential (wrong branch, environment, PR or tag, case difference, custom subject template) | Read the subject from the error and add a credential that matches it |
AADSTS700211 | Issuer mismatch | Set the issuer to https://token.actions.githubusercontent.com (GitHub Enterprise Cloud with a custom issuer uses a different URL) |
AADSTS700212 | Audience mismatch | Use api://AzureADTokenExchange in both the credential and the audience input |
Unable to get ACTIONS_ID_TOKEN_REQUEST_URL | The job has no id-token: write permission, or it runs from a fork PR | Add the permission. Fork PRs don't get OIDC tokens |
AADSTS700016 | Wrong client-id, or the app is in a different tenant | Check client-id and tenant-id |
No subscriptions found | Sign-in worked, but the identity has no role on the subscription | Assign a role, or set allow-no-subscriptions: true for tenant-only work |
AuthorizationFailed on a later step | RBAC is missing at the target scope | Assign the role at the correct scope |
AADSTS700024 partway through | The GitHub token used for the exchange has expired, and the CLI can't refresh without a new one | Split long jobs, or sign in again before late Azure steps |
Checks
1. Read the subject Entra ID actually received
The AADSTS70021 message includes Assertion Subject and Assertion Issuer. Copy them exactly. Common GitHub subject formats:
| Trigger | Subject |
|---|---|
| Push to a branch | repo:ORG/REPO:ref:refs/heads/main |
| Tag | repo:ORG/REPO:ref:refs/tags/v1.2.0 |
| Pull request | repo:ORG/REPO:pull_request |
Job with environment: | repo:ORG/REPO:environment:production |
The most common surprise is that a job with environment: production uses the environment subject whatever the branch is. A credential for ref:refs/heads/main won't match it.
If the error text isn't clear, print the token's claims from a debug run. Only claims are printed, not the token:
permissions:
id-token: write
contents: read
jobs:
debug-oidc:
runs-on: ubuntu-latest
environment: production # keep this identical to the failing job
steps:
- name: Show OIDC claims
run: |
TOKEN=$(curl -sS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange" | jq -r .value)
python3 - "$TOKEN" <<'EOF'
import sys, json, base64
p = sys.argv[1].split('.')[1]
p += '=' * (-len(p) % 4)
c = json.loads(base64.urlsafe_b64decode(p))
print(json.dumps({k: c.get(k) for k in ('iss','sub','aud','job_workflow_ref','exp')}, indent=2))
EOF
2. List the federated credentials on the identity
For an app registration:
APP_ID="<client-id>"
az ad app federated-credential list --id "$APP_ID" \
--query "[].{name:name, issuer:issuer, subject:subject, audiences:join(',', audiences)}" -o table
For a user-assigned managed identity:
az identity federated-credential list \
--identity-name id-deploy-prod --resource-group rg-identity \
--query "[].{name:name, issuer:issuer, subject:subject}" -o table
Compare the subject character by character, including organisation and repository case, branch names, and trailing spaces left by copy and paste.
3. Check for a customised subject template
An organisation or repository can change the sub claim format, for example to add repository_owner_id or job_workflow_ref. When it has, the default formats above won't match. Check:
gh api repos/ORG/REPO/actions/oidc/customization/sub
gh api orgs/ORG/actions/oidc/customization/sub
If use_default is false or include_claim_keys is set, build the credential subject from the claims printed in check 1, not from the documented defaults.
4. Check workflow permissions and inputs
permissions:
id-token: write # required to request the OIDC token
contents: read # setting permissions explicitly drops other defaults, so add back what you need
steps:
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
If the job calls a reusable workflow, the caller has to grant id-token: write as well. By default the subject still describes the calling repository and ref, not the reusable workflow's repository.
Fix
Add a credential that matches the real subject
cat > fc-prod.json <<'EOF'
{
"name": "github-repo-env-production",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:contoso/payments-api:environment:production",
"audiences": ["api://AzureADTokenExchange"],
"description": "Deploy job, production environment"
}
EOF
az ad app federated-credential create --id "$APP_ID" --parameters fc-prod.json
For a managed identity:
az identity federated-credential create \
--name github-repo-env-production \
--identity-name id-deploy-prod --resource-group rg-identity \
--issuer "https://token.actions.githubusercontent.com" \
--subject "repo:contoso/payments-api:environment:production" \
--audiences "api://AzureADTokenExchange"
The change normally takes effect within a minute or two. Re-run the failed job instead of pushing a new commit, so the subject stays the same.
Warning
Don't fix a mismatch by adding a
pull_requestcredential to a production identity. Any PR from a branch in the repository could then deploy to production. Give PR validation its own identity with read-only or sandbox roles.
An app registration or managed identity can hold only a limited number of federated credentials. Check the current limit before you create one per branch, and prefer environment-based subjects such as dev, test and production.
Fix RBAC after sign-in works
SP_OBJECT_ID=$(az ad sp show --id "$APP_ID" --query id -o tsv)
az role assignment list --assignee-object-id "$SP_OBJECT_ID" --all \
--query "[].{role:roleDefinitionName, scope:scope}" -o table
az role assignment create --assignee-object-id "$SP_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "Contributor" \
--scope "/subscriptions/<sub-id>/resourceGroups/rg-payments-prod"
New role assignments can take a few minutes to apply. If the next run still gets No subscriptions found, wait and retry before you change anything else.
Long jobs that fail with AADSTS700024
The GitHub OIDC token is short-lived. A job that signs in once and then runs for a long time can fail when the CLI needs a new access token. Your options:
- Split the work into several jobs, each with its own
azure/loginstep. - Run
azure/loginagain just before late Azure steps. - For Terraform or SDK steps, use the provider's own OIDC support (for example
ARM_USE_OIDC=truefor the azurerm provider), which requests fresh GitHub tokens as needed.
Also check that self-hosted runner clocks are synchronised, because a skewed clock produces the same error.
Prevent it next time
- Use one environment-based federated credential per deployment stage, and require reviewers on the
productionenvironment in GitHub. - Keep federated credentials in code (Bicep, Terraform or a script), so a repository rename or environment rename gets updated in one reviewed change.
- When you rename a repository or organisation, update the subjects first. The old subject stops matching straight away.
- Write the expected subject into the workflow file as a comment next to
azure/login, so the next person debugging it knows what to compare. - Alert on failed sign-ins for deployment service principals from the
AADServicePrincipalSignInLogstable:
AADServicePrincipalSignInLogs
| where TimeGenerated > ago(1d)
| where ResultType != "0"
| where AppId == "<client-id>"
| summarize failures = count(), lastSeen = max(TimeGenerated) by ResultType, ResultDescription
| order by failures desc
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get