Introduction
For years, connecting Azure DevOps pipelines to Azure subscriptions relied on Service Principals with client secrets or certificates. While functional, static credentials introduce severe operational and security liabilities:
Secret Sprawl & Expiration Outages: Client secrets expire every 6 to 24 months. Forgotten expiration dates routinely break production deployments on Friday evenings, forcing emergency credential rotations across dozens of service connections.
High-Impact Blast Radius: A leaked service principal secret allows an attacker to authenticate from anywhere outside your CI/CD runners until the credential is revoked.
Compliance & Audit Friction: Security teams must enforce manual rotation schedules, Key Vault sync jobs, and secret-scanning rules solely to protect deployment plumbing.
Workload Identity Federation (WIF) eliminates stored secrets from Azure DevOps service connections altogether. Using the OpenID Connect (OIDC) standard, Azure DevOps generates a short-lived, cryptographically signed JSON Web Token (JWT) for each pipeline job. Microsoft Entra ID validates that token against a configured federated identity credential and exchanges it for a temporary Azure access token—with zero secrets stored in Azure DevOps or Entra ID.
This article explains the underlying OIDC token-exchange architecture, walks through creating and migrating Azure Resource Manager (ARM) and Docker/ACR service connections to Workload Identity Federation, demonstrates multi-stage .NET deployment pipelines, and covers cross-tenant and self-hosted agent considerations.
Architectural Deep Dive: How OIDC Token Exchange Works
When a pipeline job runs an Azure-connected task (such as AzureCLI@2, AzureWebApp@1, KubernetesManifest@1, or Docker@2), Azure DevOps and Microsoft Entra ID execute a four-step handshake without passing any long-lived secret:
┌───────────────────────────┐ ┌───────────────────────────┐
│ Azure DevOps Pipeline │ │ Microsoft Entra ID │
│ (Job Runner) │ │ (Identity Provider) │
└─────────────┬─────────────┘ └─────────────┬─────────────┘
│ │
│ 1. Request Job OIDC Token │
│ (Issuer + Subject Claim) │
│ │
│ 2. Present Signed JWT + Client ID ─►│
│ │ 3. Verify JWT Signature
│ │ & Match Issuer + Subject
│ │ Against Federated Credential
│◄─ 4. Issue Short-Lived Access Token │
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────────┐
│ Azure Resource Manager / ACR / AKS │
│ (Enforces RBAC Role Assigned to Service Principal) │
└─────────────────────────────────────────────────────────────────┘
Anatomy of the Federated Subject Identifier (sub)
Entra ID trusts Azure DevOps tokens by matching two exact values configured on the App Registration or User-Assigned Managed Identity:
Issuer (iss): [https://vstoken.dev.azure.com/](https://vstoken.dev.azure.com/){OrganizationId}
Subject Identifier (sub): sc://{OrganizationName}/{ProjectName}/{ServiceConnectionName}
Because the subject claim is scoped down to the exact Organization, Project, and Service Connection, a token issued for a Dev service connection cannot be replayed to authenticate against a Prod service connection—even if both reside in the same Azure DevOps project.
Part 1: Creating a Zero-Secret Azure Resource Manager Service Connection
Azure DevOps supports both automatic creation (where Azure DevOps provisions the Entra ID App Registration and RBAC assignment for you) and manual configuration (recommended for enterprises using User-Assigned Managed Identities or strict Entra ID RBAC governance).
Option A: Automatic Setup (Fastest for Standard Subscriptions)
In your Azure DevOps project, navigate to Project Settings $\rightarrow$ Service connections $\rightarrow$ New service connection.
Select Azure Resource Manager $\rightarrow$ Next.
Choose Workload Identity federation (automatic) $\rightarrow$ Next.
Select your Subscription, optional Resource Group (always scope to a specific Resource Group for least privilege), and provide a Service connection name (e.g., sc-prod-enterprise-api).
Under Security, check Grant access permission to all pipelines only for non-production sandboxes. Leave it unchecked for staging and production so you can enforce explicit pipeline approvals.
Click Save. Azure DevOps automatically creates the Entra App Registration, configures the Federated Credential, and assigns the Contributor role on the target scope.
Option B: Manual Setup with a User-Assigned Managed Identity (Recommended for Enterprise)
Many enterprise security policies restrict developers from creating Entra ID App Registrations. Using a User-Assigned Managed Identity (UAMI) solves this cleanly without requiring Application Administrator privileges:
In Azure Portal (or via Bicep/Terraform):
Create a User-Assigned Managed Identity (e.g., uami-azdo-prod-deploy).
Assign granular RBAC roles to the UAMI (e.g., Website Contributor on the App Service, AcrPush on Azure Container Registry, or Azure Kubernetes Service Cluster User Role on AKS—avoid broad Owner roles).
In Azure DevOps:
Go to Project Settings $\rightarrow$ Service connections $\rightarrow$ New service connection $\rightarrow$ Azure Resource Manager.
Select Workload Identity federation (manual) $\rightarrow$ Next.
Enter the Service connection name (e.g., sc-prod-uami-deploy). Azure DevOps immediately displays the generated Issuer and Subject identifier values. Copy both.
Link the Federated Credential in Azure:
Open your User-Assigned Managed Identity in the Azure Portal $\rightarrow$ Settings $\rightarrow$ Federated credentials $\rightarrow$ + Add Credential.
Set Federated credential scenario to Other issuer.
Paste the Issuer ([https://vstoken.dev.azure.com/](https://vstoken.dev.azure.com/)<org-guid>) and Subject identifier (sc://<org>/<project>/sc-prod-uami-deploy).
Keep Audience set to api://AzureADTokenExchange and click Add.
Complete Verification in Azure DevOps:
Return to Azure DevOps, enter the Subscription ID, Subscription Name, Service Principal ID (the UAMI's Client ID), and Tenant ID, then click Verify and save.
Part 2: Converting Existing Secret-Based Service Connections Without Downtime
You do not need to recreate service connections or edit YAML files to eliminate existing secrets. Azure DevOps supports in-place conversion of existing Azure Resource Manager service connections:
Open Project Settings $\rightarrow$ Service connections and select an existing secret-based connection.
Click Edit (or select Convert in the service connection banner).
Select Convert to Workload Identity federation.
Azure DevOps automatically adds the federated identity credential to the underlying Entra ID App Registration and switches authentication to OIDC—while temporarily preserving the old secret in Entra ID so you can roll back if an older custom task does not yet support OIDC.
Run your CI/CD pipelines to verify deployment health.
Once verified, open the App Registration in Microsoft Entra ID $\rightarrow$ Certificates & secrets and delete the legacy client secret.
Note on Azure Container Registry (ACR): Dedicated Docker Registry service connections connected to Azure Container Registry also support Workload Identity Federation, eliminating admin user passwords and long-lived ACR pull/push tokens in container pipelines.
Part 3: Production Multi-Stage YAML Pipeline Using Workload Identity Federation
The pipeline below builds a .NET 9 containerized microservice, pushes it to Azure Container Registry using Workload Identity Federation, and deploys it to Azure App Service / AKS across Staging and Production environments with zero secrets anywhere in variables or Variable Groups.
YAML
trigger:
branches:
include:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
acrName: 'enterpriseprodacr'
imageRepository: 'orders-api'
imageTag: '$(Build.BuildId)'
# Service connections backed by Workload Identity Federation (no secrets)
stagingServiceConnection: 'sc-staging-uami-deploy'
prodServiceConnection: 'sc-prod-uami-deploy'
stages:
- stage: BuildAndTest
displayName: 'Build, Test & Package'
jobs:
- job: BuildDotNet
displayName: 'Build .NET 9 Solution'
steps:
- task: UseDotNet@2
displayName: 'Install .NET 9 SDK'
inputs:
packageType: 'sdk'
version: '9.0.x'
- task: DotNetCoreCLI@2
displayName: 'Restore & Build'
inputs:
command: 'build'
projects: '**/*.sln'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests'
inputs:
command: 'test'
projects: '**/*Tests.csproj'
arguments: '--configuration $(buildConfiguration) --no-build'
- task: PublishPipelineArtifact@1
displayName: 'Publish Dockerfile & Manifests'
inputs:
targetPath: '$(Build.SourcesDirectory)'
artifact: 'drop'
- stage: DeployStaging
displayName: 'Deploy to Staging (WIF)'
dependsOn: BuildAndTest
jobs:
- deployment: DeployToStaging
displayName: 'Push Image & Deploy Staging'
environment: 'Staging'
strategy:
runOnce:
deploy:
steps:
- task: AzureCLI@2
displayName: 'Build & Push Container to ACR via OIDC'
inputs:
azureSubscription: '$(stagingServiceConnection)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
# AzureCLI@2 automatically authenticates using the OIDC federated token
az acr build \
--registry $(acrName) \
--image $(imageRepository):$(imageTag) \
--image $(imageRepository):staging-latest \
$(Pipeline.Workspace)/drop
- task: AzureWebAppContainer@1
displayName: 'Deploy Container to Staging App Service'
inputs:
azureSubscription: '$(stagingServiceConnection)'
appName: 'app-orders-api-staging'
containers: '$(acrName).azurecr.io/$(imageRepository):$(imageTag)'
- stage: DeployProduction
displayName: 'Deploy to Production (WIF)'
dependsOn: DeployStaging
jobs:
- deployment: DeployToProduction
displayName: 'Promote Container to Production'
environment: 'Production' # Configure Manual Approval Gate on this Environment
strategy:
runOnce:
deploy:
steps:
- task: AzureCLI@2
displayName: 'Verify Identity & Deploy Production Workload'
inputs:
azureSubscription: '$(prodServiceConnection)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "Authenticated Principal:"
az account show --query "{subscription:name, user:user.name, type:user.type}" -o table
az webapp config container set \
--name app-orders-api-prod \
--resource-group rg-enterprise-prod \
--container-image-name $(acrName).azurecr.io/$(imageRepository):$(imageTag)
Part 4: Enterprise Governance, Cross-Tenant Scenarios, and Pitfalls
When rolling out Workload Identity Federation across an enterprise organization, keep these operational rules in mind:
1. Guard Against Service Connection Renames
Because the Entra ID Federated Credential matches the exact string sc://{Org}/{Project}/{ServiceConnectionName}, renaming a service connection in Azure DevOps breaks authentication unless you also update the Subject identifier on the corresponding Entra ID App Registration or User-Assigned Managed Identity. Establish a strict naming convention (sc-<env>-<workload>-wif) before creation.
2. Cross-Tenant Deployments
If your Azure DevOps organization is backed by Microsoft Entra Tenant A, and your target Azure subscription resides in Microsoft Entra Tenant B:
Workload Identity Federation supports cross-tenant authentication natively.
Create the App Registration or User-Assigned Managed Identity in Tenant B (where the target Azure resources live), configure the federated credential using Azure DevOps's vstoken.dev.azure.com issuer URL, and enter Tenant B's Tenant ID in the manual service connection setup.
3. Self-Hosted Agents & Network Egress Requirements
Self-hosted Linux or Windows agents work seamlessly with Workload Identity Federation, provided the agent host has outbound HTTPS (443) access to:
[https://vstoken.dev.azure.com](https://vstoken.dev.azure.com) (to request the job's OIDC JWT)
[https://login.microsoftonline.com](https://login.microsoftonline.com) (to exchange the OIDC JWT for an Entra ID access token)
[https://management.azure.com](https://management.azure.com) (for Azure Resource Manager API calls)
4. Built-in Task Compatibility
First-party Azure tasks—including AzureCLI@2, AzurePowerShell@5, AzureWebApp@1, AzureWebAppContainer@1, AzureFunctionApp@2, KubernetesManifest@1, and Docker@2—support Workload Identity Federation out of the box. If you invoke custom CLI tools (such as Terraform or Helm) inside a script step, run them inside AzureCLI@2 with addSpnToEnvironment: true so the task injects idToken, servicePrincipalId, and tenantId environment variables automatically:
YAML
- task: AzureCLI@2
displayName: 'Run Terraform with OIDC Token'
inputs:
azureSubscription: '$(prodServiceConnection)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
addSpnToEnvironment: true
inlineScript: |
export ARM_CLIENT_ID=$servicePrincipalId
export ARM_OIDC_TOKEN=$idToken
export ARM_TENANT_ID=$tenantId
export ARM_USE_OIDC=true
terraform init && terraform plan
Summary Comparison: Client Secrets vs. Workload Identity Federation
Security & Operational Factor | Legacy Service Principal (Secret) | Workload Identity Federation (OIDC) |
Credential Storage | Encrypted secret stored in Azure DevOps | None (zero stored secrets) |
Token Lifetime | Months or years until manual rotation | Minutes (single-job ephemeral JWT) |
Expiration Outages | Common when secrets expire unnoticed | Eliminated (no secret expiration) |
Replay Risk | High if secret is leaked | Minimal; bound to exact Org/Project/Connection sub |
Enterprise Identity Type | App Registration only | App Registration or User-Assigned Managed Identity |
Conclusion
Eliminating long-lived secrets from CI/CD pipelines is one of the highest-leverage security improvements an engineering organization can make. With Workload Identity Federation in Azure DevOps, pipelines authenticate to Azure Resource Manager, Azure Container Registry, and Azure Kubernetes Service through short-lived, cryptographically verifiable OIDC tokens—removing credential rotation overhead, preventing expiration-induced deployment outages, and enforcing strict least-privilege isolation per environment. By pairing User-Assigned Managed Identities with environment approval gates and in-place service connection conversion, teams can modernize existing enterprise pipelines cleanly with zero downtime.
Join the conversation! Your thoughts help the community grow.