FREE STUDY NOTES · AZ-401

Secretless authentication from GitHub Actions to Azure with OIDC

How workload identity federation lets a workflow sign in to Azure with no stored secret, and which subject claims to trust.

From Ultra Transcenders AZ-401 by Tony Rough

GitHub Actions uses OpenID Connect (OIDC) to exchange a GitHub-issued token for an Entra access token. Configured correctly, the repository stores only identifiers, never a password.

The set-up has three parts. First, create a Microsoft Entra application (with its service principal) or a user-assigned managed identity, and assign it the narrowest Azure role that the deployment needs. Second, add a federated identity credential that trusts GitHub’s issuer (https://token.actions.githubusercontent.com) for a specific subject. Third, store the client ID, tenant ID and subscription ID as GitHub secrets or variables and call azure/login@v2 from a job that has id-token: write.

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    permissions:
      id-token: write   # request the OIDC token
      contents: read
    steps:
      - uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

Subject claims decide which jobs can use the identity, and an ordinary federated credential must match exactly:

Workflow context Subject format
Job tied to an environment repo:<org>/<repo>:environment:<name>
Job without an environment, triggered from a branch or tag repo:<org>/<repo>:ref:refs/heads/<branch> or ref:refs/tags/<tag>
Workflow triggered by a pull request repo:<org>/<repo>:pull_request

Binding production credentials to an environment subject means only jobs that pass that environment’s protection rules (Chapter 10) can authenticate. An application or user-assigned managed identity can hold 20 federated identity credentials. Flexible federated identity credentials (preview) relax exact matching with an expression language, for example matching every branch of a repository, but for GitHub they must also match an immutable claim such as repository_id. Learn’s Azure Databricks guidance notes that repositories created, renamed or transferred on or after 15 July 2026 use a subject format that includes numeric IDs, so confirm the exact subject your repository’s tokens carry. azure/login defaults the audience to api://AzureADTokenExchange for public cloud. Figure 12.1 shows the token exchange and the three checks Entra ID makes.

A GitHub Actions job with id-token: write asks GitHub's OIDC issuer for a token that carries a subject claim. azure/login sends it to Microsoft Entra ID, where the federated identity credential checks the issuer, the exact subject and the audience before returning an access token. The job then deploys to Azure resources with the identity's narrowest role, and later azure/* steps reuse the session. The repository stores only the client, tenant and subscription IDs.
Figure 12.1: Secretless sign-in from GitHub Actions to Azure with OIDC

The same pattern feeds downstream tools: once azure/login succeeds, azure/cli, azure/powershell, azure/bicep-deploy and azure/webapps-deploy reuse the session.

Common trap: Creating a federated credential for ref:refs/heads/main and then adding environment: production to the job - a job tied to an environment presents the environment subject, so the credential no longer matches and sign-in fails.

Get the whole book

This note is one section of Ultra Transcenders AZ-401: Designing and Implementing Microsoft Agentic DevOps Solutions, an independent study guide that explains every topic the exam covers by technology, with comparison tables, diagrams and the common traps, plus a glossary linked to Microsoft Learn.

Amazon.co.ukKindlePaperback
Amazon.comKindlePaperback

Free to read with Kindle Unlimited. Opens Amazon in a new tab.

About the book · AZ-401 terms in the glossary · All AZ-401 study notes

More AZ-401 study notes