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: ./publishThe workflow contains no Azure client secret.
Docker Deployments Use the Same Authentication Model
The same OIDC authentication can be used when the deployment involves Azure Container Registry.
For example:
- 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: Login to Azure Container Registry
run: |
az acr login --name ${{ vars.ACR_NAME }}The workflow can then build and push the container image:
docker build -t "$IMAGE_NAME" .
docker push "$IMAGE_NAME"The important distinction is that Azure authentication and container registry authentication are connected through Azure identity rather than a static cloud password.
GitHub Environments Add Another Layer of Protection
Production deployments should generally use a GitHub environment such as:
productionThe environment can contain deployment-specific variables and protection rules.
A workflow can reference it:
jobs:
deploy:
environment: productionThis allows you to separate:
Development
|
+-- Development Azure identity
Staging
|
+-- Staging Azure identity
Production
|
+-- Production Azure identityUsing separate identities reduces the impact of a compromised workflow.
A development workflow should not automatically have the same Azure permissions as production.
Restrict Production Deployments
OIDC does not replace GitHub workflow security.
Consider restricting production authentication to:
A specific repository
A protected branch
A specific GitHub environment
Approved workflows
Required reviewers
For example, production deployment can require:
Pull Request
|
v
Code Review
|
v
Merge to main
|
v
Production Environment Approval
|
v
GitHub Actions
|
v
Azure OIDC
|
v
Azure DeploymentThis makes the deployment identity part of a controlled release process.
Avoid Giving the Workflow Too Much Permission
Using OIDC removes a long-lived secret, but it does not automatically make the workflow safe.
Consider this example:
GitHub workflow
|
v
Contributor on entire subscriptionIf an attacker can modify the workflow, the Azure identity may have broad access.
A better configuration is:
GitHub workflow
|
v
Azure identity
|
v
Specific resource group
|
v
Required Azure resourceThe deployment identity should have only the permissions required for its job.
If a workflow only deploys an App Service, there is little reason for it to have permissions over unrelated production resources.
Separate Build and Deployment Permissions
A useful CI/CD design is to separate build and deployment jobs.
For example:
Build
|
+-- Restore
+-- Test
+-- Publish
|
v
Deployment Approval
|
v
Azure Login
|
v
DeployThe build job does not need Azure credentials if it only compiles and tests the application.
Only the deployment job needs the Azure identity.
This reduces the number of workflow steps that have access to cloud permissions.
Common Mistakes
Keeping an old client secret after enabling OIDC
Once OIDC is working, remove unnecessary long-lived credentials.
Leaving old secrets in the repository increases the number of credentials that need to be managed.
Giving Contributor access to the entire subscription
This is convenient during setup but often too broad for production.
Start with the smallest useful scope.
Trusting every branch
A federated identity that accepts tokens from many branches increases the attack surface.
Restrict the subject to the workflow that actually needs access.
Forgetting id-token: write
Without this permission, GitHub cannot provide the OIDC token to the workflow.
Confusing authentication with authorization
OIDC answers:
Who is this workflow?Azure RBAC answers:
What is this workflow allowed to do?Both need to be configured correctly.
Sharing one production identity across many repositories
If several repositories use the same highly privileged Azure identity, compromising any one of them can affect all of them.
Separate identities are usually easier to control.
Putting production deployment in an unprotected environment
A workflow that can deploy directly to production should be protected by appropriate branch and environment controls.
Troubleshooting OIDC Authentication
Azure login fails with a federated credential error
Check:
GitHub repository name
Organization name
Branch name
Subject configuration
Issuer
Audience
Azure tenant
Client ID
The federated identity subject must match the identity GitHub is presenting.
Login succeeds but deployment fails
This usually indicates an authorization problem rather than authentication.
Check the Azure role assignment:
az role assignment list \
--assignee <APPLICATION_ID> \
--allThen verify that the role has access to the resource being deployed.
The workflow cannot request an identity token
Check:
permissions:
id-token: writeThe permission must be available to the job requesting Azure authentication.
The wrong Azure subscription is selected
Verify:
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}and confirm that the identity has permission on that subscription or the target resource group.
Comparing Secret-Based and OIDC Authentication
Area | Client Secret | OIDC |
|---|---|---|
Long-lived credential | Usually yes | No |
Secret rotation | Required | Not for a client secret |
GitHub secret storage | Required | Not required for Azure password |
Federated identity setup | No | Yes |
Short-lived authentication | Limited | Yes |
Least-privilege support | Yes | Yes |
Recommended for new workflows | Less desirable | Preferred approach |
OIDC does require more initial configuration.
Once configured, however, the deployment pipeline no longer depends on maintaining a long-lived Azure client secret.
Advantages and Disadvantages
Advantages
Removes the need for long-lived Azure client secrets.
Reduces credential rotation work.
Uses short-lived identity tokens.
Works naturally with GitHub Actions.
Supports Azure RBAC and least-privilege access.
Allows different identities for different environments.
Reduces the amount of sensitive credential material stored in GitHub.
Disadvantages
Initial setup is more involved than storing a client secret.
Federated identity claims must be configured correctly.
Branch and environment changes may require identity configuration changes.
Incorrect RBAC assignments can make deployments fail even when authentication succeeds.
CI/CD security still depends on protecting workflows and GitHub environments.
The setup is more deliberate, but that is useful for production deployments.
A Practical Production Setup
A production deployment can be structured like this:
GitHub Repository
|
v
Protected Branch
|
v
GitHub Actions
|
v
Production Environment
|
v
OIDC Token
|
v
Microsoft Entra ID
|
v
Federated Identity
|
v
Azure RBAC
|
v
Target Resource Group
|
v
Azure ApplicationEach layer has a separate responsibility.
GitHub controls who can trigger the deployment.
OIDC proves the workflow identity.
Microsoft Entra ID validates the federated trust.
Azure RBAC controls what the identity can do.
The Azure resource is then updated by the deployment.
Production Checklist
Before replacing Azure secrets with GitHub OIDC, verify:
An Azure application identity or suitable managed identity exists.
A federated identity credential is configured.
The issuer is the GitHub Actions OIDC issuer.
The subject is restricted appropriately.
The audience is configured correctly.
GitHub Actions has
id-token: write.The Azure identity has the minimum required RBAC role.
The RBAC scope is as narrow as practical.
Production deployments use protected GitHub environments where appropriate.
Build jobs do not receive unnecessary Azure permissions.
Old Azure client secrets are removed when no longer needed.
Deployment failures distinguish authentication problems from authorization problems.
Separate Azure identities are considered for development, staging, and production.
Workflow files are protected from unauthorized modification.
Conclusion
GitHub Actions does not need a permanent Azure client secret to deploy applications.
With OpenID Connect, a workflow can obtain a short-lived identity token and use a federated identity configured in Microsoft Entra ID. Azure then applies its normal role-based access controls to determine what that workflow is allowed to change.
The most important part is not simply replacing one authentication method with another. The deployment identity should also be tightly scoped.
A good production setup uses OIDC, least-privilege Azure RBAC, protected GitHub environments, restricted federated identity claims, and separate deployment identities where appropriate.
The result is a deployment pipeline that can authenticate to Azure without keeping a long-lived cloud credential inside the GitHub repository.
That makes the authentication model easier to manage and reduces one of the common risks associated with automated cloud deployments.

Join the conversation! Your thoughts help the community grow.