Lesson 2 of 4 Sensitive Information in Automation

Implementing Secrets and Secretless Authentication

This lesson explains stored secrets, then how workload identity federation removes them.

Learning outcomes

After completing this lesson, you will be able to:

  • Compare secret levels on each platform.
  • Explain the federation token exchange.
  • Configure a federated credential for GitHub Actions.
  • Identify the correct subject claim.

Storing secrets in pipelines

GitHub secrets

GitHub stores encrypted secrets at three levels. Organization secrets can be limited to selected repositories, repository secrets apply to one repository, and environment secrets are released only to jobs that reference the environment, after protection rules pass. This last level is valuable, as a production credential can then be held behind required reviewers. When names clash, the narrowest level wins. Secrets are read with ${{ secrets.NAME }}, and they are not passed to workflows triggered from forks.

Azure Pipelines secrets

Azure Pipelines has secret variables, set in the pipeline's settings or in a variable group, with the padlock option. They cannot be read back through the interface, and are masked in logs. Variable groups add sharing, and permissions and checks on the group.

All such values have the same weaknesses. They must be rotated, they can expire and break a release, and they can be stolen if a pipeline is compromised. This is the motivation for removing them.

True or false

Secrets in GitHub and Azure Pipelines

Exam skills 4.2.2

Check how each platform stores and releases pipeline secrets.

Log in to try this activity Interactive activities are free with an account.

How workload identity federation works

Workload identity federation replaces a stored secret with a trust relationship. Rather than proving its identity with a password, the pipeline presents a short-lived token issued by its platform, and Microsoft Entra ID decides whether to trust it. The token follows the OpenID Connect (OIDC) standard. The following sequence shows the exchange.

  1. Trust is configured

    A federated credential on an app registration or user-assigned identity names an issuer, a subject and an audience.

  2. The run starts

    GitHub or Azure DevOps issues a signed token describing the run, such as the repository and branch.

  3. The token is presented

    The login step sends the token to Microsoft Entra ID.

  4. Claims are compared

    Microsoft Entra ID validates the signature, and compares the issuer, subject and audience with the federated credential.

  5. An access token returns

    A short-lived Azure access token is issued, and deployment proceeds.

Nothing long-lived exists to steal. The token is valid only for a short period, and only a run matching the subject is accepted, so a token from a different repository or branch is refused.

The following diagram compares the subject configured on a federated credential with the one a GitHub Actions job presents.

Why azure/login found no matching federated identity record. The credential's subject names the main branch, but a job that references an environment presents an environment subject, so the two do not match. Adding a federated credential for the environment subject fixes it; a client secret would defeat the purpose.
The scenario is illustrative.
Put in order

The federation exchange

Exam skills 4.2.2

Arrange how a pipeline signs in to Azure with workload identity federation.

Log in to try this activity Interactive activities are free with an account.

Configuring GitHub Actions

Configuration has three parts: the identity, the federated credential, and the workflow. The following commands create a user-assigned identity with a credential that trusts the production environment of one repository, and they give it a role.

az identity create --name id-gh-deploy --resource-group rg-identity

az identity federated-credential create \
  --name github-production \
  --identity-name id-gh-deploy \
  --resource-group rg-identity \
  --issuer https://token.actions.githubusercontent.com \
  --subject "repo:contoso/web:environment:production" \
  --audiences api://AzureADTokenExchange

az role assignment create \
  --assignee <client-id> \
  --role "Website Contributor" \
  --scope /subscriptions/<subscription-id>/resourceGroups/rg-web

The workflow then needs the id-token: write permission, without which it cannot request a token. The client ID, tenant ID and subscription ID are identifiers and not secrets, so they can be stored as variables.

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: azure/login@v2
        with:
          client-id: ${{ vars.AZURE_CLIENT_ID }}
          tenant-id: ${{ vars.AZURE_TENANT_ID }}
          subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
      - run: az webapp list --output table

The subject claim

The subject must match exactly, and its format depends on the trigger. The default formats are shown below. The audience for Azure is api://AzureADTokenExchange, and the issuer is https://token.actions.githubusercontent.com.

TriggerSubject
Environmentrepo:ORG/REPO:environment:NAME
Branchrepo:ORG/REPO:ref:refs/heads/BRANCH
Tagrepo:ORG/REPO:ref:refs/tags/TAG
Pull requestrepo:ORG/REPO:pull_request

A job that uses an environment presents the environment subject, and not the branch subject, which is a common cause of the error no matching federated identity record found.

Immutable subject format

Since 15 July 2026, GitHub has used an immutable subject format for repositories created after that date, and for repositories renamed or transferred after it. The format adds the owner and repository IDs, such as repo:octo-org@123456/octo-repo@456789:ref:refs/heads/main. This prevents a new repository with a reused name from matching old trust. Older repositories keep the name-based format unless they opt in. Always confirm the subject that a repository really uses before creating a federated credential. Subject claims can also be customized through the REST API, and flexible federated identity credentials, in preview, allow pattern matching with an expression.

Sort into groups

Which subject will the token carry?

Exam skills 4.2.2

Decide which subject claim a GitHub Actions job in <code>contoso/web</code> presents, using the default format.

Log in to try this activity Interactive activities are free with an account.

Configuring Azure Pipelines

Azure Pipelines handles most of this through a service connection. Selecting Workload identity federation when creating an Azure Resource Manager service connection creates the app registration and federated credential automatically, if you hold Owner on the subscription. Pipelines then use the connection in the normal way, and the tasks work unchanged.

The issuer and subject depend on when the connection was created. New connections use the Microsoft Entra issuer, with a subject that ends in /sc/ORGANIZATION-ID/CONNECTION-ID. Older connections use the Azure DevOps issuer https://vstoken.dev.azure.com/ORGANIZATION-ID, with the subject sc://ORGANIZATION/PROJECT/CONNECTION-NAME, and that issuer retires on 1 July 2027. Azure DevOps shows the exact values for each connection. Existing secret-based connections can be converted from the connection's settings, and the change can be reversed for seven days.

Stored secret
Credential at restYes
LifetimeMonths or years
RotationManual or scripted
Scope of trustAnything holding the secret
Choose when The target does not support federation.
Workload identity federation
Credential at restNone
LifetimeMinutes
RotationNot needed
Scope of trustNamed repository, branch, environment or connection
Choose when The target is Azure, or another OIDC-capable service.
Match the pairs

Federation values in Azure Pipelines

Exam skills 4.2.2 · 4.1.3

Match each federation detail for Azure Pipelines service connections.

Log in to try this activity Interactive activities are free with an account.
Worked example

A failing login

A workflow on the main branch deploys through the production environment, and it fails at azure/login with an error stating that no matching federated identity record was found. The federated credential's subject is repo:contoso/web:ref:refs/heads/main. What is wrong?

A job that references an environment presents the subject repo:contoso/web:environment:production, so the credential does not match. You should add a federated credential for the environment subject, or the matching immutable form for a newer repository. Adding a client secret would defeat the purpose. The id-token: write permission is present if the token request succeeded, and the error is about the match itself.

Check yourself

What is the audience value for Azure in a federated credential?

Show answer

api://AzureADTokenExchange. The issuer and subject must match as well.

Exam Tips

Remember for the exam

  • Environment secrets are released only after protection rules pass.
  • Federated credentials trust an issuer, subject and audience.
  • A workflow needs id-token: write to request an OIDC token.
  • A job using an environment presents the environment subject.
  • Repositories created after 15 July 2026 use the immutable subject format.