Imagine a pipeline that fails on a Friday afternoon with an authentication error. The cause is an AZURE_CREDENTIALS secret created two years ago with a client secret that just expired. While rotating it, someone notices that the same JSON blob is also stored in a second repository, in an old fork, and in a teammate's local .env file. Nobody knows who else has a copy.
OpenID Connect (OIDC) federation removes that secret entirely. GitHub issues a short-lived token for each job. Microsoft Entra ID checks where the token came from and exchanges it for a short-lived Azure access token. There's nothing to expire, rotate, or leak from your repository settings.
A federated setup that's actually safer comes down to a few decisions:
- Trust an exact subject, not "anything from this repository".
- Use environments as the gate for production access.
- Plan for repository renames and transfers, which change the subject.
- Give pull requests no Azure access, or read-only access at most.
- Scope the identity's roles as tightly as you scope the trust.
- Protect the federated credential itself, because adding one is a new way in.
How the exchange works
The flow has three parts:
- GitHub issues a signed OIDC token to a job that has the
id-token: writepermission. The token's issuer ishttps://token.actions.githubusercontent.com, and its claims describe the job, including the repository, branch, environment, and a subject string, per GitHub's OIDC reference. - Microsoft Entra ID has a federated identity credential on an app registration or a managed identity. It says: trust tokens from this issuer, with this subject, for this audience. Per Microsoft's workload identity federation overview, the issuer, subject, and audience must match the token case-sensitively.
- The azure/login action requests the GitHub token and exchanges it for an Azure access token, using only the client ID, tenant ID, and subscription ID. None of those three values is a secret.
GitHub's OIDC concepts page describes the result as a short-lived access token valid only for a single job. Microsoft's access token documentation puts the default Azure access token lifetime at 60 to 90 minutes. The recommended audience value is api://AzureADTokenExchange.
App registration or user-assigned managed identity
You can attach the federated credential to either of two identities. Microsoft's GitHub OIDC guide documents both as options without ranking them:
- A Microsoft Entra app registration. This is the classic service principal. It's managed in Entra through the admin center or Microsoft Graph, which usually needs directory-level permissions.
- A user-assigned managed identity. It lives in an Azure resource group, can be created in Bicep with its federated credentials, and is deleted with that resource group.
A system-assigned managed identity isn't supported for this, per the managed identity trust guide.
For teams that manage infrastructure in Bicep, a user-assigned identity is often easier to keep in code. An app registration fits better when the same identity must also sign in to other Entra-protected APIs. Either way, each identity holds at most 20 federated credentials, per Microsoft's federation considerations. Plan one identity per environment, not one shared identity with dozens of subjects.
The subject is the whole security boundary
Azure's standard federated credentials match the subject exactly. As of November 2026, wildcards aren't supported in any federated credential property. The subject therefore decides which jobs can get Azure access. GitHub's OIDC reference documents four default formats:
- Environment:
repo:ORG/REPO:environment:prod, used whenever the job references an environment. - Branch:
repo:ORG/REPO:ref:refs/heads/main, but only if the job doesn't reference an environment and the workflow wasn't triggered by a pull request event. - Tag:
repo:ORG/REPO:ref:refs/tags/v1.2.0, under the same environment rule. - Pull request:
repo:ORG/REPO:pull_request, for workflows triggered by a pull request event.
The environment rule catches many teams. A credential that trusts the main branch works until someone adds environment: production to the job. From then on, the token's subject is the environment form, the branch credential no longer matches, and the login fails.
The other trap is silent misconfiguration. Microsoft's considerations page says a credential with a wrong subject is created without any error. The problem only appears when the token exchange fails. Copy the exact subject from a failing run's error message, not from memory.
Renames, transfers, and immutable subjects
The default subject contains the organization and repository names. Names can change, and names can be reused.
GitHub announced immutable subject claims in 2026. Per GitHub's Azure OIDC guide, repositories created after July 15, 2026, and repositories renamed or transferred after that date, use a default subject that includes the owner and repository IDs, for example repo:octo-org@123456/octo-repo@456789:ref:refs/heads/main. Existing repositories keep the old format unless they opt in through the OIDC settings. As of November 2026, the ID-based format isn't available on GitHub Enterprise Server.
Two consequences follow:
- A rename can break CI. If an older repository is renamed or transferred, its token subject switches to the ID-based format, and existing name-based credentials stop matching.
- Name-based subjects can be recycled. Microsoft's immutable subjects guide describes subject recycling. A repository is deleted or renamed, someone else takes the name, and their tokens match your credential. Microsoft also warns about dangling credentials that outlive the repository they trusted.
Microsoft's migration pattern avoids downtime:
- Add a second federated credential with the ID-based subject.
- Opt the repository in on GitHub.
- Confirm a run succeeds.
- Delete the old name-based credential.
Delete credentials for archived or deleted repositories as part of the same review.
Pull requests, forks, and pull_request_target
The pull_request subject doesn't say which branch or fork the pull request came from. A credential that trusts it trusts every pull request workflow run in that repository.
GitHub's workflow syntax reference says that for forked repositories you can typically adjust read permissions, but you can't grant write access. The exception is an organization setting that sends write tokens to workflows from fork pull requests. Requesting an OIDC token needs id-token: write, so check that setting, and test with a fork, before assuming fork pull requests are excluded.
The bigger risk is pull_request_target. It runs in the context of the base repository with more privileges, even for pull requests from forks. GitHub's events reference warns that running untrusted code under pull_request_target can lead to cache poisoning and unintended access to write privileges or secrets. Never check out and run pull request code in a job that can request Azure tokens.
A practical rule: pull request workflows get no Azure credential at all. If they truly need cloud access, for example to run a Bicep what-if, give them a separate identity with read-only roles.
Use environments as the gate for production
Binding the production credential to an environment subject, such as repo:ORG/REPO:environment:production, lets GitHub's environment rules guard the Azure access. Per GitHub's environments reference, you can:
- Require specific people or teams to approve jobs that reference the environment.
- Prevent the person who started the run from approving it.
- Restrict which branches and tags can use the environment.
A job that references the environment can't start until it's approved. The production identity is therefore only usable by jobs that passed those checks. Use one Azure identity per environment, each with its own federated credential and roles, so a staging job can never get a production token.
Reusable workflows and flexible credentials
Larger organizations often move pipeline logic into shared, reusable workflows. Two features help, with caveats:
- Customized subjects. GitHub lets you change the subject template for a repository with the
include_claim_keyssetting, through its OIDC subject customization REST API, as described in the OIDC reference. The same endpoint,PUT /repos/{owner}/{repo}/actions/oidc/customization/sub, resets the template to the default. Per GitHub's reusable workflow guide, includingjob_workflow_refin the subject lets you trust only jobs that run a specific approved workflow. Changing the template changes every subject in that repository, so update the Azure credentials at the same time. - Flexible federated credentials. As of November 2026 these are in preview. They replace the exact subject with a matching expression that supports patterns. For GitHub, the expression must also match the immutable
repository_idorrepository_owner_idclaim, which stops a pattern from matching another organization's repository. Microsoft notes that the Azure CLI, Azure PowerShell, and Terraform don't support them yet.
Patterns bring back some of the breadth that exact matching removed. Use them to reduce credential sprawl, not to trust a whole organization.
Scope the role, not just the trust
A perfect trust in front of an over-powered identity is still a big blast radius. Microsoft's RBAC best practices say to grant the least privilege needed and avoid broad roles at broad scopes. A few specifics for CI identities:
- Contributor is a privileged role. Microsoft's role assignment guide lists Contributor among the privileged administrator roles. If CI needs it, assign it at a single resource group, not the subscription.
- Role assignments in Bicep. Contributor can't create role assignments. When a template grants a Container App its pull access, teams are tempted to make the CI identity Owner. Microsoft's guidance is to avoid that and, when a role can assign roles, to constrain it with a condition. Role Based Access Control Administrator with a condition limiting which roles it can grant is the narrower option.
- Container registry pushes. Per the ACR roles overview, the push role depends on the registry's permission mode: AcrPush in the standard RBAC mode, or Container Registry Repository Writer when repository-level ABAC is enabled.
- Key Vault. For reading secrets during a job, Key Vault Secrets User is enough. Microsoft's Key Vault RBAC guide warns that a Contributor on a vault that uses access policies can grant itself data access. That's one more reason not to give CI broad Contributor rights.
The earlier post on Azure RBAC least privilege goes deeper on scopes and conditions.
Protect the trust itself
Adding a federated credential creates a new way to sign in as that identity, and it's easy to overlook. Per Microsoft's considerations page, anyone who can add a secret or certificate to an app registration can add a federated credential. For a user-assigned identity, the trust guide lists Contributor or Owner as the required role.
In practice:
- Treat Contributor on the identity's resource group as the power to add a new trusted repository. Keep production identities in a resource group with tight access.
- Use Azure Policy to deny new federated credentials on user-assigned identities where you don't expect them. Microsoft's considerations page describes this option.
- Review federated credentials periodically, alongside app registration owners, and remove anything that trusts a repository you no longer use.
Migrating off the old secret
You can switch without a broken pipeline:
- Create the identity, the federated credential with the exact subject, and the role assignments.
- Update the workflow. Add
id-token: writeandcontents: readpermissions, and pass client ID, tenant ID, and subscription ID to the login action. - Use the current major version of the login action. As of November 2026, the azure/login README marks v3 as supported and v2 as maintenance mode, though some Microsoft examples still show v2.
- Remove the old
credsinput. The README says that if any of the client, tenant, or subscription IDs is set,credsis ignored. A leftover line doesn't fail, but it hides what's actually being used. - Allow for propagation. Microsoft says a new federated credential can take several minutes to propagate, and early requests may fail with AADSTS70021. Retry before you start debugging.
- Once runs succeed, delete the client secret from the app registration, and delete the
AZURE_CREDENTIALSsecret at the repository, environment, and organization levels. - Check the sign-in logs. Per Microsoft's sign-in log documentation, service principal sign-ins exclude managed identity sign-ins, which appear in a separate log. Look in both before concluding that nothing still uses the old secret.
If the secret was ever exposed, rotating it isn't enough. The earlier post on responding to a committed secret covers checking what it was used for.
Errors you'll see
Most failures come from a mismatch between the token and the credential. Microsoft's workload identity troubleshooting guide, written for Azure DevOps but using the same Entra error codes, and the Entra error code reference cover the common ones:
- AADSTS70021, no matching federated identity record. The subject, issuer, or audience doesn't match, or the new credential hasn't propagated yet. Compare the subject in the error with the credential, character by character, including case.
- AADSTS700213, no matching subject. The subject specifically doesn't match. Check for the environment-vs-branch rule and the ID-based format.
- AADSTS700211, no matching issuer. The issuer on the credential is wrong. For GitHub.com it's the token.actions.githubusercontent.com URL.
- AADSTS7000215, invalid client secret. You're still using the old secret-based login.
- A 409 conflict when creating credentials. Microsoft notes that creating several federated credentials on the same user-assigned identity at the same time fails with a conflict. Create them one after another, for example with a dependency between them or the
batchSizedecorator on a Bicep loop.
Checklist
- One identity per environment, with roles scoped to a resource group or resource.
- Federated credentials that trust exact subjects, preferring environment subjects for production.
- Production behind a GitHub environment with required reviewers and branch rules.
- No Azure credential for pull request workflows, or a separate read-only one, and no
pull_request_targetjobs that run pull request code. - Repositories opted in to ID-based subjects, with name-based and dangling credentials removed.
- Contributor avoided where narrower roles work, with conditions on any role that can assign roles.
- Federated credentials protected by tight access, Azure Policy where useful, and periodic review.
- The current azure/login major version, with no leftover
credsinput. - The old client secret and
AZURE_CREDENTIALSdeleted, and both sign-in logs checked. - For the rest of your pipeline's supply chain, see the earlier post on securing third-party actions.



