Lesson 3 of 7 Authentication and Access

Managing Azure DevOps Service Connections and Personal Access Tokens

This lesson explains how to configure connections safely, and how token rules have changed.

Learning outcomes

After completing this lesson, you will be able to:

  • Choose an Azure Resource Manager connection option.
  • Secure a service connection.
  • Describe current rules for personal access tokens.
  • Use System.AccessToken and Entra tokens.

Service connections

A service connection stores the details needed for a pipeline to reach an external service, such as Azure, GitHub, a container registry or a Kubernetes cluster. It is defined in Project settings, and pipelines refer to it by name, so authors never see the credentials. Each type has its own form, and an Azure Resource Manager connection is the one used for deploying to Azure.

Azure Resource Manager options

Microsoft recommends workload identity federation for any new connection. The following table lists the options.

OptionStatusUse when
App registration (automatic) with workload identity federationRecommendedYou have Owner rights on the subscription
Managed identity, creating a federated credential on a user-assigned identityRecommendedYou cannot create app registrations
App registration or managed identity (manual)SupportedThe automatic flow fails or a different tenant is involved
Automatic app registration with a secretLegacyAvoid for new connections
Agent-assigned managed identityLegacyOnly for self-hosted agents with an existing design
Publish profileLegacyAvoid for new connections

An existing connection that uses a secret can be converted to federation, and the change can be reverted for seven days. New connections now use the Microsoft Entra issuer, and the Azure DevOps issuer https://vstoken.dev.azure.com retires on 1 July 2027, so older connections should be updated. A service connection that has gone unused may also be disabled automatically after 100 days.

Sort into groups

Recommended or legacy?

Exam skills 4.1.3

Classify each Azure Resource Manager service connection option.

Log in to try this activity Interactive activities are free with an account.

Securing service connections

A service connection is a powerful resource, as it can often change production. The following controls apply.

  • Pipeline permissions: leave Grant access permission to all pipelines off, and authorize selected pipelines. An unauthorized pipeline stops with a request for permission.
  • Scope: limit the identity to a resource group, not a subscription.
  • Roles: separate the User role, for pipelines that use a connection, from the Administrator role, for those who manage it.
  • Checks: add Approvals, Branch control or Required template to the connection. They apply to every pipeline that uses it.
  • Separation: use one connection per environment.

Connections can also be shared with other projects. Managing them centrally avoids scattered copies of credentials.

The following diagram compares a service connection that uses a client secret with one that uses workload identity federation.

Converting an Azure Resource Manager service connection to workload identity federation. With a client secret, the credential expires every six months and its expiry stopped production deployments. With federation, Azure DevOps exchanges a short-lived token for Azure access, so there is no secret to expire or leak.
The scenario is illustrative.
Select all that apply

Securing a production service connection

Exam skills 4.1.3

Pick the controls that protect a powerful service connection.

Log in to try this activity Interactive activities are free with an account.

Personal access tokens

A personal access token (PAT) lets a script or tool act as a user in Azure DevOps, through the REST API, the Azure CLI or Git. Each token has an organization scope, permission scopes and an expiry. Scope it to the narrowest level, for example Code (read), rather than Full access.

Microsoft now advises avoiding PATs wherever a safer method exists, and using Microsoft Entra tokens, managed identities or service principals for applications and automation. Important changes have occurred recently.

  • Global PATs, which work across all organizations of a user, can no longer be created, and all existing ones stop working on 1 December 2026. Create only organization-scoped PATs.
  • In organizations backed by Microsoft Entra, a new PAT must be used for sign-in within 90 days, or it becomes inactive.
  • Administrators can use policies to restrict creation, scope and lifetime, through Microsoft Entra settings in Azure DevOps.
  • Azure DevOps OAuth has been deprecated, and new applications should use Microsoft Entra ID OAuth.

Inside a pipeline, a PAT is rarely required. System.AccessToken provides a short-lived token for the build identity, which must be mapped to a script explicitly.

- script: az pipelines runs list --org $(System.CollectionUri) --project $(System.TeamProject) --top 5
  env:
    AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

Outside a pipeline, a script can request a Microsoft Entra token instead of a PAT. The value 499b84ac-1321-427f-aa17-267ca6975798 is the resource ID of Azure DevOps.

TOKEN=$(az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv)
curl -H "Authorization: Bearer $TOKEN" "https://dev.azure.com/contoso/_apis/projects?api-version=7.1"
True or false

Azure DevOps tokens today

Exam skills 4.1.3

Check the current rules for Azure DevOps personal access tokens.

Log in to try this activity Interactive activities are free with an account.

Build service identities

Pipelines run as a build service identity, which is either project-scoped, named Project Build Service, or collection-scoped. Limiting a job's authorization scope to the current project, a project setting, keeps the token from reaching other projects. Permissions for this identity are granted like those for any user, for example Contribute on a repository if a pipeline must push tags.

Scenario questions

The build service identity

Exam skills 4.1.3

Apply the rules for the identity that pipelines run as.

Log in to try this activity Interactive activities are free with an account.
Worked example

Replacing a secret

A pipeline's Azure Resource Manager service connection uses a client secret that expires every six months, and a recent expiry stopped production deployments. Security wants no stored secrets. What should you do?

Convert the connection to workload identity federation. Azure DevOps then exchanges a short-lived token for Azure access, so there is no secret to expire or leak. Extending the secret's lifetime would keep a stored credential, and moving it to Key Vault would still leave a secret that expires. A PAT is unrelated, as it authenticates to Azure DevOps and not Azure.

Check yourself

Which role is required for the automatic workload identity federation option?

Show answer

Owner on the subscription. The managed identity option suits people who cannot create app registrations.

Exam Tips

Remember for the exam

  • Use workload identity federation for new Azure service connections.
  • Do not grant a connection to all pipelines.
  • Add checks to a service connection, and they apply to every pipeline using it.
  • Global PATs stop working on 1 December 2026.
  • System.AccessToken must be mapped to scripts explicitly.