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.
| Option | Status | Use when |
|---|---|---|
| App registration (automatic) with workload identity federation | Recommended | You have Owner rights on the subscription |
| Managed identity, creating a federated credential on a user-assigned identity | Recommended | You cannot create app registrations |
| App registration or managed identity (manual) | Supported | The automatic flow fails or a different tenant is involved |
| Automatic app registration with a secret | Legacy | Avoid for new connections |
| Agent-assigned managed identity | Legacy | Only for self-hosted agents with an existing design |
| Publish profile | Legacy | Avoid 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.
Recommended or legacy?
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.

Securing a production service connection
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"Azure DevOps tokens today
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.
The build service identity
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.
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.