Public preview of Workload identity federation for Azure Pipelines

Eric van Wijk

Do you want to stop storing secrets and certificates in Azure service connections? Are you tired rotating these secrets whenever they expire? We are now announcing a public preview of workload identity federation for Azure service connections. Workload identity federation uses an industry-standard technology, Open ID Connect (OIDC), to simplify the authentication between Azure Pipelines and Azure. Instead of secrets, a federation subject is used to facilitate this authentication.

How it works

As part of this feature, the Azure (ARM) service connection has been updated with an additional scheme to support workload identity federation. This allows Pipeline tasks that use the Azure service connection to authenticate using a federation subject (sc://<org>/<project>/<service connection name>). The main benefits of using this scheme over existing authentication schemes are as follows:

  • Simplified management: You do not need to generate, copy, and store secrets from service principals in Azure Entra ID to Azure DevOps anymore. Secrets that are used in other authentication schemes of Azure service connections (e.g., service principal) expire after a certain period (2 years currently). When they expire, pipelines fail. You have to generate a new secret and update the service connection. Switching to workload identity federation eliminates the need to manage these secrets and improves the overall experience of creating and managing service connections.
  • Improved security: With workload identity federation, the federation subject (sc://<org>/<project>/<service connection name>) uniquely identifies what the identity can be used for, which provides a better constraint than a (shared) secret. There is no persistent secret involved in the communication between Azure Pipelines and Azure. As a result, tasks running in pipeline jobs cannot leak or exfiltrate secrets that have access to your production environments. This has often been a concern for our customers.

How can I use it?

You can take advantage of workload identity federation in two ways:

  • Convert your existing Azure service connections based on secrets to the new scheme. You can perform this conversion one connection at a time. Best of all, you do not have to modify any of the pipelines that use those service connections. They will automatically leverage the new scheme once you complete the conversion.
  • Use the new workload identity federation scheme whenever you create a new Azure service connection. Moving forward, this will be the recommended method.

Converting an existing Azure service connection

To convert a previously created Azure service connection, select the “Convert” action after selecting the connection:

You can roll back from a conversion to use a secret by clicking the revert link on the service connection details page:

Create a new Azure service connection

To create a new Azure service connection using workload identity federation, simply select Workload identity federation (automatic) in the Azure service connection creation experience:

Create manually with a Managed Identity or Service Principal

You can also create an Azure service connection using workload identity federation manually with either a Service Principal or Managed Identity. Developers that do not have permission to create App Registrations in Azure Entra ID (AAD) can create Azure service connections with Workload identity federation by configuring the federation on a Managed Identity instead of a Service Principal. Using a Managed Identity in federation does not require assignment and works across all agent hosting models (Hosted, Self-hosted, Scale set agents). See manual configuration instructions for a step by step guide.

Built-in Pipeline tasks

Azure Pipelines built-in tasks that target Azure have been updated to take advantage of workload identity federation. This is the complete list: AzureAppServiceManage, AzureAppServiceSettings, AzureCLI, AzureCloudPowerShellDeployment, AzureContainerApps, AzureFunctionAppContainer, AzureFunctionApp, AzureKeyVault, AzureMonitor, AzureMysqlDeployment, AzurePolicy, AzurePowerShell, AzureResourceGroupDeployment, AzureResourceManagerTemplateDeployment, AzureRmWebAppDeployment, AzureSpringCloud, AzureVmssDeployment, AzureWebAppContainer, AzureWebApp, DockerCompose, Docker, HelmDeploy, InvokeRestApi, JavaToolInstaller, JenkinsDownloadArtifacts, Kubernetes.

Azure CLI task support for inline authentication

If a tool does not have a task or you prefer to use tools directly inside a script you provide, you can use the AzureCLI@2 task task to access the federated token used during authentication. Setting property addSpnToEnvironment: true will populate the idToken, servicePrincipalId and tenantId environment variables.

This example shows inline configuration of Terraform azuread/azurerm providers:

  - task: AzureCLI@2
    inputs:
      addSpnToEnvironment: true
      azureSubscription: 'my-azure-service-connection'
      scriptType: bash
      scriptLocation: inlineScript
      inlineScript: |
        # Inherit Azure CLI service connection
        export ARM_CLIENT_ID=$servicePrincipalId
        export ARM_OIDC_TOKEN=$idToken
        export ARM_TENANT_ID=$tenantId
        export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
        export ARM_USE_OIDC=true

        terraform init
        terraform apply -auto-approve

The idToken has a lifetime of 10 minutes.

Custom Azure tasks and extensions

If you are using a task from the Marketplace or a home-grown custom task to deploy to Azure, then it may not support workload identity federation yet. In these cases, we ask task developers to support workload identity federation to improve security.

Image oidc collaboration

Tasks that take a connectedService:AzureRM input in task.json can be updated so support workload identity federation with the following steps:

  • Request an idToken using the new Oidctoken REST API (arrow 1 in above diagram).
  • Exchange the idToken for an access token using the federated credential flow of the OAuth API, specifying the idToken as client_assertion (arrows 2 & 4 in above diagram);
    or:
  • For tasks that act as a wrapper around a tool that performs authentication itself, use the tools’ authentication method to specify the federated token.

You can also publish extensions to the Marketplace with Workload identity federation. This blog post explains how.

Terraform tasks

The Terraform DevLabs and Azure Pipelines Terraform Tasks extensions have been updated to support workload identity federation. The Terraform DevLabs extension uses the azure-pipelines-tasks-artifacts-common npm package to get the idToken, see code example.

If you are a Terraform user, you should review this great walkthrough on the Tech Community that uses the Azure-Samples/azure-devops-terraform-oidc-ci-cd repository to create and use Azure service connections with Terraform.

Public preview

The feature will roll out over the next few weeks. For this preview, we support workload identity federation only for Azure service connections. This scheme does not work with any other types of service connections. See our docs for more details.

35 comments

Discussion is closed. Login to edit/delete existing comments.

  • Bas C. 0

    Hello Eric, thank you for the great post about this feature. Are there any plans to implement Workload Identity for Azure Devops Environment? It seems the Kubernetes environment there still only supports service connections via service accounts. We do use it for AKS deployments. Thanks! 🙂

  • Selva Kumar 0

    Do we have the Azure powershell task to support inline authentication for workload identity federation?

    • Eric van WijkMicrosoft employee 0

      Hi Selva. No, the AzureCLI task supports inline authentication (through addSpnToEnvironment: true).

  • Surya Gudla (CSI INTERFUSION INC)Microsoft employee 2

    We have a pipeline that uses a service principal with access to multiple subscriptions. We’re trying to migrate this service principal to Workload Identity Federation (WIF) and have created a new WIF service connection for this purpose. However, when the pipeline is executed, it throws a subscription access issue. We’re looking for a solution to ensure that WIF has access to multiple subscriptions, similar to a service principal.

Feedback usabilla icon