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.
Secrets in GitHub and Azure Pipelines
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.
-
Trust is configured
A federated credential on an app registration or user-assigned identity names an issuer, a subject and an audience.
-
The run starts
GitHub or Azure DevOps issues a signed token describing the run, such as the repository and branch.
-
The token is presented
The login step sends the token to Microsoft Entra ID.
-
Claims are compared
Microsoft Entra ID validates the signature, and compares the issuer, subject and audience with the federated credential.
-
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.

The federation exchange
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-webThe 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 tableThe 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.
| Trigger | Subject |
|---|---|
| Environment | repo:ORG/REPO:environment:NAME |
| Branch | repo:ORG/REPO:ref:refs/heads/BRANCH |
| Tag | repo:ORG/REPO:ref:refs/tags/TAG |
| Pull request | repo: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.
Which subject will the token carry?
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.
Federation values in Azure Pipelines
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.
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.