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.

9 comments

Leave a comment

  • David Corrigan 1

    Where is the documentation for creating service connections to non-Azure services? Can additional claims and audiences be configured either in a service connection credential configuration or when requesting the OIDC token in the pipeline?

    • David Corrigan 0

      Guess the preview is officially only for Azure connections, so the question is when will it be available for custom connections? We prototyped some other connection types (Hashicorp Vault, JFrog Artifactory, k8s) and it mostly worked great, but waiting on the official availability to schedule our work to get the final versions written and deployed so we can stop relying on hard coded credentials for those services.

  • James Dawson 0

    Nice to see this feature arrive for Azure DevOps, we’ve been using it in GitHub Actions for a little while. Is the 10 minute lifetime of the idToken ever likely to be configurable?

    This has proven to been quite a showstopper for us in GitHub, where we have scripted deployment processes that run longer than 10 minutes.

    Sometimes this is fine, as the Azure CLI or Azure PowerShell access tokens have a longer lifetime, however, when a deployment process includes a step towards the end that involves requesting an access token for another service (e.g. a data plane operation), then this fails as the idToken has expired. For example, trying to make configuration changes to a Synapse Workspace once ARM has provisioned it.

    • Eric van WijkMicrosoft employee 0

      I don’t expect idToken lifetime to be an issue. An idToken is acquired for every task run that consumes a Service Connection that uses Workload identity federation. As long as an idToken is exchanged for an AAD token at the start of a task run (which is the case for all Built-in tasks), it is the AAD token lifetime that matters. Let me know if you have an actual issue.

      • James Dawson 1

        Interesting – thanks for the reply. I’ll convert a GHA workflow we setup to repro the issue and see what happens.

        UPDATE: Having now done the above, I can confirm that we don’t see the equivalent token expiry issue when running in Azure Pipelines. Many Thanks!

  • Bill Kan 0

    I am using docker built in task for service connection and itโ€™s not asking me to convert to workload identity federation. I do see it in my other arm connections just not docker.

    • Eric van WijkMicrosoft employee 0

      Correct, we will add support to use Workload identity federation for Azure Container Registry to Docker Registry Service Connections later.

  • Shobit Mahajan 0

    I would love to see this work for other cloud services as well. I used OIDC to connect to my AWS account using Gitlab. I am looking forward to connect to my AWS account from Azure Pipelines as well. I hope support for this is coming soon. ๐Ÿ™‚

Feedback usabilla icon