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:

Code
GitHub Actions
      |
      | Azure credentials
      v
Microsoft Entra ID
      |
      v
Azure

The workflow might use a stored secret:

YAML
- name: Login to Azure
  uses: azure/login@v2
  with:
    creds: ${{ secrets.AZURE_CREDENTIALS }}

The secret can contain information such as:

JSON
{
  "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:

Code
GitHub Actions
      |
      | Requests OIDC token
      v
GitHub Identity Provider
      |
      v
Microsoft Entra ID
      |
      | Validates token claims
      v
Azure Access Token
      |
      v
Azure Resource

The 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:

Code
GitHub repository/workflow
          |
          | Trusted identity
          v
Microsoft Entra ID
          |
          v
Azure permissions

The 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:

Code
Create
  |
  v
Store
  |
  v
Use
  |
  v
Rotate
  |
  v
Eventually revoke

An OIDC token is temporary:

Code
Workflow starts
      |
      v
Identity token issued
      |
      v
Azure validates it
      |
      v
Short-lived access
      |
      v
Token expires

There 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:

Bash
az ad app create \
  --display-name "github-actions-deployment"

You can then create a service principal for the application.

Bash
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:

Code
Application Registration
        |
        v
Service Principal
        |
        v
Federated Identity Credential
        |
        v
Azure Role Assignment

Create 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:

Bash
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:

Code
issuer
subject
audiences

The 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:

Code
repo:my-org/my-app:ref:refs/heads/main

This 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:

Bash
az role assignment create \
  --assignee <APPLICATION_ID> \
  --role Contributor \
  --scope /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/my-app-rg

The 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:

Code
Better:

Subscription
   |
   +-- Resource Group
         |
         +-- App Service

Instead of:

Code
Subscription
   |
   +-- Contributor access to everything

Least 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:

YAML
permissions:
  id-token: write
  contents: read

For example:

YAML
name: Deploy

on:
  push:
    branches:
      - main

permissions:
  id-token: write
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

The important permission is:

YAML
id-token: write

Without 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:

YAML
- 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:

YAML
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:

Code
AZURE_CLIENT_ID
AZURE_TENANT_ID
AZURE_SUBSCRIPTION_ID

are 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:

SQL
GitHub Variables
    |
    +-- Client ID
    +-- Tenant ID
    +-- Subscription ID

GitHub OIDC
    |
    +-- Temporary identity token

Azure
    |
    +-- Federated identity
    +-- Role assignment

The 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:

YAML
- name: Deploy to Azure App Service
  uses: azure/webapps-deploy@v3
  with:
    app-name: my-production-api
    package: ./publish

A complete simplified workflow might look like this:

YAML
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

The 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:

YAML
- 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:

Bash
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:

Code
production

The environment can contain deployment-specific variables and protection rules.

A workflow can reference it:

YAML
jobs:
  deploy:
    environment: production

This allows you to separate:

Code
Development
    |
    +-- Development Azure identity

Staging
    |
    +-- Staging Azure identity

Production
    |
    +-- Production Azure identity

Using 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:

Code
Pull Request
     |
     v
Code Review
     |
     v
Merge to main
     |
     v
Production Environment Approval
     |
     v
GitHub Actions
     |
     v
Azure OIDC
     |
     v
Azure Deployment

This 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:

Code
GitHub workflow
      |
      v
Contributor on entire subscription

If an attacker can modify the workflow, the Azure identity may have broad access.

A better configuration is:

Code
GitHub workflow
      |
      v
Azure identity
      |
      v
Specific resource group
      |
      v
Required Azure resource

The 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:

Code
Build
  |
  +-- Restore
  +-- Test
  +-- Publish
  |
  v
Deployment Approval
  |
  v
Azure Login
  |
  v
Deploy

The 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:

Code
Who is this workflow?

Azure RBAC answers:

Code
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:

Bash
az role assignment list \
  --assignee <APPLICATION_ID> \
  --all

Then verify that the role has access to the resource being deployed.

The workflow cannot request an identity token

Check:

YAML
permissions:
  id-token: write

The permission must be available to the job requesting Azure authentication.

The wrong Azure subscription is selected

Verify:

YAML
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:

Code
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 Application

Each 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:

  1. An Azure application identity or suitable managed identity exists.

  2. A federated identity credential is configured.

  3. The issuer is the GitHub Actions OIDC issuer.

  4. The subject is restricted appropriately.

  5. The audience is configured correctly.

  6. GitHub Actions has id-token: write.

  7. The Azure identity has the minimum required RBAC role.

  8. The RBAC scope is as narrow as practical.

  9. Production deployments use protected GitHub environments where appropriate.

  10. Build jobs do not receive unnecessary Azure permissions.

  11. Old Azure client secrets are removed when no longer needed.

  12. Deployment failures distinguish authentication problems from authorization problems.

  13. Separate Azure identities are considered for development, staging, and production.

  14. 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.