Federating GitHub Actions to Azure lets a workflow exchange a short-lived GitHub OIDC token for a Microsoft Entra access token, so no Azure client secret ever needs to sit in a GitHub repository. This guide takes you from a service principal with a stored secret to a federated credential that only trusts the repository, branch or environment you name, then shows how to verify the change and remove the old secret.
The pattern mirrors our How to set up workload identity federation for GitHub Actions to AWS guide, but the Azure side works differently. Instead of an IAM OIDC provider and a role trust policy, you add a federated identity credential to an Entra app registration or a user-assigned managed identity, and the match is an exact string comparison on issuer, subject and audience. Getting that subject string right is most of the work.
This is an independent guide from NHI Mgmt Group, based on Microsoft's public documentation and GitHub's public documentation as of November 2026. It is not sponsored or reviewed by Microsoft or GitHub. Product features change, so confirm settings against Microsoft's and GitHub's current documentation.
Key takeaways
- A client secret in
AZURE_CREDENTIALSis a long-lived non-human credential that anyone with repository admin or a compromised workflow can copy. Federation removes it. - Each federated credential trusts one exact subject: an environment, a branch, a tag or pull requests for one repository. Wildcards are not supported in any property.
- Prefer the environment entity type for deployments, and protect the environment with required reviewers and branch rules in GitHub.
- The workflow needs
id-token: write. Grant it at job level, only to jobs that log in to Azure. - A subject mismatch does not fail when you create the credential. It fails later, at token exchange, so test before you delete the secret.
- Federation fixes authentication, not authorisation. Scope the Azure RBAC role assignment for the identity to the smallest resource group that works.
When you need this
- Your workflows use
azure/loginwith acredsJSON blob or a client secret stored as a GitHub secret. - Your secret scanning or audit has found Azure client secrets in repository, organisation or environment secrets, and you want to stop rotating them by hand.
- You are building a new deployment pipeline and want it secretless from day one.
- Your Entra tenant has secret expiry alerts firing for app registrations used only by CI. Our How to replace Azure app secrets with federated credentials guide covers the wider Entra clean-up; this page is the GitHub Actions procedure.
The risk with a stored client secret is not only theft. Secrets outlive the people and pipelines that created them, they are copied into forks, local scripts and other repositories, and they keep working from anywhere on the internet until they expire or someone rotates them. A federated credential changes each of those properties. The token GitHub issues is minted per job, is bound to the repository and context in its claims, and is only accepted by Entra if it matches a trust you configured. Nothing reusable is left in the repository, and the trust can be reviewed as configuration rather than discovered as a leaked string. That is why the OWASP Non-Human Identities Top 10 treats long-lived secrets as a core risk for machine identities.
Before you start
- Decide the identity type. You can federate an Entra app registration (with its service principal) or a user-assigned managed identity. Both accept federated credentials and both are limited to 20 federated identity credentials each, according to Microsoft's documentation. A managed identity avoids an app registration that someone might later add a secret to; an app registration is useful if the same identity also needs Microsoft Graph application permissions.
- Know your trust boundary. List the exact GitHub organisation, repository and either the environment names, branches or tags that should be able to deploy. Write them down before you open the portal.
- Check the subject format. GitHub's documentation notes that for repositories created after 15 July 2026, and for repositories renamed or transferred after that date, the default
subclaim is immutable and includes owner and repository IDs. Existing repositories keep the previous format unless they opt in, and the change is not available on GitHub Enterprise Server. Confirm which format your repository emits, because the Azure subject must match it exactly. - Find the current role assignments. Record the RBAC roles and scopes the existing service principal holds. Use this as an opportunity to reduce them, not to copy them.
- Permissions. You need rights to manage the app registration or managed identity (for example Application Administrator or owner of the app) and to create role assignments at the target scope.
Step-by-step
1. Create or choose the identity
GitHub's Azure guide lists three setup steps: create a Microsoft Entra ID application and a service principal, add federated credentials to that application, and create GitHub secrets that store the Azure configuration. If you are converting an existing pipeline, you can reuse its app registration so that existing role assignments keep working. If you are starting fresh, create a dedicated identity per repository and environment pair, such as gh-payments-api-prod, so that a single compromised pipeline cannot reach other workloads.
2. Add the federated credential
In the Microsoft Entra admin center, open the app registration and go to Certificates & secrets, then Federated credentials, then Add credential. Choose the scenario GitHub actions deploying Azure resources, then enter the organisation, repository and entity type. Microsoft's documentation lists the entity types and the subjects they produce:
| Entity type | Subject format |
|---|---|
| Environment | repo:<Org>/<Repo>:environment:<Name> |
| Branch | repo:<Org>/<Repo>:ref:refs/heads/main |
| Tag | repo:<Org>/<Repo>:ref:refs/tags/v2 |
| Pull request | repo:<Org>/<Repo>:pull-request |
The issuer is https://token.actions.githubusercontent.com and the audience is api://AzureADTokenExchange. The portal fills both in. The credential name must be 3 to 120 URL-friendly characters and cannot be changed after creation, so pick a name that records the repository and entity, such as payments-api-env-production.
To script it, create a JSON file and run az ad app federated-credential create --id <app-object-id-or-client-id> --parameters credential.json. The file holds name, issuer, subject, an optional description and an audiences array containing api://AzureADTokenExchange. PowerShell users can use New-AzADAppFederatedCredential, and Microsoft Graph exposes the same object at /applications/{objectId}/federatedIdentityCredentials. Managing these credentials in infrastructure as code gives you review and history for every trust change.
Microsoft notes that branch and tag pattern matching is not supported. If a workflow runs on many branches, use an environment instead of creating one credential per branch. Microsoft also lists flexible federated identity credentials, which match on a claims expression, as a preview feature; treat preview matching rules with caution in production trust paths.
3. Assign the Azure role
Create a role assignment for the service principal or managed identity at the narrowest scope that works: a resource group or a single resource rather than the subscription. Use a built-in role that fits the deployment, or a custom role if the built-ins are too broad. Our Azure RBAC and Service Principals Guide covers scoping in detail.
4. Store identifiers, not secrets, in GitHub
Create three GitHub secrets or variables: AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_SUBSCRIPTION_ID. None of these is a credential, but the azure/login README says to pass values only from secrets into these inputs, so follow that. If you use an environment entity type, store them as environment secrets on that environment so that only jobs bound to it can read them.
5. Update the workflow
Add the permissions block and replace the creds input with the three identifiers. GitHub's documentation explains that id-token: write lets GitHub's OIDC provider create a JWT for the run and does not grant write access to repository resources.
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: azure/login@<full commit SHA>
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
GitHub's own example pins azure/login to a full commit SHA rather than a tag. Do the same; see How to Pin GitHub Actions to Commit SHAs. The README notes that if any of client-id, tenant-id or subscription-id is set, creds is ignored, so remove creds entirely to avoid confusion. Use allow-no-subscriptions: true only for jobs that act on the tenant rather than a subscription, and set enable-AzPSSession: true only if later steps use Azure PowerShell.
6. Protect the environment
If the credential trusts an environment, the environment becomes the security boundary. GitHub recommends protection rules for environments, such as deployment rules that restrict which branches and tags can deploy. Add required reviewers for production and restrict deployment branches to main or release tags. Without these rules, anyone who can push a branch and edit a workflow could target the environment and receive the Azure token.
Verify it worked
- Run the workflow on the intended branch or environment. Add a step that runs
az account showand confirm the expected tenant, subscription and client ID appear. - Run it from a context that should not be trusted, such as a feature branch or a fork pull request, and confirm login fails.
- In the Entra sign-in logs, filter service principal sign-ins for the application and confirm federated credential sign-ins are recorded. Our How to audit Entra workload identity federated credentials guide covers what to look for.
- Confirm the existing client secret is no longer used: its sign-ins should stop once all workflows are migrated.
- Delete the client secret from the app registration, then delete the
AZURE_CREDENTIALSsecret from GitHub at repository, environment and organisation level.
Rollback and common errors
Keep the old secret valid but unused for a short, agreed window while you test, then remove it. If you need to roll back, revert the workflow commit; the federated credential can stay in place, because it grants nothing unless a matching token is presented.
- No matching federated identity record found. The subject in the token does not exactly match the credential. Compare the expected format against the actual claim. Common causes are an environment name with different capitalisation, a job without
environment:that therefore emits arefsubject, or a repository using the new immutable subject format. - Unable to get ACTIONS_ID_TOKEN_REQUEST_URL. The job lacks
id-token: write, often because a reusable workflow or job-levelpermissionsblock overrides the workflow default. - Audience errors. A non-default
audiencewas set in the workflow, or the job targets a sovereign cloud. The README notes that non-public clouds needenvironmentandaudienceupdated together. - Login works, deployment fails. Authentication succeeded but the identity lacks the RBAC role at the target scope, or the role assignment has not yet applied.
- Credential limit reached. You hit 20 credentials on one identity. Move to environments, or split identities per workload.
For cross-platform troubleshooting, see the Multi-Cloud Workload Identity Troubleshooting Guide and the GitHub Actions OIDC Errors Troubleshooting Guide.
Hardening afterwards
- One identity per workload and environment. Avoid one app registration with dozens of federated credentials across repositories. It concentrates privilege and approaches the 20-credential limit.
- Block secrets on federated apps. Once an app relies on federation, prevent new client secrets being added, and alert if one appears. A managed identity removes this risk by design.
- Restrict pull request trust. Be cautious with the pull request entity type. Pull requests can run modified workflow code, so give any identity they use read-only or test-only roles.
- Watch Dependabot. GitHub notes that Dependabot update jobs carry an
event_nameclaim ofdynamic. Check that your environment rules do not let unexpected event types reach production identities. - Token lifetime. The azure/login README states that a service principal access token is expected to last one hour by default and a managed identity token 24 hours. Keep deployments short and leave the action's post-step cleanup enabled; it runs by default unless
AZURE_LOGIN_POST_CLEANUPis set tofalse. - Self-hosted runners. Tokens on self-hosted runners can persist in the runner's Azure CLI profile between jobs. Use ephemeral runners for jobs that hold production identities.
- Review the trust inventory. List federated credentials per app on a schedule with
az ad app federated-credential listand remove any that reference deleted repositories or environments. A renamed or deleted repository name could later be claimed by someone else, which is one reason GitHub moved to ID-based subjects. - Least privilege on the branch side too. Scope trust to a branch and an environment where possible; our How to Scope CI OIDC Trust to Branch and Environment guide explains the trade-offs.
Other pipelines in your estate can follow the same model: see How to federate Azure DevOps to Azure without secrets and How to set up workload identity federation for GitLab CI to Azure.
Practitioner checklist
- Every Azure client secret used by GitHub Actions is inventoried with its app registration and repositories.
- A dedicated app registration or user-assigned managed identity exists per workload and environment.
- Each federated credential names one exact repository and environment, branch or tag, using the subject format the repository emits.
- Production credentials use the environment entity type, and the GitHub environment has required reviewers and deployment branch rules.
- RBAC role assignments are scoped to a resource group or resource, not the subscription.
id-token: writeis granted at job level, only to jobs that log in to Azure.azure/loginis pinned to a full commit SHA and thecredsinput is removed.- Untrusted branches and fork pull requests have been tested and fail to log in.
- The old client secret is deleted from Entra and from every GitHub secret scope.
- Alerts fire if a new secret is added to a federated app registration.
- Federated credentials are reviewed quarterly and stale ones removed.
Standards and references
- Microsoft Learn: Configure an app to trust an external identity provider
- GitHub Docs: Configuring OpenID Connect in Azure
- Azure/login action README
- OWASP Non-Human Identities Top 10
- GitHub Actions OIDC Federation Hardening Guide
- Azure Managed Identities Security Guide
Related NHI Mgmt Group resources: How to set up workload identity federation for GitHub Actions to AWS · GitHub and GitHub Actions Security Guide · How to replace Azure app secrets with federated credentials · Azure RBAC and Service Principals Guide