Microsoft Azure Learning Journey

Azure Pipelines: Workload Identity, Approvals, and Environments

Connect Azure DevOps to Azure without a stored service-principal secret, then protect the stage that changes production.

7 min read · 1389 words
Microsoft AzureCI/CDGitHub ActionsAzure DevOpsDevOps
Azure Pipelines: Workload Identity, Approvals, and Environments cover image

A YAML pipeline can say “deploy to production,” but a contributor who can edit that YAML should not be the only person who can approve the deployment. Azure Pipelines separates pipeline logic from checks on protected resources. Combined with a workload-identity-federated Azure Resource Manager service connection, that separation gives teams short-lived authentication and an approval boundary outside the repository.

What you’ll learn

Prerequisites

The service connection is a trust boundary

Azure Pipelines organizes work into pipelines, stages, jobs, and tasks. A job runs on an agent. The Azure Resource Manager service connection supplies the task with an Azure identity. That identity’s federated credential trusts the Azure DevOps issuer and the intended project/pipeline context. Azure RBAC then authorizes the operation at its assigned scope.

Prefer WIF over a client secret for new Azure connections. Azure DevOps can configure an app registration automatically in scenarios where the creator has sufficient permission; Microsoft’s current guidance says the automatic option requires subscription Owner access. Do not grant Owner just to make setup convenient. Ask an authorized administrator to create a federated service connection with the narrow role and scope the pipeline needs, or use an appropriately scoped managed identity when supported.

Azure DevOps documentation also describes a public-cloud issuer transition: new applicable WIF connections use the Microsoft Entra issuer, while the legacy Azure DevOps issuer is scheduled to retire on July 1, 2027. Verify the issuer and exact subject shown by the service connection before configuring a federated credential. The retirement has cloud and connection-type exceptions; do not assume every tenant uses the same format.

Approvals belong to protected resources

Environments can record deployment history and target resources. Approvals and checks on Azure Pipelines environments, service connections, repositories, and other protected resources are managed by resource owners outside the pipeline YAML. The pipeline pauses before the stage that consumes a protected resource until its checks pass. This prevents a YAML-only condition from being the sole production gate.

Use a production environment with explicit approvers, branch-control checks, and a reasonable timeout. Limit who can administer service connections and change environment checks. A pipeline author should not approve their own risky change when separation of duties is required.

Hosted versus self-hosted agents

Hands-on: separate validation and deployment stages

This YAML assumes an Azure Resource Manager service connection named sc-azure-dev-wif. Configure a dev environment and a production environment in Azure DevOps, then add an approval/check to production using the environment’s Approvals and checks settings. For Azure Repos Git, configure pull-request validation through branch policies; the YAML pr trigger is not supported for Azure Repos Git.

trigger:
  branches:
    include:
      - main

pool:
  vmImage: ubuntu-24.04

stages:
  - stage: Validate
    jobs:
      - job: Tests
        steps:
          - checkout: self
          - script: |
              npm ci
              npm test
            displayName: Test the application

  - stage: DeployDev
    dependsOn: Validate
    condition: succeeded()
    jobs:
      - deployment: DeployDevApp
        environment: dev
        strategy:
          runOnce:
            deploy:
              steps:
                - checkout: self
                - task: AzureCLI@2
                  displayName: Deploy to development
                  inputs:
                    azureSubscription: sc-azure-dev-wif
                    scriptType: bash
                    scriptLocation: inlineScript
                    inlineScript: |
                      set -euo pipefail
                      az account show --output table
                      az containerapp update \
                        --name "$AZURE_CONTAINER_APP" \
                        --resource-group "$AZURE_RESOURCE_GROUP" \
                        --image "$AZURE_IMAGE_DIGEST" \
                        --output none
                  env:
                    AZURE_CONTAINER_APP: $(containerAppName)
                    AZURE_RESOURCE_GROUP: $(resourceGroupName)
                    AZURE_IMAGE_DIGEST: $(imageDigest)

  - stage: DeployProduction
    dependsOn: DeployDev
    condition: succeeded()
    jobs:
      - deployment: DeployProductionApp
        environment: production
        strategy:
          runOnce:
            deploy:
              steps:
                - checkout: self
                - task: AzureCLI@2
                  displayName: Promote the verified image
                  inputs:
                    azureSubscription: sc-azure-prod-wif
                    scriptType: bash
                    scriptLocation: inlineScript
                    inlineScript: |
                      set -euo pipefail
                      az containerapp update \
                        --name "$AZURE_CONTAINER_APP" \
                        --resource-group "$AZURE_RESOURCE_GROUP" \
                        --image "$AZURE_IMAGE_DIGEST" \
                        --output none
                  env:
                    AZURE_CONTAINER_APP: $(prodContainerAppName)
                    AZURE_RESOURCE_GROUP: $(prodResourceGroupName)
                    AZURE_IMAGE_DIGEST: $(imageDigest)

The sample’s variables represent an image digest created by an earlier build stage; do not accept it from an untrusted pull-request title or comment. AzureCLI@2 uses the selected service connection to authenticate. The connection is not a secret store, and a successful login does not grant access beyond the service principal or managed identity’s Azure roles.

✅ Checkpoint: A validation failure prevents DeployDev; DeployProduction depends on a successful dev stage and pauses at the separately configured production environment checks.

Security and operational design

Use a different service connection or identity for production where practical. Scope dev and production identities to separate resource groups and give the production app’s managed identity its own data-plane permissions. Avoid granting subscription Contributor if the task only updates one application. Keep service connection administration separate from ordinary pipeline editing.

Pipeline artifacts should be immutable and traceable to a commit. Retain test, approval, and deployment records. Use explicit stage dependencies and conditions; avoid broad always() conditions that can deploy after validation failed. A deployment environment records history but is not a backup or rollback mechanism.

Troubleshooting

Cost and production considerations

Microsoft-hosted agents consume included or paid parallel-job capacity depending on the organization. Self-hosted agents incur VM, storage, network, maintenance, and security costs. Azure deployment costs are driven by the target services, not by whether a pipeline deployed them. Keep build artifacts and logs only as long as needed for diagnosis, compliance, and rollback.

Five-pillar readiness checklist

Cleanup

The example created no Azure resources. Remove only lab-owned service connections, federated credentials, environments, and agent pools after confirming no other pipeline depends on them. Keep audit records required by your organization.

Key takeaways

Next: DevSecOps for Azure workloads.

Series navigation: Previous: GitHub Actions and Azure · Current: Phase 7, Part 3 · Next: DevSecOps

References

Share this article

LinkedIn post draft