GitHub Actions is commonly used to build, test, and deploy applications automatically. A typical workflow may compile a .NET application, run tests, create a Docker image, and then deploy that image to Azure.
The deployment part usually needs permission to access Azure resources.
A simple approach is to store an Azure client ID, client secret, subscription ID, or another credential in GitHub Secrets and use that credential during the workflow.
It works, but there is a better option for many environments.
GitHub Actions can authenticate to Azure using OpenID Connect, commonly called OIDC. With OIDC, the workflow receives a short-lived identity token and exchanges it with Microsoft Entra ID for Azure access.
The GitHub repository does not need to store a long-lived Azure password or client secret.
This article explains how the authentication flow works, how to configure an Azure federated identity, and how to use it from a GitHub Actions workflow.
The Traditional Secret-Based Approach
A deployment workflow often looks like this:
GitHub Actions
|
| Azure credentials
v
Microsoft Entra ID
|
v
AzureThe workflow might use a stored secret:
- name: Login to Azure
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}The secret can contain information such as:
{
"clientId": "...",
"clientSecret": "...",
"subscriptionId": "...",
"tenantId": "..."
}This approach creates a credential that has to be protected.
If the credential is long-lived, there is also a rotation problem.
The longer a credential remains valid, the longer it remains useful if it is accidentally exposed.
What Changes With OpenID Connect?
With OIDC, GitHub does not need to store the Azure client secret.
The authentication flow becomes:
GitHub Actions
|
| Requests OIDC token
v
GitHub Identity Provider
|
v
Microsoft Entra ID
|
| Validates token claims
v
Azure Access Token
|
v
Azure ResourceThe important difference is that GitHub is proving its identity for a particular workflow execution.
The workflow does not need a permanent Azure password.
The Azure Identity Model
For this setup, an Azure application registration or user-assigned managed identity can be configured with a federated identity credential.
The federated identity establishes a trust relationship:
GitHub repository/workflow
|
| Trusted identity
v
Microsoft Entra ID
|
v
Azure permissionsThe trust should be restricted.
For example, you can configure it so that only a specific repository and branch can authenticate.
That is much safer than allowing every GitHub workflow to use the same Azure identity.
Why Short-Lived Authentication Is Better
A long-lived secret has a lifecycle:
Create
|
v
Store
|
v
Use
|
v
Rotate
|
v
Eventually revokeAn OIDC token is temporary:
Workflow starts
|
v
Identity token issued
|
v
Azure validates it
|
v
Short-lived access
|
v
Token expiresThere is no permanent Azure client secret sitting in GitHub Secrets.
This reduces the amount of credential material that needs to be managed.
Create an Azure Application Identity
The first step is to create an identity that GitHub Actions can use.
For example, with Azure CLI:
az ad app create \
--display-name "github-actions-deployment"You can then create a service principal for the application.
az ad sp create \
--id <APPLICATION_ID>Store the application ID and tenant information somewhere secure during configuration.
The exact Azure CLI commands can vary depending on how the identity is managed in your organization, so the important part is understanding the resulting identity model:
Application Registration
|
v
Service Principal
|
v
Federated Identity Credential
|
v
Azure Role AssignmentCreate a Federated Identity Credential
The federated credential tells Microsoft Entra ID which GitHub identity it should trust.
The configuration can be created through Azure CLI.
For example:
az ad app federated-credential create \
--id <APPLICATION_ID> \
--parameters '{
"name": "github-main-branch",
"issuer": "https://token.actions.githubusercontent.com",
"subject": "repo:my-org/my-app:ref:refs/heads/main",
"audiences": [
"api://AzureADTokenExchange"
]
}'The important values are:
issuer
subject
audiencesThe issuer identifies GitHub as the identity provider.
The subject identifies the GitHub identity that is allowed to authenticate.
The audience identifies the intended token exchange.
Restrict the Subject
The subject is one of the most important security controls.
A broad trust relationship is dangerous.
For example, trusting every branch of every repository in an organization gives the identity a much larger attack surface.
A more specific subject can look like:
repo:my-org/my-app:ref:refs/heads/mainThis means the trust applies to a specific repository and branch.
You can also configure trust for environments or other GitHub identity claims depending on your workflow design.
The principle is simple:
Give the Azure identity access only to the GitHub workflow that actually needs it.
Assign Azure Permissions
Authentication only proves who the workflow is.
It does not automatically give the workflow permission to modify Azure resources.
You still need an Azure role assignment.
For example:
az role assignment create \
--assignee <APPLICATION_ID> \
--role Contributor \
--scope /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-app-rgThe important part is the scope.
Avoid assigning broad subscription-level permissions when the deployment only needs access to one resource group or service.
For example:
Better:
Subscription
|
+-- Resource Group
|
+-- App ServiceInstead of:
Subscription
|
+-- Contributor access to everythingLeast privilege is especially important for CI/CD identities because workflows execute automatically.
Add GitHub Actions Permissions
The GitHub workflow needs permission to request an OIDC token.
Add this at the workflow or job level:
permissions:
id-token: write
contents: readFor example:
name: Deploy
on:
push:
branches:
- main
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4The important permission is:
id-token: writeWithout it, the workflow cannot request the OIDC token needed for Azure authentication.
Login to Azure Without a Client Secret
The Azure login action can use OIDC:
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}Notice what is missing.
There is no:
client-secret:There is no long-lived Azure credential stored in GitHub.
The workflow receives an identity token from GitHub and Azure validates the configured federated identity.
Store Configuration Separately From Secrets
Not every value needs to be stored as a secret.
For example:
AZURE_CLIENT_ID
AZURE_TENANT_ID
AZURE_SUBSCRIPTION_IDare identifiers rather than passwords.
They can generally be stored as GitHub repository or environment variables rather than encrypted secrets.
The authentication trust is provided by OIDC and the federated identity configuration.
A useful separation is:
GitHub Variables
|
+-- Client ID
+-- Tenant ID
+-- Subscription ID
GitHub OIDC
|
+-- Temporary identity token
Azure
|
+-- Federated identity
+-- Role assignmentThe exact storage choice should still follow your organization's security policy.
Deploy an ASP.NET Core Application to Azure App Service
Once Azure login works, the rest of the workflow can use Azure CLI or an Azure deployment action.
For example:
- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v3
with:
app-name: my-production-api
package: ./publishA complete simplified workflow might look like this:
name: Deploy API
on:
push:
branches:
- main
permissions:
id-token: write
contents: read
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "latest"
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build
- name: Publish
run: dotnet publish \
--configuration Release \
--output ./publish
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Deploy
uses: azure/webapps-deploy@v3
with:
app-name: my-production-api
package: ./publish
Join the conversation! Your thoughts help the community grow.